Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / token / tests / src / Kernel / ArrayTest.php
1 <?php
2
3 namespace Drupal\Tests\token\Kernel;
4
5 /**
6  * Tests array tokens.
7  *
8  * @group token
9  */
10 class ArrayTest extends KernelTestBase {
11
12   function testArrayTokens() {
13     // Test a simple array.
14     $array = [0 => 'a', 1 => 'b', 2 => 'c', 4 => 'd'];
15     $tokens = [
16       'first' => 'a',
17       'last' => 'd',
18       'value:0' => 'a',
19       'value:2' => 'c',
20       'count' => 4,
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',
27       'join' => 'abcd',
28       'join:, ' => 'a, b, c, d',
29       'join: ' => 'a b c d',
30     ];
31     $this->assertTokens('array', ['array' => $array], $tokens);
32
33     // Test a mixed simple and render array.
34     // 2 => c, 0 => a, 4 => d, 1 => b
35     $array = [
36       '#property' => 'value',
37       0 => 'a',
38       1 => ['#markup' => 'b', '#weight' => 0.01],
39       2 => ['#markup' => 'c', '#weight' => -10],
40       4 => ['#markup' => 'd', '#weight' => 0],
41     ];
42     $tokens = [
43       'first' => 'c',
44       'last' => 'b',
45       'value:0' => 'a',
46       'value:2' => 'c',
47       'count' => 4,
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',
54       'join' => 'cadb',
55       'join:, ' => 'c, a, d, b',
56       'join: ' => 'c a d b',
57     ];
58     $this->assertTokens('array', ['array' => $array], $tokens);
59   }
60
61 }