Passed
Push — master ( adbf7e...2ad942 )
by Aimeos
02:05
created

GettextTest::testDtInvalid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2018
6
 */
7
8
9
namespace Aimeos\MW\Translation;
10
11
12
class GettextTest 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...
13
{
14
	private $object;
15
16
17
	protected function setUp()
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()
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->getAll( '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