82226d0d3425d2266f701c879284eb88b86d87e5
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Serialization / YamlTestBase.php
1 <?php
2
3 namespace Drupal\Tests\Component\Serialization;
4
5 use PHPUnit\Framework\TestCase;
6
7 /**
8  * Provides standard data to validate different YAML implementations.
9  */
10 abstract class YamlTestBase extends TestCase {
11
12   /**
13    * Some data that should be able to be serialized.
14    */
15   public function providerEncodeDecodeTests() {
16     return [
17       [
18         'foo' => 'bar',
19         'id' => 'schnitzel',
20         'ponies' => ['nope', 'thanks'],
21         'how' => [
22           'about' => 'if',
23           'i' => 'ask',
24           'nicely',
25         ],
26         'the' => [
27           'answer' => [
28             'still' => 'would',
29             'be' => 'Y',
30           ],
31         ],
32         'how_many_times' => 123,
33         'should_i_ask' => FALSE,
34         1,
35         FALSE,
36         [1, FALSE],
37         [10],
38         [0 => '123456'],
39       ],
40       [NULL],
41     ];
42   }
43
44   /**
45    * Some data that should be able to be de-serialized.
46    */
47   public function providerDecodeTests() {
48     $data = [
49       // NULL files.
50       ['', NULL],
51       ["\n", NULL],
52       ["---\n...\n", NULL],
53
54       // Node anchors.
55       [
56         "
57 jquery.ui:
58   version: &jquery_ui 1.10.2
59
60 jquery.ui.accordion:
61   version: *jquery_ui
62 ",
63         [
64           'jquery.ui' => [
65             'version' => '1.10.2',
66           ],
67           'jquery.ui.accordion' => [
68             'version' => '1.10.2',
69           ],
70         ],
71       ],
72     ];
73
74     // 1.2 Bool values.
75     foreach ($this->providerBoolTest() as $test) {
76       $data[] = ['bool: ' . $test[0], ['bool' => $test[1]]];
77     }
78     $data = array_merge($data, $this->providerBoolTest());
79
80     return $data;
81   }
82
83   /**
84    * Tests different boolean serialization and de-serialization.
85    */
86   public function providerBoolTest() {
87     return [
88       ['true', TRUE],
89       ['TRUE', TRUE],
90       ['True', TRUE],
91       ['y', 'y'],
92       ['Y', 'Y'],
93       ['false', FALSE],
94       ['FALSE', FALSE],
95       ['False', FALSE],
96       ['n', 'n'],
97       ['N', 'N'],
98     ];
99   }
100
101 }