Skip to content

Commit 4cff39a

Browse files
Merge MC-35015-updated into 2.3.6-bugfixes-08072020
2 parents fda3267 + 69e0975 commit 4cff39a

File tree

3 files changed

+125
-4
lines changed

3 files changed

+125
-4
lines changed

app/code/Magento/ImportExport/Block/Adminhtml/Import/Frame/Result.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function addError($message)
102102
$this->addError($row);
103103
}
104104
} else {
105-
$this->_messages['error'][] = $message;
105+
$this->_messages['error'][] = $this->escapeHtml($message);
106106
}
107107
return $this;
108108
}
@@ -140,7 +140,8 @@ public function addSuccess($message, $appendImportButton = false)
140140
$this->addSuccess($row);
141141
}
142142
} else {
143-
$this->_messages['success'][] = $message . ($appendImportButton ? $this->getImportButtonHtml() : '');
143+
$escapedMessage = $this->escapeHtml($message);
144+
$this->_messages['success'][] = $escapedMessage . ($appendImportButton ? $this->getImportButtonHtml() : '');
144145
}
145146
return $this;
146147
}

app/code/Magento/ImportExport/Controller/Adminhtml/ImportResult.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function __construct(
5656
}
5757

5858
/**
59+
* Add Error Messages for Import
60+
*
5961
* @param \Magento\Framework\View\Element\AbstractBlock $resultBlock
6062
* @param ProcessingErrorAggregatorInterface $errorAggregator
6163
* @return $this
@@ -68,7 +70,7 @@ protected function addErrorMessages(
6870
$message = '';
6971
$counter = 0;
7072
foreach ($this->getErrorMessages($errorAggregator) as $error) {
71-
$message .= ++$counter . '. ' . $error . '<br>';
73+
$message .= (++$counter) . '. ' . $error . '<br>';
7274
if ($counter >= self::LIMIT_ERRORS_MESSAGE) {
7375
break;
7476
}
@@ -88,7 +90,7 @@ protected function addErrorMessages(
8890
. '<a href="'
8991
. $this->createDownloadUrlImportHistoryFile($this->createErrorReport($errorAggregator))
9092
. '">' . __('Download full report') . '</a><br>'
91-
. '<div class="import-error-list">' . $message . '</div></div>'
93+
. '<div class="import-error-list">' . $resultBlock->escapeHtml($message) . '</div></div>'
9294
);
9395
} catch (\Exception $e) {
9496
foreach ($this->getErrorMessages($errorAggregator) as $errorMessage) {
@@ -101,6 +103,8 @@ protected function addErrorMessages(
101103
}
102104

103105
/**
106+
* Get all Error Messages from Import Results
107+
*
104108
* @param \Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface $errorAggregator
105109
* @return array
106110
*/
@@ -115,6 +119,8 @@ protected function getErrorMessages(ProcessingErrorAggregatorInterface $errorAgg
115119
}
116120

117121
/**
122+
* Get System Generated Exception
123+
*
118124
* @param ProcessingErrorAggregatorInterface $errorAggregator
119125
* @return \Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError[]
120126
*/
@@ -124,6 +130,8 @@ protected function getSystemExceptions(ProcessingErrorAggregatorInterface $error
124130
}
125131

126132
/**
133+
* Generate Error Report File
134+
*
127135
* @param ProcessingErrorAggregatorInterface $errorAggregator
128136
* @return string
129137
*/
@@ -141,6 +149,8 @@ protected function createErrorReport(ProcessingErrorAggregatorInterface $errorAg
141149
}
142150

143151
/**
152+
* Get Import History Url
153+
*
144154
* @param string $fileName
145155
* @return string
146156
*/
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ImportExport\Test\Unit\Block\Adminhtml\Import\Frame;
9+
10+
use Magento\Framework\Escaper;
11+
use PHPUnit\Framework\MockObject\MockObject;
12+
use PHPUnit\Framework\TestCase;
13+
use Magento\ImportExport\Block\Adminhtml\Import\Frame\Result;
14+
use Magento\Backend\Block\Template\Context;
15+
use Magento\Framework\Json\EncoderInterface;
16+
17+
/**
18+
* Unit test for Magento\ImportExport\Block\Adminhtml\Import\Frame\Result
19+
*
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21+
*/
22+
class ResultTest extends TestCase
23+
{
24+
/**
25+
* @var Result
26+
*/
27+
private $result;
28+
29+
/**
30+
* @var EncoderInterface|MockObject
31+
*/
32+
private $encoderMock;
33+
34+
/**
35+
* @var Context|MockObject
36+
*/
37+
private $contextMock;
38+
39+
/**
40+
* @var Escaper|MockObject
41+
*/
42+
private $escaperMock;
43+
44+
/**
45+
* Initialize Class Dependencies
46+
*
47+
* @inheritDoc
48+
*/
49+
protected function setUp(): void
50+
{
51+
$this->contextMock = $this->createMock(Context::class);
52+
$this->encoderMock = $this->getMockBuilder(EncoderInterface::class)
53+
->disableOriginalConstructor()
54+
->getMockForAbstractClass();
55+
56+
$this->escaperMock = $this->createPartialMock(Escaper::class, ['escapeHtml']);
57+
$this->contextMock->expects($this->once())->method('getEscaper')->willReturn($this->escaperMock);
58+
$this->result = new Result(
59+
$this->contextMock,
60+
$this->encoderMock
61+
);
62+
}
63+
64+
/**
65+
* Test error message
66+
*
67+
* @return void
68+
*/
69+
public function testAddError(): void
70+
{
71+
$errors = ['first error', 'second error','third error'];
72+
$this->escaperMock
73+
->expects($this->exactly(count($errors)))
74+
->method('escapeHtml')
75+
->willReturnOnConsecutiveCalls(...array_values($errors));
76+
77+
$this->result->addError($errors);
78+
$this->assertEquals(count($errors), count($this->result->getMessages()['error']));
79+
}
80+
81+
/**
82+
* Test success message
83+
*
84+
* @return void
85+
*/
86+
public function testAddSuccess(): void
87+
{
88+
$success = ['first message', 'second message','third message'];
89+
$this->escaperMock
90+
->expects($this->exactly(count($success)))
91+
->method('escapeHtml')
92+
->willReturnOnConsecutiveCalls(...array_values($success));
93+
94+
$this->result->addSuccess($success);
95+
$this->assertEquals(count($success), count($this->result->getMessages()['success']));
96+
}
97+
98+
/**
99+
* Test Add Notice message
100+
*
101+
* @return void
102+
*/
103+
public function testAddNotice(): void
104+
{
105+
$notice = ['notice 1', 'notice 2','notice 3'];
106+
107+
$this->result->addNotice($notice);
108+
$this->assertEquals(count($notice), count($this->result->getMessages()['notice']));
109+
}
110+
}

0 commit comments

Comments
 (0)