|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2018 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\MW\Translation; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Test class for \Aimeos\MW\Translation\Zend2Test. |
|
14
|
|
|
*/ |
|
15
|
|
|
class Zend2Test extends \PHPUnit\Framework\TestCase |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
private $object; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Sets up the fixture, for example, opens a network connection. |
|
22
|
|
|
* This method is called before a test is executed. |
|
23
|
|
|
* |
|
24
|
|
|
* @access protected |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
if( !class_exists( '\Zend\I18n\Translator\Translator' ) ) { |
|
29
|
|
|
$this->markTestSkipped( '\Zend\I18n\Translator\Translator is not available' ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
33
|
|
|
|
|
34
|
|
|
$this->translationSources = array( |
|
|
|
|
|
|
35
|
|
|
'testDomain' => array( __DIR__ . $ds . 'testfiles' . $ds . 'case1' ), |
|
36
|
|
|
'otherTestDomain' => array( __DIR__ . $ds . 'testfiles' . $ds . 'case2' ), |
|
37
|
|
|
'thirdTestDomain' => array( __DIR__ . $ds . 'testfiles' . $ds . 'case3' ), |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
$this->object = new \Aimeos\MW\Translation\Zend2( $this->translationSources, 'PhpArray', 'ru_ZD' ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Tears down the fixture, for example, closes a network connection. |
|
46
|
|
|
* This method is called after a test is executed. |
|
47
|
|
|
* |
|
48
|
|
|
* @access protected |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function tearDown() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->object = null; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
public function testDt() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->assertEquals( 'singular translation', $this->object->dt( 'testDomain', 'File' ) ); |
|
59
|
|
|
$this->assertEquals( 'Test default return', $this->object->dt( 'otherTestDomain', 'Test default return' ) ); |
|
60
|
|
|
$this->assertEquals( 'test', $this->object->dt( 'invalidTestDomain', 'test' ) ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
public function testDtInvalid() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->assertEquals( '', $this->object->dt( 'testDomain', null ) ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
public function testDn() |
|
71
|
|
|
{ |
|
72
|
|
|
/* |
|
73
|
|
|
* plural for RU: 3 pl forms |
|
74
|
|
|
* 0, if $n == 1, 21, 31, 41, ... |
|
75
|
|
|
* 1, if $n == 2..4, 22..24, 32..34, ... |
|
76
|
|
|
* 2, if $n == 5..20, 25..30, 35..40, . |
|
77
|
|
|
*/ |
|
78
|
|
|
$this->assertEquals( 'plural 2 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 0 ) ); |
|
79
|
|
|
$this->assertEquals( 'singular translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 1 ) ); |
|
80
|
|
|
$this->assertEquals( 'plural 1 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 2 ) ); |
|
81
|
|
|
$this->assertEquals( 'plural 2 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 5 ) ); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertEquals( 'plural 1 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 22 ) ); |
|
84
|
|
|
$this->assertEquals( 'plural 2 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 25 ) ); |
|
85
|
|
|
$this->assertEquals( 'singular translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 31 ) ); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals( 'tests', $this->object->dn( 'invalidTestDomain', 'test', 'tests', 2 ) ); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
public function testDnInvalid() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->assertEquals( '', $this->object->dn( 'otherTestDomain', '', null, 1 ) ); |
|
94
|
|
|
$this->assertEquals( '', $this->object->dn( 'otherTestDomain', '', '', null ) ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
// test using the testfiles/case1/ka_GE file; lang: german |
|
99
|
|
|
public function testAdapterGettext() |
|
100
|
|
|
{ |
|
101
|
|
|
$object = new \Aimeos\MW\Translation\Zend2( $this->translationSources, 'gettext', 'ka_GE', array('disableNotices'=>true) ); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertEquals( 'Aktualisierung', $object->dt( 'testDomain', 'Update' ) ); |
|
104
|
|
|
|
|
105
|
|
|
$this->assertEquals( 'Autos', $object->dn( 'testDomain', 'Car', 'Cars', 0 ) ); |
|
106
|
|
|
$this->assertEquals( 'Datei', $object->dn( 'testDomain', 'File', 'Files', 1 ) ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
public function testDnOverwriteFile() |
|
111
|
|
|
{ |
|
112
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
113
|
|
|
|
|
114
|
|
|
$translationSources = array( |
|
115
|
|
|
'testDomain' => array( |
|
116
|
|
|
__DIR__ . $ds . 'testfiles' . $ds . 'case2', |
|
117
|
|
|
__DIR__ . $ds . 'testfiles' . $ds . 'case3', |
|
118
|
|
|
), |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
|
|
$object = new \Aimeos\MW\Translation\Zend2( $translationSources, 'PhpArray', 'ru_ZD' ); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertEquals( 'plural 11 translation', $object->dn( 'testDomain', 'File', 'Files', 25 ) ); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
public function testDnOverwriteGettextSingular() |
|
128
|
|
|
{ |
|
129
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
130
|
|
|
|
|
131
|
|
|
$translationSources = array( |
|
132
|
|
|
'testDomain' => array( |
|
133
|
|
|
__DIR__ . $ds . 'testfiles' . $ds . 'case1', |
|
134
|
|
|
__DIR__ . $ds . 'testfiles' . $ds . 'case2', |
|
135
|
|
|
), |
|
136
|
|
|
); |
|
137
|
|
|
|
|
138
|
|
|
$object = new \Aimeos\MW\Translation\Zend2( $translationSources, 'gettext', 'ka_GE' ); |
|
139
|
|
|
$this->assertEquals( 'Neue Version', $object->dt( 'testDomain', 'Update' ) ); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
public function testDnOverwriteGettextPlural() |
|
144
|
|
|
{ |
|
145
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
146
|
|
|
|
|
147
|
|
|
$translationSources = array( |
|
148
|
|
|
'testDomain' => array( |
|
149
|
|
|
__DIR__ . $ds . 'testfiles' . $ds . 'case1', |
|
150
|
|
|
__DIR__ . $ds . 'testfiles' . $ds . 'case2', |
|
151
|
|
|
), |
|
152
|
|
|
); |
|
153
|
|
|
|
|
154
|
|
|
$object = new \Aimeos\MW\Translation\Zend2( $translationSources, 'gettext', 'ka_GE' ); |
|
155
|
|
|
$this->assertEquals( 'KFZs', $object->dn( 'testDomain', 'Car', 'Cars', 25 ) ); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
public function testGetAll() |
|
160
|
|
|
{ |
|
161
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
162
|
|
|
|
|
163
|
|
|
$translationSources = array( |
|
164
|
|
|
'testDomain' => array( |
|
165
|
|
|
__DIR__ . $ds . 'testfiles' . $ds . 'case1', |
|
166
|
|
|
__DIR__ . $ds . 'testfiles' . $ds . 'case2', |
|
167
|
|
|
), |
|
168
|
|
|
); |
|
169
|
|
|
|
|
170
|
|
|
$object = new \Aimeos\MW\Translation\Zend2( $translationSources, 'gettext', 'ka_GE' ); |
|
171
|
|
|
$result = $object->getAll( 'testDomain' ); |
|
172
|
|
|
|
|
173
|
|
|
$this->assertArrayHasKey( 'Car', $result ); |
|
174
|
|
|
$this->assertEquals( 'KFZ', $result['Car'][0] ); |
|
175
|
|
|
$this->assertEquals( 'KFZs', $result['Car'][1] ); |
|
176
|
|
|
$this->assertArrayHasKey( 'File', $result ); |
|
177
|
|
|
$this->assertEquals( 'Datei mehr', $result['File'][0] ); |
|
178
|
|
|
$this->assertEquals( 'Dateien mehr', $result['File'][1] ); |
|
179
|
|
|
$this->assertArrayHasKey( 'Update', $result ); |
|
180
|
|
|
$this->assertEquals( 'Neue Version', $result['Update'] ); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
} |
|
184
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths