Skip to content

Commit de98503

Browse files
authored
Merge pull request #7841 from magento-cia/cia-2.4.6-bugfixes-08182022
cia-2.4.6-develop-bugfixes-08182022
2 parents 72fbdfd + 2f5429b commit de98503

File tree

7 files changed

+220
-12
lines changed

7 files changed

+220
-12
lines changed

app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Backend\Block\System\Store\Grid\Render;
77

8+
use Magento\Framework\DataObject;
9+
810
/**
911
* Store render group
1012
*
@@ -13,9 +15,9 @@
1315
class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
1416
{
1517
/**
16-
* {@inheritdoc}
18+
* @inheritDoc
1719
*/
18-
public function render(\Magento\Framework\DataObject $row)
20+
public function render(DataObject $row): ?string
1921
{
2022
if (!$row->getData($this->getColumn()->getIndex())) {
2123
return null;
@@ -28,6 +30,6 @@ public function render(\Magento\Framework\DataObject $row)
2830
'">' .
2931
$this->escapeHtml($row->getData($this->getColumn()->getIndex())) .
3032
'</a><br />'
31-
. '(' . __('Code') . ': ' . $row->getGroupCode() . ')';
33+
. '(' . __('Code') . ': ' . $this->escapeHtml($row->getGroupCode()) . ')';
3234
}
3335
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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\Customer\Plugin\Webapi\Controller\Rest;
9+
10+
use Magento\Webapi\Controller\Rest\ParamsOverrider;
11+
12+
/**
13+
* Validates Customer Data
14+
*/
15+
class ValidateCustomerData
16+
{
17+
private const CUSTOMER_KEY = 'customer';
18+
19+
/**
20+
* Before Overriding to validate data
21+
*
22+
* @param ParamsOverrider $subject
23+
* @param array $inputData
24+
* @param array $parameters
25+
* @return array[]
26+
*
27+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
28+
*/
29+
public function beforeOverride(ParamsOverrider $subject, array $inputData, array $parameters): array
30+
{
31+
if (isset($inputData[self:: CUSTOMER_KEY])) {
32+
$inputData[self:: CUSTOMER_KEY] = $this->validateInputData($inputData[self:: CUSTOMER_KEY]);
33+
}
34+
return [$inputData, $parameters];
35+
}
36+
37+
/**
38+
* Validates InputData
39+
*
40+
* @param array $inputData
41+
* @return array
42+
*/
43+
private function validateInputData(array $inputData): array
44+
{
45+
$result = [];
46+
47+
$data = array_filter($inputData, function ($k) use (&$result) {
48+
$key = is_string($k) ? strtolower($k) : $k;
49+
return !isset($result[$key]) && ($result[$key] = true);
50+
}, ARRAY_FILTER_USE_KEY);
51+
52+
return array_map(function ($value) {
53+
return is_array($value) ? $this->validateInputData($value) : $value;
54+
}, $data);
55+
}
56+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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\Customer\Test\Unit\Plugin\Webapi\Controller\Rest;
9+
10+
use Exception;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Customer\Plugin\Webapi\Controller\Rest\ValidateCustomerData;
13+
use PHPUnit\Framework\TestCase;
14+
use ReflectionClass;
15+
16+
/**
17+
* Unit test for ValidateCustomerData plugin
18+
*/
19+
class ValidateCustomerDataTest extends TestCase
20+
{
21+
22+
/**
23+
* @var ValidateCustomerData
24+
*/
25+
private $validateCustomerDataObject;
26+
27+
/**
28+
* @var ReflectionClass
29+
*
30+
*/
31+
private $reflectionObject;
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function setUp(): void
37+
{
38+
$this->validateCustomerDataObject = ObjectManager::getInstance()->get(ValidateCustomerData::class);
39+
$this->reflectionObject = new ReflectionClass(get_class($this->validateCustomerDataObject));
40+
}
41+
42+
/**
43+
* Test if the customer Info is valid
44+
*
45+
* @param array $customerInfo
46+
* @param array $result
47+
* @dataProvider dataProviderInputData
48+
* @throws Exception
49+
*/
50+
public function testValidateInputData(array $customerInfo, array $result)
51+
{
52+
$this->assertEquals(
53+
$result,
54+
$this->invokeValidateInputData('validateInputData', [$customerInfo])
55+
);
56+
}
57+
58+
/**
59+
* @param string $methodName
60+
* @param array $arguments
61+
* @return mixed
62+
* @throws Exception
63+
*/
64+
private function invokeValidateInputData(string $methodName, array $arguments = [])
65+
{
66+
$validateInputDataMethod = $this->reflectionObject->getMethod($methodName);
67+
$validateInputDataMethod->setAccessible(true);
68+
return $validateInputDataMethod->invokeArgs($this->validateCustomerDataObject, $arguments);
69+
}
70+
71+
/**
72+
* @return array
73+
*/
74+
public function dataProviderInputData(): array
75+
{
76+
return [
77+
[
78+
['customer' =>
79+
[
80+
'id' => -1,
81+
'Id' => 1,
82+
'name' =>
83+
[
84+
'firstName' => 'Test',
85+
'LastName' => 'user'
86+
],
87+
'isHavingOwnHouse' => 1,
88+
'address' =>
89+
[
90+
'street' => '1st Street',
91+
'Street' => '3rd Street',
92+
'city' => 'London'
93+
],
94+
]
95+
],
96+
['customer' =>
97+
[
98+
'id' => -1,
99+
'name' =>
100+
[
101+
'firstName' => 'Test',
102+
'LastName' => 'user'
103+
],
104+
'isHavingOwnHouse' => 1,
105+
'address' =>
106+
[
107+
'street' => '1st Street',
108+
'city' => 'London'
109+
],
110+
]
111+
],
112+
]
113+
];
114+
}
115+
}

app/code/Magento/Customer/etc/webapi_rest/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
</argument>
3232
</arguments>
3333
</type>
34+
<type name="Magento\Webapi\Controller\Rest\ParamsOverrider">
35+
<plugin name="validateCustomerData" type="Magento\Customer\Plugin\Webapi\Controller\Rest\ValidateCustomerData" sortOrder="1" disabled="false" />
36+
</type>
3437
<preference for="Magento\Customer\Api\AccountManagementInterface"
3538
type="Magento\Customer\Model\AccountManagementApi" />
3639
</config>

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
*/
1010
namespace Magento\Store\Model;
1111

12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
14+
use Magento\Store\Model\Validation\StoreValidator;
15+
1216
/**
13-
* Class Group
17+
* Store Group model class used to retrieve and format group information
1418
*
1519
* @api
1620
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -21,9 +25,9 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
2125
\Magento\Store\Api\Data\GroupInterface,
2226
\Magento\Framework\App\ScopeInterface
2327
{
24-
const ENTITY = 'store_group';
28+
public const ENTITY = 'store_group';
2529

26-
const CACHE_TAG = 'store_group';
30+
public const CACHE_TAG = 'store_group';
2731

2832
/**
2933
* @var bool
@@ -101,10 +105,15 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
101105
private $eventManager;
102106

103107
/**
104-
* @var \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface
108+
* @var PoisonPillPutInterface
105109
*/
106110
private $pillPut;
107111

112+
/**
113+
* @var StoreValidator
114+
*/
115+
private $modelValidator;
116+
108117
/**
109118
* @param \Magento\Framework\Model\Context $context
110119
* @param \Magento\Framework\Registry $registry
@@ -117,7 +126,8 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
117126
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
118127
* @param array $data
119128
* @param \Magento\Framework\Event\ManagerInterface|null $eventManager
120-
* @param \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface|null $pillPut
129+
* @param PoisonPillPutInterface|null $pillPut
130+
* @param StoreValidator|null $modelValidator
121131
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
122132
*/
123133
public function __construct(
@@ -132,15 +142,18 @@ public function __construct(
132142
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
133143
array $data = [],
134144
\Magento\Framework\Event\ManagerInterface $eventManager = null,
135-
\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface $pillPut = null
145+
PoisonPillPutInterface $pillPut = null,
146+
StoreValidator $modelValidator = null
136147
) {
137148
$this->_configDataResource = $configDataResource;
138149
$this->_storeListFactory = $storeListFactory;
139150
$this->_storeManager = $storeManager;
140151
$this->eventManager = $eventManager ?: \Magento\Framework\App\ObjectManager::getInstance()
141152
->get(\Magento\Framework\Event\ManagerInterface::class);
142153
$this->pillPut = $pillPut ?: \Magento\Framework\App\ObjectManager::getInstance()
143-
->get(\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface::class);
154+
->get(PoisonPillPutInterface::class);
155+
$this->modelValidator = $modelValidator ?: ObjectManager::getInstance()
156+
->get(StoreValidator::class);
144157
parent::__construct(
145158
$context,
146159
$registry,
@@ -162,6 +175,17 @@ protected function _construct()
162175
$this->_init(\Magento\Store\Model\ResourceModel\Group::class);
163176
}
164177

178+
/**
179+
* Validation rules for store
180+
*
181+
* @return \Zend_Validate_Interface|null
182+
* @throws \Zend_Validate_Exception
183+
*/
184+
protected function _getValidationRulesBeforeSave(): ?\Zend_Validate_Interface
185+
{
186+
return $this->modelValidator;
187+
}
188+
165189
/**
166190
* Load store collection and set internal data
167191
*

dev/tests/integration/testsuite/Magento/Catalog/Console/Command/ProductAttributesCleanUpTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private function prepareAdditionalStore()
104104
$storeGroup = $this->objectManager->create(\Magento\Store\Model\Group::class);
105105
$storeGroup->setWebsiteId($website->getId());
106106
$storeGroup->setName('Fixture Store Group');
107+
$storeGroup->setCode('fixturestoregroup');
107108
$storeGroup->setRootCategoryId(2);
108109
$storeGroup->setDefaultStoreId($store->getId());
109110
$storeGroup->save();

dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
56
*/
6-
declare(strict_types=1);
77

88
namespace Magento\Catalog\Model\Indexer\Product\Flat;
99

@@ -17,6 +17,7 @@
1717

1818
/**
1919
* Integration tests for \Magento\Catalog\Model\Indexer\Product\Flat\Processor.
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2021
*/
2122
class ProcessorTest extends TestCase
2223
{
@@ -145,7 +146,13 @@ public function testAddNewStoreGroup(): void
145146
\Magento\Store\Model\Group::class
146147
);
147148
$storeGroup->setData(
148-
['website_id' => 1, 'name' => 'New Store Group', 'root_category_id' => 2, 'group_id' => null]
149+
[
150+
'website_id' => 1,
151+
'name' => 'New Store Group',
152+
'root_category_id' => 2,
153+
'group_id' => null,
154+
'code' => 'newstoregroup'
155+
]
149156
);
150157
$storeGroup->save();
151158
$this->assertTrue($this->processor->getIndexer()->isInvalid());

0 commit comments

Comments
 (0)