MonthNameUnlocalizerTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 67
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testUnlocalize() 0 9 1
A localizedDateProvider() 0 50 1
1
<?php
2
3
namespace ValueParsers\Test;
4
5
use PHPUnit_Framework_TestCase;
6
use ValueParsers\MonthNameUnlocalizer;
7
8
/**
9
 * @covers ValueParsers\MonthNameUnlocalizer
10
 *
11
 * @group DataValue
12
 * @group DataValueExtensions
13
 * @group ValueParsers
14
 *
15
 * @license GPL-2.0+
16
 * @author Addshore
17
 * @author Thiemo Kreuz
18
 */
19
class MonthNameUnlocalizerTest extends PHPUnit_Framework_TestCase {
20
21
	/**
22
	 * @dataProvider localizedDateProvider
23
	 */
24
	public function testUnlocalize(
25
		$date,
26
		$expected,
27
		array $replacements
28
	) {
29
		$unlocalizer = new MonthNameUnlocalizer( $replacements );
30
31
		$this->assertEquals( $expected, $unlocalizer->unlocalize( $date ) );
32
	}
33
34
	public function localizedDateProvider() {
35
		return array(
36
			// No replacements given
37
			array( '', '', array() ),
38
			array( 'Jul', 'Jul', array() ),
39
40
			// Longer strings do have higher priority
41
			array( 'Juli', 'July', array(
42
				'Jul' => 'bad',
43
				'Juli' => 'July',
44
			) ),
45
			array( 'Juli', 'July', array(
46
				'Juli' => 'July',
47
				'Jul' => 'bad',
48
			) ),
49
50
			// Do not mess with strings that are clearly not a valid date.
51
			array( 'July July', 'July July', array(
52
				'July' => 'bad',
53
			) ),
54
55
			// Do not mess with already unlocalized month names.
56
			array( 'July', 'July', array(
57
				'Jul' => 'July',
58
			) ),
59
60
			// But shortening is ok even if a substring looks like it's already unlocalized.
61
			array( 'July', 'Jul', array(
62
				'July' => 'Jul',
63
			) ),
64
65
			// Word boundaries currently do not prevent unlocalization on purpose.
66
			array( '1Jul2015', '1July2015', array(
67
				'Jul' => 'July',
68
			) ),
69
			array( '1stJulLastYear', '1stJulyLastYear', array(
70
				'Jul' => 'July',
71
			) ),
72
73
			// Capitalization is currently significant. This may need to depend on the languages.
74
			array( 'jul', 'jul', array(
75
				'Jul' => 'bad',
76
			) ),
77
78
			// Some translations (e.g. ko) just repeat the number of the month
79
			array( '2000', '2000', array(
80
				'2' => 'February',
81
			) ),
82
		);
83
	}
84
85
}
86