-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1808 from magento-engcom/2.2-develop-prs
[EngCom] Public Pull Requests - 2.2-develop - MAGETWO-84981: Trying to get data from non existent products #12539 - MAGETWO-84979: [Backport 2.2-develop] Fix swagger-ui on instances of Magento running on a non-standard port #12541 - MAGETWO-84903: Added namespace to product videos fotorama events #12469 - MAGETWO-84862: [Backport 2.2-develop] #11409: Too many password reset requests even when disabled in settings #11435 - MAGETWO-84856: Issue 12506: Fixup typo getDispretionPath -> getDispersionPath #12507 - MAGETWO-84808: 12110: Missing cascade into attribute set deletion. #12167 - MAGETWO-83503: [2.2] - Add command to view mview state and queue #12122 - MAGETWO-80223: Fix syntax of expectException() calls #11099
- Loading branch information
Showing
100 changed files
with
877 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/code/Magento/Catalog/Plugin/Model/AttributeSetRepository/RemoveProducts.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Plugin\Model\AttributeSetRepository; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\Collection; | ||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; | ||
use Magento\Eav\Api\AttributeSetRepositoryInterface; | ||
use Magento\Eav\Api\Data\AttributeSetInterface; | ||
|
||
/** | ||
* Delete related products after attribute set successfully removed. | ||
*/ | ||
class RemoveProducts | ||
{ | ||
/** | ||
* Retrieve products related to specific attribute set. | ||
* | ||
* @var CollectionFactory | ||
*/ | ||
private $collectionFactory; | ||
|
||
/** | ||
* RemoveProducts constructor. | ||
* | ||
* @param CollectionFactory $collectionFactory | ||
*/ | ||
public function __construct(CollectionFactory $collectionFactory) | ||
{ | ||
$this->collectionFactory = $collectionFactory; | ||
} | ||
|
||
/** | ||
* Delete related to specific attribute set products, if attribute set was removed successfully. | ||
* | ||
* @param AttributeSetRepositoryInterface $subject | ||
* @param bool $result | ||
* @param AttributeSetInterface $attributeSet | ||
* @return bool | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterDelete( | ||
AttributeSetRepositoryInterface $subject, | ||
bool $result, | ||
AttributeSetInterface $attributeSet | ||
) { | ||
/** @var Collection $productCollection */ | ||
$productCollection = $this->collectionFactory->create(); | ||
$productCollection->addFieldToFilter('attribute_set_id', ['eq' => $attributeSet->getId()]); | ||
$productCollection->delete(); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...code/Magento/Catalog/Test/Unit/Plugin/Model/AttributeSetRepository/RemoveProductsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Test\Unit\Plugin\Model\AttributeSetRepository; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\Collection; | ||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; | ||
use Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts; | ||
use Magento\Eav\Api\AttributeSetRepositoryInterface; | ||
use Magento\Eav\Api\Data\AttributeSetInterface; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Provide tests for RemoveProducts plugin. | ||
*/ | ||
class RemoveProductsTest extends TestCase | ||
{ | ||
/** | ||
* @var RemoveProducts | ||
*/ | ||
private $testSubject; | ||
|
||
/** | ||
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $collectionFactory; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManager = new ObjectManager($this); | ||
$this->collectionFactory = $this->getMockBuilder(CollectionFactory::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['create']) | ||
->getMock(); | ||
$this->testSubject = $objectManager->getObject( | ||
RemoveProducts::class, | ||
[ | ||
'collectionFactory' => $this->collectionFactory, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Test plugin will delete all related products for given attribute set. | ||
*/ | ||
public function testAfterDelete() | ||
{ | ||
$attributeSetId = '1'; | ||
|
||
/** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collection */ | ||
$collection = $this->getMockBuilder(Collection::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$collection->expects(self::once()) | ||
->method('addFieldToFilter') | ||
->with(self::identicalTo('attribute_set_id'), self::identicalTo(['eq' => $attributeSetId])); | ||
$collection->expects(self::once()) | ||
->method('delete'); | ||
|
||
$this->collectionFactory->expects(self::once()) | ||
->method('create') | ||
->willReturn($collection); | ||
|
||
/** @var AttributeSetRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject $attributeSetRepository */ | ||
$attributeSetRepository = $this->getMockBuilder(AttributeSetRepositoryInterface::class) | ||
->disableOriginalConstructor() | ||
->getMockForAbstractClass(); | ||
|
||
/** @var AttributeSetInterface|\PHPUnit_Framework_MockObject_MockObject $attributeSet */ | ||
$attributeSet = $this->getMockBuilder(AttributeSetInterface::class) | ||
->setMethods(['getId']) | ||
->disableOriginalConstructor() | ||
->getMockForAbstractClass(); | ||
$attributeSet->expects(self::once()) | ||
->method('getId') | ||
->willReturn($attributeSetId); | ||
|
||
self::assertTrue($this->testSubject->afterDelete($attributeSetRepository, true, $attributeSet)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.