|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\i18n\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Core\Convert; |
|
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
7
|
|
|
use SilverStripe\i18n\Messages\YamlWriter; |
|
8
|
|
|
|
|
9
|
|
|
class YamlWriterTest extends SapphireTest |
|
10
|
|
|
{ |
|
11
|
|
|
public function testYamlWriter() |
|
12
|
|
|
{ |
|
13
|
|
|
$writer = new YamlWriter(); |
|
14
|
|
|
$entities = [ |
|
15
|
|
|
'Level1.Level2.EntityName' => 'Text', |
|
16
|
|
|
'Level1.OtherEntityName' => 'Other Text', |
|
17
|
|
|
'Level1.Plurals' => [ |
|
18
|
|
|
'context' => 'Some ignored context', |
|
19
|
|
|
'one' => 'An item', |
|
20
|
|
|
'other' => '{count} items', |
|
21
|
|
|
], |
|
22
|
|
|
'Level1.PluralString1' => 'An item|{count} items', |
|
23
|
|
|
'Level1.PluralString2' => [ |
|
24
|
|
|
'context' => 'Another ignored context', |
|
25
|
|
|
'default' => 'An item|{count} items', |
|
26
|
|
|
], |
|
27
|
|
|
// Some near-false-positives for plurals |
|
28
|
|
|
'Level1.NotPlural1' => 'Not a plural|string', // no count |
|
29
|
|
|
'Level1.NotPlural2' => 'Not|a|plural|string{count}', // unexpected number |
|
30
|
|
|
'Level1.NotPlural3' => 'Not a plural string {count}', // no pipe |
|
31
|
|
|
'Level1.BoolTest' => 'True', |
|
32
|
|
|
'Level1.FlagTest' => 'No', |
|
33
|
|
|
'Level1.TextTest' => 'Maybe', |
|
34
|
|
|
'Template.ss.Key' => 'Template var', |
|
35
|
|
|
'TopLevel' => 'The Top', |
|
36
|
|
|
]; |
|
37
|
|
|
$yaml = <<<YAML |
|
38
|
|
|
de: |
|
39
|
|
|
Level1: |
|
40
|
|
|
BoolTest: 'True' |
|
41
|
|
|
FlagTest: 'No' |
|
42
|
|
|
Level2.EntityName: Text |
|
43
|
|
|
NotPlural1: 'Not a plural|string' |
|
44
|
|
|
NotPlural2: 'Not|a|plural|string{count}' |
|
45
|
|
|
NotPlural3: 'Not a plural string {count}' |
|
46
|
|
|
OtherEntityName: 'Other Text' |
|
47
|
|
|
PluralString1: |
|
48
|
|
|
one: 'An item' |
|
49
|
|
|
other: '{count} items' |
|
50
|
|
|
PluralString2: |
|
51
|
|
|
one: 'An item' |
|
52
|
|
|
other: '{count} items' |
|
53
|
|
|
Plurals: |
|
54
|
|
|
one: 'An item' |
|
55
|
|
|
other: '{count} items' |
|
56
|
|
|
TextTest: Maybe |
|
57
|
|
|
Template.ss: |
|
58
|
|
|
Key: 'Template var' |
|
59
|
|
|
TopLevel: 'The Top' |
|
60
|
|
|
|
|
61
|
|
|
YAML; |
|
62
|
|
|
$this->assertEquals($yaml, Convert::nl2os($writer->getYaml($entities, 'de'))); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|