More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Serialization / YamlSymfonyTest.php
1 <?php
2
3 namespace Drupal\Tests\Component\Serialization;
4
5 use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
6 use Drupal\Component\Serialization\YamlSymfony;
7
8 /**
9  * Tests the YamlSymfony serialization implementation.
10  *
11  * @group Drupal
12  * @group Serialization
13  * @coversDefaultClass \Drupal\Component\Serialization\YamlSymfony
14  */
15 class YamlSymfonyTest extends YamlTestBase {
16
17   /**
18    * Tests encoding and decoding basic data structures.
19    *
20    * @covers ::encode
21    * @covers ::decode
22    * @dataProvider providerEncodeDecodeTests
23    */
24   public function testEncodeDecode($data) {
25     $this->assertEquals($data, YamlSymfony::decode(YamlSymfony::encode($data)));
26   }
27
28   /**
29    * Tests decoding YAML node anchors.
30    *
31    * @covers ::decode
32    * @dataProvider providerDecodeTests
33    */
34   public function testDecode($string, $data) {
35     $this->assertEquals($data, YamlSymfony::decode($string));
36   }
37
38   /**
39    * Tests our encode settings.
40    *
41    * @covers ::encode
42    */
43   public function testEncode() {
44     $this->assertEquals('foo:
45   bar: \'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis\'
46 ', YamlSymfony::encode(['foo' => ['bar' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis']]));
47   }
48
49   /**
50    * @covers ::getFileExtension
51    */
52   public function testGetFileExtension() {
53     $this->assertEquals('yml', YamlSymfony::getFileExtension());
54   }
55
56   /**
57    * Tests that invalid YAML throws an exception.
58    *
59    * @covers ::decode
60    */
61   public function testError() {
62     if (method_exists($this, 'expectException')) {
63       $this->expectException(InvalidDataTypeException::class);
64     }
65     else {
66       $this->setExpectedException(InvalidDataTypeException::class);
67     }
68     YamlSymfony::decode('foo: [ads');
69   }
70
71   /**
72    * Ensures that php object support is disabled.
73    *
74    * @covers ::encode
75    */
76   public function testObjectSupportDisabled() {
77     if (method_exists($this, 'expectException')) {
78       $this->expectException(InvalidDataTypeException::class);
79       $this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.');
80     }
81     else {
82       $this->setExpectedException(InvalidDataTypeException::class, 'Object support when dumping a YAML file has been disabled.');
83     }
84     $object = new \stdClass();
85     $object->foo = 'bar';
86     YamlSymfony::encode([$object]);
87   }
88
89 }