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