GettextTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 7
eloc 45
c 6
b 0
f 0
dl 0
loc 105
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testDt() 0 3 1
A tearDown() 0 3 1
A setUp() 0 9 1
A testDnOverwritePlural() 0 13 1
A testGetAll() 0 22 1
A testDn() 0 19 1
A testDnOverwriteSingular() 0 13 1
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\MW\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
		$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...
22
			'testDomain' => array( __DIR__ . $ds . 'testfiles' . $ds . 'case1' ),
23
		);
24
25
		$this->object = new \Aimeos\MW\Translation\Gettext( $this->translationSources, 'de_DE' );
26
	}
27
28
29
	protected function tearDown() : void
30
	{
31
		$this->object = null;
32
	}
33
34
35
	public function testDt()
36
	{
37
		$this->assertEquals( 'Datei', $this->object->dt( 'testDomain', 'File' ) );
38
	}
39
40
41
	public function testDn()
42
	{
43
		/*
44
		 * plural for RU: 3 pl forms
45
		 * 0, if $n == 1, 21, 31, 41, ...
46
		 * 1, if $n == 2..4, 22..24, 32..34, ...
47
		 * 2, if $n == 5..20, 25..30, 35..40, .
48
		 */
49
50
		$object = new \Aimeos\MW\Translation\Gettext( $this->translationSources, 'ru' );
51
52
		$this->assertEquals( 'plural 2', $object->dn( 'testDomain', 'File', 'Files', 0 ) );
53
		$this->assertEquals( 'singular', $object->dn( 'testDomain', 'File', 'Files', 1 ) );
54
		$this->assertEquals( 'plural 1', $object->dn( 'testDomain', 'File', 'Files', 2 ) );
55
		$this->assertEquals( 'plural 2', $object->dn( 'testDomain', 'File', 'Files', 5 ) );
56
57
		$this->assertEquals( 'plural 1', $object->dn( 'testDomain', 'File', 'Files', 22 ) );
58
		$this->assertEquals( 'plural 2', $object->dn( 'testDomain', 'File', 'Files', 25 ) );
59
		$this->assertEquals( 'singular', $object->dn( 'testDomain', 'File', 'Files', 31 ) );
60
	}
61
62
63
	public function testDnOverwriteSingular()
64
	{
65
		$ds = DIRECTORY_SEPARATOR;
66
67
		$translationSources = array(
68
			'testDomain' => array(
69
				__DIR__ . $ds . 'testfiles' . $ds . 'case1',
70
				__DIR__ . $ds . 'testfiles' . $ds . 'case2',
71
			),
72
		);
73
74
		$object = new \Aimeos\MW\Translation\Gettext( $translationSources, 'de_DE' );
75
		$this->assertEquals( 'Neue Version', $object->dt( 'testDomain', 'Update' ) );
76
	}
77
78
79
	public function testDnOverwritePlural()
80
	{
81
		$ds = DIRECTORY_SEPARATOR;
82
83
		$translationSources = array(
84
			'testDomain' => array(
85
				__DIR__ . $ds . 'testfiles' . $ds . 'case1',
86
				__DIR__ . $ds . 'testfiles' . $ds . 'case2',
87
			),
88
		);
89
90
		$object = new \Aimeos\MW\Translation\Gettext( $translationSources, 'de_DE' );
91
		$this->assertEquals( 'KFZs', $object->dn( 'testDomain', 'Car', 'Cars', 25 ) );
92
	}
93
94
95
	public function testGetAll()
96
	{
97
		$ds = DIRECTORY_SEPARATOR;
98
99
		$translationSources = array(
100
			'testDomain' => array(
101
				__DIR__ . $ds . 'testfiles' . $ds . 'case1',
102
				__DIR__ . $ds . 'testfiles' . $ds . 'case2',
103
			),
104
		);
105
106
		$object = new \Aimeos\MW\Translation\Gettext( $translationSources, 'de_DE' );
107
		$result = $object->all( 'testDomain' );
108
109
		$this->assertArrayHasKey( 'Car', $result );
110
		$this->assertEquals( 'KFZ', $result['Car'][0] );
111
		$this->assertEquals( 'KFZs', $result['Car'][1] );
112
		$this->assertArrayHasKey( 'File', $result );
113
		$this->assertEquals( 'Datei mehr', $result['File'][0] );
114
		$this->assertEquals( 'Dateien mehr', $result['File'][1] );
115
		$this->assertArrayHasKey( 'Update', $result );
116
		$this->assertEquals( 'Neue Version', $result['Update'] );
117
	}
118
119
}
120