Skip to content

Commit 57562d5

Browse files
committed
AC-10528:Fix for Order Invoice Comment
1 parent 092f67b commit 57562d5

File tree

4 files changed

+8
-40
lines changed

4 files changed

+8
-40
lines changed

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
use Magento\Framework\Controller\Result\JsonFactory;
2020
use Magento\Framework\View\Result\PageFactory;
2121
use Magento\Framework\Controller\Result\RawFactory;
22-
use Magento\Framework\Escaper;
2322

2423
/**
25-
* Action Controller for adding Comment to Invoice of an order
26-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24+
* Class AddComment
2725
*/
2826
class AddComment extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View implements
2927
HttpPostActionInterface
@@ -53,11 +51,6 @@ class AddComment extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInv
5351
*/
5452
protected $invoiceRepository;
5553

56-
/**
57-
* @var Escaper
58-
*/
59-
private Escaper $escaper;
60-
6154
/**
6255
* @param Context $context
6356
* @param Registry $registry
@@ -66,8 +59,7 @@ class AddComment extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInv
6659
* @param JsonFactory $resultJsonFactory
6760
* @param PageFactory $resultPageFactory
6861
* @param RawFactory $resultRawFactory
69-
* @param InvoiceRepositoryInterface|null $invoiceRepository
70-
* @param Escaper|null $escaper
62+
* @param InvoiceRepositoryInterface $invoiceRepository
7163
*/
7264
public function __construct(
7365
Context $context,
@@ -77,17 +69,14 @@ public function __construct(
7769
JsonFactory $resultJsonFactory,
7870
PageFactory $resultPageFactory,
7971
RawFactory $resultRawFactory,
80-
InvoiceRepositoryInterface $invoiceRepository = null,
81-
Escaper $escaper = null,
72+
InvoiceRepositoryInterface $invoiceRepository = null
8273
) {
8374
$this->invoiceCommentSender = $invoiceCommentSender;
8475
$this->resultJsonFactory = $resultJsonFactory;
8576
$this->resultPageFactory = $resultPageFactory;
8677
$this->resultRawFactory = $resultRawFactory;
8778
$this->invoiceRepository = $invoiceRepository ?:
8879
ObjectManager::getInstance()->get(InvoiceRepositoryInterface::class);
89-
$this->escaper = $escaper ?:
90-
ObjectManager::getInstance()->get(Escaper::class);
9180
parent::__construct($context, $registry, $resultForwardFactory, $invoiceRepository);
9281
}
9382

@@ -104,21 +93,19 @@ public function execute()
10493
if (empty($data['comment'])) {
10594
throw new LocalizedException(__('The comment is missing. Enter and try again.'));
10695
}
107-
$comment = $this->escaper->escapeHtml($data['comment']);
108-
10996
$invoice = $this->getInvoice();
11097
if (!$invoice) {
11198
/** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
11299
$resultForward = $this->resultForwardFactory->create();
113100
return $resultForward->forward('noroute');
114101
}
115102
$invoice->addComment(
116-
$comment,
103+
$data['comment'],
117104
isset($data['is_customer_notified']),
118105
isset($data['is_visible_on_front'])
119106
);
120107

121-
$this->invoiceCommentSender->send($invoice, !empty($data['is_customer_notified']), $comment);
108+
$this->invoiceCommentSender->send($invoice, !empty($data['is_customer_notified']), $data['comment']);
122109
$this->invoiceRepository->save($invoice);
123110

124111
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Magento\Framework\Controller\Result\JsonFactory;
1616
use Magento\Framework\Controller\Result\Raw;
1717
use Magento\Framework\Controller\Result\RawFactory;
18-
use Magento\Framework\Escaper;
1918
use Magento\Framework\Exception\LocalizedException;
2019
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2120
use Magento\Framework\View\Layout;
@@ -102,11 +101,6 @@ class AddCommentTest extends TestCase
102101
*/
103102
protected $invoiceRepository;
104103

105-
/**
106-
* @var Escaper|MockObject
107-
*/
108-
private $escaper;
109-
110104
/**
111105
* SetUp method
112106
*
@@ -191,8 +185,6 @@ protected function setUp(): void
191185
->disableOriginalConstructor()
192186
->getMockForAbstractClass();
193187

194-
$this->escaper = $this->createPartialMock(Escaper::class, ['escapeHtml']);
195-
196188
$this->controller = $objectManager->getObject(
197189
AddComment::class,
198190
[
@@ -201,8 +193,7 @@ protected function setUp(): void
201193
'resultPageFactory' => $this->resultPageFactoryMock,
202194
'resultRawFactory' => $this->resultRawFactoryMock,
203195
'resultJsonFactory' => $this->resultJsonFactoryMock,
204-
'escaper' => $this->escaper,
205-
'invoiceRepository' => $this->invoiceRepository,
196+
'invoiceRepository' => $this->invoiceRepository
206197
]
207198
);
208199

@@ -276,10 +267,6 @@ public function testExecute(): void
276267
->method('send')
277268
->with($invoiceMock, false, $data['comment']);
278269

279-
$this->escaper->expects($this->any())
280-
->method('escapeHtml')
281-
->willReturn($data['comment']);
282-
283270
$resultRaw = $this->getMockBuilder(Raw::class)
284271
->disableOriginalConstructor()
285272
->getMock();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<?php endif; ?>
7171
</span>
7272
<div class="note-list-comment">
73-
<?= $escaper->escapeHtml($_comment->getComment(), ['b', 'br', 'strong', 'i', 'u', 'a']) ?>
73+
<?= nl2br($escaper->escapeHtml($_comment->getComment(), ['b', 'br', 'strong', 'i', 'u', 'a'])) ?>
7474
</div>
7575
</li>
7676
<?php endforeach; ?>

dev/tests/integration/testsuite/Magento/Sales/Controller/Adminhtml/Order/Invoice/AddCommentTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
use PHPUnit\Framework\Constraint\RegularExpression;
1111
use PHPUnit\Framework\Constraint\StringContains;
12-
use Magento\TestFramework\Helper\Bootstrap;
13-
use Magento\Framework\Escaper;
1412

1513
/**
1614
* Class verifies invoice add comment functionality.
@@ -41,11 +39,7 @@ public function testSendEmailOnAddInvoiceComment(): void
4139
$this->dispatch('backend/sales/order_invoice/addComment');
4240

4341
$html = $this->getResponse()->getBody();
44-
45-
$escaper = Bootstrap::getObjectManager()
46-
->get(Escaper::class);
47-
48-
$this->assertStringContainsString($escaper->escapeHtml($comment), $html);
42+
$this->assertStringContainsString($comment, $html);
4943

5044
$message = $this->transportBuilder->getSentMessage();
5145
$this->assertNotNull($message);

0 commit comments

Comments
 (0)