/** * Test default address attribute mapping array */ public function testGetDefaultAddressAttributeMapping() { $attributeMapping = $this->_model->getDefaultAddressAttributeMapping(); $this->assertInternalType('array', $attributeMapping, 'Default address attribute mapping must be an array.'); $this->assertArrayHasKey(Mage_ImportExport_Model_Import_Entity_Eav_Customer_Address::COLUMN_DEFAULT_BILLING, $attributeMapping, 'Default address attribute mapping array must have a default billing column.'); $this->assertArrayHasKey(Mage_ImportExport_Model_Import_Entity_Eav_Customer_Address::COLUMN_DEFAULT_SHIPPING, $attributeMapping, 'Default address attribute mapping array must have a default shipping column.'); }
/** * Test export method */ public function testExport() { $websiteCode = Mage_ImportExport_Model_Export_Entity_Eav_Customer_Address::COLUMN_WEBSITE; $emailCode = Mage_ImportExport_Model_Export_Entity_Eav_Customer_Address::COLUMN_EMAIL; $entityIdCode = Mage_ImportExport_Model_Export_Entity_Eav_Customer_Address::COLUMN_ADDRESS_ID; $expectedAttributes = array(); /** @var $collection Mage_Customer_Model_Resource_Address_Attribute_Collection */ $collection = Mage::getResourceModel('Mage_Customer_Model_Resource_Address_Attribute_Collection'); /** @var $attribute Mage_Customer_Model_Attribute */ foreach ($collection as $attribute) { $expectedAttributes[] = $attribute->getAttributeCode(); } // Get customer default addresses column name to customer attribute mapping array. $defaultAddressMap = Mage_ImportExport_Model_Import_Entity_Eav_Customer_Address::getDefaultAddressAttributeMapping(); $this->_model->setWriter(Mage::getModel('Mage_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'); // Get addresses /** @var $customers Mage_Customer_Model_Customer[] */ $customers = Mage::registry('_fixture/Mage_ImportExport_Customers_Array'); foreach ($customers as $customer) { /** @var $address Mage_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'); } } } }
/** * Test _saveCustomerDefaults * * @magentoDataFixture Mage/ImportExport/_files/customer_with_addresses.php * @covers Mage_ImportExport_Model_Import_Entity_Eav_Customer_Address::_saveCustomerDefaults */ public function testSaveCustomerDefaults() { // get not default address $customers = Mage::registry($this->_fixtureKey); /** @var $notDefaultAddress Mage_Customer_Model_Address */ $notDefaultAddress = null; /** @var $addressCustomer Mage_Customer_Model_Customer */ $addressCustomer = null; /** @var $customer Mage_Customer_Model_Customer */ foreach ($customers as $customer) { /** @var $address Mage_Customer_Model_Address */ foreach ($customer->getAddressesCollection() as $address) { if (!$customer->getDefaultBillingAddress() && !$customer->getDefaultShippingAddress()) { $notDefaultAddress = $address; $addressCustomer = $customer; break; } if ($notDefaultAddress) { break; } } } $this->assertNotNull($notDefaultAddress, 'Not default address must exists.'); $this->assertNotNull($addressCustomer, 'Not default address customer must exists.'); $addressId = $notDefaultAddress->getId(); $customerId = $addressCustomer->getId(); // set customer defaults $defaults = array(); foreach (Mage_ImportExport_Model_Import_Entity_Eav_Customer_Address::getDefaultAddressAttributeMapping() as $attributeCode) { /** @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */ $attribute = $addressCustomer->getAttribute($attributeCode); $attributeTable = $attribute->getBackend()->getTable(); $attributeId = $attribute->getId(); $defaults[$attributeTable][$customerId][$attributeId] = $addressId; } // invoke _saveCustomerDefaults $saveDefaults = new ReflectionMethod($this->_testClassName, '_saveCustomerDefaults'); $saveDefaults->setAccessible(true); $saveDefaults->invoke($this->_entityAdapter, $defaults); // check DB /** @var $testCustomer Mage_Customer_Model_Customer */ $testCustomer = Mage::getModel('Mage_Customer_Model_Customer'); $testCustomer->load($customerId); $this->assertEquals($customerId, $testCustomer->getId(), 'Customer must exists.'); $this->assertNotNull($testCustomer->getDefaultBillingAddress(), 'Default billing address must exists.'); $this->assertNotNull($testCustomer->getDefaultShippingAddress(), 'Default shipping address must exists.'); $this->assertEquals($addressId, $testCustomer->getDefaultBillingAddress()->getId(), 'Incorrect default billing address.'); $this->assertEquals($addressId, $testCustomer->getDefaultShippingAddress()->getId(), 'Incorrect default shipping address.'); }