Ejemplo n.º 1
0
 /**
  * Test if correct methods are invoked according to different custom behaviours
  *
  * @covers Mage_ImportExport_Model_Import_Entity_Eav_Customer_Address::_importData
  */
 public function testImportDataWithCustomBehaviour()
 {
     $this->_model = $this->_getModelMockForTestImportDataWithCustomBehaviour();
     $this->_model->setParameters(array('behavior' => Mage_ImportExport_Model_Import::BEHAVIOR_CUSTOM));
     // validation in validateSaveAddressEntities and validateDeleteAddressEntities
     $this->_model->importData();
 }
Ejemplo n.º 2
0
 /**
  * Test import data method with delete behaviour
  *
  * @magentoDataFixture Mage/ImportExport/_files/customers_for_address_import.php
  * @covers Mage_ImportExport_Model_Import_Entity_Eav_Customer_Address::_importData
  */
 public function testImportDataDelete()
 {
     // set behaviour
     $this->_entityAdapter->setParameters(array('behavior' => Mage_ImportExport_Model_Import::BEHAVIOR_DELETE));
     // set fixture CSV file
     $sourceFile = __DIR__ . '/../_files/address_import_delete.csv';
     $result = $this->_entityAdapter->setSource(Mage_ImportExport_Model_Import_Adapter::findAdapterFor($sourceFile))->isDataValid();
     $this->assertTrue($result, 'Validation result must be true.');
     // import data
     $this->_entityAdapter->importData();
     // key attribute
     $keyAttribute = 'postcode';
     // get addresses
     /** @var $addressCollection Mage_Customer_Model_Resource_Address_Collection */
     $addressCollection = Mage::getResourceModel('Mage_Customer_Model_Resource_Address_Collection');
     $addressCollection->addAttributeToSelect($keyAttribute);
     $addresses = array();
     /** @var $address Mage_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.');
 }
Ejemplo n.º 3
0
 /**
  * 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');
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Returns number of checked entities
  *
  * @return int
  */
 public function getProcessedEntitiesCount()
 {
     return $this->_customerEntity->getProcessedEntitiesCount() + $this->_addressEntity->getProcessedEntitiesCount();
 }