Skip to content

Commit 032ab4e

Browse files
MTA-3952: Refactoring comments history block in Order module
2 parents e732ddc + b1d546c commit 032ab4e

12 files changed

+207
-213
lines changed

dev/tests/functional/tests/app/Magento/Braintree/Test/Constraint/AssertTransactionIsPresentInSettlementReport.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Sales\Test\Page\Adminhtml\SalesOrderView;
1212

1313
/**
14-
* Class AssertTransactionIsPresentInSettlementReport
14+
* Assert that comment with transaction id exists in Comments History section on order page in Admin.
1515
*/
1616
class AssertTransactionIsPresentInSettlementReport extends AbstractConstraint
1717
{
@@ -26,6 +26,8 @@ class AssertTransactionIsPresentInSettlementReport extends AbstractConstraint
2626
private $settlementReportIndex;
2727

2828
/**
29+
* Assert that comment with transaction id exists in Comments History section on order page in Admin.
30+
*
2931
* @param $orderId
3032
* @param OrderIndex $orderIndex
3133
* @param SalesOrderView $salesOrderView
@@ -58,23 +60,28 @@ public function processAssert(
5860
}
5961

6062
/**
61-
* @inheritdoc
63+
* Returns a string representation of the object.
64+
*
65+
* @return string
6266
*/
6367
public function toString()
6468
{
6569
return 'Transaction is present in settlement report.';
6670
}
6771

6872
/**
69-
* Get transaction id from order comments
70-
* @return mixed
73+
* Get transaction id from order comments.
74+
*
75+
* @return null|string
7176
*/
7277
private function getTransactionId()
7378
{
74-
$comments = $this->salesOrderView->getOrderHistoryBlock()->getCommentsHistory();
79+
/** @var \Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info $infoTab */
80+
$infoTab = $this->salesOrderView->getOrderForm()->openTab('info')->getTab('info');
81+
$latestComment = $infoTab->getCommentsHistoryBlock()->getLatestComment();
7582
$transactionId = null;
7683

77-
preg_match('/(\w+-*\w+)"/', $comments, $matches);
84+
preg_match('/(\w+-*\w+)"/', $latestComment['comment'], $matches);
7885
if (!empty($matches[1])) {
7986
$transactionId = $matches[1];
8087
}

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/History.php

Lines changed: 0 additions & 175 deletions
This file was deleted.

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Sales\Test\Block\Adminhtml\Order\View\Tab;
88

99
use Magento\Backend\Test\Block\Widget\Tab;
10+
use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\CommentsHistoryBlock;
1011
use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\PaymentInfoBlock;
1112

1213
/**
@@ -28,6 +29,13 @@ class Info extends Tab
2829
*/
2930
private $paymentInfoBlockSelector = '.order-payment-method';
3031

32+
/**
33+
* Selector for Comments history block.
34+
*
35+
* @var string
36+
*/
37+
private $commentsHistoryBlockSelector = '#order_history_block';
38+
3139
/**
3240
* Get order status from info block.
3341
*
@@ -50,4 +58,17 @@ public function getPaymentInfoBlock()
5058
['element' => $this->_rootElement->find($this->paymentInfoBlockSelector)]
5159
);
5260
}
61+
62+
/**
63+
* Returns Comments history block.
64+
*
65+
* @return CommentsHistoryBlock
66+
*/
67+
public function getCommentsHistoryBlock()
68+
{
69+
return $this->blockFactory->create(
70+
CommentsHistoryBlock::class,
71+
['element' => $this->_rootElement->find($this->commentsHistoryBlockSelector)]
72+
);
73+
}
5374
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info;
8+
9+
use Magento\Mtf\Block\Block;
10+
11+
/**
12+
* Order comments history block.
13+
*/
14+
class CommentsHistoryBlock extends Block
15+
{
16+
/**
17+
* Comment history list locator.
18+
*
19+
* @var string
20+
*/
21+
protected $commentHistory = '.note-list-item';
22+
23+
/**
24+
* Comment date.
25+
*
26+
* @var string
27+
*/
28+
protected $commentHistoryDate = '.note-list-date';
29+
30+
/**
31+
* Comment time.
32+
*
33+
* @var string
34+
*/
35+
protected $commentHistoryTime = '.note-list-time';
36+
37+
/**
38+
* Comment status.
39+
*
40+
* @var string
41+
*/
42+
protected $commentHistoryStatus = '.note-list-status';
43+
44+
/**
45+
* Comment notified status.
46+
*
47+
* @var string
48+
*/
49+
protected $commentHistoryNotifiedStatus = '.note-list-customer';
50+
51+
/**
52+
* Comment locator.
53+
*
54+
* @var string
55+
*/
56+
protected $comment = '.note-list-comment';
57+
58+
/**
59+
* Get comment history block data.
60+
*
61+
* @return array
62+
*/
63+
public function getComments()
64+
{
65+
$result = [];
66+
$elements = $this->_rootElement->getElements($this->commentHistory);
67+
foreach ($elements as $key => $item) {
68+
$result[$key] = [
69+
'date' => $item->find($this->commentHistoryDate)->getText(),
70+
'time' => $item->find($this->commentHistoryTime)->getText(),
71+
'status' => $item->find($this->commentHistoryStatus)->getText(),
72+
'is_customer_notified' => $item->find($this->commentHistoryNotifiedStatus)->getText(),
73+
'comment' => $item->find($this->comment)->getText()
74+
];
75+
}
76+
77+
return $result;
78+
}
79+
80+
/**
81+
* Get last comment.
82+
*
83+
* @return array
84+
*/
85+
public function getLatestComment()
86+
{
87+
$comments = $this->getComments();
88+
return current($comments);
89+
}
90+
}

0 commit comments

Comments
 (0)