You are here

protected function UcAddressesApiTestCase::doHandlerTests in Ubercart Addresses 7

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

Do handler tests.

Parameters

UcAddressesSchemaAddress $address: The address that requested the handler.

string $field: The field that belongs to the handler.

UcAddressesFieldHandler $handler: The handler to test.

Return value

void

1 call to UcAddressesApiTestCase::doHandlerTests()
UcAddressesApiTestCase::testFieldHandlerApi in tests/uc_addresses.api.test
Tests field handler with an UcAddressesSchemaAddress.

File

tests/uc_addresses.api.test, line 384
Test cases for the api component.

Class

UcAddressesApiTestCase
Test cases for the api component.

Code

protected function doHandlerTests(UcAddressesSchemaAddress $address, $field, UcAddressesFieldHandler $handler) {
  $vars = array(
    '%field' => $field,
  );
  $address_values1 = array();
  $value1 = self::generateAddressFieldValue($field, $address_values1);
  $address_values2 = array();
  $value2 = self::generateAddressFieldValue($field, $address_values2);

  // Getters.
  $this
    ->assertEqual($handler
    ->getFieldName(), $field, format_string('The method getFieldName() for field %field returns the expected value.', $vars));
  $this
    ->assertEqual($handler
    ->getAddress(), $address, format_string('The method getAddress() for field %field returns the expected value.', $vars));
  $this
    ->assertTrue(is_string($handler
    ->getContext()), format_string('The method getContext() for field %field returns the expected format.', $vars));
  $this
    ->assertTrue(is_string($handler
    ->getFieldTitle()), format_string('The method getFieldTitle() for field %field returns the expected format.', $vars));
  $form = array();
  $form_state = array();
  $form_field = $handler
    ->getFormField($form, $form_state);
  $render = drupal_render($form_field);
  $this
    ->assertTrue(is_bool($handler
    ->isFieldEnabled()), format_string('The method isFieldEnabled() for field %field returns the expected format.', $vars));
  $this
    ->assertTrue(is_bool($handler
    ->isFieldRequired()), format_string('The method isFieldRequired() for field %field returns the expected format.', $vars));

  // Setters.
  $handler
    ->setValue($value1);
  $this
    ->assertEqual($address
    ->getField($field), $value1, format_string('The method setValue() had set the expected value.', $vars));

  // Action.
  $handler
    ->validateValue($value2);
  $this
    ->assertTrue(is_bool($handler
    ->checkContext()), format_string('The method checkContext() for field %field returns the expected format.', $vars));

  // Feeds.
  $this
    ->assertTrue(is_array($handler
    ->getMappingTargets()), format_string('The method getMappingTargets() for field %field returns the expected format.', $vars));
  $handler
    ->mapValue($value2);
  $this
    ->assertEqual($address
    ->getField($field), $value2, format_string('The method mapValue() for field %field has set the expected value.', $vars));

  // Output.
  $this
    ->assertTrue(is_array($handler
    ->getTokenInfo()), format_string('The method getTokenInfo() for field %field returns the expected format.', $vars));
  $this
    ->assertTrue(is_array($handler
    ->getOutputFormats()), format_string('The method getOutputFormats() for field %field returns the expected format.', $vars));
  $this
    ->assertTrue(is_string($handler
    ->outputValue()), format_string('The method outputValue() for field %field returns the expected format.', $vars));
}