2017-01-18 04:58:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\i18n\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Convert;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\i18n\Messages\YamlWriter;
|
|
|
|
|
|
|
|
class YamlWriterTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testYamlWriter()
|
|
|
|
{
|
|
|
|
$writer = new YamlWriter();
|
|
|
|
$entities = [
|
|
|
|
'Level1.Level2.EntityName' => 'Text',
|
|
|
|
'Level1.OtherEntityName' => 'Other Text',
|
|
|
|
'Level1.Plurals' => [
|
2017-01-25 04:35:13 +01:00
|
|
|
'context' => 'Some ignored context',
|
2017-01-18 04:58:48 +01:00
|
|
|
'one' => 'An item',
|
|
|
|
'other' => '{count} items',
|
|
|
|
],
|
2017-01-25 04:35:13 +01:00
|
|
|
'Level1.PluralString1' => 'An item|{count} items',
|
|
|
|
'Level1.PluralString2' => [
|
|
|
|
'context' => 'Another ignored context',
|
|
|
|
'default' => 'An item|{count} items',
|
|
|
|
],
|
|
|
|
// Some near-false-positives for plurals
|
|
|
|
'Level1.NotPlural1' => 'Not a plural|string', // no count
|
|
|
|
'Level1.NotPlural2' => 'Not|a|plural|string{count}', // unexpected number
|
|
|
|
'Level1.NotPlural3' => 'Not a plural string {count}', // no pipe
|
2017-01-18 04:58:48 +01:00
|
|
|
'Level1.BoolTest' => 'True',
|
|
|
|
'Level1.FlagTest' => 'No',
|
|
|
|
'Level1.TextTest' => 'Maybe',
|
2017-01-25 04:35:13 +01:00
|
|
|
'Template.ss.Key' => 'Template var',
|
2017-01-18 04:58:48 +01:00
|
|
|
'TopLevel' => 'The Top',
|
|
|
|
];
|
|
|
|
$yaml = <<<YAML
|
|
|
|
de:
|
|
|
|
Level1:
|
2017-01-25 04:35:13 +01:00
|
|
|
BoolTest: 'True'
|
|
|
|
FlagTest: 'No'
|
2017-01-18 04:58:48 +01:00
|
|
|
Level2.EntityName: Text
|
2017-01-25 04:35:13 +01:00
|
|
|
NotPlural1: 'Not a plural|string'
|
|
|
|
NotPlural2: 'Not|a|plural|string{count}'
|
|
|
|
NotPlural3: 'Not a plural string {count}'
|
2017-01-18 04:58:48 +01:00
|
|
|
OtherEntityName: 'Other Text'
|
2017-01-25 04:35:13 +01:00
|
|
|
PluralString1:
|
|
|
|
one: 'An item'
|
|
|
|
other: '{count} items'
|
|
|
|
PluralString2:
|
|
|
|
one: 'An item'
|
|
|
|
other: '{count} items'
|
2017-01-18 04:58:48 +01:00
|
|
|
Plurals:
|
|
|
|
one: 'An item'
|
|
|
|
other: '{count} items'
|
|
|
|
TextTest: Maybe
|
2017-01-25 04:35:13 +01:00
|
|
|
Template.ss:
|
|
|
|
Key: 'Template var'
|
2017-01-18 04:58:48 +01:00
|
|
|
TopLevel: 'The Top'
|
|
|
|
|
|
|
|
YAML;
|
|
|
|
$this->assertEquals($yaml, Convert::nl2os($writer->getYaml($entities, 'de')));
|
|
|
|
}
|
|
|
|
}
|