Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCaptureInCommentsHistory.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Constraint\AbstractConstraint;
11 use Magento\Sales\Test\Page\Adminhtml\OrderIndex;
12 use Magento\Sales\Test\Page\Adminhtml\SalesOrderView;
13 
17 class AssertCaptureInCommentsHistory extends AbstractConstraint
18 {
22  const CAPTURED_AMOUNT_PATTERN = '/^Captured amount of .+?%s online\. Transaction ID: "[\w\-]*"/';
23 
33  public function processAssert(
34  SalesOrderView $salesOrderView,
35  OrderIndex $salesOrder,
36  OrderInjectable $order,
37  $orderId
38  ) {
39  $capturedPrices = $order->getPrice()['captured_prices'];
40  $salesOrder->open();
41  $salesOrder->getSalesOrderGrid()->searchAndOpen(['id' => $orderId]);
42 
44  $infoTab = $salesOrderView->getOrderForm()->openTab('info')->getTab('info');
45  $comments = $infoTab->getCommentsHistoryBlock()->getComments();
46 
47  foreach ($comments as $key => $comment) {
48  if (strstr($comment['comment'], 'Captured') === false) {
49  unset($comments[$key]);
50  }
51  }
52  $comments = array_values($comments);
53 
54  foreach ($capturedPrices as $key => $capturedPrice) {
55  \PHPUnit\Framework\Assert::assertRegExp(
56  sprintf(self::CAPTURED_AMOUNT_PATTERN, preg_quote(number_format($capturedPrice, 2, '.', ''))),
57  $comments[$key]['comment'],
58  'Incorrect captured amount value for the order #' . $orderId
59  );
60  }
61  }
62 
68  public function toString()
69  {
70  return "Message about captured amount is available in Comments History section.";
71  }
72 }
$order
Definition: order.php:55