Skip to content

Commit

Permalink
Merge pull request #1808 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
[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
ishakhsuvarov authored Dec 7, 2017
2 parents 276c690 + 18a568a commit 321278b
Show file tree
Hide file tree
Showing 100 changed files with 877 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function testBeforeSave($value, $errorMessage = null)
\Magento\Backend\Model\Config\SessionLifetime\BackendModel::class
);
if ($errorMessage !== null) {
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $errorMessage);
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage($errorMessage);
}
$model->setValue($value);
$object = $model->beforeSave();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function addImage(
}

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

$fileName = $this->getNotDuplicatedFilename($fileName, $dispretionPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function validate($processingParams, $option)
$extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);

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

$filePath = $dispersion;

Expand Down
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;
}
}
22 changes: 22 additions & 0 deletions app/code/Magento/Catalog/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class UpgradeSchema implements UpgradeSchemaInterface
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
Expand Down Expand Up @@ -126,6 +128,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
$this->fixCustomerGroupIdColumn($setup);
}

if (version_compare($context->getVersion(), '2.2.4', '<')) {
$this->removeAttributeSetRelation($setup);
}

$setup->endSetup();
}

Expand Down Expand Up @@ -699,4 +705,20 @@ private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $r
);
$setup->getConnection()->query($sql);
}

/**
* Remove foreign key between catalog_product_entity and eav_attribute_set tables.
* Drop foreign key to delegate cascade on delete to plugin.
* @see \Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts
*
* @param SchemaSetupInterface $setup
* @return void
*/
private function removeAttributeSetRelation(SchemaSetupInterface $setup)
{
$setup->getConnection()->dropForeignKey(
$setup->getTable('catalog_product_entity'),
$setup->getFkName('catalog_product_entity', 'attribute_set_id', 'eav_attribute_set', 'attribute_set_id')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ public function testSaveWithException()
*/
public function testSaveWithValidateCategoryException($error, $expectedException, $expectedExceptionMessage)
{
$this->expectException($expectedException, $expectedExceptionMessage);
$this->expectException($expectedException);
$this->expectExceptionMessage($expectedExceptionMessage);
$categoryId = 5;
$categoryMock = $this->createMock(\Magento\Catalog\Model\Category::class);
$this->extensibleDataObjectConverterMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function testExecuteWithAdapterErrorThrowsException()
$tableSwitcherMock
);

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

$model->execute();
}
Expand Down
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));
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,7 @@
<argument name="scopeOverriddenValue" xsi:type="object">Magento\Catalog\Model\Attribute\ScopeOverriddenValue</argument>
</arguments>
</type>
<type name="Magento\Eav\Api\AttributeSetRepositoryInterface">
<plugin name="remove_products" type="Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts"/>
</type>
</config>
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Catalog" setup_version="2.2.3">
<module name="Magento_Catalog" setup_version="2.2.4">
<sequence>
<module name="Magento_Eav"/>
<module name="Magento_Cms"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function testExecuteWithAdapterErrorThrowsException()
]
);

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

$model->execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public function testRenderCellTemplateWrongColumnName()

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

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

$this->object->renderCellTemplate($columnName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public function testProcess()
*/
public function testProcessWithValidatorException(LocalizedException $exception)
{
$this->expectException(ValidatorException::class, 'Some error');
$this->expectException(ValidatorException::class);
$this->expectExceptionMessage('Some error');
$this->scopeValidatorMock->expects($this->once())
->method('isValid')
->willThrowException($exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function testConvertWithInvalidRelativePath()

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

$this->expectException('InvalidArgumentException', $exceptionMessage);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage($exceptionMessage);
$this->_sut->convert($nodePath, $relativePath);
}

Expand All @@ -35,7 +36,8 @@ public function testConvertWithInvalidRelativePath()
*/
public function testConvertWithInvalidArguments($nodePath, $relativePath)
{
$this->expectException('InvalidArgumentException', 'Invalid arguments');
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid arguments');
$this->_sut->convert($nodePath, $relativePath);
}

Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Config/Test/Unit/Model/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ public function testSetDataByPathEmpty()
public function testSetDataByPathWrongDepth($path, $expectedException)
{
$expectedException = 'Allowed depth of configuration is 3 (<section>/<group>/<field>). ' . $expectedException;
$this->expectException('\UnexpectedValueException', $expectedException);
$this->expectException('\UnexpectedValueException');
$this->expectExceptionMessage($expectedException);
$value = 'value';
$this->_model->setDataByPath($path, $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ public function testGetListNotConfigurableProduct()
*/
public function testValidateNewOptionData($attributeId, $label, $optionValues, $msg)
{
$this->expectException(\Magento\Framework\Exception\InputException::class, $msg);
$this->expectException(\Magento\Framework\Exception\InputException::class);
$this->expectExceptionMessage($msg);
$optionValueMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\OptionValueInterface::class)
->setMethods(['getValueIndex', 'getPricingValue', 'getIsPercent'])
->getMockForAbstractClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ protected function setUp()

public function testGetWithScalar()
{
$this->expectException(\InvalidArgumentException::class, 'Provided argument is not an object');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Provided argument is not an object');
$this->model->getTags('scalar');
}

public function testGetTagsWithObject()
{
$this->expectException(\InvalidArgumentException::class, 'Provided argument must be a product');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Provided argument must be a product');
$this->model->getTags(new \stdClass());
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Model/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function moveTemporaryFile($fileName)
{
$fileName = ltrim($fileName, '/');

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

if (!$this->mediaDirectory->create($destinationPath)) {
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Customer/Test/Unit/Model/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function testLog($customerId, $data)
$data = array_filter($data);

if (!$data) {
$this->expectException('\InvalidArgumentException', 'Log data is empty');
$this->expectException('\InvalidArgumentException');
$this->expectExceptionMessage('Log data is empty');
$this->logger->log($customerId, $data);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ protected function setUp()
*/
public function testConstructorException(array $configData, $expectedException)
{
$this->expectException('InvalidArgumentException', $expectedException);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage($expectedException);
new \Magento\Directory\Model\Currency\Import\Config($configData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function testValidateWithExistingName($attributeSetName, $exceptionMessag
{
$this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(false));

$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage($exceptionMessage);
$this->_model->setAttributeSetName($attributeSetName);
$this->_model->validate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ public function testGetterMethodUnknownField(
array $fixtureFields = [],
$argument = null
) {
$this->expectException('UnexpectedValueException', $expectedException);
$this->expectException('UnexpectedValueException');
$this->expectExceptionMessage($expectedException);
$dataStorage = $this->createPartialMock(\Magento\Email\Model\Template\Config\Data::class, ['get']);
$dataStorage->expects(
$this->atLeastOnce()
Expand Down
Loading

0 comments on commit 321278b

Please sign in to comment.