diff --git a/core/tests/Drupal/Tests/Component/Yaml/YamlTest.php b/core/tests/Drupal/Tests/Component/Yaml/YamlTest.php new file mode 100644 index 0000000..a94c572 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Yaml/YamlTest.php @@ -0,0 +1,90 @@ + 'YAML handling', + 'description' => "Test the parsing and dumping of YAML is consistent between the PECL and Symfony implementations.", + 'group' => 'YAML', + ); + } + + /** + * Tests dumping with Symfony and parsing with PECL. + * + * @dataProvider providerYamlData + */ + public function testAlternateDumperParser($data, $parser_class, $dumper_class) { + $dumper = new $dumper_class; + $parser = new $parser_class; + + $dumped = $dumper->dump($data); + + $parsed = $parser->parse($dumped); + + $this->assertEquals($data, $parsed); + } + + /** + * Data provider for YAML instance tests. + * + * @return array + */ + public function providerYamlData() { + $object = array( + 'foo' => 'bar', + 'id' => 'schnitzel', + 'ponies' => array('nope', 'thanks'), + 'how' => array( + 'about' => 'if', + 'i' => 'ask', + 'nicely' + ), + 'the' => array( + 'answer' => array( + 'still' => 'would', + 'be' => 'nope', + ), + ), + 'how_many_times' => 123, + 'should_i_ask' => FALSE, + 1, + FALSE, + array(1, FALSE), + array(10), + array(0 => '123456'), + ); + // Test parsing with Symfony and dumping with PECL. + $data[] = array( + $object, + 'Drupal\Component\Yaml\Symfony', + 'Drupal\Component\Yaml\Pecl' + ); + + // Test parsing with PECL and dumping with Symfony. + $data[] = array( + $object, + 'Drupal\Component\Yaml\Pecl', + 'Drupal\Component\Yaml\Symfony' + ); + + return $data; + } + +}