3 namespace Drupal\Tests\token\Kernel;
10 class ArrayTest extends KernelTestBase {
12 function testArrayTokens() {
13 // Test a simple array.
14 $array = [0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd'];
21 'keys' => '0, 1, 2, 4',
22 'keys:value:3' => '4',
23 'keys:join' => '0124',
24 'reversed' => 'd, c, b, a',
25 'reversed:keys' => '4, 2, 1, 0',
26 'join:/' => 'a/b/c/d',
28 'join:, ' => 'a, b, c, d',
29 'join: ' => 'a b c d',
31 $this->assertTokens('array', ['array' => $array], $tokens);
33 // Test a mixed simple and render array.
34 // 2 => c, 0 => a, 4 => d, 1 => b
36 '#property' => 'value',
38 1 => ['#markup' => 'b', '#weight' => 0.01],
39 2 => ['#markup' => 'c', '#weight' => -10],
40 4 => ['#markup' => 'd', '#weight' => 0],
48 'keys' => '2, 0, 4, 1',
49 'keys:value:3' => '1',
50 'keys:join' => '2041',
51 'reversed' => 'b, d, a, c',
52 'reversed:keys' => '1, 4, 0, 2',
53 'join:/' => 'c/a/d/b',
55 'join:, ' => 'c, a, d, b',
56 'join: ' => 'c a d b',
58 $this->assertTokens('array', ['array' => $array], $tokens);