Example #1
0
 /**
  * @magentoDbIsolation enabled
  */
 public function testProductWithInvalidWeight()
 {
     // import data from CSV file
     $pathToFile = __DIR__ . '/_files/product_to_import_invalid_weight.csv';
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem');
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = new \Magento\ImportExport\Model\Import\Source\Csv($pathToFile, $directory);
     $validationResult = $this->_model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND])->isDataValid();
     $expectedErrors = ["Product weight is invalid" => [2]];
     $this->assertFalse($validationResult);
     $this->assertEquals($expectedErrors, $this->_model->getErrorMessages());
 }
Example #2
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/products_with_multiselect_attribute.php
  */
 public function testValidateInvalidMultiselectValues()
 {
     // import data from CSV file
     $pathToFile = __DIR__ . '/_files/products_with_invalid_multiselect_values.csv';
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Filesystem');
     $directory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $source = new \Magento\ImportExport\Model\Import\Source\Csv($pathToFile, $directory);
     $validationResult = $this->_model->setSource($source)->setParameters(array('behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND))->isDataValid();
     $this->assertFalse($validationResult);
     $errors = $this->_model->getErrorMessages();
     $expectedErrors = array("Please correct the value for 'multiselect_attribute'." => [2], "Orphan rows that will be skipped due default row errors" => [3, 4]);
     foreach ($expectedErrors as $message => $invalidRows) {
         $this->assertArrayHasKey($message, $errors);
         $this->assertEquals($invalidRows, $errors[$message]);
     }
 }