Skip to content

Commit 321278b

Browse files
Merge pull request magento#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 magento#12539 - MAGETWO-84979: [Backport 2.2-develop] Fix swagger-ui on instances of Magento running on a non-standard port magento#12541 - MAGETWO-84903: Added namespace to product videos fotorama events magento#12469 - MAGETWO-84862: [Backport 2.2-develop] magento#11409: Too many password reset requests even when disabled in settings magento#11435 - MAGETWO-84856: Issue 12506: Fixup typo getDispretionPath -> getDispersionPath magento#12507 - MAGETWO-84808: 12110: Missing cascade into attribute set deletion. magento#12167 - MAGETWO-83503: [2.2] - Add command to view mview state and queue magento#12122 - MAGETWO-80223: Fix syntax of expectException() calls magento#11099
2 parents 276c690 + 18a568a commit 321278b

File tree

100 files changed

+877
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+877
-203
lines changed

app/code/Magento/Backend/Test/Unit/Model/Config/SessionLifetime/BackendModelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public function testBeforeSave($value, $errorMessage = null)
2020
\Magento\Backend\Model\Config\SessionLifetime\BackendModel::class
2121
);
2222
if ($errorMessage !== null) {
23-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $errorMessage);
23+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
24+
$this->expectExceptionMessage($errorMessage);
2425
}
2526
$model->setValue($value);
2627
$object = $model->beforeSave();

app/code/Magento/Catalog/Model/Product/Gallery/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function addImage(
149149
}
150150

151151
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($pathinfo['basename']);
152-
$dispretionPath = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
152+
$dispretionPath = \Magento\MediaStorage\Model\File\Uploader::getDispersionPath($fileName);
153153
$fileName = $dispretionPath . '/' . $fileName;
154154

155155
$fileName = $this->getNotDuplicatedFilename($fileName, $dispretionPath);

app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function validate($processingParams, $option)
150150
$extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
151151

152152
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($fileInfo['name']);
153-
$dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
153+
$dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispersionPath($fileName);
154154

155155
$filePath = $dispersion;
156156

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Plugin\Model\AttributeSetRepository;
8+
9+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
10+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
11+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
12+
use Magento\Eav\Api\Data\AttributeSetInterface;
13+
14+
/**
15+
* Delete related products after attribute set successfully removed.
16+
*/
17+
class RemoveProducts
18+
{
19+
/**
20+
* Retrieve products related to specific attribute set.
21+
*
22+
* @var CollectionFactory
23+
*/
24+
private $collectionFactory;
25+
26+
/**
27+
* RemoveProducts constructor.
28+
*
29+
* @param CollectionFactory $collectionFactory
30+
*/
31+
public function __construct(CollectionFactory $collectionFactory)
32+
{
33+
$this->collectionFactory = $collectionFactory;
34+
}
35+
36+
/**
37+
* Delete related to specific attribute set products, if attribute set was removed successfully.
38+
*
39+
* @param AttributeSetRepositoryInterface $subject
40+
* @param bool $result
41+
* @param AttributeSetInterface $attributeSet
42+
* @return bool
43+
*
44+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
45+
*/
46+
public function afterDelete(
47+
AttributeSetRepositoryInterface $subject,
48+
bool $result,
49+
AttributeSetInterface $attributeSet
50+
) {
51+
/** @var Collection $productCollection */
52+
$productCollection = $this->collectionFactory->create();
53+
$productCollection->addFieldToFilter('attribute_set_id', ['eq' => $attributeSet->getId()]);
54+
$productCollection->delete();
55+
56+
return $result;
57+
}
58+
}

app/code/Magento/Catalog/Setup/UpgradeSchema.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class UpgradeSchema implements UpgradeSchemaInterface
2121
/**
2222
* {@inheritdoc}
2323
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
24+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
25+
* @SuppressWarnings(PHPMD.NPathComplexity)
2426
*/
2527
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
2628
{
@@ -126,6 +128,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
126128
$this->fixCustomerGroupIdColumn($setup);
127129
}
128130

131+
if (version_compare($context->getVersion(), '2.2.4', '<')) {
132+
$this->removeAttributeSetRelation($setup);
133+
}
134+
129135
$setup->endSetup();
130136
}
131137

@@ -699,4 +705,20 @@ private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $r
699705
);
700706
$setup->getConnection()->query($sql);
701707
}
708+
709+
/**
710+
* Remove foreign key between catalog_product_entity and eav_attribute_set tables.
711+
* Drop foreign key to delegate cascade on delete to plugin.
712+
* @see \Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts
713+
*
714+
* @param SchemaSetupInterface $setup
715+
* @return void
716+
*/
717+
private function removeAttributeSetRelation(SchemaSetupInterface $setup)
718+
{
719+
$setup->getConnection()->dropForeignKey(
720+
$setup->getTable('catalog_product_entity'),
721+
$setup->getFkName('catalog_product_entity', 'attribute_set_id', 'eav_attribute_set', 'attribute_set_id')
722+
);
723+
}
702724
}

app/code/Magento/Catalog/Test/Unit/Model/CategoryRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ public function testSaveWithException()
255255
*/
256256
public function testSaveWithValidateCategoryException($error, $expectedException, $expectedExceptionMessage)
257257
{
258-
$this->expectException($expectedException, $expectedExceptionMessage);
258+
$this->expectException($expectedException);
259+
$this->expectExceptionMessage($expectedExceptionMessage);
259260
$categoryId = 5;
260261
$categoryMock = $this->createMock(\Magento\Catalog\Model\Category::class);
261262
$this->extensibleDataObjectConverterMock

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public function testExecuteWithAdapterErrorThrowsException()
4848
$tableSwitcherMock
4949
);
5050

51-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
51+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
52+
$this->expectExceptionMessage($exceptionMessage);
5253

5354
$model->execute();
5455
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Plugin\Model\AttributeSetRepository;
8+
9+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
10+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
11+
use Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts;
12+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
13+
use Magento\Eav\Api\Data\AttributeSetInterface;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Provide tests for RemoveProducts plugin.
19+
*/
20+
class RemoveProductsTest extends TestCase
21+
{
22+
/**
23+
* @var RemoveProducts
24+
*/
25+
private $testSubject;
26+
27+
/**
28+
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $collectionFactory;
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
protected function setUp()
36+
{
37+
$objectManager = new ObjectManager($this);
38+
$this->collectionFactory = $this->getMockBuilder(CollectionFactory::class)
39+
->disableOriginalConstructor()
40+
->setMethods(['create'])
41+
->getMock();
42+
$this->testSubject = $objectManager->getObject(
43+
RemoveProducts::class,
44+
[
45+
'collectionFactory' => $this->collectionFactory,
46+
]
47+
);
48+
}
49+
50+
/**
51+
* Test plugin will delete all related products for given attribute set.
52+
*/
53+
public function testAfterDelete()
54+
{
55+
$attributeSetId = '1';
56+
57+
/** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collection */
58+
$collection = $this->getMockBuilder(Collection::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
$collection->expects(self::once())
62+
->method('addFieldToFilter')
63+
->with(self::identicalTo('attribute_set_id'), self::identicalTo(['eq' => $attributeSetId]));
64+
$collection->expects(self::once())
65+
->method('delete');
66+
67+
$this->collectionFactory->expects(self::once())
68+
->method('create')
69+
->willReturn($collection);
70+
71+
/** @var AttributeSetRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject $attributeSetRepository */
72+
$attributeSetRepository = $this->getMockBuilder(AttributeSetRepositoryInterface::class)
73+
->disableOriginalConstructor()
74+
->getMockForAbstractClass();
75+
76+
/** @var AttributeSetInterface|\PHPUnit_Framework_MockObject_MockObject $attributeSet */
77+
$attributeSet = $this->getMockBuilder(AttributeSetInterface::class)
78+
->setMethods(['getId'])
79+
->disableOriginalConstructor()
80+
->getMockForAbstractClass();
81+
$attributeSet->expects(self::once())
82+
->method('getId')
83+
->willReturn($attributeSetId);
84+
85+
self::assertTrue($this->testSubject->afterDelete($attributeSetRepository, true, $attributeSet));
86+
}
87+
}

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,7 @@
184184
<argument name="scopeOverriddenValue" xsi:type="object">Magento\Catalog\Model\Attribute\ScopeOverriddenValue</argument>
185185
</arguments>
186186
</type>
187+
<type name="Magento\Eav\Api\AttributeSetRepositoryInterface">
188+
<plugin name="remove_products" type="Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts"/>
189+
</type>
187190
</config>

app/code/Magento/Catalog/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Catalog" setup_version="2.2.3">
9+
<module name="Magento_Catalog" setup_version="2.2.4">
1010
<sequence>
1111
<module name="Magento_Eav"/>
1212
<module name="Magento_Cms"/>

app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/FullTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function testExecuteWithAdapterErrorThrowsException()
4444
]
4545
);
4646

47-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
47+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
48+
$this->expectExceptionMessage($exceptionMessage);
4849

4950
$model->execute();
5051
}

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/RegexceptionsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public function testRenderCellTemplateWrongColumnName()
128128

129129
$this->object->addColumn($wrongColumnName, $this->cellParameters);
130130

131-
$this->expectException('\Exception', 'Wrong column name specified.');
131+
$this->expectException('\Exception');
132+
$this->expectExceptionMessage('Wrong column name specified.');
132133

133134
$this->object->renderCellTemplate($columnName);
134135
}

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ProcessorFacadeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ public function testProcess()
132132
*/
133133
public function testProcessWithValidatorException(LocalizedException $exception)
134134
{
135-
$this->expectException(ValidatorException::class, 'Some error');
135+
$this->expectException(ValidatorException::class);
136+
$this->expectExceptionMessage('Some error');
136137
$this->scopeValidatorMock->expects($this->once())
137138
->method('isValid')
138139
->willThrowException($exception);

app/code/Magento/Config/Test/Unit/Model/Config/Structure/Mapper/Helper/RelativePathConverterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public function testConvertWithInvalidRelativePath()
2424

2525
$exceptionMessage = sprintf('Invalid relative path %s in %s node', $relativePath, $nodePath);
2626

27-
$this->expectException('InvalidArgumentException', $exceptionMessage);
27+
$this->expectException('InvalidArgumentException');
28+
$this->expectExceptionMessage($exceptionMessage);
2829
$this->_sut->convert($nodePath, $relativePath);
2930
}
3031

@@ -35,7 +36,8 @@ public function testConvertWithInvalidRelativePath()
3536
*/
3637
public function testConvertWithInvalidArguments($nodePath, $relativePath)
3738
{
38-
$this->expectException('InvalidArgumentException', 'Invalid arguments');
39+
$this->expectException('InvalidArgumentException');
40+
$this->expectExceptionMessage('Invalid arguments');
3941
$this->_sut->convert($nodePath, $relativePath);
4042
}
4143

app/code/Magento/Config/Test/Unit/Model/ConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ public function testSetDataByPathEmpty()
280280
public function testSetDataByPathWrongDepth($path, $expectedException)
281281
{
282282
$expectedException = 'Allowed depth of configuration is 3 (<section>/<group>/<field>). ' . $expectedException;
283-
$this->expectException('\UnexpectedValueException', $expectedException);
283+
$this->expectException('\UnexpectedValueException');
284+
$this->expectExceptionMessage($expectedException);
284285
$value = 'value';
285286
$this->_model->setDataByPath($path, $value);
286287
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/OptionRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ public function testGetListNotConfigurableProduct()
356356
*/
357357
public function testValidateNewOptionData($attributeId, $label, $optionValues, $msg)
358358
{
359-
$this->expectException(\Magento\Framework\Exception\InputException::class, $msg);
359+
$this->expectException(\Magento\Framework\Exception\InputException::class);
360+
$this->expectExceptionMessage($msg);
360361
$optionValueMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\OptionValueInterface::class)
361362
->setMethods(['getValueIndex', 'getPricingValue', 'getIsPercent'])
362363
->getMockForAbstractClass();

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Cache/Tag/ConfigurableTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ protected function setUp()
3232

3333
public function testGetWithScalar()
3434
{
35-
$this->expectException(\InvalidArgumentException::class, 'Provided argument is not an object');
35+
$this->expectException(\InvalidArgumentException::class);
36+
$this->expectExceptionMessage('Provided argument is not an object');
3637
$this->model->getTags('scalar');
3738
}
3839

3940
public function testGetTagsWithObject()
4041
{
41-
$this->expectException(\InvalidArgumentException::class, 'Provided argument must be a product');
42+
$this->expectException(\InvalidArgumentException::class);
43+
$this->expectExceptionMessage('Provided argument must be a product');
4244
$this->model->getTags(new \stdClass());
4345
}
4446

app/code/Magento/Customer/Model/FileProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function moveTemporaryFile($fileName)
202202
{
203203
$fileName = ltrim($fileName, '/');
204204

205-
$dispersionPath = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
205+
$dispersionPath = \Magento\MediaStorage\Model\File\Uploader::getDispersionPath($fileName);
206206
$destinationPath = $this->entityTypeCode . $dispersionPath;
207207

208208
if (!$this->mediaDirectory->create($destinationPath)) {

app/code/Magento/Customer/Test/Unit/Model/LoggerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public function testLog($customerId, $data)
7171
$data = array_filter($data);
7272

7373
if (!$data) {
74-
$this->expectException('\InvalidArgumentException', 'Log data is empty');
74+
$this->expectException('\InvalidArgumentException');
75+
$this->expectExceptionMessage('Log data is empty');
7576
$this->logger->log($customerId, $data);
7677
return;
7778
}

app/code/Magento/Directory/Test/Unit/Model/Currency/Import/ConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ protected function setUp()
2929
*/
3030
public function testConstructorException(array $configData, $expectedException)
3131
{
32-
$this->expectException('InvalidArgumentException', $expectedException);
32+
$this->expectException('InvalidArgumentException');
33+
$this->expectExceptionMessage($expectedException);
3334
new \Magento\Directory\Model\Currency\Import\Config($configData);
3435
}
3536

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function testValidateWithExistingName($attributeSetName, $exceptionMessag
4444
{
4545
$this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(false));
4646

47-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
47+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
48+
$this->expectExceptionMessage($exceptionMessage);
4849
$this->_model->setAttributeSetName($attributeSetName);
4950
$this->_model->validate();
5051
}

app/code/Magento/Email/Test/Unit/Model/Template/ConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ public function testGetterMethodUnknownField(
311311
array $fixtureFields = [],
312312
$argument = null
313313
) {
314-
$this->expectException('UnexpectedValueException', $expectedException);
314+
$this->expectException('UnexpectedValueException');
315+
$this->expectExceptionMessage($expectedException);
315316
$dataStorage = $this->createPartialMock(\Magento\Email\Model\Template\Config\Data::class, ['get']);
316317
$dataStorage->expects(
317318
$this->atLeastOnce()

0 commit comments

Comments
 (0)