Skip to content

Commit 29a9f6a

Browse files
authored
Merge pull request #5652 from magento-tsg/2.4.0-develop-pr33
[TSG] Fixes for 2.4 (pr33) (2.4.0-develop)
2 parents a0178bf + 6ca60fc commit 29a9f6a

File tree

5 files changed

+82
-29
lines changed

5 files changed

+82
-29
lines changed

app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/ImageTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ public function testValidate()
247247
->with(FileProcessor::TMP_DIR . '/' . $value['name'])
248248
->willReturn(true);
249249

250+
$this->ioFileSystemMock->expects($this->once())
251+
->method('getPathInfo')
252+
->with($value['name'])
253+
->willReturn(['extension' => 'gif']);
254+
250255
$model = $this->initialize([
251256
'value' => $value,
252257
'isAjax' => false,
@@ -300,6 +305,11 @@ public function testValidateMaxFileSize()
300305
->with(FileProcessor::TMP_DIR . '/' . $value['name'])
301306
->willReturn(true);
302307

308+
$this->ioFileSystemMock->expects($this->once())
309+
->method('getPathInfo')
310+
->with($value['name'])
311+
->willReturn(['extension' => 'gif']);
312+
303313
$model = $this->initialize([
304314
'value' => $value,
305315
'isAjax' => false,
@@ -352,6 +362,11 @@ public function testValidateMaxImageWidth()
352362
->with(FileProcessor::TMP_DIR . '/' . $value['name'])
353363
->willReturn(true);
354364

365+
$this->ioFileSystemMock->expects($this->once())
366+
->method('getPathInfo')
367+
->with($value['name'])
368+
->willReturn(['extension' => 'gif']);
369+
355370
$model = $this->initialize([
356371
'value' => $value,
357372
'isAjax' => false,
@@ -404,6 +419,11 @@ public function testValidateMaxImageHeight()
404419
->with(FileProcessor::TMP_DIR . '/' . $value['name'])
405420
->willReturn(true);
406421

422+
$this->ioFileSystemMock->expects($this->once())
423+
->method('getPathInfo')
424+
->with($value['name'])
425+
->willReturn(['extension' => 'gif']);
426+
407427
$model = $this->initialize([
408428
'value' => $value,
409429
'isAjax' => false,

app/code/Magento/ImportExport/Block/Adminhtml/Grid/Column/Renderer/Download.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class Download extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Text
2020
*/
2121
public function _getValue(\Magento\Framework\DataObject $row)
2222
{
23-
return '<p> ' . $row->getData('imported_file') . '</p><a href="'
23+
return '<p> ' . $this->escapeHtml($row->getData('imported_file')) . '</p><a href="'
2424
. $this->getUrl('*/*/download', ['filename' => $row->getData('imported_file')]) . '">'
25-
. __('Download')
25+
. $this->escapeHtml(__('Download'))
2626
. '</a>';
2727
}
2828
}

app/code/Magento/ImportExport/Block/Adminhtml/Grid/Column/Renderer/Error.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public function _getValue(\Magento\Framework\DataObject $row)
2222
{
2323
$result = '';
2424
if ($row->getData('error_file') != '') {
25-
$result = '<p> ' . $row->getData('error_file') . '</p><a href="'
25+
$result = '<p> ' . $this->escapeHtml($row->getData('error_file')) . '</p><a href="'
2626
. $this->getUrl('*/*/download', ['filename' => $row->getData('error_file')]) . '">'
27-
. __('Download')
27+
. $this->escapeHtml(__('Download'))
2828
. '</a>';
2929
}
3030
return $result;

app/code/Magento/ImportExport/Test/Unit/Block/Adminhtml/Grid/Column/Renderer/DownloadTest.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@
1010
use Magento\Backend\Block\Context;
1111
use Magento\Backend\Model\Url;
1212
use Magento\Framework\DataObject;
13+
use Magento\Framework\Escaper;
1314
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1415
use Magento\ImportExport\Block\Adminhtml\Grid\Column\Renderer\Download;
16+
use PHPUnit\Framework\MockObject\MockObject;
1517
use PHPUnit\Framework\TestCase;
1618

19+
/**
20+
* Test for \Magento\ImportExport\Block\Adminhtml\Grid\Column\Renderer\Download class.
21+
*/
1722
class DownloadTest extends TestCase
1823
{
1924
/**
20-
* @var Context
25+
* @var Context|MockObject
2126
*/
2227
protected $context;
2328

@@ -32,22 +37,29 @@ class DownloadTest extends TestCase
3237
protected $download;
3338

3439
/**
35-
* Set up
40+
* @var Escaper|MockObject
41+
*/
42+
private $escaperMock;
43+
44+
/**
45+
* @inheritdoc
3646
*/
3747
protected function setUp(): void
3848
{
49+
$this->escaperMock = $this->createMock(Escaper::class);
3950
$urlModel = $this->createPartialMock(Url::class, ['getUrl']);
4051
$urlModel->expects($this->any())->method('getUrl')->willReturn('url');
41-
$this->context = $this->createPartialMock(Context::class, ['getUrlBuilder']);
52+
$this->context = $this->createPartialMock(Context::class, ['getUrlBuilder', 'getEscaper']);
4253
$this->context->expects($this->any())->method('getUrlBuilder')->willReturn($urlModel);
54+
$this->context->expects($this->any())->method('getEscaper')->willReturn($this->escaperMock);
4355
$data = [];
4456

4557
$this->objectManagerHelper = new ObjectManagerHelper($this);
4658
$this->download = $this->objectManagerHelper->getObject(
4759
Download::class,
4860
[
4961
'context' => $this->context,
50-
'data' => $data
62+
'data' => $data,
5163
]
5264
);
5365
}
@@ -59,6 +71,14 @@ public function testGetValue()
5971
{
6072
$data = ['imported_file' => 'file.csv'];
6173
$row = new DataObject($data);
74+
$this->escaperMock->expects($this->at(0))
75+
->method('escapeHtml')
76+
->with('file.csv')
77+
->willReturn('file.csv');
78+
$this->escaperMock->expects($this->at(1))
79+
->method('escapeHtml')
80+
->with('Download')
81+
->willReturn('Download');
6282
$this->assertEquals('<p> file.csv</p><a href="url">Download</a>', $this->download->_getValue($row));
6383
}
6484
}

app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Queue/PreviewTest.php

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,23 @@ protected function setUp(): void
100100
->willReturn($backendSession);
101101

102102
$templateFactory = $this->createPartialMock(TemplateFactory::class, ['create']);
103-
$this->templateMock = $this->createPartialMock(
104-
Template::class,
105-
[
106-
'isPlain',
107-
'setId',
108-
'setTemplateType',
109-
'setTemplateText',
110-
'setTemplateStyles',
111-
]
112-
);
103+
$this->templateMock = $this->getMockBuilder(Template::class)
104+
->disableOriginalConstructor()
105+
->setMethods(
106+
[
107+
'isPlain',
108+
'setId',
109+
]
110+
)
111+
->addMethods(
112+
[
113+
'setTemplateType',
114+
'setTemplateText',
115+
'setTemplateStyles',
116+
]
117+
)
118+
->getMock();
119+
113120
$templateFactory->expects($this->once())
114121
->method('create')
115122
->willReturn($this->templateMock);
@@ -121,16 +128,22 @@ protected function setUp(): void
121128
->willReturn($this->subscriberMock);
122129

123130
$queueFactory = $this->createPartialMock(QueueFactory::class, ['create']);
124-
$this->queueMock = $this->createPartialMock(
125-
Queue::class,
126-
[
127-
'load',
128-
'getTemplateId',
129-
'getNewsletterType',
130-
'getNewsletterText',
131-
'getNewsletterStyles',
132-
]
133-
);
131+
$this->queueMock = $this->getMockBuilder(Queue::class)
132+
->disableOriginalConstructor()
133+
->setMethods(
134+
[
135+
'load',
136+
]
137+
)
138+
->addMethods(
139+
[
140+
'getTemplateId',
141+
'getNewsletterType',
142+
'getNewsletterText',
143+
'getNewsletterStyles',
144+
]
145+
)
146+
->getMock();
134147
$queueFactory->expects($this->any())
135148
->method('create')
136149
->willReturn($this->queueMock);
@@ -148,7 +161,7 @@ protected function setUp(): void
148161
'context' => $context,
149162
'templateFactory' => $templateFactory,
150163
'subscriberFactory' => $subscriberFactory,
151-
'queueFactory' => $queueFactory
164+
'queueFactory' => $queueFactory,
152165
]
153166
);
154167
}

0 commit comments

Comments
 (0)