CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Date--Test.php
Go to the documentation of this file.
1 <?PHP
2
3 class Date_Test extends PHPUnit\Framework\TestCase
4 {
9 public function testInputFormats()
10 {
11 $FormatsToTest = [
12 [
13 "Inputs" => [
14 "1999-9-19",
15 "9-19-1999",
16 "19-9-1999",
17 "Sep 19 1999",
18 "Sep 19, 1999",
19 "Sep 19th, 1999",
20 "19990919",
21 "19-Sep-1999",
22 "19 Sep 1999",
23 ],
24 "Precision" => Date::PRE_BEGINYEAR
25 | Date::PRE_BEGINMONTH
26 | Date::PRE_BEGINDAY,
27 "Formatted" => "1999-09-19",
28 "BeginDate" => "1999-09-19",
29 "EndDate" => NULL,
30 ],
31 [
32 "Inputs" => [
33 ["1999-9-19", "0000-00-00"],
34 ["9-19-1999", "0000-00-00"],
35 ["19-9-1999", "0000-00-00"],
36 ["Sep 19 1999", "0000-00-00"],
37 ["Sep 19, 1999", "0000-00-00"],
38 ["Sep 19th, 1999", "0000-00-00"],
39 ["19990919", "0000-00-00"],
40 ["19-Sep-1999", "0000-00-00"],
41 ["19 Sep 1999", "0000-00-00"],
42 ],
43 "Precision" => Date::PRE_BEGINYEAR
44 | Date::PRE_BEGINMONTH
45 | Date::PRE_BEGINDAY,
46 "Formatted" => "1999-09-19",
47 "BeginDate" => "1999-09-19",
48 "EndDate" => NULL,
49 ],
50 [
51 "Inputs" => [
52 ["2010-9-19", "0000-00-00"],
53 ["9-19-2010", "0000-00-00"],
54 ["19-9-2010", "0000-00-00"],
55 ["Sep 19 2010", "0000-00-00"],
56 ["Sep 19, 2010", "0000-00-00"],
57 ["Sep 19th, 2010", "0000-00-00"],
58 ["20100919", "0000-00-00"],
59 ["19-Sep-2010", "0000-00-00"],
60 ["19 Sep 2010", "0000-00-00"],
61 ],
62 "Precision" => Date::PRE_BEGINYEAR
63 | Date::PRE_BEGINMONTH
64 | Date::PRE_BEGINDAY,
65 "Formatted" => "2010-09-19",
66 "BeginDate" => "2010-09-19",
67 "EndDate" => NULL,
68 ],
69 [
70 "Inputs" => [
71 "9/19/01",
72 "9-19-01",
73 ],
74 "Precision" => Date::PRE_BEGINYEAR
75 | Date::PRE_BEGINMONTH
76 | Date::PRE_BEGINDAY,
77 "Formatted" => "2001-09-19",
78 "BeginDate" => "2001-09-19",
79 "EndDate" => NULL,
80 ],
81 [
82 "Inputs" => [
83 "1999-9",
84 "Sep-1999",
85 "Sep 1999",
86 "199909",
87 ],
88 "Precision" => Date::PRE_BEGINYEAR
89 | Date::PRE_BEGINMONTH,
90 "Formatted" => "1999-09",
91 "BeginDate" => "1999-09-01",
92 "EndDate" => NULL,
93 ],
108 [
109 "Inputs" => [
110 "c1999",
111 ],
112 "Precision" => Date::PRE_BEGINYEAR
113 | Date::PRE_COPYRIGHT,
114 "Formatted" => "c1999",
115 "BeginDate" => "1999-01-01",
116 "EndDate" => NULL,
117 ],
118 ];
119
120 foreach ($FormatsToTest as $Format)
121 {
122 foreach ($Format["Inputs"] as $InputArgs)
123 {
124 if (!is_array($InputArgs)) { $InputArgs = [ $InputArgs ]; }
125 $TestDate = (new ReflectionClass("Date"))->newInstanceArgs($InputArgs);
126 $Input = join($InputArgs, ", ");
127
128 $this->assertInstanceOf(Date::class, $TestDate,
129 "Input: ".$Input);
130 $this->assertEquals($Format["BeginDate"], $TestDate->BeginDate(),
131 "Testing BeginDate() with input \"".$Input."\"");
132 $this->assertEquals($Format["EndDate"], $TestDate->EndDate(),
133 "Testing EndDate() with input \"".$Input."\"");
134 $this->assertEquals($Format["Precision"], $TestDate->Precision(),
135 "Testing Precision() with input \"".$Input."\"");
136 $this->assertEquals($Format["Formatted"], $TestDate->Formatted(),
137 "Testing Formatted() with input \"".$Input."\"");
138 }
139 }
140 }
141 }
Date_Test\testInputFormats
testInputFormats()
Test date input formats we are supposed to handle, to make sure they result in the right precision an...
Definition: Date--Test.php:9
Date\PRE_BEGINDAY
const PRE_BEGINDAY
Definition: Date.php:24
Date_Test
Definition: Date--Test.php:3
Date\PRE_COPYRIGHT
const PRE_COPYRIGHT
Definition: Date.php:33
PHP
PHP
Definition: RSSClient--Test.php:12
Date\PRE_BEGINMONTH
const PRE_BEGINMONTH
Definition: Date.php:23
Date\PRE_BEGINYEAR
const PRE_BEGINYEAR
Definition: Date.php:22