ZendTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 62
dl 0
loc 157
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetAll() 0 22 1
A testDn() 0 18 1
A tearDown() 0 3 1
A setUp() 0 15 2
A testDnOverwriteGettextSingular() 0 13 1
A testAdapterGettext() 0 8 1
A testDt() 0 6 1
A testDnOverwriteCsv() 0 14 1
A testDnOverwriteGettextPlural() 0 13 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2014-2018
7
 */
8
9
10
namespace Aimeos\MW\Translation;
11
12
13
/**
14
 * Test class for \Aimeos\MW\Translation\ZendTest.
15
 */
16
class ZendTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
{
18
	/**
19
	 * @var \Aimeos\MW\Translation\Zend
20
	 */
21
	private $object;
22
23
24
	/**
25
	 * Sets up the fixture, for example, opens a network connection.
26
	 * This method is called before a test is executed.
27
	 *
28
	 * @access protected
29
	 */
30
	protected function setUp()
31
	{
32
		if( !class_exists( 'Zend_Translate' ) ) {
33
			$this->markTestSkipped( 'Zend_Translate is not available' );
34
		}
35
36
		$ds = DIRECTORY_SEPARATOR;
37
38
		$this->translationSources = array(
0 ignored issues
show
Bug Best Practice introduced by
The property translationSources does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
39
			'testDomain' => array( dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case1' ),
40
			'otherTestDomain' => array( dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case2' ), // no file!
41
			'thirdTestDomain' => array( dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case3' ),
42
		);
43
44
		$this->object = new \Aimeos\MW\Translation\Zend( $this->translationSources, 'csv', 'ru_ZD' );
45
	}
46
47
48
	/**
49
	 * Tears down the fixture, for example, closes a network connection.
50
	 * This method is called after a test is executed.
51
	 *
52
	 * @access protected
53
	 */
54
	protected function tearDown()
55
	{
56
		$this->object = null;
57
	}
58
59
60
	public function testDt()
61
	{
62
		$this->assertEquals( 'singular translation', $this->object->dt( 'testDomain', 'File' ) );
63
		$this->assertEquals( 'Test default return', $this->object->dt( 'otherTestDomain', 'Test default return' ) );
64
65
		$this->assertEquals( 'test', $this->object->dt( 'invalidTestDomain', 'test' ) );
66
	}
67
68
69
	public function testDn()
70
	{
71
		/*
72
		 * plural for RU: 3 pl forms
73
		 * 0, if $n == 1, 21, 31, 41, ...
74
		 * 1, if $n == 2..4, 22..24, 32..34, ...
75
		 * 2, if $n == 5..20, 25..30, 35..40, .
76
		 */
77
		$this->assertEquals( 'plural 2 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 0 ) );
78
		$this->assertEquals( 'singular translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 1 ) );
79
		$this->assertEquals( 'plural 1 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 2 ) );
80
		$this->assertEquals( 'plural 2 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 5 ) );
81
82
		$this->assertEquals( 'plural 1 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 22 ) );
83
		$this->assertEquals( 'plural 2 translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 25 ) );
84
		$this->assertEquals( 'singular translation', $this->object->dn( 'otherTestDomain', 'File', 'Files', 31 ) );
85
86
		$this->assertEquals( 'tests', $this->object->dn( 'invalidTestDomain', 'test', 'tests', 2 ) );
87
	}
88
89
90
	// test using the testfiles/case1/ka_GE file; lang: german
91
	public function testAdapterGettext()
92
	{
93
		$object = new \Aimeos\MW\Translation\Zend( $this->translationSources, 'gettext', 'ka_GE', array('disableNotices'=>true) );
94
95
		$this->assertEquals( 'Aktualisierung', $object->dt( 'testDomain', 'Update' ) );
96
97
		$this->assertEquals( 'Auto', $object->dn( 'testDomain', 'Car', 'Cars', 0 ) );
98
		$this->assertEquals( 'Datei', $object->dn( 'testDomain', 'File', 'Files', 1 ) );
99
	}
100
101
102
	public function testDnOverwriteCsv()
103
	{
104
		$ds = DIRECTORY_SEPARATOR;
105
106
		$translationSources = array(
107
			'testDomain' => array(
108
				dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case2',
109
				dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case3',
110
			),
111
		);
112
113
		$object = new \Aimeos\MW\Translation\Zend( $translationSources, 'csv', 'ru_ZD' );
114
115
		$this->assertEquals( 'plural 11 translation', $object->dn( 'testDomain', 'File', 'Files', 25 ) );
116
	}
117
118
119
	public function testDnOverwriteGettextSingular()
120
	{
121
		$ds = DIRECTORY_SEPARATOR;
122
123
		$translationSources = array(
124
			'testDomain' => array(
125
				dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case1',
126
				dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case2',
127
			),
128
		);
129
130
		$object = new \Aimeos\MW\Translation\Zend( $translationSources, 'gettext', 'ka_GE' );
131
		$this->assertEquals( 'Neue Version', $object->dt( 'testDomain', 'Update' ) );
132
	}
133
134
135
	public function testDnOverwriteGettextPlural()
136
	{
137
		$ds = DIRECTORY_SEPARATOR;
138
139
		$translationSources = array(
140
			'testDomain' => array(
141
				dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case1',
142
				dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case2',
143
			),
144
		);
145
146
		$object = new \Aimeos\MW\Translation\Zend( $translationSources, 'gettext', 'ka_GE' );
147
		$this->assertEquals( 'KFZ', $object->dn( 'testDomain', 'Car', 'Cars', 25 ) );
148
	}
149
150
151
	public function testGetAll()
152
	{
153
		$ds = DIRECTORY_SEPARATOR;
154
155
		$translationSources = array(
156
			'testDomain' => array(
157
				dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case1',
158
				dirname(__FILE__) . $ds . 'testfiles' . $ds . 'case2',
159
			),
160
		);
161
162
		$object = new \Aimeos\MW\Translation\Zend( $translationSources, 'gettext', 'ka_GE' );
163
		$result = $object->getAll( 'testDomain' );
164
165
		$this->assertArrayHasKey( 'Car', $result );
166
		$this->assertEquals( 'KFZ', $result['Car'][0] );
167
		$this->assertEquals( 'KFZs', $result['Car'][1] );
168
		$this->assertArrayHasKey( 'File', $result );
169
		$this->assertEquals( 'Datei mehr', $result['File'][0] );
170
		$this->assertEquals( 'Dateien mehr', $result['File'][1] );
171
		$this->assertArrayHasKey( 'Update', $result );
172
		$this->assertEquals( 'Neue Version', $result['Update'] );
173
	}
174
}
175