Skip to content

Commit

Permalink
Merge pull request #7841 from magento-cia/cia-2.4.6-bugfixes-08182022
Browse files Browse the repository at this point in the history
cia-2.4.6-develop-bugfixes-08182022
  • Loading branch information
admanesachin authored Aug 25, 2022
2 parents 72fbdfd + 2f5429b commit de98503
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Backend\Block\System\Store\Grid\Render;

use Magento\Framework\DataObject;

/**
* Store render group
*
Expand All @@ -13,9 +15,9 @@
class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
/**
* {@inheritdoc}
* @inheritDoc
*/
public function render(\Magento\Framework\DataObject $row)
public function render(DataObject $row): ?string
{
if (!$row->getData($this->getColumn()->getIndex())) {
return null;
Expand All @@ -28,6 +30,6 @@ public function render(\Magento\Framework\DataObject $row)
'">' .
$this->escapeHtml($row->getData($this->getColumn()->getIndex())) .
'</a><br />'
. '(' . __('Code') . ': ' . $row->getGroupCode() . ')';
. '(' . __('Code') . ': ' . $this->escapeHtml($row->getGroupCode()) . ')';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Plugin\Webapi\Controller\Rest;

use Magento\Webapi\Controller\Rest\ParamsOverrider;

/**
* Validates Customer Data
*/
class ValidateCustomerData
{
private const CUSTOMER_KEY = 'customer';

/**
* Before Overriding to validate data
*
* @param ParamsOverrider $subject
* @param array $inputData
* @param array $parameters
* @return array[]
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeOverride(ParamsOverrider $subject, array $inputData, array $parameters): array
{
if (isset($inputData[self:: CUSTOMER_KEY])) {
$inputData[self:: CUSTOMER_KEY] = $this->validateInputData($inputData[self:: CUSTOMER_KEY]);
}
return [$inputData, $parameters];
}

/**
* Validates InputData
*
* @param array $inputData
* @return array
*/
private function validateInputData(array $inputData): array
{
$result = [];

$data = array_filter($inputData, function ($k) use (&$result) {
$key = is_string($k) ? strtolower($k) : $k;
return !isset($result[$key]) && ($result[$key] = true);
}, ARRAY_FILTER_USE_KEY);

return array_map(function ($value) {
return is_array($value) ? $this->validateInputData($value) : $value;
}, $data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Test\Unit\Plugin\Webapi\Controller\Rest;

use Exception;
use Magento\Framework\App\ObjectManager;
use Magento\Customer\Plugin\Webapi\Controller\Rest\ValidateCustomerData;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
* Unit test for ValidateCustomerData plugin
*/
class ValidateCustomerDataTest extends TestCase
{

/**
* @var ValidateCustomerData
*/
private $validateCustomerDataObject;

/**
* @var ReflectionClass
*
*/
private $reflectionObject;

/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->validateCustomerDataObject = ObjectManager::getInstance()->get(ValidateCustomerData::class);
$this->reflectionObject = new ReflectionClass(get_class($this->validateCustomerDataObject));
}

/**
* Test if the customer Info is valid
*
* @param array $customerInfo
* @param array $result
* @dataProvider dataProviderInputData
* @throws Exception
*/
public function testValidateInputData(array $customerInfo, array $result)
{
$this->assertEquals(
$result,
$this->invokeValidateInputData('validateInputData', [$customerInfo])
);
}

/**
* @param string $methodName
* @param array $arguments
* @return mixed
* @throws Exception
*/
private function invokeValidateInputData(string $methodName, array $arguments = [])
{
$validateInputDataMethod = $this->reflectionObject->getMethod($methodName);
$validateInputDataMethod->setAccessible(true);
return $validateInputDataMethod->invokeArgs($this->validateCustomerDataObject, $arguments);
}

/**
* @return array
*/
public function dataProviderInputData(): array
{
return [
[
['customer' =>
[
'id' => -1,
'Id' => 1,
'name' =>
[
'firstName' => 'Test',
'LastName' => 'user'
],
'isHavingOwnHouse' => 1,
'address' =>
[
'street' => '1st Street',
'Street' => '3rd Street',
'city' => 'London'
],
]
],
['customer' =>
[
'id' => -1,
'name' =>
[
'firstName' => 'Test',
'LastName' => 'user'
],
'isHavingOwnHouse' => 1,
'address' =>
[
'street' => '1st Street',
'city' => 'London'
],
]
],
]
];
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Customer/etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
</argument>
</arguments>
</type>
<type name="Magento\Webapi\Controller\Rest\ParamsOverrider">
<plugin name="validateCustomerData" type="Magento\Customer\Plugin\Webapi\Controller\Rest\ValidateCustomerData" sortOrder="1" disabled="false" />
</type>
<preference for="Magento\Customer\Api\AccountManagementInterface"
type="Magento\Customer\Model\AccountManagementApi" />
</config>
38 changes: 31 additions & 7 deletions app/code/Magento/Store/Model/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
*/
namespace Magento\Store\Model;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
use Magento\Store\Model\Validation\StoreValidator;

/**
* Class Group
* Store Group model class used to retrieve and format group information
*
* @api
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand All @@ -21,9 +25,9 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
\Magento\Store\Api\Data\GroupInterface,
\Magento\Framework\App\ScopeInterface
{
const ENTITY = 'store_group';
public const ENTITY = 'store_group';

const CACHE_TAG = 'store_group';
public const CACHE_TAG = 'store_group';

/**
* @var bool
Expand Down Expand Up @@ -101,10 +105,15 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
private $eventManager;

/**
* @var \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface
* @var PoisonPillPutInterface
*/
private $pillPut;

/**
* @var StoreValidator
*/
private $modelValidator;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand All @@ -117,7 +126,8 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
* @param \Magento\Framework\Event\ManagerInterface|null $eventManager
* @param \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface|null $pillPut
* @param PoisonPillPutInterface|null $pillPut
* @param StoreValidator|null $modelValidator
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -132,15 +142,18 @@ public function __construct(
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = [],
\Magento\Framework\Event\ManagerInterface $eventManager = null,
\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface $pillPut = null
PoisonPillPutInterface $pillPut = null,
StoreValidator $modelValidator = null
) {
$this->_configDataResource = $configDataResource;
$this->_storeListFactory = $storeListFactory;
$this->_storeManager = $storeManager;
$this->eventManager = $eventManager ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Event\ManagerInterface::class);
$this->pillPut = $pillPut ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface::class);
->get(PoisonPillPutInterface::class);
$this->modelValidator = $modelValidator ?: ObjectManager::getInstance()
->get(StoreValidator::class);
parent::__construct(
$context,
$registry,
Expand All @@ -162,6 +175,17 @@ protected function _construct()
$this->_init(\Magento\Store\Model\ResourceModel\Group::class);
}

/**
* Validation rules for store
*
* @return \Zend_Validate_Interface|null
* @throws \Zend_Validate_Exception
*/
protected function _getValidationRulesBeforeSave(): ?\Zend_Validate_Interface
{
return $this->modelValidator;
}

/**
* Load store collection and set internal data
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private function prepareAdditionalStore()
$storeGroup = $this->objectManager->create(\Magento\Store\Model\Group::class);
$storeGroup->setWebsiteId($website->getId());
$storeGroup->setName('Fixture Store Group');
$storeGroup->setCode('fixturestoregroup');
$storeGroup->setRootCategoryId(2);
$storeGroup->setDefaultStoreId($store->getId());
$storeGroup->save();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

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

Expand All @@ -17,6 +17,7 @@

/**
* Integration tests for \Magento\Catalog\Model\Indexer\Product\Flat\Processor.
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ProcessorTest extends TestCase
{
Expand Down Expand Up @@ -145,7 +146,13 @@ public function testAddNewStoreGroup(): void
\Magento\Store\Model\Group::class
);
$storeGroup->setData(
['website_id' => 1, 'name' => 'New Store Group', 'root_category_id' => 2, 'group_id' => null]
[
'website_id' => 1,
'name' => 'New Store Group',
'root_category_id' => 2,
'group_id' => null,
'code' => 'newstoregroup'
]
);
$storeGroup->save();
$this->assertTrue($this->processor->getIndexer()->isInvalid());
Expand Down

0 comments on commit de98503

Please sign in to comment.