public function UcAddressesApiTestCase::testFieldHandlerApi in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 tests/uc_addresses.api.test \UcAddressesApiTestCase::testFieldHandlerApi()
Tests field handler with an UcAddressesSchemaAddress.
File
- tests/
uc_addresses.api.test, line 297 - Test cases for the api component.
Class
- UcAddressesApiTestCase
- Test cases for the api component.
Code
public function testFieldHandlerApi() {
$schemaAddress = new UcAddressesSchemaAddress();
$addressBookAddress = UcAddressesAddressBook::newAddress();
$address_values = self::getEditAddressValues();
foreach ($address_values['values'] as $field => $value) {
$schemaAddress
->setField($field, $value);
$addressBookAddress
->setField($field, $value);
}
// Test each handler in action.
foreach ($address_values['values'] as $field => $value) {
$vars = array(
'%field' => $field,
);
$handler = $schemaAddress
->getHandler($field);
$this
->assertTrue($handler instanceof UcAddressesFieldHandler, t('The handler for field %field is UcAddressesFieldHandler.', $vars));
$this
->doHandlerTests($schemaAddress, $field, $handler);
}
// Assert that handlers for fields 'name', 'default_shipping' and
// 'default_billing' can't be used with an UcAddressesSchemaAddress
// instance.
foreach (array(
'address_name',
'default_shipping',
'default_billing',
) as $field) {
$vars = array(
'%field' => $field,
);
$handler = $schemaAddress
->getHandler($field);
$this
->assertTrue($handler instanceof UcAddressesMissingFieldHandler, t('The handler for field %field is UcAddressesMissingFieldHandler when using UcAddressesSchemaAddress.', $vars));
// Ensure that calling methods from a missing handler doesn't result into
// fatal errors.
$this
->doHandlerTests($schemaAddress, $field, $handler);
// Ensure that the handler is not missing for this field with an
// UcAddressesAddress instance.
$handler = $addressBookAddress
->getHandler($field);
$this
->assertFalse($handler instanceof UcAddressesMissingFieldHandler, t('The handler for field %field is not UcAddressesMissingFieldHandler when using UcAddressesAddress.', $vars));
}
}