/** * Test if correct methods are invoked according to different custom behaviours * * @covers \Magento\CustomerImportExport\Model\Import\Address::_importData */ public function testImportDataWithCustomBehaviour() { $this->_model = $this->_getModelMockForTestImportDataWithCustomBehaviour(); $this->_model->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_CUSTOM]); // validation in validateSaveAddressEntities and validateDeleteAddressEntities $this->_model->importData(); }
/** * 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.'); }
/** * Test export method */ public function testExport() { $websiteCode = Address::COLUMN_WEBSITE; $emailCode = Address::COLUMN_EMAIL; $entityIdCode = Address::COLUMN_ADDRESS_ID; $expectedAttributes = array(); /** @var $collection \Magento\Customer\Model\Resource\Address\Attribute\Collection */ $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Resource\\Address\\Attribute\\Collection'); /** @var $attribute \Magento\Customer\Model\Attribute */ foreach ($collection as $attribute) { $expectedAttributes[] = $attribute->getAttributeCode(); } // Get customer default addresses column name to customer attribute mapping array. $defaultAddressMap = ImportAddress::getDefaultAddressAttributeMapping(); $this->_model->setWriter(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\ImportExport\\Model\\Export\\Adapter\\Csv')); $this->_model->setParameters(array()); $data = $this->_csvToArray($this->_model->export(), $entityIdCode); $this->assertEquals(count($expectedAttributes), count(array_intersect($expectedAttributes, $data['header'])), 'Expected attribute codes were not exported'); $this->assertNotEmpty($data['data'], 'No data was exported'); /** @var $objectManager \Magento\TestFramework\ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); // Get addresses /** @var $customers \Magento\Customer\Model\Customer[] */ $customers = $objectManager->get('Magento\\Framework\\Registry')->registry('_fixture/Magento_ImportExport_Customers_Array'); foreach ($customers as $customer) { /** @var $address \Magento\Customer\Model\Address */ foreach ($customer->getAddresses() as $address) { // Check unique key $data['data'][$address->getId()][$websiteCode] = $this->_websites[$customer->getWebsiteId()]; $data['data'][$address->getId()][$emailCode] = $customer->getEmail(); $data['data'][$address->getId()][$entityIdCode] = $address->getId(); // Check by expected attributes foreach ($expectedAttributes as $code) { if (!in_array($code, $this->_model->getDisabledAttributes())) { $this->assertEquals($address->getData($code), $data['data'][$address->getId()][$code], 'Attribute "' . $code . '" is not equal'); } } // Check customer default addresses column name to customer attribute mapping array foreach ($defaultAddressMap as $exportCode => $code) { $this->assertEquals($address->getData($code), (int) $data['data'][$address->getId()][$exportCode], 'Attribute "' . $code . '" is not equal'); } } } }
/** * Returns number of checked entities * * @return int */ public function getProcessedEntitiesCount() { return $this->_customerEntity->getProcessedEntitiesCount() + $this->_addressEntity->getProcessedEntitiesCount(); }