You are here

protected function UcAddressesApiTestCase::doHandlerTests in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 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 353
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, t('The method getFieldName() for field %field returns the expected value.', $vars));
  $this
    ->assertEqual($handler
    ->getAddress(), $address, t('The method getAddress() for field %field returns the expected value.', $vars));
  $this
    ->assertTrue(is_string($handler
    ->getContext()), t('The method getContext() for field %field returns the expected format.', $vars));
  $this
    ->assertTrue(is_string($handler
    ->getFieldTitle()), t('The method getFieldTitle() for field %field returns the expected format.', $vars));
  $form = array();
  $form_state = array();
  $form[$field] = $handler
    ->getFormField($form, $form_state);
  drupal_prepare_form('dummy', $form, $form_state);
  $form['#post'] = $_POST;
  drupal_process_form('dummy', $form, $form_state);
  $render = drupal_render_form('dummy', $form);
  $this
    ->assertTrue(is_bool($handler
    ->isFieldEnabled()), t('The method isFieldEnabled() for field %field returns the expected format.', $vars));
  $this
    ->assertTrue(is_bool($handler
    ->isFieldRequired()), t('The method isFieldRequired() for field %field returns the expected format.', $vars));

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

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

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