/** * Test import data method with delete behaviour * * @magentoDataFixture Magento/Customer/_files/import_export/customers_for_address_import.php */ public function testImportDataDelete() { // set behaviour $this->_entityAdapter->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_DELETE]); // set fixture CSV file $sourceFile = __DIR__ . '/_files/address_import_delete.csv'; /** @var $objectManager \Magento\TestFramework\ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $filesystem = $objectManager->create('Magento\\Framework\\Filesystem'); $directoryWrite = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $result = $this->_entityAdapter->setSource(\Magento\ImportExport\Model\Import\Adapter::findAdapterFor($sourceFile, $directoryWrite))->validateData()->hasToBeTerminated(); $this->assertTrue(!$result, 'Validation result must be true.'); // import data $this->_entityAdapter->importData(); // key attribute $keyAttribute = 'postcode'; // get addresses /** @var $addressCollection \Magento\Customer\Model\ResourceModel\Address\Collection */ $addressCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\ResourceModel\\Address\\Collection'); $addressCollection->addAttributeToSelect($keyAttribute); $addresses = []; /** @var $address \Magento\Customer\Model\Address */ foreach ($addressCollection as $address) { $addresses[$address->getData($keyAttribute)] = $address; } // is addresses exists $this->assertArrayNotHasKey($this->_deleteData['delete'], $addresses, 'Address must not exist.'); $this->assertArrayHasKey($this->_deleteData['not_delete'], $addresses, 'Address must exist.'); }
/** * Source model setter * * @param \Magento\ImportExport\Model\Import\AbstractSource $source * @return \Magento\ImportExport\Model\Import\AbstractEntity */ public function setSource(\Magento\ImportExport\Model\Import\AbstractSource $source) { $this->_customerEntity->setSource($source); $this->_addressEntity->setSource($source); return parent::setSource($source); }