Skip to content

Commit ce3a02e

Browse files
author
Hwashiang Yu
committed
Merge remote-tracking branch 'upstream/2.3.4-develop' into cia-16003-19827-pr
2 parents f44f09b + 9019755 commit ce3a02e

File tree

16 files changed

+440
-55
lines changed

16 files changed

+440
-55
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Category.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ protected function _beforeSave(\Magento\Framework\DataObject $object)
284284
$object->setAttributeSetId(
285285
$object->getAttributeSetId() ?: $this->getEntityType()->getDefaultAttributeSetId()
286286
);
287+
288+
$this->castPathIdsToInt($object);
289+
287290
if ($object->isObjectNew()) {
288291
if ($object->getPosition() === null) {
289292
$object->setPosition($this->_getMaxPosition($object->getPath()) + 1);
@@ -1188,4 +1191,25 @@ public function getCategoryWithChildren(int $categoryId): array
11881191

11891192
return $connection->fetchAll($select);
11901193
}
1194+
1195+
/**
1196+
* Cast category path ids to int.
1197+
*
1198+
* @param DataObject $object
1199+
* @return void
1200+
*/
1201+
private function castPathIdsToInt(DataObject $object): void
1202+
{
1203+
if (is_string($object->getPath())) {
1204+
$pathIds = explode('/', $object->getPath());
1205+
1206+
array_walk(
1207+
$pathIds,
1208+
function (&$pathId) {
1209+
$pathId = (int)$pathId;
1210+
}
1211+
);
1212+
$object->setPath(implode('/', $pathIds));
1213+
}
1214+
}
11911215
}

app/code/Magento/Catalog/Model/ResourceModel/Category/Tree.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Model\ResourceModel\Category;
79

810
use Magento\Framework\Data\Tree\Dbp;
911
use Magento\Catalog\Api\Data\CategoryInterface;
1012
use Magento\Framework\EntityManager\MetadataPool;
1113

1214
/**
15+
* Category Tree model.
16+
*
1317
* @api
1418
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1519
* @since 100.0.2
@@ -483,6 +487,14 @@ public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductC
483487

484488
foreach ($this->_conn->fetchAll($select) as $item) {
485489
$pathIds = explode('/', $item['path']);
490+
491+
array_walk(
492+
$pathIds,
493+
function (&$pathId) {
494+
$pathId = (int)$pathId;
495+
}
496+
);
497+
486498
$level = (int)$item['level'];
487499
while ($level > 0) {
488500
$pathIds[count($pathIds) - 1] = '%';
@@ -680,6 +692,8 @@ public function getExistingCategoryIdsBySpecifiedIds($ids)
680692
}
681693

682694
/**
695+
* Return MetadataPool object.
696+
*
683697
* @return \Magento\Framework\EntityManager\MetadataPool
684698
*/
685699
private function getMetadataPool()

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Websites.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ protected function getFieldsForFieldset()
186186
'componentType' => Form\Field::NAME,
187187
'formElement' => Form\Element\Checkbox::NAME,
188188
'description' => __($website['name']),
189+
'__disableTmpl' => true,
189190
'tooltip' => $tooltip,
190191
'sortOrder' => $sortOrder,
191192
'dataScope' => 'website_ids.' . $website['id'],
@@ -353,18 +354,21 @@ protected function getWebsitesOptionsList()
353354
$websiteOption = [
354355
'value' => '0.' . $website['id'],
355356
'label' => __($website['name']),
357+
'__disableTmpl' => true,
356358
];
357359
$groupOptions = [];
358360
foreach ($website['groups'] as $group) {
359361
$groupOption = [
360362
'value' => '0.' . $website['id'] . '.' . $group['id'],
361363
'label' => __($group['name']),
364+
'__disableTmpl' => true,
362365
];
363366
$storeViewOptions = [];
364367
foreach ($group['stores'] as $storeView) {
365368
$storeViewOptions[] = [
366369
'value' => $storeView['id'],
367370
'label' => __($storeView['name']),
371+
'__disableTmpl' => true,
368372
];
369373
}
370374
if (!empty($storeViewOptions)) {

app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
<settings>
133133
<addField>true</addField>
134134
<filter>text</filter>
135-
<bodyTmpl>ui/grid/cells/html</bodyTmpl>
135+
<bodyTmpl>ui/grid/cells/text</bodyTmpl>
136136
<label translate="true">Name</label>
137137
</settings>
138138
</column>
@@ -155,7 +155,7 @@
155155
<column name="sku" sortOrder="60">
156156
<settings>
157157
<filter>text</filter>
158-
<bodyTmpl>ui/grid/cells/html</bodyTmpl>
158+
<bodyTmpl>ui/grid/cells/text</bodyTmpl>
159159
<label translate="true">SKU</label>
160160
</settings>
161161
</column>

app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/Cms/OptionsTest.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testToOptionArray()
7171
$expectedOptions = [
7272
[
7373
'label' => __('All Store Views'),
74-
'value' => '0'
74+
'value' => '0',
7575
],
7676
[
7777
'label' => 'Main Website',
@@ -81,11 +81,14 @@ public function testToOptionArray()
8181
'value' => [
8282
[
8383
'label' => ' Default Store View',
84-
'value' => '1'
84+
'value' => '1',
85+
'__disableTmpl' => true,
8586
]
86-
]
87+
],
88+
'__disableTmpl' => true,
8789
]
88-
]
90+
],
91+
'__disableTmpl' => true,
8992
]
9093
];
9194

@@ -104,14 +107,6 @@ public function testToOptionArray()
104107
$this->storeMock->expects($this->atLeastOnce())->method('getName')->willReturn('Default Store View');
105108
$this->storeMock->expects($this->atLeastOnce())->method('getId')->willReturn('1');
106109

107-
$this->escaperMock->expects($this->atLeastOnce())->method('escapeHtml')->willReturnMap(
108-
[
109-
['Default Store View', null, 'Default Store View'],
110-
['Main Website Store', null, 'Main Website Store'],
111-
['Main Website', null, 'Main Website']
112-
]
113-
);
114-
115110
$this->assertEquals($expectedOptions, $this->options->toOptionArray());
116111
}
117112
}

app/code/Magento/ImportExport/Controller/Adminhtml/Export/File/Download.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ public function __construct(
5959
*/
6060
public function execute()
6161
{
62-
if (empty($fileName = $this->getRequest()->getParam('filename'))) {
63-
throw new LocalizedException(__('Please provide export file name'));
62+
$fileName = $this->getRequest()->getParam('filename');
63+
if (empty($fileName) || preg_match('/\.\.(\\\|\/)/', $fileName) !== 0) {
64+
throw new LocalizedException(__('Please provide valid export file name'));
6465
}
6566
try {
6667
$path = 'export/' . $fileName;
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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\Controller\Adminhtml\Export\File;
9+
10+
use Magento\Framework\Filesystem;
11+
use Magento\Backend\App\Action\Context;
12+
use Magento\Framework\App\Request\Http;
13+
use Magento\Framework\App\ResponseInterface;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use Magento\Framework\Filesystem\Directory\Read;
16+
use Magento\Framework\App\Filesystem\DirectoryList;
17+
use Magento\Framework\App\Response\Http\FileFactory;
18+
use Magento\ImportExport\Controller\Adminhtml\Export\File\Download;
19+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
20+
21+
/**
22+
* Unit tests for \Magento\ImportExport\Controller\Adminhtml\Export\File\Download.
23+
*/
24+
class DownloadTest extends \PHPUnit\Framework\TestCase
25+
{
26+
/**
27+
* @var Download
28+
*/
29+
private $controller;
30+
31+
/**
32+
* @var ObjectManagerHelper
33+
*/
34+
private $objectManager;
35+
36+
/**
37+
* @var Context|MockObject
38+
*/
39+
private $contextMock;
40+
41+
/**
42+
* @var FileFactory|MockObject
43+
*/
44+
private $fileFactoryMock;
45+
46+
/**
47+
* @var Filesystem|MockObject
48+
*/
49+
private $fileSystemMock;
50+
51+
/**
52+
* @var Http|MockObject
53+
*/
54+
private $requestMock;
55+
56+
/**
57+
* @var Read|MockObject
58+
*/
59+
private $readMock;
60+
61+
/**
62+
* @inheritdoc
63+
*/
64+
protected function setUp()
65+
{
66+
$this->objectManager = new ObjectManagerHelper($this);
67+
68+
$this->contextMock = $this->createPartialMock(
69+
Context::class,
70+
['getRequest', 'getObjectManager', 'getResultRedirectFactory']
71+
);
72+
$this->fileFactoryMock = $this->createPartialMock(FileFactory::class, ['create']);
73+
$this->fileSystemMock = $this->createPartialMock(Filesystem::class, ['getDirectoryRead']);
74+
$this->requestMock = $this->createPartialMock(Http::class, ['getParam']);
75+
$this->readMock = $this->createPartialMock(Read::class, ['isFile', 'readFile']);
76+
77+
$this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock);
78+
79+
$this->controller = $this->objectManager->getObject(
80+
Download::class,
81+
[
82+
'context' => $this->contextMock,
83+
'fileFactory' => $this->fileFactoryMock,
84+
'filesystem' => $this->fileSystemMock,
85+
]
86+
);
87+
}
88+
89+
/**
90+
* Check download controller behavior.
91+
*
92+
* @return void
93+
*/
94+
public function testExecute(): void
95+
{
96+
$fileName = 'customer.csv';
97+
$path = 'export/' . $fileName;
98+
$fileContent = 'content';
99+
100+
$this->processDownloadAction($fileName, $path);
101+
$this->readMock->expects($this->once())->method('readFile')->with($path)->willReturn($fileContent);
102+
$response = $this->createMock(ResponseInterface::class);
103+
$this->fileFactoryMock->expects($this->once())
104+
->method('create')
105+
->with($path, $fileContent, DirectoryList::VAR_DIR)
106+
->willReturn($response);
107+
108+
$this->controller->execute();
109+
}
110+
111+
/**
112+
* Check behavior with incorrect filename.
113+
*
114+
* @expectedException \Magento\Framework\Exception\LocalizedException
115+
* @expectedExceptionMessage Please provide valid export file name
116+
* @return void
117+
*/
118+
public function testExecuteWithEmptyFileName(): void
119+
{
120+
$this->requestMock->expects($this->once())->method('getParam')->with('filename')->willReturn('');
121+
122+
$this->controller->execute();
123+
}
124+
125+
/**
126+
* Check behavior when method throw exception.
127+
*
128+
* @expectedException \Magento\Framework\Exception\LocalizedException
129+
* @expectedExceptionMessage There are no export file with such name customer.csv
130+
* @return void
131+
*/
132+
public function testExecuteWithNonExistanceFile(): void
133+
{
134+
$fileName = 'customer.csv';
135+
$path = 'export/' . $fileName;
136+
137+
$this->processDownloadAction($fileName, $path);
138+
$this->readMock->expects($this->once())
139+
->method('readFile')
140+
->with($path)
141+
->willThrowException(new \Exception('Message'));
142+
143+
$this->controller->execute();
144+
}
145+
146+
/**
147+
* Check that parameter valid and file exist.
148+
*
149+
* @param string $fileName
150+
* @param string $path
151+
* @return void
152+
*/
153+
private function processDownloadAction(string $fileName, string $path): void
154+
{
155+
$this->requestMock->expects($this->once())->method('getParam')->with('filename')->willReturn($fileName);
156+
$this->fileSystemMock->expects($this->once())
157+
->method('getDirectoryRead')
158+
->with(DirectoryList::VAR_DIR)
159+
->willReturn($this->readMock);
160+
$this->readMock->expects($this->once())->method('isFile')->with($path)->willReturn(true);
161+
}
162+
}

app/code/Magento/Store/Model/System/Store.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function getStoreValuesForForm($empty = false, $all = false)
142142
$values[] = [
143143
'label' => str_repeat($nonEscapableNbspChar, 4) . $store->getName(),
144144
'value' => $store->getId(),
145+
'__disableTmpl' => true,
145146
];
146147
}
147148
if (!empty($values)) {

app/code/Magento/Store/Test/Unit/Model/System/StoreTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,15 @@ public function getStoreValuesForFormDataProvider()
271271
[
272272
'label' => str_repeat($nonEscapableNbspChar, 4) . $groupName,
273273
'value' => [
274-
['label' => str_repeat($nonEscapableNbspChar, 4) . $storeName, 'value' => $storeId]
274+
[
275+
'label' => str_repeat($nonEscapableNbspChar, 4) . $storeName,
276+
'value' => $storeId,
277+
'__disableTmpl' => true,
278+
],
275279
],
276280
'__disableTmpl' => true
277281
],
278-
]
282+
],
279283
],
280284
];
281285
}

0 commit comments

Comments
 (0)