/** * @param string $behavior * @param array $attrParams * @param array $rowData * @param bool $isValid * @param string $attrCode * @dataProvider attributeValidationProvider */ public function testAttributeValidation($behavior, $attrParams, $rowData, $isValid, $attrCode = 'attribute_code') { $this->context->expects($this->any())->method('getBehavior')->willReturn($behavior); $result = $this->validator->isAttributeValid($attrCode, $attrParams, $rowData); $this->assertEquals($isValid, $result); if (!$isValid) { $this->assertTrue($this->validator->hasMessages()); } }
/** * Test for afterImportData() * Covers afterImportData() + protected methods used inside except related to generateUrls() ones. * generateUrls will be covered separately. * * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::afterImportData * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::_populateForUrlGeneration * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::isGlobalScope * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::populateGlobalProduct * @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::addProductToImport * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testAfterImportData() { $newSku = ['entity_id' => 'value']; $websiteId = 'websiteId value'; $productsCount = count($this->products); $websiteMock = $this->getMock('\\Magento\\Store\\Model\\Website', ['getStoreIds'], [], '', false); $storeIds = [1, Store::DEFAULT_STORE_ID]; $websiteMock->expects($this->once())->method('getStoreIds')->willReturn($storeIds); $this->storeManager->expects($this->once())->method('getWebsite')->with($websiteId)->willReturn($websiteMock); $this->importProduct->expects($this->exactly($productsCount))->method('getNewSku')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]])->willReturn($newSku); $this->importProduct->expects($this->exactly($productsCount))->method('getProductCategories')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]]); $getProductWebsitesCallsCount = $productsCount * 2; $this->importProduct->expects($this->exactly($getProductWebsitesCallsCount))->method('getProductWebsites')->willReturn([$newSku['entity_id'] => $websiteId]); $map = [[$this->products[0][ImportProduct::COL_STORE], $this->products[0][ImportProduct::COL_STORE]], [$this->products[1][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]]]; $this->importProduct->expects($this->exactly(1))->method('getStoreIdByCode')->will($this->returnValueMap($map)); $product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'setId', 'getSku', 'setStoreId', 'getStoreId'], [], '', false); $product->expects($this->exactly($productsCount))->method('setId')->with($newSku['entity_id']); $product->expects($this->any())->method('getId')->willReturn($newSku['entity_id']); $product->expects($this->exactly($productsCount))->method('getSku')->will($this->onConsecutiveCalls($this->products[0]['sku'], $this->products[1]['sku'])); $product->expects($this->exactly($productsCount))->method('getStoreId')->will($this->onConsecutiveCalls($this->products[0][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE])); $product->expects($this->once())->method('setStoreId')->with($this->products[1][ImportProduct::COL_STORE]); $this->catalogProductFactory->expects($this->exactly($productsCount))->method('create')->willReturn($product); $this->connection->expects($this->exactly(4))->method('quoteInto')->withConsecutive(['(store_id = ?', $storeIds[0]], [' AND entity_id = ?)', $newSku['entity_id']]); $productUrls = ['url 1', 'url 2']; $importMock = $this->getImportMock(['generateUrls', 'canonicalUrlRewriteGenerate', 'categoriesUrlRewriteGenerate', 'currentUrlRewritesRegenerate', 'cleanOverriddenUrlKey']); $importMock->expects($this->once())->method('generateUrls')->willReturn($productUrls); $this->urlPersist->expects($this->once())->method('replace')->with($productUrls); $importMock->afterImportData($this->observer); }
public function testIsRowValidError() { $rowData = ['_attribute_set' => 'attribute_set_name']; $rowNum = 1; $this->entityModel->expects($this->any())->method('getRowScope')->willReturn(1); $this->entityModel->expects($this->once())->method('addRowError')->with(\Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface::ERROR_VALUE_IS_REQUIRED, 1, 'attr_code')->willReturnSelf(); $this->assertFalse($this->simpleType->isRowValid($rowData, $rowNum)); }
/** * @dataProvider dataForUploaderDir */ public function testSetUploaderDirFalse($newSku, $bunch, $allowImport) { $this->connectionMock->expects($this->any())->method('fetchAll')->with($this->select)->willReturnOnConsecutiveCalls([['attribute_set_name' => '1', 'attribute_id' => '1'], ['attribute_set_name' => '2', 'attribute_id' => '2']]); $this->downloadableModelMock = $this->objectManagerHelper->getObject('\\Magento\\DownloadableImportExport\\Model\\Import\\Product\\Type\\Downloadable', ['attrSetColFac' => $this->attrSetColFacMock, 'prodAttrColFac' => $this->prodAttrColFacMock, 'resource' => $this->resourceMock, 'params' => $this->paramsArray, 'uploaderHelper' => $this->uploaderHelper, 'downloadableHelper' => $this->downloadableHelper]); $this->entityModelMock->expects($this->once())->method('getNewSku')->will($this->returnValue($newSku)); $this->entityModelMock->expects($this->at(1))->method('getNextBunch')->will($this->returnValue($bunch)); $this->entityModelMock->expects($this->at(2))->method('getNextBunch')->will($this->returnValue(null)); $this->entityModelMock->expects($this->any())->method('isRowAllowedToImport')->willReturn($allowImport); $exception = new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Error')); $this->setExpectedException('\\Magento\\Framework\\Exception\\LocalizedException'); $this->setExpectedException('\\Exception'); $this->uploaderMock->expects($this->any())->method('move')->will($this->throwException($exception)); $this->downloadableModelMock->saveData(); }
public function testSaveData() { $this->_entityModel->expects($this->any())->method('getNewSku')->will($this->returnValue(['configurableskuI22' => ['entity_id' => 1, 'type_id' => 'configurable', 'attr_set_code' => 'Default'], 'testconf2-attr2val1-testattr3v1' => ['entity_id' => 2, 'type_id' => 'simple', 'attr_set_code' => 'Default'], 'testconf2-attr2val1-testattr30v1' => ['entity_id' => 20, 'type_id' => 'simple', 'attr_set_code' => 'Default'], 'testconf2-attr2val1-testattr3v2' => ['entity_id' => 3, 'type_id' => 'simple', 'attr_set_code' => 'Default'], 'testSimple' => ['entity_id' => 4, 'type_id' => 'simple', 'attr_set_code' => 'Default'], 'testSimpleToSkip' => ['entity_id' => 5, 'type_id' => 'simple', 'attr_set_code' => 'Default'], 'configurableskuI22withoutLabels' => ['entity_id' => 6, 'type_id' => 'configurable', 'attr_set_code' => 'Default'], 'configurableskuI22withoutVariations' => ['entity_id' => 7, 'type_id' => 'configurable', 'attr_set_code' => 'Default'], 'configurableskuI22Duplicated' => ['entity_id' => 8, 'type_id' => 'configurable', 'attr_set_code' => 'Default'], 'configurableskuI22BadPrice' => ['entity_id' => 9, 'type_id' => 'configurable', 'attr_set_code' => 'Default']])); $this->_connection->expects($this->any())->method('select')->will($this->returnValue($this->select)); $this->_connection->expects($this->any())->method('fetchAll')->with($this->select)->will($this->returnValue([['attribute_id' => 131, 'product_id' => 1, 'option_id' => 1, 'product_super_attribute_id' => 131], ['attribute_id' => 131, 'product_id' => 2, 'option_id' => 1, 'product_super_attribute_id' => 131], ['attribute_id' => 131, 'product_id' => 2, 'option_id' => 2, 'product_super_attribute_id' => 131], ['attribute_id' => 131, 'product_id' => 2, 'option_id' => 3, 'product_super_attribute_id' => 131], ['attribute_id' => 131, 'product_id' => 20, 'option_id' => 1, 'product_super_attribute_id' => 131], ['attribute_id' => 131, 'product_id' => 20, 'option_id' => 2, 'product_super_attribute_id' => 131], ['attribute_id' => 131, 'product_id' => 20, 'option_id' => 3, 'product_super_attribute_id' => 131], ['attribute_id' => 132, 'product_id' => 1, 'option_id' => 1, 'product_super_attribute_id' => 132], ['attribute_id' => 132, 'product_id' => 1, 'option_id' => 2, 'product_super_attribute_id' => 132], ['attribute_id' => 132, 'product_id' => 1, 'option_id' => 3, 'product_super_attribute_id' => 132], ['attribute_id' => 132, 'product_id' => 1, 'option_id' => 4, 'product_super_attribute_id' => 132], ['attribute_id' => 132, 'product_id' => 1, 'option_id' => 5, 'product_super_attribute_id' => 132], ['attribute_id' => 132, 'product_id' => 1, 'option_id' => 6, 'product_super_attribute_id' => 132], ['attribute_id' => 132, 'product_id' => 3, 'option_id' => 3, 'product_super_attribute_id' => 132], ['attribute_id' => 132, 'product_id' => 4, 'option_id' => 4, 'product_super_attribute_id' => 132], ['attribute_id' => 132, 'product_id' => 5, 'option_id' => 5, 'product_super_attribute_id' => 132]])); $this->_connection->expects($this->any())->method('fetchAll')->with($this->select)->will($this->returnValue([])); $bunch = $this->_getBunch(); $this->_entityModel->expects($this->at(2))->method('getNextBunch')->will($this->returnValue($bunch)); $this->_entityModel->expects($this->at(3))->method('getNextBunch')->will($this->returnValue([])); $this->_entityModel->expects($this->any())->method('isRowAllowedToImport')->will($this->returnCallback([$this, 'isRowAllowedToImport'])); $this->_entityModel->expects($this->any())->method('getOldSku')->will($this->returnValue(['testSimpleOld' => ['entity_id' => 10, 'type_id' => 'simple', 'attr_set_code' => 'Default']])); $this->_entityModel->expects($this->any())->method('getAttrSetIdToName')->willReturn([4 => 'Default']); $this->configurable->saveData(); }
/** * Test saveData() with store row scope */ public function testSaveDataScopeStore() { $this->entityModel->expects($this->once())->method('getNewSku')->will($this->returnValue(['sku_assoc1' => ['entity_id' => 1], 'productSku' => ['entity_id' => 2, 'attr_set_code' => 'Default', 'type_id' => 'grouped']])); $this->entityModel->expects($this->once())->method('getOldSku')->will($this->returnValue(['sku_assoc2' => ['entity_id' => 3]])); $attributes = ['position' => ['id' => 0], 'qty' => ['id' => 0]]; $this->links->expects($this->once())->method('getAttributes')->will($this->returnValue($attributes)); $bunch = [['associated_skus' => 'sku_assoc1=1, sku_assoc2=2', 'sku' => 'productSku', 'product_type' => 'grouped']]; $this->entityModel->expects($this->at(2))->method('getNextBunch')->will($this->returnValue($bunch)); $this->entityModel->expects($this->any())->method('isRowAllowedToImport')->will($this->returnValue(true)); $this->entityModel->expects($this->at(4))->method('getRowScope')->will($this->returnValue(\Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT)); $this->entityModel->expects($this->at(5))->method('getRowScope')->will($this->returnValue(\Magento\CatalogImportExport\Model\Import\Product::SCOPE_STORE)); $this->links->expects($this->once())->method('saveLinksData'); $this->grouped->saveData(); }
/** * Test for afterImportData() * Covers afterImportData() + protected methods used inside * * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::afterImportData * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::_populateForUrlGeneration * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::isGlobalScope * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::populateGlobalProduct * @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::addProductToImport * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testAfterImportData() { $newSku = [['entity_id' => 'value'], ['entity_id' => 'value3']]; $websiteId = 'websiteId value'; $productsCount = count($this->products); $websiteMock = $this->getMock('\\Magento\\Store\\Model\\Website', ['getStoreIds'], [], '', false); $storeIds = [1, Store::DEFAULT_STORE_ID]; $websiteMock->expects($this->once())->method('getStoreIds')->willReturn($storeIds); $this->storeManager->expects($this->once())->method('getWebsite')->with($websiteId)->willReturn($websiteMock); $this->importProduct->expects($this->exactly($productsCount))->method('getNewSku')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]])->will($this->onConsecutiveCalls($newSku[0], $newSku[1])); $this->importProduct->expects($this->exactly($productsCount))->method('getProductCategories')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]])->willReturn([]); $getProductWebsitesCallsCount = $productsCount * 2; $this->importProduct->expects($this->exactly($getProductWebsitesCallsCount))->method('getProductWebsites')->willReturnOnConsecutiveCalls([$newSku[0]['entity_id'] => $websiteId], [$newSku[0]['entity_id'] => $websiteId], [$newSku[1]['entity_id'] => $websiteId], [$newSku[1]['entity_id'] => $websiteId]); $map = [[$this->products[0][ImportProduct::COL_STORE], $this->products[0][ImportProduct::COL_STORE]], [$this->products[1][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]]]; $this->importProduct->expects($this->exactly(1))->method('getStoreIdByCode')->will($this->returnValueMap($map)); $product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'setId', 'getSku', 'setStoreId', 'getStoreId'], [], '', false); $product->expects($this->exactly($productsCount))->method('setId')->withConsecutive([$newSku[0]['entity_id']], [$newSku[1]['entity_id']]); $product->expects($this->any())->method('getId')->willReturnOnConsecutiveCalls($newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[1]['entity_id'], $newSku[1]['entity_id'], $newSku[1]['entity_id']); $product->expects($this->exactly($productsCount))->method('getSku')->will($this->onConsecutiveCalls($this->products[0]['sku'], $this->products[1]['sku'])); $product->expects($this->exactly($productsCount))->method('getStoreId')->will($this->onConsecutiveCalls($this->products[0][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE])); $product->expects($this->exactly($productsCount))->method('setStoreId')->withConsecutive([$this->products[0][ImportProduct::COL_STORE]], [$this->products[1][ImportProduct::COL_STORE]]); $this->catalogProductFactory->expects($this->exactly($productsCount))->method('create')->willReturn($product); $this->connection->expects($this->exactly(4))->method('quoteInto')->withConsecutive(['(store_id = ?', $storeIds[0]], [' AND entity_id = ?)', $newSku[0]['entity_id']], ['(store_id = ?', $storeIds[0]], [' AND entity_id = ?)', $newSku[1]['entity_id']]); $this->connection->expects($this->once())->method('fetchAll')->willReturn([]); $this->select->expects($this->any())->method('from')->willReturnSelf(); $this->select->expects($this->any())->method('where')->willReturnSelf(); $this->urlFinder->expects($this->any())->method('findAllByData')->willReturn([]); $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->willReturn('urlPathWithSuffix'); $this->productUrlPathGenerator->expects($this->any())->method('getUrlPath')->willReturn('urlPath'); $this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->willReturn('canonicalUrlPath'); $this->urlRewrite->expects($this->any())->method('setStoreId')->willReturnSelf(); $this->urlRewrite->expects($this->any())->method('setEntityId')->willReturnSelf(); $this->urlRewrite->expects($this->any())->method('setEntityType')->willReturnSelf(); $this->urlRewrite->expects($this->any())->method('setRequestPath')->willReturnSelf(); $this->urlRewrite->expects($this->any())->method('setTargetPath')->willReturnSelf(); $this->urlRewrite->expects($this->any())->method('getTargetPath')->willReturn('targetPath'); $this->urlRewrite->expects($this->any())->method('getStoreId')->willReturnOnConsecutiveCalls(0, 'not global'); $this->urlRewriteFactory->expects($this->any())->method('create')->willReturn($this->urlRewrite); $productUrls = ['targetPath-0' => $this->urlRewrite, 'targetPath-not global' => $this->urlRewrite]; $this->urlPersist->expects($this->once())->method('replace')->with($productUrls); $this->import->execute($this->observer); }
public function testSaveData() { $associatedSku = 'sku_assoc'; $productSku = 'productSku'; $this->entityModel->expects($this->once())->method('getNewSku')->will($this->returnValue([$associatedSku => ['entity_id' => 1], $productSku => ['entity_id' => 2]])); $attributes = ['position' => ['id' => 0], 'qty' => ['id' => 0]]; $this->links->expects($this->once())->method('getAttributes')->will($this->returnValue($attributes)); $bunch = [['_associated_sku' => $associatedSku, 'sku' => $productSku, '_type' => 'grouped', '_associated_default_qty' => 4, '_associated_position' => 6]]; $this->entityModel->expects($this->at(0))->method('getNextBunch')->will($this->returnValue($bunch)); $this->entityModel->expects($this->at(1))->method('getNextBunch')->will($this->returnValue($bunch)); $this->entityModel->expects($this->any())->method('isRowAllowedToImport')->will($this->returnValue(true)); $this->entityModel->expects($this->any())->method('getRowScope')->will($this->returnValue(\Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT)); $this->links->expects($this->once())->method("saveLinksData"); $this->grouped->saveData(); }
/** * Test for isRowValid() */ public function testIsRowValid() { $this->entityModel->expects($this->any())->method('getRowScope')->will($this->returnValue(-1)); $rowData = ['bundle_price_type' => 'dynamic', 'bundle_price_view' => 'bundle_price_view']; $this->assertEquals($this->bundle->isRowValid($rowData, 0), true); }
public function testIsBooleanAttributeValid() { $this->context->expects($this->any())->method('getBehavior')->willReturn(\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE); $result = $this->validator->isAttributeValid('boolean_attribute', ['type' => 'boolean', 'apply_to' => ['simple'], 'is_required' => false], ['product_type' => 'simple', 'boolean_attribute' => 'Yes']); $this->assertTrue($result); }