Пример #1
0
 public function testSetCustomerFilter()
 {
     $collection = new Mage_Customer_Model_Resource_Address_Collection();
     $select = $collection->getSelect();
     $this->assertSame($collection, $collection->setCustomerFilter(array(1, 2)));
     $customer = Mage::getObjectManager()->create('Mage_Customer_Model_Customer');
     $collection->setCustomerFilter($customer);
     $customer->setId(3);
     $collection->setCustomerFilter($customer);
     $this->assertStringMatchesFormat('%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%A', (string) $select);
 }
Пример #2
0
 /**
  * Test setCustomerFilter() using array of Ids as possible filter
  */
 public function testSetArrayAsCustomerFilter()
 {
     $customerIds = array(1, 2);
     $expectedString = "parent_id IN (" . implode(',', $customerIds) . ")";
     $this->_collection->getConnection()->expects($this->any())->method('prepareSqlCondition')->with($this->stringContains('parent_id'), array('in' => $customerIds))->will($this->returnValue($expectedString));
     $this->_collection->setCustomerFilter($customerIds);
     $this->assertContains('(' . $expectedString . ')', $this->_collection->getSelect()->getPart(Zend_Db_Select::WHERE));
 }
Пример #3
0
 /**
  * Export process
  *
  * @return string
  */
 public function export()
 {
     // skip and filter by customer address attributes
     $this->_addressCollection = $this->_prepareEntityCollection($this->_addressCollection);
     $this->_addressCollection->setCustomerFilter(array_keys($this->_customers));
     // prepare headers
     $this->getWriter()->setHeaderCols(array_merge($this->_permanentAttributes, $this->_getExportAttributeCodes(), array_keys(self::$_defaultAddressAttributeMapping)));
     $this->_exportCollectionByPages($this->_addressCollection);
     return $this->getWriter()->getContents();
 }
Пример #4
0
 /**
  * Test import data method with add/update behaviour
  *
  * @magentoDataFixture Mage/ImportExport/_files/customers_for_address_import.php
  * @covers Mage_ImportExport_Model_Import_Entity_Eav_Customer_Address::_importData
  */
 public function testImportDataAddUpdate()
 {
     // set behaviour
     $this->_entityAdapter->setParameters(array('behavior' => Mage_ImportExport_Model_Import::BEHAVIOR_ADD_UPDATE));
     // set fixture CSV file
     $sourceFile = __DIR__ . '/../_files/address_import_update.csv';
     $result = $this->_entityAdapter->setSource(Mage_ImportExport_Model_Import_Adapter::findAdapterFor($sourceFile))->isDataValid();
     $this->assertFalse($result, 'Validation result must be false.');
     // import data
     $this->_entityAdapter->importData();
     // form attribute list
     $keyAttribute = 'postcode';
     $requiredAttributes[] = array($keyAttribute);
     foreach (array('update', 'remove') as $action) {
         foreach ($this->_updateData[$action] as $attributes) {
             $requiredAttributes = array_merge($requiredAttributes, array_keys($attributes));
         }
     }
     // get addresses
     $addressCollection = new Mage_Customer_Model_Resource_Address_Collection();
     $addressCollection->addAttributeToSelect($requiredAttributes);
     $addresses = array();
     /** @var $address Mage_Customer_Model_Address */
     foreach ($addressCollection as $address) {
         $addresses[$address->getData($keyAttribute)] = $address;
     }
     // is addresses exists
     $this->assertArrayHasKey($this->_updateData['address']['update'], $addresses, 'Address must exist.');
     $this->assertArrayHasKey($this->_updateData['address']['new'], $addresses, 'Address must exist.');
     $this->assertArrayNotHasKey($this->_updateData['address']['no_customer'], $addresses, 'Address must not exist.');
     $this->assertArrayHasKey($this->_updateData['address']['new_no_address_id'], $addresses, 'Address must exist.');
     // are updated address fields have new values
     $updatedAddressId = $this->_updateData['address']['update'];
     /** @var $updatedAddress Mage_Customer_Model_Address */
     $updatedAddress = $addresses[$updatedAddressId];
     $updatedData = $this->_updateData['update'][$updatedAddressId];
     foreach ($updatedData as $fieldName => $fieldValue) {
         $this->assertEquals($fieldValue, $updatedAddress->getData($fieldName));
     }
     // are removed data fields have old values
     $removedData = $this->_updateData['remove'][$updatedAddressId];
     foreach ($removedData as $fieldName => $fieldValue) {
         $this->assertEquals($fieldValue, $updatedAddress->getData($fieldName));
     }
     // are default billing/shipping addresses have new value
     /** @var $customer Mage_Customer_Model_Customer */
     $customer = Mage::getModel('Mage_Customer_Model_Customer');
     $customer->setWebsiteId(0);
     $customer->loadByEmail('*****@*****.**');
     $defaultsData = $this->_updateData['default'];
     $this->assertEquals($defaultsData['billing'], $customer->getDefaultBillingAddress()->getData($keyAttribute), 'Incorrect default billing address');
     $this->assertEquals($defaultsData['shipping'], $customer->getDefaultShippingAddress()->getData($keyAttribute), 'Incorrect default shipping address');
 }