/** * @expectedException Mage_Core_Exception * @expectedExceptionMessage The address with the specified ID not found. */ public function testPrepareCustomerAddressForSaveException() { $this->_customer->expects($this->any())->method('getId')->will($this->returnValue(1)); $address = $this->_createAddress(true, 1); $this->_customer->expects($this->once())->method('getAddressItemById')->with($address->getId())->will($this->returnValue(false)); $this->_service->update(1, array(), array(array('entity_id' => 1, 'city' => 'test'))); }
/** * Test beforeSave and afterSave callback * * @magentoDataFixture Mage/Customer/_files/customer.php */ public function testCallback() { $customer = $this->_customerFactory->create()->load(1); $customerData = array('firstname' => 'Updated name'); $customer->addData($customerData); $addressData = array(array('firstname' => 'John', 'lastname' => 'Smith', 'street' => 'Green str, 67', 'country_id' => 'AL', 'city' => 'CityM', 'postcode' => '75477', 'telephone' => '3468676')); $callbackCount = 0; $callback = function ($actualCustomer, $actualData, $actualAddresses) use($customer, $customerData, $addressData, &$callbackCount) { $callbackCount++; // Remove updated_at as in afterSave updated_at may be changed $expectedCustomerData = $customer->getData(); unset($expectedCustomerData['updated_at']); PHPUnit_Framework_Assert::assertEquals($expectedCustomerData, $actualCustomer->toArray(array_keys($expectedCustomerData))); PHPUnit_Framework_Assert::assertEquals($customerData, $actualData); PHPUnit_Framework_Assert::assertEquals($addressData, $actualAddresses); }; $this->_model->setBeforeSaveCallback($callback); $this->_model->setAfterSaveCallback($callback); $this->_model->update(1, $customerData, $addressData); $this->assertEquals(2, $callbackCount, 'Not all expected callbacks were called.'); }