/** * 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.'); }
/** * Test beforeSave and afterSave callback are set correctly */ public function testSetAfterSaveCallback() { $this->assertInstanceOf('Mage_Customer_Service_Customer', $this->_service->setAfterSaveCallback('intval')); $this->assertAttributeEquals('intval', '_afterSaveCallback', $this->_service); }