Skip to content

Commit

Permalink
Merge branch '2.3-develop' of https://github.com/magento/magento2ce i…
Browse files Browse the repository at this point in the history
…nto pr_2019_03_20
  • Loading branch information
vkolesny committed Mar 25, 2019
2 parents 05e8120 + 677f1b6 commit 267a2b9
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 66 deletions.
17 changes: 15 additions & 2 deletions app/code/Magento/AsynchronousOperations/Model/MassSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Psr\Log\LoggerInterface;
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\OperationRepository;
use Magento\Authorization\Model\UserContextInterface;
use Magento\Framework\Encryption\Encryptor;

/**
* Class MassSchedule used for adding multiple entities as Operations to Bulk Management with the status tracking
Expand Down Expand Up @@ -63,6 +64,11 @@ class MassSchedule
*/
private $userContext;

/**
* @var Encryptor
*/
private $encryptor;

/**
* Initialize dependencies.
*
Expand All @@ -73,6 +79,7 @@ class MassSchedule
* @param LoggerInterface $logger
* @param OperationRepository $operationRepository
* @param UserContextInterface $userContext
* @param Encryptor|null $encryptor
*/
public function __construct(
IdentityGeneratorInterface $identityService,
Expand All @@ -81,7 +88,8 @@ public function __construct(
BulkManagementInterface $bulkManagement,
LoggerInterface $logger,
OperationRepository $operationRepository,
UserContextInterface $userContext = null
UserContextInterface $userContext = null,
Encryptor $encryptor = null
) {
$this->identityService = $identityService;
$this->itemStatusInterfaceFactory = $itemStatusInterfaceFactory;
Expand All @@ -90,6 +98,7 @@ public function __construct(
$this->logger = $logger;
$this->operationRepository = $operationRepository;
$this->userContext = $userContext ?: ObjectManager::getInstance()->get(UserContextInterface::class);
$this->encryptor = $encryptor ?: ObjectManager::getInstance()->get(Encryptor::class);
}

/**
Expand Down Expand Up @@ -130,9 +139,13 @@ public function publishMass($topicName, array $entitiesArray, $groupId = null, $
$requestItem = $this->itemStatusInterfaceFactory->create();

try {
$operations[] = $this->operationRepository->createByTopic($topicName, $entityParams, $groupId);
$operation = $this->operationRepository->createByTopic($topicName, $entityParams, $groupId);
$operations[] = $operation;
$requestItem->setId($key);
$requestItem->setStatus(ItemStatusInterface::STATUS_ACCEPTED);
$requestItem->setDataHash(
$this->encryptor->hash($operation->getSerializedData(), Encryptor::HASH_VERSION_SHA256)
);
$requestItems[] = $requestItem;
} catch (\Exception $exception) {
$this->logger->error($exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
<editor>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
<rule name="validate-xml-identifier" xsi:type="boolean">true</rule>
</validation>
<editorType>text</editorType>
</editor>
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/ConfigurableProduct/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,11 @@
<type name="Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector">
<plugin name="apply_tax_class_id" type="Magento\ConfigurableProduct\Plugin\Tax\Model\Sales\Total\Quote\CommonTaxCollector" />
</type>
<type name="Magento\Eav\Model\Entity\Attribute\Group">
<arguments>
<argument name="reservedSystemNames" xsi:type="array">
<item name="configurable" xsi:type="string">configurable</item>
</argument>
</arguments>
</type>
</config>
11 changes: 8 additions & 3 deletions app/code/Magento/Customer/Block/Address/Grid.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Block\Address;

use Magento\Customer\Model\ResourceModel\Address\CollectionFactory as AddressCollectionFactory;
Expand Down Expand Up @@ -236,8 +237,12 @@ private function getAddressCollection(): \Magento\Customer\Model\ResourceModel\A
}
/** @var \Magento\Customer\Model\ResourceModel\Address\Collection $collection */
$collection = $this->addressCollectionFactory->create();
$collection->setOrder('entity_id', 'desc')
->setCustomerFilter([$this->getCustomer()->getId()]);
$collection->setOrder('entity_id', 'desc');
$collection->addFieldToFilter(
'entity_id',
['nin' => [$this->getDefaultBilling(), $this->getDefaultShipping()]]
);
$collection->setCustomerFilter([$this->getCustomer()->getId()]);
$this->addressCollection = $collection;
}
return $this->addressCollection;
Expand Down
10 changes: 6 additions & 4 deletions app/code/Magento/Customer/Test/Unit/Block/Address/GridTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function setUp()
public function testGetChildHtml()
{
$customerId = 1;

$outputString = 'OutputString';
/** @var \Magento\Framework\View\Element\BlockInterface|\PHPUnit_Framework_MockObject_MockObject $block */
$block = $this->getMockBuilder(\Magento\Framework\View\Element\BlockInterface::class)
->setMethods(['setCollection'])
Expand All @@ -93,7 +93,7 @@ public function testGetChildHtml()
/** @var \PHPUnit_Framework_MockObject_MockObject */
$addressCollection = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Address\Collection::class)
->disableOriginalConstructor()
->setMethods(['setOrder', 'setCustomerFilter', 'load'])
->setMethods(['setOrder', 'setCustomerFilter', 'load','addFieldToFilter'])
->getMock();

$layout->expects($this->atLeastOnce())->method('getChildName')->with('NameInLayout', 'pager')
Expand All @@ -108,12 +108,13 @@ public function testGetChildHtml()
->willReturnSelf();
$addressCollection->expects($this->atLeastOnce())->method('setCustomerFilter')->with([$customerId])
->willReturnSelf();
$addressCollection->expects(static::any())->method('addFieldToFilter')->willReturnSelf();
$this->addressCollectionFactory->expects($this->atLeastOnce())->method('create')
->willReturn($addressCollection);
$block->expects($this->atLeastOnce())->method('setCollection')->with($addressCollection)->willReturnSelf();
$this->gridBlock->setNameInLayout('NameInLayout');
$this->gridBlock->setLayout($layout);
$this->assertEquals('OutputString', $this->gridBlock->getChildHtml('pager'));
$this->assertEquals($outputString, $this->gridBlock->getChildHtml('pager'));
}

/**
Expand All @@ -137,7 +138,7 @@ public function testGetAdditionalAddresses()
/** @var \PHPUnit_Framework_MockObject_MockObject */
$addressCollection = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Address\Collection::class)
->disableOriginalConstructor()
->setMethods(['setOrder', 'setCustomerFilter', 'load', 'getIterator'])
->setMethods(['setOrder', 'setCustomerFilter', 'load', 'getIterator','addFieldToFilter'])
->getMock();
$addressDataModel = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\AddressInterface::class);
$address = $this->getMockBuilder(\Magento\Customer\Model\Address::class)
Expand All @@ -157,6 +158,7 @@ public function testGetAdditionalAddresses()
->willReturnSelf();
$addressCollection->expects($this->atLeastOnce())->method('setCustomerFilter')->with([$customerId])
->willReturnSelf();
$addressCollection->expects(static::any())->method('addFieldToFilter')->willReturnSelf();
$addressCollection->expects($this->atLeastOnce())->method('getIterator')
->willReturn(new \ArrayIterator($collection));
$this->addressCollectionFactory->expects($this->atLeastOnce())->method('create')
Expand Down
50 changes: 33 additions & 17 deletions app/code/Magento/Eav/Model/Entity/Attribute/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Eav\Model\Entity\Attribute;

use Magento\Eav\Api\Data\AttributeGroupExtensionInterface;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\Exception\LocalizedException;

/**
* Entity attribute group model
*
* @api
* @method int getSortOrder()
* @method \Magento\Eav\Model\Entity\Attribute\Group setSortOrder(int $value)
Expand All @@ -27,6 +32,11 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
*/
private $translitFilter;

/**
* @var array
*/
private $reservedSystemNames = [];

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand All @@ -35,7 +45,8 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
* @param \Magento\Framework\Filter\Translit $translitFilter
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param array $data (optional)
* @param array $reservedSystemNames (optional)
*/
public function __construct(
\Magento\Framework\Model\Context $context,
Expand All @@ -45,7 +56,8 @@ public function __construct(
\Magento\Framework\Filter\Translit $translitFilter,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
array $reservedSystemNames = []
) {
parent::__construct(
$context,
Expand All @@ -56,6 +68,7 @@ public function __construct(
$resourceCollection,
$data
);
$this->reservedSystemNames = $reservedSystemNames;
$this->translitFilter = $translitFilter;
}

Expand All @@ -74,6 +87,7 @@ protected function _construct()
* Checks if current attribute group exists
*
* @return bool
* @throws LocalizedException
* @codeCoverageIgnore
*/
public function itemExists()
Expand All @@ -85,6 +99,7 @@ public function itemExists()
* Delete groups
*
* @return $this
* @throws LocalizedException
* @codeCoverageIgnore
*/
public function deleteGroups()
Expand All @@ -110,9 +125,10 @@ public function beforeSave()
),
'-'
);
if (empty($attributeGroupCode)) {
$isReservedSystemName = in_array(strtolower($attributeGroupCode), $this->reservedSystemNames);
if (empty($attributeGroupCode) || $isReservedSystemName) {
// in the following code md5 is not used for security purposes
$attributeGroupCode = md5($groupName);
$attributeGroupCode = md5(strtolower($groupName));
}
$this->setAttributeGroupCode($attributeGroupCode);
}
Expand All @@ -121,7 +137,8 @@ public function beforeSave()
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @codeCoverageIgnoreStart
*/
public function getAttributeGroupId()
Expand All @@ -130,64 +147,63 @@ public function getAttributeGroupId()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getAttributeGroupName()
{
return $this->getData(self::GROUP_NAME);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getAttributeSetId()
{
return $this->getData(self::ATTRIBUTE_SET_ID);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setAttributeGroupId($attributeGroupId)
{
return $this->setData(self::GROUP_ID, $attributeGroupId);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setAttributeGroupName($attributeGroupName)
{
return $this->setData(self::GROUP_NAME, $attributeGroupName);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setAttributeSetId($attributeSetId)
{
return $this->setData(self::ATTRIBUTE_SET_ID, $attributeSetId);
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @return \Magento\Eav\Api\Data\AttributeGroupExtensionInterface|null
* @return AttributeGroupExtensionInterface|null
*/
public function getExtensionAttributes()
{
return $this->_getExtensionAttributes();
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @param \Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes
* @param AttributeGroupExtensionInterface $extensionAttributes
* @return $this
*/
public function setExtensionAttributes(
\Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes
) {
public function setExtensionAttributes(AttributeGroupExtensionInterface $extensionAttributes)
{
return $this->_setExtensionAttributes($extensionAttributes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function setUp()
'resource' => $this->resourceMock,
'translitFilter' => $translitFilter,
'context' => $contextMock,
'reservedSystemNames' => ['configurable'],
];
$objectManager = new ObjectManager($this);
$this->model = $objectManager->getObject(
Expand Down Expand Up @@ -67,6 +68,8 @@ public function attributeGroupCodeDataProvider()
{
return [
['General Group', 'general-group'],
['configurable', md5('configurable')],
['configurAble', md5('configurable')],
['///', md5('///')],
];
}
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Eav/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,3 @@
</arguments>
</type>
</config>

Loading

0 comments on commit 267a2b9

Please sign in to comment.