Example #1
0
 /**
  * @magentoAppArea adminhtml
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  */
 public function testBundleImport()
 {
     // import data from CSV file
     $pathToFile = __DIR__ . '/../../_files/import_bundle.csv';
     $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
     $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData();
     $this->assertTrue($errors->getErrorsCount() == 0);
     $this->model->importData();
     $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
     $productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME);
     $this->assertTrue(is_numeric($productId));
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
     $product->load($productId);
     $this->assertFalse($product->isObjectNew());
     $this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName());
     $this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId());
     $this->assertEquals(1, $product->getShipmentType());
     $optionIdList = $resource->getProductsIdsBySkus($this->optionSkuList);
     $bundleOptionCollection = $product->getExtensionAttributes()->getBundleProductOptions();
     $this->assertEquals(2, count($bundleOptionCollection));
     foreach ($bundleOptionCollection as $optionKey => $option) {
         $this->assertEquals('checkbox', $option->getData('type'));
         $this->assertEquals('Option ' . ($optionKey + 1), $option->getData('title'));
         $this->assertEquals(self::TEST_PRODUCT_NAME, $option->getData('sku'));
         $this->assertEquals($optionKey + 1, count($option->getData('product_links')));
         foreach ($option->getData('product_links') as $linkKey => $productLink) {
             $optionSku = 'Simple ' . ($optionKey + 1 + $linkKey);
             $this->assertEquals($optionIdList[$optionSku], $productLink->getData('entity_id'));
             $this->assertEquals($optionSku, $productLink->getData('sku'));
         }
     }
 }
 /**
  * @magentoDataFixture Magento/AdvancedPricingImportExport/_files/create_products.php
  * @magentoAppArea adminhtml
  */
 public function testImportReplace()
 {
     // import data from CSV file
     $pathToFile = __DIR__ . '/_files/import_advanced_pricing.csv';
     $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
     $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE, 'entity' => 'advanced_pricing'])->validateData();
     $this->assertEquals(0, $errors->getErrorsCount(), 'Advanced pricing import validation error');
     $this->model->importData();
     /** @var \Magento\Catalog\Model\ResourceModel\Product $resource */
     $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
     $productIdList = $resource->getProductsIdsBySkus(array_keys($this->expectedTierPrice));
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
     foreach ($productIdList as $sku => $productId) {
         $product->load($productId);
         $tierPriceCollection = $product->getTierPrices();
         $this->assertEquals(3, count($tierPriceCollection));
         /** @var \Magento\Catalog\Model\Product\TierPrice $tierPrice */
         foreach ($tierPriceCollection as $tierPrice) {
             $this->assertContains($tierPrice->getData(), $this->expectedTierPrice[$sku]);
         }
     }
 }
 /**
  * @magentoAppArea adminhtml
  * @magentoDbIsolation disabled
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/Catalog/_files/category_duplicates.php
  */
 public function testProductDuplicateCategories()
 {
     $csvFixture = 'products_duplicate_category.csv';
     // import data from CSV file
     $pathToFile = __DIR__ . '/_files/' . $csvFixture;
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Framework\Filesystem::class);
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
     $errors = $this->_model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData();
     $this->assertTrue($errors->getErrorsCount() === 0);
     /** @var \Magento\Catalog\Model\Category $category */
     $category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class);
     $category->setStoreId(1);
     $category->load(444);
     $this->assertTrue($category !== null);
     $category->setName('Category 2-updated')->save();
     $this->_model->importData();
     $errorProcessor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregator::class);
     $errorCount = count($errorProcessor->getAllErrors());
     $errorMessage = $errorProcessor->getAllErrors()[0]->getErrorMessage();
     $this->assertContains('URL key for specified store already exists', $errorMessage);
     $this->assertContains('Default Category/Category 2', $errorMessage);
     $this->assertTrue($errorCount === 1, 'Error expected');
     $categoryAfter = $this->loadCategoryByName('Category 2');
     $this->assertTrue($categoryAfter === null);
     /** @var \Magento\Catalog\Model\Product $product */
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
     $product->load(1);
     $categories = $product->getCategoryIds();
     $this->assertTrue(count($categories) == 1);
 }
Example #4
0
 /**
  * @magentoAppArea adminhtml
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  */
 public function testImport()
 {
     // Import data from CSV file
     $pathToFile = __DIR__ . '/../../_files/grouped_product.csv';
     $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
     $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData();
     $this->assertTrue($errors->getErrorsCount() == 0);
     $this->model->importData();
     $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
     $productId = $resource->getIdBySku('Test Grouped');
     $this->assertTrue(is_numeric($productId));
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
     $product->load($productId);
     $this->assertFalse($product->isObjectNew());
     $this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName());
     $this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId());
     $childProductCollection = $product->getTypeInstance()->getAssociatedProducts($product);
     foreach ($childProductCollection as $childProduct) {
         $this->assertContains($childProduct->getSku(), $this->optionSkuList);
     }
 }
Example #5
0
 /**
  * @magentoAppIsolation enabled
  */
 public function testProductWithUseConfigSettings()
 {
     $products = ['simple1' => true, 'simple2' => true, 'simple3' => false];
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem');
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create('\\Magento\\ImportExport\\Model\\Import\\Source\\Csv', ['file' => __DIR__ . '/_files/products_to_import_with_use_config_settings.csv', 'directory' => $directory]);
     $errors = $this->_model->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->setSource($source)->validateData();
     $this->assertTrue($errors->getErrorsCount() == 0);
     $this->_model->importData();
     foreach ($products as $sku => $manageStockUseConfig) {
         /** @var \Magento\CatalogInventory\Model\StockRegistry $stockRegistry */
         $stockRegistry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\CatalogInventory\\Model\\StockRegistry');
         $stockItem = $stockRegistry->getStockItemBySku($sku);
         $this->assertEquals($manageStockUseConfig, $stockItem->getUseConfigManageStock());
     }
 }
Example #6
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/categories.php
  * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
  * @magentoDataFixture Magento/Catalog/Model/Layer/Filter/_files/attribute_with_option.php
  * @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_attribute.php
  * @magentoAppIsolation enabled
  */
 public function testProductsWithMultipleStores()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $filesystem = $objectManager->create('Magento\\Framework\\Filesystem');
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = new \Magento\ImportExport\Model\Import\Source\Csv(__DIR__ . '/_files/products_multiple_stores.csv', $directory);
     $this->_model->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->setSource($source)->isDataValid();
     $this->_model->importData();
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $objectManager->create('Magento\\Catalog\\Model\\Product');
     $id = $product->getIdBySku('Configurable 03');
     $product->load($id);
     $this->assertEquals('1', $product->getHasOptions());
     $objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->setCurrentStore('fixturestore');
     /** @var \Magento\Catalog\Model\Product $simpleProduct */
     $simpleProduct = $objectManager->create('Magento\\Catalog\\Model\\Product');
     $id = $simpleProduct->getIdBySku('Configurable 03-option_0');
     $simpleProduct->load($id);
     $this->assertEquals('Option Label', $simpleProduct->getAttributeText('attribute_with_option'));
 }
Example #7
0
 /**
  * @magentoAppArea adminhtml
  * @dataProvider categoryTestDataProvider
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  */
 public function testProductCategories($fixture, $separator)
 {
     // import data from CSV file
     $pathToFile = __DIR__ . '/_files/' . $fixture;
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem');
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create('\\Magento\\ImportExport\\Model\\Import\\Source\\Csv', ['file' => $pathToFile, 'directory' => $directory]);
     $errors = $this->_model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product', Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR => $separator])->validateData();
     $this->assertTrue($errors->getErrorsCount() == 0);
     $this->_model->importData();
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $resource = $objectManager->get('Magento\\Catalog\\Model\\ResourceModel\\Product');
     $productId = $resource->getIdBySku('simple1');
     $this->assertTrue(is_numeric($productId));
     /** @var \Magento\Catalog\Model\Product $product */
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->load($productId);
     $this->assertFalse($product->isObjectNew());
     $categories = $product->getCategoryIds();
     $this->assertTrue(count($categories) == 2);
 }
 /**
  * @magentoAppArea adminhtml
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testDownloadableImport()
 {
     // import data from CSV file
     $pathToFile = __DIR__ . '/../../_files/import_downloadable.csv';
     $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
     $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData();
     $this->assertTrue($errors->getErrorsCount() == 0);
     $this->model->importData();
     $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
     $productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME);
     $this->assertTrue(is_numeric($productId));
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
     $product->load($productId);
     $this->assertFalse($product->isObjectNew());
     $this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName());
     $this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId());
     $downloadableProductLinks = $product->getExtensionAttributes()->getDownloadableProductLinks();
     $downloadableLinks = $product->getDownloadableLinks();
     $downloadableProductSamples = $product->getExtensionAttributes()->getDownloadableProductSamples();
     $downloadableSamples = $product->getDownloadableSamples();
     //TODO: Track Fields: id, link_id, link_file and sample_file)
     $expectedLinks = ['file' => ['title' => 'TEST Import Link Title File', 'sort_order' => '78', 'sample_type' => 'file', 'price' => '123.0000', 'number_of_downloads' => '123', 'is_shareable' => '0', 'link_type' => 'file'], 'url' => ['title' => 'TEST Import Link Title URL', 'sort_order' => '42', 'sample_type' => 'url', 'sample_url' => 'http://www.bing.com', 'price' => '1.0000', 'number_of_downloads' => '0', 'is_shareable' => '1', 'link_type' => 'url', 'link_url' => 'http://www.google.com']];
     foreach ($downloadableProductLinks as $link) {
         $actualLink = $link->getData();
         $this->assertArrayHasKey('link_type', $actualLink);
         foreach ($expectedLinks[$actualLink['link_type']] as $expectedKey => $expectedValue) {
             $this->assertArrayHasKey($expectedKey, $actualLink);
             $this->assertEquals($actualLink[$expectedKey], $expectedValue);
         }
     }
     foreach ($downloadableLinks as $link) {
         $actualLink = $link->getData();
         $this->assertArrayHasKey('link_type', $actualLink);
         $this->assertArrayHasKey('product_id', $actualLink);
         $this->assertEquals($actualLink['product_id'], $product->getData($this->productMetadata->getLinkField()));
         foreach ($expectedLinks[$actualLink['link_type']] as $expectedKey => $expectedValue) {
             $this->assertArrayHasKey($expectedKey, $actualLink);
             $this->assertEquals($actualLink[$expectedKey], $expectedValue);
         }
     }
     //TODO: Track Fields: id, sample_id and sample_file)
     $expectedSamples = ['file' => ['title' => 'TEST Import Sample File', 'sort_order' => '178', 'sample_type' => 'file'], 'url' => ['title' => 'TEST Import Sample URL', 'sort_order' => '178', 'sample_type' => 'url', 'sample_url' => 'http://www.yahoo.com']];
     foreach ($downloadableProductSamples as $sample) {
         $actualSample = $sample->getData();
         $this->assertArrayHasKey('sample_type', $actualSample);
         foreach ($expectedSamples[$actualSample['sample_type']] as $expectedKey => $expectedValue) {
             $this->assertArrayHasKey($expectedKey, $actualSample);
             $this->assertEquals($actualSample[$expectedKey], $expectedValue);
         }
     }
     foreach ($downloadableSamples as $sample) {
         $actualSample = $sample->getData();
         $this->assertArrayHasKey('sample_type', $actualSample);
         $this->assertArrayHasKey('product_id', $actualSample);
         $this->assertEquals($actualSample['product_id'], $product->getData($this->productMetadata->getLinkField()));
         foreach ($expectedSamples[$actualSample['sample_type']] as $expectedKey => $expectedValue) {
             $this->assertArrayHasKey($expectedKey, $actualSample);
             $this->assertEquals($actualSample[$expectedKey], $expectedValue);
         }
     }
 }
 /**
  * @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_attribute.php
  * @magentoAppArea adminhtml
  */
 public function testConfigurableImport()
 {
     // import data from CSV file
     $pathToFile = __DIR__ . '/../../_files/import_configurable.csv';
     $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
     $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData();
     $this->assertTrue($errors->getErrorsCount() == 0);
     $this->model->importData();
     /** @var \Magento\Catalog\Model\ResourceModel\Product $resource */
     $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
     $productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME);
     $this->assertTrue(is_numeric($productId));
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->get(ProductRepositoryInterface::class)->getById($productId);
     $this->assertFalse($product->isObjectNew());
     $this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName());
     $this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId());
     $optionCollection = $product->getTypeInstance()->getConfigurableOptions($product);
     foreach ($optionCollection as $option) {
         foreach ($option as $optionData) {
             $this->assertContains($optionData['sku'], $this->optionSkuList);
         }
     }
     $optionIdList = $resource->getProductsIdsBySkus($this->optionSkuList);
     foreach ($optionIdList as $optionId) {
         $this->assertArrayHasKey($optionId, $product->getExtensionAttributes()->getConfigurableProductLinks());
     }
     $configurableOptionCollection = $product->getExtensionAttributes()->getConfigurableProductOptions();
     $this->assertEquals(1, count($configurableOptionCollection));
     foreach ($configurableOptionCollection as $option) {
         $optionData = $option->getData();
         $this->assertArrayHasKey('product_super_attribute_id', $optionData);
         $this->assertArrayHasKey('product_id', $optionData);
         $this->assertEquals($product->getData($this->productMetadata->getLinkField()), $optionData['product_id']);
         $this->assertArrayHasKey('attribute_id', $optionData);
         $this->assertArrayHasKey('position', $optionData);
         $this->assertArrayHasKey('extension_attributes', $optionData);
         $this->assertArrayHasKey('product_attribute', $optionData);
         $productAttributeData = $optionData['product_attribute']->getData();
         $this->assertArrayHasKey('attribute_id', $productAttributeData);
         $this->assertArrayHasKey('entity_type_id', $productAttributeData);
         $this->assertArrayHasKey('attribute_code', $productAttributeData);
         $this->assertEquals('test_configurable', $productAttributeData['attribute_code']);
         $this->assertArrayHasKey('frontend_label', $productAttributeData);
         $this->assertEquals('Test Configurable', $productAttributeData['frontend_label']);
         $this->assertArrayHasKey('label', $optionData);
         $this->assertEquals('test_configurable', $optionData['label']);
         $this->assertArrayHasKey('use_default', $optionData);
         $this->assertArrayHasKey('options', $optionData);
         $this->assertEquals('Option 1', $optionData['options'][0]['label']);
         $this->assertEquals('Option 1', $optionData['options'][0]['default_label']);
         $this->assertEquals('Option 1', $optionData['options'][0]['store_label']);
         $this->assertEquals('Option 2', $optionData['options'][1]['label']);
         $this->assertEquals('Option 2', $optionData['options'][1]['default_label']);
         $this->assertEquals('Option 2', $optionData['options'][1]['store_label']);
         $this->assertArrayHasKey('values', $optionData);
         $valuesData = $optionData['values'];
         $this->assertEquals(2, count($valuesData));
     }
 }