You are here

public function UcAddressesApiTestCase::testFieldHandlerApi in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 tests/uc_addresses.api.test \UcAddressesApiTestCase::testFieldHandlerApi()

Tests field handler with an UcAddressesSchemaAddress.

File

tests/uc_addresses.api.test, line 328
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, format_string('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, format_string('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, format_string('The handler for field %field is not UcAddressesMissingFieldHandler when using UcAddressesAddress.', $vars));
  }
}