/**
  * @magentoAppArea adminhtml
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testImportDelete()
 {
     $productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
     $index = 0;
     $ids = [];
     $origPricingData = [];
     while (isset($skus[$index])) {
         $ids[$index] = $productRepository->get($skus[$index])->getId();
         $origPricingData[$index] = $this->objectManager->create(\Magento\Catalog\Model\Product::class)->load($ids[$index])->getTierPrices();
         $index++;
     }
     $csvfile = uniqid('importexport_') . '.csv';
     /** @var \Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing $exportModel */
     $exportModel = $this->objectManager->create(\Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing::class);
     $exportModel->setWriter(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\ImportExport\Model\Export\Adapter\Csv::class, ['fileSystem' => $this->fileSystem, 'destination' => $csvfile]));
     $this->assertNotEmpty($exportModel->export());
     $directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $csvfile, 'directory' => $directory]);
     $errors = $this->model->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_DELETE, 'entity' => 'advanced_pricing'])->setSource($source)->validateData();
     $this->assertTrue($errors->getErrorsCount() == 0, 'Advanced Pricing import error, imported from file:' . $csvfile);
     $this->model->importData();
     while ($index > 0) {
         $index--;
         $newPricingData = $this->objectManager->create(\Magento\Catalog\Model\Product::class)->load($ids[$index])->getTierPrices();
         $this->assertEquals(0, count($newPricingData));
     }
 }
 /**
  * @magentoDataFixture Magento/Store/_files/website.php
  * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
  * @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/product_simple.php
  * @magentoAppIsolation enabled
  */
 public function testValidateUrlKeysMultipleStores()
 {
     $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_check_valid_url_keys_multiple_stores.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);
 }
 /**
  * @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());
     }
 }
 /**
  * @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'));
 }