From 0e60eac1103a4551379fc3548c09a6461834bb7e Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Wed, 9 Aug 2017 15:57:29 +0300 Subject: [PATCH 1/2] MAGETWO-71431: ImportProductsTest random failures --- .../Test/TestCase/ImportProductsTest.xml | 12 +++++ .../CatalogImportExport/Test/etc/testcase.xml | 3 +- .../Indexer/Test/TestStep/ReindexStep.php | 50 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 dev/tests/functional/tests/app/Magento/Indexer/Test/TestStep/ReindexStep.php diff --git a/dev/tests/functional/tests/app/Magento/CatalogImportExport/Test/TestCase/ImportProductsTest.xml b/dev/tests/functional/tests/app/Magento/CatalogImportExport/Test/TestCase/ImportProductsTest.xml index cb29537c8dea0..2c7f6665df0aa 100644 --- a/dev/tests/functional/tests/app/Magento/CatalogImportExport/Test/TestCase/ImportProductsTest.xml +++ b/dev/tests/functional/tests/app/Magento/CatalogImportExport/Test/TestCase/ImportProductsTest.xml @@ -29,6 +29,10 @@ + + catalog_category_product + catalog_product_category + @@ -45,6 +49,10 @@ 4 catalogProductSimple::default_in_custom_website catalogProductSimple::default + + catalog_category_product + catalog_product_category + @@ -60,6 +68,10 @@ 7 7 catalogProductSimple::default_in_custom_website + + catalog_category_product + catalog_product_category + diff --git a/dev/tests/functional/tests/app/Magento/CatalogImportExport/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/CatalogImportExport/Test/etc/testcase.xml index 3438787d668f7..be8bf8b89dd16 100644 --- a/dev/tests/functional/tests/app/Magento/CatalogImportExport/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/CatalogImportExport/Test/etc/testcase.xml @@ -11,6 +11,7 @@ - + + diff --git a/dev/tests/functional/tests/app/Magento/Indexer/Test/TestStep/ReindexStep.php b/dev/tests/functional/tests/app/Magento/Indexer/Test/TestStep/ReindexStep.php new file mode 100644 index 0000000000000..1a3cb4a034765 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Indexer/Test/TestStep/ReindexStep.php @@ -0,0 +1,50 @@ +indexer = $indexer; + $this->indexerType = $indexerType; + } + + /** + * Run reindex process. + * All indexers will be refreshed in a case of empty $indexerType array. + * + * @return void + */ + public function run() + { + $this->indexer->reindex($this->indexerType); + } +} From 869b246a126fec8b209fea0a0df1ddf0c54a5d6d Mon Sep 17 00:00:00 2001 From: Iryna Lagno Date: Wed, 9 Aug 2017 12:20:45 +0300 Subject: [PATCH 2/2] MAGETWO-71385: Remove Deprecated AroundProductRepositorySave Plugin --- .../Catalog/Model/ProductRepository.php | 2 +- .../Test/Unit/Model/ProductRepositoryTest.php | 3 +- .../Plugin/AroundProductRepositorySave.php | 44 --- .../AroundProductRepositorySaveTest.php | 351 ------------------ app/code/Magento/CatalogInventory/etc/di.xml | 3 - .../Model/Plugin/ProductRepositorySave.php | 4 +- .../Magento/Catalog/Api/CostStorageTest.php | 2 +- .../Api/ProductRepositoryTest.php | 1 + 8 files changed, 7 insertions(+), 403 deletions(-) delete mode 100644 app/code/Magento/CatalogInventory/Model/Plugin/AroundProductRepositorySave.php delete mode 100644 app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php diff --git a/app/code/Magento/Catalog/Model/ProductRepository.php b/app/code/Magento/Catalog/Model/ProductRepository.php index aac9ec4807cbf..4a72539e982f2 100644 --- a/app/code/Magento/Catalog/Model/ProductRepository.php +++ b/app/code/Magento/Catalog/Model/ProductRepository.php @@ -641,7 +641,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO } unset($this->instances[$product->getSku()]); unset($this->instancesById[$product->getId()]); - return $this->get($product->getSku()); + return $this->get($product->getSku(), false, $product->getStoreId()); } /** diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php index 44d38adc5c15c..b537e2c406cab 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php @@ -193,7 +193,8 @@ protected function setUp() 'validate', 'save', 'getMediaGalleryEntries', - 'setData' + 'setData', + 'getStoreId' ]); $this->initializedProductMock->expects($this->any()) ->method('hasGalleryAttribute') diff --git a/app/code/Magento/CatalogInventory/Model/Plugin/AroundProductRepositorySave.php b/app/code/Magento/CatalogInventory/Model/Plugin/AroundProductRepositorySave.php deleted file mode 100644 index d8378556ec3c2..0000000000000 --- a/app/code/Magento/CatalogInventory/Model/Plugin/AroundProductRepositorySave.php +++ /dev/null @@ -1,44 +0,0 @@ -get($product->getSku(), false, $product->getStoreId()); - } -} diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php deleted file mode 100644 index 049313a9a3108..0000000000000 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AroundProductRepositorySaveTest.php +++ /dev/null @@ -1,351 +0,0 @@ -markTestSkipped('Test needs to be refactored.'); - $this->stockRegistry = $this->getMockBuilder(StockRegistryInterface::class) - ->setMethods(['getStockItem', 'updateStockItemBySku']) - ->getMockForAbstractClass(); - $this->storeManager = $this->getMockBuilder(StoreManagerInterface::class) - ->getMockForAbstractClass(); - $this->stockConfiguration = $this->getMockBuilder(StockConfigurationInterface::class) - ->setMethods(['getDefaultScopeId']) - ->getMockForAbstractClass(); - - $this->plugin = new AroundProductRepositorySave( - $this->stockRegistry, - $this->storeManager, - $this->stockConfiguration - ); - - $this->savedProduct = $this->getMockBuilder(ProductInterface::class) - ->setMethods(['getExtensionAttributes', 'getStoreId']) - ->getMockForAbstractClass(); - - $this->productRepository = $this->getMockBuilder(ProductRepositoryInterface::class) - ->setMethods(['get']) - ->getMockForAbstractClass(); - $this->product = $this->getMockBuilder(ProductInterface::class) - ->setMethods(['getExtensionAttributes', 'getStoreId']) - ->getMockForAbstractClass(); - $this->productExtension = $this->getMockForAbstractClass( - ProductExtensionInterface::class, - [], - '', - false, - false, - true, - ['getStockItem'] - ); - $this->stockItem = $this->getMockBuilder(StockItemInterface::class) - ->setMethods(['setWebsiteId', 'getWebsiteId', 'getStockId']) - ->getMockForAbstractClass(); - $this->defaultStock = $this->getMockBuilder(StockInterface::class) - ->setMethods(['getStockId']) - ->getMockForAbstractClass(); - } - - public function testAfterSaveWhenProductHasNoStockItemNeedingToBeUpdated() - { - // pretend we have no extension attributes at all - $this->product->expects($this->once()) - ->method('getExtensionAttributes') - ->willReturn(null); - $this->productExtension->expects($this->never())->method('getStockItem'); - - // pretend that the product already has existing stock item information - $this->stockRegistry->expects($this->once())->method('getStockItem')->willReturn($this->stockItem); - $this->stockItem->expects($this->once())->method('getItemId')->willReturn(1); - $this->stockItem->expects($this->never())->method('setProductId'); - $this->stockItem->expects($this->never())->method('setWebsiteId'); - - // expect that there are no changes to the existing stock item information - $result = $this->plugin->afterSave($this->productRepository, $this->savedProduct, $this->product); - $this->assertEquals( - $this->savedProduct, - $result - ); - } - - public function testAfterSaveWhenProductHasNoPersistentStockItemInfo() - { - // pretend we do have extension attributes, but none for 'stock_item' - $this->product->expects($this->once()) - ->method('getExtensionAttributes') - ->willReturn($this->productExtension); - $this->productExtension->expects($this->once()) - ->method('getStockItem') - ->willReturn(null); - - $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn(1); - $this->stockRegistry->expects($this->once())->method('getStockItem')->willReturn($this->stockItem); - $this->stockRegistry->expects($this->once())->method('updateStockItemBySku'); - - $this->stockItem->expects($this->once())->method('getItemId')->willReturn(null); - $this->stockItem->expects($this->once())->method('setProductId'); - $this->stockItem->expects($this->once())->method('setWebsiteId'); - $this->product->expects(($this->atLeastOnce()))->method('getStoreId')->willReturn(20); - - $newProductMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class) - ->disableOriginalConstructor()->getMock(); - $this->productRepository->expects($this->once())->method('get')->willReturn($newProductMock); - - $this->assertEquals( - $newProductMock, - $this->plugin->afterSave($this->productRepository, $this->savedProduct, $this->product) - ); - } - - public function testAfterSave() - { - $productId = 5494; - $storeId = 2; - $sku = 'my product that needs saving'; - $defaultScopeId = 100; - $this->stockConfiguration->expects($this->exactly(2)) - ->method('getDefaultScopeId') - ->willReturn($defaultScopeId); - $this->stockRegistry->expects($this->once()) - ->method('getStock') - ->with($defaultScopeId) - ->willReturn($this->defaultStock); - - $this->product->expects($this->once()) - ->method('getExtensionAttributes') - ->willReturn($this->productExtension); - $this->productExtension->expects($this->once()) - ->method('getStockItem') - ->willReturn($this->stockItem); - - $storedStockItem = $this->getMockBuilder(StockItemInterface::class) - ->setMethods(['getItemId']) - ->getMockForAbstractClass(); - $storedStockItem->expects($this->once()) - ->method('getItemId') - ->willReturn(500); - $this->stockRegistry->expects($this->once()) - ->method('getStockItem') - ->willReturn($storedStockItem); - - $this->product->expects(($this->exactly(2)))->method('getId')->willReturn($productId); - $this->product->expects(($this->atLeastOnce()))->method('getStoreId')->willReturn($storeId); - $this->product->expects($this->atLeastOnce())->method('getSku')->willReturn($sku); - - $this->stockItem->expects($this->once())->method('setProductId')->with($productId); - $this->stockItem->expects($this->once())->method('setWebsiteId')->with($defaultScopeId); - - $this->stockRegistry->expects($this->once()) - ->method('updateStockItemBySku') - ->with($sku, $this->stockItem); - - $newProductMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class) - ->disableOriginalConstructor()->getMock(); - $this->productRepository->expects($this->once()) - ->method('get') - ->with($sku, false, $storeId, true) - ->willReturn($newProductMock); - - $this->assertEquals( - $newProductMock, - $this->plugin->afterSave($this->productRepository, $this->savedProduct, $this->product) - ); - } - - /** - * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Invalid stock id: 100500. Only default stock with id 50 allowed - */ - public function testAfterSaveWithInvalidStockId() - { - $stockId = 100500; - $defaultScopeId = 100; - $defaultStockId = 50; - - $this->stockItem->expects($this->once()) - ->method('getStockId') - ->willReturn($stockId); - $this->stockRegistry->expects($this->once()) - ->method('getStock') - ->with($defaultScopeId) - ->willReturn($this->defaultStock); - $this->stockConfiguration->expects($this->once()) - ->method('getDefaultScopeId') - ->willReturn($defaultScopeId); - $this->defaultStock->expects($this->once()) - ->method('getStockId') - ->willReturn($defaultStockId); - - $this->product->expects($this->once()) - ->method('getExtensionAttributes') - ->willReturn($this->productExtension); - $this->productExtension->expects($this->once()) - ->method('getStockItem') - ->willReturn($this->stockItem); - - $this->plugin->afterSave($this->productRepository, $this->savedProduct, $this->product); - } - - /** - * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Invalid stock item id: 0. Should be null or numeric value greater than 0 - */ - public function testAfterSaveWithInvalidStockItemId() - { - $stockId = 80; - $stockItemId = 0; - $defaultScopeId = 100; - $defaultStockId = 80; - - $this->stockItem->expects($this->once()) - ->method('getStockId') - ->willReturn($stockId); - $this->stockRegistry->expects($this->once()) - ->method('getStock') - ->with($defaultScopeId) - ->willReturn($this->defaultStock); - $this->stockConfiguration->expects($this->once()) - ->method('getDefaultScopeId') - ->willReturn($defaultScopeId); - $this->defaultStock->expects($this->once()) - ->method('getStockId') - ->willReturn($defaultStockId); - - $this->product->expects($this->once()) - ->method('getExtensionAttributes') - ->willReturn($this->productExtension); - $this->productExtension->expects($this->once()) - ->method('getStockItem') - ->willReturn($this->stockItem); - - $this->stockItem->expects($this->once()) - ->method('getItemId') - ->willReturn($stockItemId); - - $this->plugin->afterSave($this->productRepository, $this->savedProduct, $this->product); - } - - /** - * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Invalid stock item id: 35. Assigned stock item id is 40 - */ - public function testAfterSaveWithNotAssignedStockItemId() - { - $stockId = 80; - $stockItemId = 35; - $defaultScopeId = 100; - $defaultStockId = 80; - $storedStockitemId = 40; - - $this->stockItem->expects($this->once()) - ->method('getStockId') - ->willReturn($stockId); - $this->stockRegistry->expects($this->once()) - ->method('getStock') - ->with($defaultScopeId) - ->willReturn($this->defaultStock); - $this->stockConfiguration->expects($this->once()) - ->method('getDefaultScopeId') - ->willReturn($defaultScopeId); - $this->defaultStock->expects($this->once()) - ->method('getStockId') - ->willReturn($defaultStockId); - - $this->product->expects($this->once()) - ->method('getExtensionAttributes') - ->willReturn($this->productExtension); - $this->productExtension->expects($this->once()) - ->method('getStockItem') - ->willReturn($this->stockItem); - - $this->stockItem->expects($this->once()) - ->method('getItemId') - ->willReturn($stockItemId); - - $storedStockItem = $this->getMockBuilder(StockItemInterface::class) - ->setMethods(['getItemId']) - ->getMockForAbstractClass(); - $storedStockItem->expects($this->once()) - ->method('getItemId') - ->willReturn($storedStockitemId); - $this->stockRegistry->expects($this->once()) - ->method('getStockItem') - ->willReturn($storedStockItem); - - $this->plugin->afterSave($this->productRepository, $this->savedProduct, $this->product); - } -} diff --git a/app/code/Magento/CatalogInventory/etc/di.xml b/app/code/Magento/CatalogInventory/etc/di.xml index e62470b3ae0fb..2f64d71595c86 100644 --- a/app/code/Magento/CatalogInventory/etc/di.xml +++ b/app/code/Magento/CatalogInventory/etc/di.xml @@ -71,9 +71,6 @@ - - - Magento\CatalogInventory\Model\Indexer\Stock\Processor diff --git a/app/code/Magento/ConfigurableProduct/Model/Plugin/ProductRepositorySave.php b/app/code/Magento/ConfigurableProduct/Model/Plugin/ProductRepositorySave.php index f6b2623cd9f32..62146a4b343ed 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Plugin/ProductRepositorySave.php +++ b/app/code/Magento/ConfigurableProduct/Model/Plugin/ProductRepositorySave.php @@ -85,9 +85,9 @@ public function afterSave( $attributeCodes[] = $attributeCode; } $this->validateProductLinks($attributeCodes, $configurableLinks); - $product->getTypeInstance()->resetConfigurableAttributes($product); + $result->getTypeInstance()->resetConfigurableAttributes($product); - return $product; + return $result; } /** diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CostStorageTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CostStorageTest.php index 7cdcf1f0e73ab..0316010b6ec1c 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CostStorageTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CostStorageTest.php @@ -49,7 +49,7 @@ public function testGet() 'soap' => [ 'service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, - 'operation' => self::SERVICE_NAME . 'Delete', + 'operation' => self::SERVICE_NAME . 'Get', ], ]; $response = $this->_webApiCall($serviceInfo, ['skus' => [self::SIMPLE_PRODUCT_SKU]]); diff --git a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php index 6444a857da748..37bdd24e05d92 100644 --- a/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/ProductRepositoryTest.php @@ -265,6 +265,7 @@ public function testUpdateConfigurableProductLinks() ]; $response = $this->saveProduct($response); + $currentOptions = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options']; $this->assertEquals($options, $currentOptions);