1 token.test TokenArrayTestCase::testArrayTokens()

File

core/modules/simpletest/tests/token.test, line 913
Test integration for the token module.

Class

TokenArrayTestCase

Code

function testArrayTokens() {
  // Test a simple array.
  $array = array(0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd');
  $tokens = array(
    'first' => 'a',
    'last' => 'd',
    'value:0' => 'a',
    'value:2' => 'c',
    'count' => 4,
    'keys' => '0, 1, 2, 4',
    'keys:value:3' => '4',
    'keys:join' => '0124',
    'reversed' => 'd, c, b, a',
    'reversed:keys' => '4, 2, 1, 0',
    'join:/' => 'a/b/c/d',
    'join' => 'abcd',
    'join:, ' => 'a, b, c, d',
    'join: ' => 'a b c d',
  );
  $this->assertTokens('array', array('array' => $array), $tokens);

  // Test a render array.
  // 2 => c, 0 => a, 4 => d, 1 => b
  $array = array(
    '#property' => 'value',
    0 => array('#markup' => 'a', '#weight' => -0.001),
    1 => array('#markup' => 'b', '#weight' => 0.01),
    2 => array('#markup' => 'c', '#weight' => -10),
    4 => array('#markup' => 'd', '#weight' => 0),
  );
  $tokens = array(
    'first' => 'c',
    'last' => 'b',
    'value:0' => 'a',
    'value:2' => 'c',
    'count' => 4,
    'keys' => '2, 0, 4, 1',
    'keys:value:3' => '1',
    'keys:join' => '2041',
    'reversed' => 'b, d, a, c',
    'reversed:keys' => '1, 4, 0, 2',
    'join:/' => 'c/a/d/b',
    'join' => 'cadb',
    'join:, ' => 'c, a, d, b',
    'join: ' => 'c a d b',
  );
  $this->assertTokens('array', array('array' => $array), $tokens, array('array sort' => TRUE));
}