Passed
Push — master ( f17c4a...767498 )
by Aimeos
02:18
created

GettextTest::testDtFallback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2022
6
 */
7
8
9
namespace Aimeos\Base\Translation;
10
11
12
class GettextTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
16
17
	protected function setUp() : void
18
	{
19
		$ds = DIRECTORY_SEPARATOR;
20
21
		$translationSources = array(
22
			'testDomain' => array( __DIR__ . $ds . 'testfiles' . $ds . 'case1' ),
23
		);
24
25
		$this->object = new \Aimeos\Base\Translation\Gettext( $translationSources, 'de_DE' );
26
	}
27
28
29
	protected function tearDown() : void
30
	{
31
		unset( $this->object );
32
	}
33
34
35
	public function testDomainInvalid()
36
	{
37
		$this->expectException( \Aimeos\Base\Translation\Exception::class );
38
		$this->object->dt( 'invalid', 'File' );
39
	}
40
41
42
	public function testDt()
43
	{
44
		$this->assertEquals( 'Datei', $this->object->dt( 'testDomain', 'File' ) );
45
	}
46
47
48
	public function testDtFallback()
49
	{
50
		$this->assertEquals( 'notexisting', $this->object->dt( 'testDomain', 'notexisting' ) );
51
	}
52
53
54
	public function testDn()
55
	{
56
		/*
57
		 * plural for RU: 3 pl forms
58
		 * 0, if $n == 1, 21, 31, 41, ...
59
		 * 1, if $n == 2..4, 22..24, 32..34, ...
60
		 * 2, if $n == 5..20, 25..30, 35..40, .
61
		 */
62
		$ds = DIRECTORY_SEPARATOR;
63
64
		$translationSources = array(
65
			'testDomain' => array( __DIR__ . $ds . 'testfiles' . $ds . 'case1' ),
66
		);
67
68
		$object = new \Aimeos\Base\Translation\Gettext( $translationSources, 'ru' );
69
70
		$this->assertEquals( 'plural 2', $object->dn( 'testDomain', 'File', 'Files', 0 ) );
71
		$this->assertEquals( 'singular', $object->dn( 'testDomain', 'File', 'Files', 1 ) );
72
		$this->assertEquals( 'plural 1', $object->dn( 'testDomain', 'File', 'Files', 2 ) );
73
		$this->assertEquals( 'plural 2', $object->dn( 'testDomain', 'File', 'Files', 5 ) );
74
75
		$this->assertEquals( 'plural 1', $object->dn( 'testDomain', 'File', 'Files', 22 ) );
76
		$this->assertEquals( 'plural 2', $object->dn( 'testDomain', 'File', 'Files', 25 ) );
77
		$this->assertEquals( 'singular', $object->dn( 'testDomain', 'File', 'Files', 31 ) );
78
	}
79
80
81
	public function testDnFallback()
82
	{
83
		$this->assertEquals( 'notexists', $this->object->dn( 'testDomain', 'notexists', 'notexisting', 1 ) );
84
		$this->assertEquals( 'notexisting', $this->object->dn( 'testDomain', 'notexists', 'notexisting', 2 ) );
85
	}
86
87
88
	public function testDnOverwriteSingular()
89
	{
90
		$ds = DIRECTORY_SEPARATOR;
91
92
		$translationSources = array(
93
			'testDomain' => array(
94
				__DIR__ . $ds . 'testfiles' . $ds . 'case1',
95
				__DIR__ . $ds . 'testfiles' . $ds . 'case2',
96
			),
97
		);
98
99
		$object = new \Aimeos\Base\Translation\Gettext( $translationSources, 'de_DE' );
100
		$this->assertEquals( 'Neue Version', $object->dt( 'testDomain', 'Update' ) );
101
	}
102
103
104
	public function testDnOverwritePlural()
105
	{
106
		$ds = DIRECTORY_SEPARATOR;
107
108
		$translationSources = array(
109
			'testDomain' => array(
110
				__DIR__ . $ds . 'testfiles' . $ds . 'case1',
111
				__DIR__ . $ds . 'testfiles' . $ds . 'case2',
112
			),
113
		);
114
115
		$object = new \Aimeos\Base\Translation\Gettext( $translationSources, 'de_DE' );
116
		$this->assertEquals( 'KFZs', $object->dn( 'testDomain', 'Car', 'Cars', 25 ) );
117
	}
118
119
120
	public function testGetAll()
121
	{
122
		$ds = DIRECTORY_SEPARATOR;
123
124
		$translationSources = array(
125
			'testDomain' => array(
126
				__DIR__ . $ds . 'testfiles' . $ds . 'case1',
127
				__DIR__ . $ds . 'testfiles' . $ds . 'case2',
128
			),
129
		);
130
131
		$object = new \Aimeos\Base\Translation\Gettext( $translationSources, 'de_DE' );
132
		$result = $object->all( 'testDomain' );
133
134
		$this->assertArrayHasKey( 'Car', $result );
135
		$this->assertEquals( 'KFZ', $result['Car'][0] );
136
		$this->assertEquals( 'KFZs', $result['Car'][1] );
137
		$this->assertArrayHasKey( 'File', $result );
138
		$this->assertEquals( 'Datei mehr', $result['File'][0] );
139
		$this->assertEquals( 'Dateien mehr', $result['File'][1] );
140
		$this->assertArrayHasKey( 'Update', $result );
141
		$this->assertEquals( 'Neue Version', $result['Update'] );
142
	}
143
144
}
145