/** * @covers Mage_ImportExport_Model_Import_Entity_CustomerComposite::setErrorMessages */ public function testGetErrorMessages() { $errorMessages = array('Required field' => array(1, 2, 3), 'Bad password' => array(1), 'Wrong website' => array(1, 2)); $customerEntity = $this->_getCustomerEntityMock(); $customerEntity->expects($this->once())->method('getErrorMessages')->will($this->returnValue($errorMessages)); $errorMessages = array('Required field' => array(2, 3, 4, 5), 'Wrong address' => array(1, 2)); $addressEntity = $this->_getAddressEntityMock(); $addressEntity->expects($this->once())->method('getErrorMessages')->will($this->returnValue($errorMessages)); $data = $this->_getModelDependencies(); $data['customer_entity'] = $customerEntity; $data['address_entity'] = $addressEntity; $this->_model = new Mage_ImportExport_Model_Import_Entity_CustomerComposite($data); $this->_model->addRowError('Bad password', 1); $expectedErrors = array('Required field' => array(1, 2, 3, 4, 5), 'Bad password' => array(2), 'Wrong website' => array(1, 2), 'Wrong address' => array(1, 2)); $actualErrors = $this->_model->getErrorMessages(); foreach ($expectedErrors as $error => $rows) { $this->assertArrayHasKey($error, $actualErrors); $this->assertSame($rows, array_values($actualErrors[$error])); } }
/** * @param string $behavior * @param string $sourceFile * @param array $dataBefore * @param array $dataAfter * @param array $errors * * @magentoDataFixture Mage/ImportExport/_files/customers_for_address_import.php * @magentoAppIsolation enabled * * @dataProvider importDataDataProvider * @covers Mage_ImportExport_Model_Import_Entity_CustomerComposite::_importData */ public function testImportData($behavior, $sourceFile, array $dataBefore, array $dataAfter, array $errors = array()) { // set entity adapter parameters $this->_entityAdapter->setParameters(array('behavior' => $behavior)); // set fixture CSV file $result = $this->_entityAdapter->setSource(Mage_ImportExport_Model_Import_Adapter::findAdapterFor($sourceFile))->isDataValid(); if ($errors) { $this->assertFalse($result); } else { $this->assertTrue($result); } // assert validation errors // can't use error codes because entity adapter gathers only error messages from aggregated adapters $actualErrors = array_values($this->_entityAdapter->getErrorMessages()); $this->assertEquals($errors, $actualErrors); // assert data before import $this->_assertCustomerData($dataBefore); // import data $this->_entityAdapter->importData(); // assert data after import $this->_assertCustomerData($dataAfter); }