Skip to content

Commit 42d96f3

Browse files
committed
Merge remote-tracking branch 'magento-l3/ACP2E-1775' into MAR212023_PR_sarmistha
2 parents 031d8a8 + d575c89 commit 42d96f3

File tree

5 files changed

+129
-4
lines changed

5 files changed

+129
-4
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/AddComment.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public function execute()
4040
try {
4141
$data = $this->getRequest()->getPost('history');
4242
if (empty($data['comment']) && $data['status'] == $order->getDataByKey('status')) {
43-
throw new \Magento\Framework\Exception\LocalizedException(
44-
__('The comment is missing. Enter and try again.')
45-
);
43+
$error = 'Please provide a comment text or ' .
44+
'update the order status to be able to submit a comment for this order.';
45+
throw new \Magento\Framework\Exception\LocalizedException(__($error));
4646
}
4747

4848
$orderStatus = $this->getOrderStatus($order->getDataByKey('status'), $data['status']);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminOrderInformationCommentHintTest">
12+
<annotations>
13+
<features value="Sales"/>
14+
<stories value="Admin order information page"/>
15+
<title value="Dialog box error message when submitting comment in Order Details page"/>
16+
<description value="Check comment hint and dialog box error message visible"/>
17+
<severity value="AVERAGE"/>
18+
<testCaseId value="AC-8374"/>
19+
<useCaseId value="ACP2E-1775"/>
20+
<group value="sales"/>
21+
</annotations>
22+
<before>
23+
<createData entity="_defaultCategory" stepKey="createCategory"/>
24+
<createData entity="SimpleProduct" stepKey="createProduct">
25+
<requiredEntity createDataKey="createCategory"/>
26+
</createData>
27+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
28+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
29+
<!-- Create order -->
30+
<createData entity="CustomerCart" stepKey="createCustomerCart">
31+
<requiredEntity createDataKey="createCustomer"/>
32+
</createData>
33+
<createData entity="CustomerCartItem" stepKey="addCartItem">
34+
<requiredEntity createDataKey="createCustomerCart"/>
35+
<requiredEntity createDataKey="createProduct"/>
36+
</createData>
37+
<createData entity="CustomerAddressInformation" stepKey="addCustomerOrderAddress">
38+
<requiredEntity createDataKey="createCustomerCart"/>
39+
</createData>
40+
<updateData createDataKey="createCustomerCart" entity="CustomerOrderPaymentMethod" stepKey="createFirstOrder">
41+
<requiredEntity createDataKey="createCustomerCart"/>
42+
</updateData>
43+
</before>
44+
<after>
45+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
46+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
47+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
48+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
49+
</after>
50+
51+
<!-- Open Admin Order page -->
52+
<actionGroup ref="AdminOpenOrderViewPageByOrderIdActionGroup" stepKey="openOrder">
53+
<argument name="orderId" value="$createCustomerCart.return$"/>
54+
</actionGroup>
55+
56+
<!--Go to submit comment section and verify the comment hint text-->
57+
<scrollTo selector="#order_history_block" stepKey="scrollToSection"/>
58+
<see userInput="A status change or comment text is required to submit a comment." stepKey="seeMessageNotesForThisOrder"/>
59+
</test>
60+
</tests>

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/AddCommentTest.php

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Backend\Model\View\Result\RedirectFactory;
1313
use Magento\Framework\App\Request\Http;
1414
use Magento\Framework\AuthorizationInterface;
15+
use Magento\Framework\Controller\Result\Json;
16+
use Magento\Framework\Controller\Result\JsonFactory;
1517
use Magento\Framework\ObjectManagerInterface;
1618
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1719
use Magento\Sales\Api\OrderRepositoryInterface;
@@ -77,6 +79,12 @@ class AddCommentTest extends TestCase
7779
*/
7880
private $objectManagerMock;
7981

82+
/** @var JsonFactory|MockObject */
83+
private $jsonFactory;
84+
85+
/** @var Json|MockObject */
86+
private $resultJson;
87+
8088
/**
8189
* Test setup
8290
*/
@@ -94,14 +102,22 @@ protected function setUp(): void
94102

95103
$this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock);
96104

105+
$this->resultJson = $this->getMockBuilder(Json::class)
106+
->disableOriginalConstructor()
107+
->getMock();
108+
$this->jsonFactory = $this->getMockBuilder(JsonFactory::class)
109+
->disableOriginalConstructor()
110+
->getMock();
111+
97112
$objectManagerHelper = new ObjectManager($this);
98113
$this->addCommentController = $objectManagerHelper->getObject(
99114
AddComment::class,
100115
[
101116
'context' => $this->contextMock,
102117
'orderRepository' => $this->orderRepositoryMock,
103118
'_authorization' => $this->authorizationMock,
104-
'_objectManager' => $this->objectManagerMock
119+
'_objectManager' => $this->objectManagerMock,
120+
'resultJsonFactory' => $this->jsonFactory
105121
]
106122
);
107123
}
@@ -205,4 +221,44 @@ public function executeWillNotifyCustomerDataProvider()
205221
],
206222
];
207223
}
224+
225+
/**
226+
* Assert error message for empty comment value
227+
*
228+
* @return void
229+
*/
230+
public function testExecuteForEmptyCommentMessage(): void
231+
{
232+
$orderId = 30;
233+
$orderStatus = 'processing';
234+
$historyData = [
235+
'comment' => '',
236+
'is_customer_notified' => false,
237+
'status' => 'processing'
238+
];
239+
240+
$this->requestMock->expects($this->once())->method('getParam')->with('order_id')->willReturn($orderId);
241+
$this->orderMock->expects($this->atLeastOnce())->method('getDataByKey')
242+
->with('status')->willReturn($orderStatus);
243+
$this->orderRepositoryMock->expects($this->once())
244+
->method('get')
245+
->willReturn($this->orderMock);
246+
$this->requestMock->expects($this->once())->method('getPost')->with('history')->willReturn($historyData);
247+
248+
$this->resultJson->expects($this->once())
249+
->method('setData')
250+
->with(
251+
[
252+
'error' => true,
253+
'message' => 'Please provide a comment text or ' .
254+
'update the order status to be able to submit a comment for this order.'
255+
]
256+
)
257+
->willReturnSelf();
258+
$this->jsonFactory->expects($this->once())
259+
->method('create')
260+
->willReturn($this->resultJson);
261+
262+
$this->assertSame($this->resultJson, $this->addCommentController->execute());
263+
}
208264
}

app/code/Magento/Sales/i18n/en_US.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,5 @@ If set YES Email field will be required during Admin order creation for new Cust
808808
"This creditmemo no longer exists.","This creditmemo no longer exists."
809809
"Add to address book","Add to address book"
810810
"Logo for PDF Print-outs","Logo for PDF Print-outs"
811+
"Please provide a comment text or update the order status to be able to submit a comment for this order.", "Please provide a comment text or update the order status to be able to submit a comment for this order."
812+
"A status change or comment text is required to submit a comment.", "A status change or comment text is required to submit a comment."

app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
cols="5"
3737
id="history_comment"
3838
class="admin__control-textarea"></textarea>
39+
<div class="admin__field-note">
40+
<span>
41+
<?= $block->escapeHtml(
42+
__('A status change or comment text is required to submit a comment.')
43+
)?>
44+
</span>
45+
</div>
3946
</div>
4047
</div>
4148

0 commit comments

Comments
 (0)