You are here

protected function UcAddressesTokenTestCase::doAddressTokenTests in Ubercart Addresses 7

Helper function for testAddressTokens().

@access protected

Parameters

array $tokens: The address tokens to test for replacement.

array $data: The data to pass to token_replace().

UcAddressesAddress $address: The address object to test the values for.

string $prefix: (optional) The prefix to add before each token. Defaults to "uc_addresses:".

Return value

void

1 call to UcAddressesTokenTestCase::doAddressTokenTests()
UcAddressesTokenTestCase::testAddressTokens in tests/uc_addresses.tokens.test
Test if tokens defined by Ubercart Addresses work.

File

tests/uc_addresses.tokens.test, line 129
Test cases for the token replacement.

Class

UcAddressesTokenTestCase
Test cases for the api component.

Code

protected function doAddressTokenTests($tokens, $data, UcAddressesAddress $address, $prefix = 'uc_addresses:') {
  foreach ($tokens as $token) {
    $fieldName = $token;
    $format = '';
    if (strpos($fieldName, ':')) {
      $token_pieces = explode(':', $fieldName);
      $fieldName = $token_pieces[0];
      $format = $token_pieces[1];
    }
    $text = '[' . $prefix . $token . ']';
    $replaced = token_replace($text, $data);
    $this
      ->assertEqual($replaced, $address
      ->getFieldValue($fieldName, $format, 'token'), t('The token @token got replaced correctly. Value: @value', array(
      '@token' => $text,
      '@value' => $replaced,
    )));
  }
}