1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<?php
/**
* Tests for yaml wrapper.
*
* @author Niklas Laxström
* @license GPL-2.0-or-later
*/
class TranslateYamlTest extends MediaWikiIntegrationTestCase {
protected function setUp() : void {
parent::setUp();
$this->setMwGlobals( [
'wgTranslateYamlLibrary' => 'phpyaml',
] );
}
/**
* TODO: test other drivers too.
* @requires function yaml_parse
* @dataProvider provideTestLoadString
*/
public function testLoadStringPhpyaml( $input, $expected, $comment ) {
$output = TranslateYaml::loadString( $input );
$this->assertEquals( $expected, $output, $comment );
}
public function provideTestLoadString() {
$tests = [];
$tests[] = [
'a: b',
[ 'a' => 'b' ],
'Simple key-value'
];
$tests[] = [
'a: !php/object "O:8:\"stdClass\":1:{s:1:\"a\";s:1:\"b\";}"',
[ 'a' => 'O:8:"stdClass":1:{s:1:"a";s:1:"b";}' ],
'PHP objects must not be unserialized'
];
return $tests;
}
/**
* Tests workaround for https://bugs.php.net/bug.php?id=76309
* @requires function yaml_emit
*/
public function testBug76309() {
$input = [
'a' => '2.',
'b' => '22222222222222222222222222222222222222222222222222222222222222.',
'c' => 2.0,
'd' => "2.0"
];
$expected = <<<YAML
---
a: "2."
b: "22222222222222222222222222222222222222222222222222222222222222."
c: 2.000000
d: "2.0"
...
YAML;
$output = TranslateYaml::dump( $input );
$this->assertEquals( $expected, $output, "Floaty strings outputted as strings" );
$parsed = TranslateYaml::loadString( $output );
$this->assertEquals( $input, $parsed, "Floaty strings roundtrip" );
}
}
|