Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\Component\Serialization; | |
4 | |
5 use Drupal\Component\Serialization\Exception\InvalidDataTypeException; | |
6 use Drupal\Component\Serialization\YamlPecl; | |
7 | |
8 /** | |
9 * Tests the YamlPecl serialization implementation. | |
10 * | |
11 * @group Drupal | |
12 * @group Serialization | |
13 * @coversDefaultClass \Drupal\Component\Serialization\YamlPecl | |
14 * @requires extension yaml | |
15 */ | |
16 class YamlPeclTest extends YamlTestBase { | |
17 | |
18 /** | |
19 * Tests encoding and decoding basic data structures. | |
20 * | |
21 * @covers ::encode | |
22 * @covers ::decode | |
23 * @dataProvider providerEncodeDecodeTests | |
24 */ | |
25 public function testEncodeDecode($data) { | |
26 $this->assertEquals($data, YamlPecl::decode(YamlPecl::encode($data))); | |
27 } | |
28 | |
29 /** | |
30 * Ensures that php object support is disabled. | |
31 */ | |
32 public function testObjectSupportDisabled() { | |
33 $object = new \stdClass(); | |
34 $object->foo = 'bar'; | |
35 $this->assertEquals(['O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}'], YamlPecl::decode(YamlPecl::encode([$object]))); | |
36 $this->assertEquals(0, ini_get('yaml.decode_php')); | |
37 } | |
38 | |
39 /** | |
40 * Tests decoding YAML node anchors. | |
41 * | |
42 * @covers ::decode | |
43 * @dataProvider providerDecodeTests | |
44 */ | |
45 public function testDecode($string, $data) { | |
46 $this->assertEquals($data, YamlPecl::decode($string)); | |
47 } | |
48 | |
49 /** | |
50 * Tests our encode settings. | |
51 * | |
52 * @covers ::encode | |
53 */ | |
54 public function testEncode() { | |
55 $this->assertEquals('--- | |
56 foo: | |
57 bar: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis | |
58 ... | |
59 ', YamlPecl::encode(['foo' => ['bar' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis']])); | |
60 } | |
61 | |
62 /** | |
63 * Tests YAML boolean callback. | |
64 * | |
65 * @param string $string | |
66 * String value for the YAML boolean. | |
67 * @param string|bool $expected | |
68 * The expected return value. | |
69 * | |
70 * @covers ::applyBooleanCallbacks | |
71 * @dataProvider providerBoolTest | |
72 */ | |
73 public function testApplyBooleanCallbacks($string, $expected) { | |
74 $this->assertEquals($expected, YamlPecl::applyBooleanCallbacks($string, 'bool', NULL)); | |
75 } | |
76 | |
77 /** | |
78 * @covers ::getFileExtension | |
79 */ | |
80 public function testGetFileExtension() { | |
81 $this->assertEquals('yml', YamlPecl::getFileExtension()); | |
82 } | |
83 | |
84 /** | |
85 * Tests that invalid YAML throws an exception. | |
86 * | |
87 * @covers ::errorHandler | |
88 */ | |
89 public function testError() { | |
90 $this->setExpectedException(InvalidDataTypeException::class); | |
91 YamlPecl::decode('foo: [ads'); | |
92 } | |
93 | |
94 } |