1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ValueFormatters\Test; |
4
|
|
|
|
5
|
|
|
use DataValues\TimeValue; |
6
|
|
|
use ValueFormatters\FormatterOptions; |
7
|
|
|
use ValueFormatters\TimeFormatter; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers ValueFormatters\TimeFormatter |
11
|
|
|
* |
12
|
|
|
* @group ValueFormatters |
13
|
|
|
* @group DataValueExtensions |
14
|
|
|
* |
15
|
|
|
* @license GPL-2.0+ |
16
|
|
|
* @author H. Snater < [email protected] > |
17
|
|
|
* @author Thiemo Kreuz |
18
|
|
|
*/ |
19
|
|
|
class TimeFormatterTest extends ValueFormatterTestBase { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @see ValueFormatterTestBase::getInstance |
23
|
|
|
* |
24
|
|
|
* @param FormatterOptions|null $options |
25
|
|
|
* |
26
|
|
|
* @return TimeFormatter |
27
|
|
|
*/ |
28
|
|
|
protected function getInstance( FormatterOptions $options = null ) { |
29
|
|
|
return new TimeFormatter( $options ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @see ValueFormatterTestBase::validProvider |
34
|
|
|
*/ |
35
|
|
|
public function validProvider() { |
36
|
|
|
$gregorian = 'http://www.wikidata.org/entity/Q1985727'; |
37
|
|
|
$julian = 'http://www.wikidata.org/entity/Q1985786'; |
38
|
|
|
|
39
|
|
|
$baseOptions = new FormatterOptions(); |
40
|
|
|
|
41
|
|
|
$tests = array( |
42
|
|
|
'+2013-07-16T00:00:00Z' => array( |
43
|
|
|
'+2013-07-16T00:00:00Z', |
44
|
|
|
), |
45
|
|
|
'+0000-01-01T00:00:00Z' => array( |
46
|
|
|
'+0000-01-01T00:00:00Z', |
47
|
|
|
), |
48
|
|
|
|
49
|
|
|
// Different calendar models |
50
|
|
|
'+0001-01-14T00:00:00Z' => array( |
51
|
|
|
'+0001-01-14T00:00:00Z', |
52
|
|
|
TimeValue::PRECISION_DAY, |
53
|
|
|
$julian |
54
|
|
|
), |
55
|
|
|
|
56
|
|
|
// Different years |
57
|
|
|
'+10000-01-01T00:00:00Z' => array( |
58
|
|
|
'+10000-01-01T00:00:00Z', |
59
|
|
|
), |
60
|
|
|
'-0001-01-01T00:00:00Z' => array( |
61
|
|
|
'-0001-01-01T00:00:00Z', |
62
|
|
|
), |
63
|
|
|
|
64
|
|
|
// Different precisions |
65
|
|
|
'+2013-07-17T00:00:00Z' => array( |
66
|
|
|
'+2013-07-17T00:00:00Z', |
67
|
|
|
TimeValue::PRECISION_MONTH, |
68
|
|
|
), |
69
|
|
|
'+2013-07-18T00:00:00Z' => array( |
70
|
|
|
'+2013-07-18T00:00:00Z', |
71
|
|
|
TimeValue::PRECISION_YEAR, |
72
|
|
|
), |
73
|
|
|
'+2013-07-19T00:00:00Z' => array( |
74
|
|
|
'+2013-07-19T00:00:00Z', |
75
|
|
|
TimeValue::PRECISION_YEAR10, |
76
|
|
|
), |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$argLists = array(); |
80
|
|
|
|
81
|
|
|
foreach ( $tests as $expected => $args ) { |
82
|
|
|
$timestamp = $args[0]; |
83
|
|
|
$precision = isset( $args[1] ) ? $args[1] : TimeValue::PRECISION_DAY; |
84
|
|
|
$calendarModel = isset( $args[2] ) ? $args[2] : $gregorian; |
85
|
|
|
$options = isset( $args[3] ) ? $args[3] : $baseOptions; |
86
|
|
|
|
87
|
|
|
$argLists[] = array( |
88
|
|
|
new TimeValue( $timestamp, 0, 0, 0, $precision, $calendarModel ), |
89
|
|
|
$expected, |
90
|
|
|
$options |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $argLists; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|