1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EVB\Weather; |
4
|
|
|
|
5
|
|
|
// use Anax\DI\DIFactoryConfig; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use AnaxMocks\MockDI; |
8
|
|
|
use AnaxMocks\MockPage; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Test JsonController for Weather. |
12
|
|
|
*/ |
13
|
|
|
class JsonControllerTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Subject under test. |
17
|
|
|
* |
18
|
|
|
* @var JsonController |
19
|
|
|
*/ |
20
|
|
|
private $sut; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* DI container / Service Locator mock. |
24
|
|
|
* |
25
|
|
|
* @var MockDI |
26
|
|
|
*/ |
27
|
|
|
private $di; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Setup before each test. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function setUp() |
35
|
|
|
{ |
36
|
|
|
$this->di = new MockDI(); |
37
|
|
|
$this->sut = new JsonController(); |
38
|
|
|
$this->sut->setDI($this->di); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Test the route "doc" (GET). |
43
|
|
|
*/ |
44
|
|
|
public function testDocAction() |
45
|
|
|
{ |
46
|
|
|
$page = new MockPage(); |
47
|
|
|
|
48
|
|
|
$this->di->set("page", $page); |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
$result = $this->sut->docActionGet(); |
52
|
|
|
|
53
|
|
|
$this->assertInternalType("array", $result->args); |
|
|
|
|
54
|
|
|
$this->assertArrayHasKey("title", $result->args); |
55
|
|
|
$this->assertInternalType("string", $result->args["title"]); |
|
|
|
|
56
|
|
|
$this->assertNotEmpty($result->adds); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Test the "renderPage" method. |
61
|
|
|
* No errors. |
62
|
|
|
*/ |
63
|
|
|
public function testRenderPage() |
64
|
|
|
{ |
65
|
|
|
$argSearch = []; |
66
|
|
|
$argResult = [ |
67
|
|
|
[ |
68
|
|
|
"currently" => [ |
69
|
|
|
"summary" => "test", |
70
|
|
|
"precipProbability" => 1, |
71
|
|
|
"temperature" => 1, |
72
|
|
|
"apparentTemperature" => 1, |
73
|
|
|
"windSpeed" => 1, |
74
|
|
|
"windGust" => 1 |
75
|
|
|
], |
76
|
|
|
"hourly" => [ |
77
|
|
|
"summary" => "test", |
78
|
|
|
"data" => [ |
79
|
|
|
[ |
80
|
|
|
"time" => 1576249313, |
81
|
|
|
"summary" => "test", |
82
|
|
|
"precipProbability" => 1, |
83
|
|
|
"temperature" => 1, |
84
|
|
|
"apparentTemperature" => 1, |
85
|
|
|
"windSpeed" => 1, |
86
|
|
|
"windGust" => 1 |
87
|
|
|
] |
88
|
|
|
] |
89
|
|
|
], |
90
|
|
|
"daily" => [ |
91
|
|
|
"summary" => "test", |
92
|
|
|
"data" => [ |
93
|
|
|
[ |
94
|
|
|
"time" => 1576249313, |
95
|
|
|
"summary" => "test", |
96
|
|
|
"precipProbability" => 1, |
97
|
|
|
"temperatureMin" => 1, |
98
|
|
|
"temperatureMax" => 1, |
99
|
|
|
"apparentTemperatureMin" => 1, |
100
|
|
|
"apparentTemperatureMax" => 1, |
101
|
|
|
"windSpeed" => 1, |
102
|
|
|
"windGust" => 1 |
103
|
|
|
] |
104
|
|
|
] |
105
|
|
|
], |
106
|
|
|
], |
107
|
|
|
[ |
108
|
|
|
"daily" => [ |
109
|
|
|
"data" => [ |
110
|
|
|
[ |
111
|
|
|
"time" => 1576249313, |
112
|
|
|
"summary" => "test", |
113
|
|
|
"precipProbability" => 1, |
114
|
|
|
"temperatureMin" => 1, |
115
|
|
|
"temperatureMax" => 1, |
116
|
|
|
"apparentTemperatureMin" => 1, |
117
|
|
|
"apparentTemperatureMax" => 1, |
118
|
|
|
"windSpeed" => 1, |
119
|
|
|
"windGust" => 1 |
120
|
|
|
] |
121
|
|
|
] |
122
|
|
|
] |
123
|
|
|
] |
124
|
|
|
]; |
125
|
|
|
$argMapLink = "test"; |
126
|
|
|
$argError = ""; |
127
|
|
|
|
128
|
|
|
$result = $this->sut->renderPage($argSearch, $argResult, $argMapLink, $argError); |
129
|
|
|
|
130
|
|
|
$this->assertInternalType("array", $result); |
|
|
|
|
131
|
|
|
$this->assertInternalType("array", $result[0]); |
|
|
|
|
132
|
|
|
$this->assertArrayHasKey("forecast", $result[0]); |
133
|
|
|
$this->assertArrayHasKey("historical", $result[0]); |
134
|
|
|
$this->assertArrayHasKey("poweredBy", $result[0]); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Test the "renderPage" method. |
139
|
|
|
* With errors. |
140
|
|
|
* |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
public function testRenderPageError() |
144
|
|
|
{ |
145
|
|
|
$result = $this->sut->renderPage([], [], "test", "test"); |
146
|
|
|
|
147
|
|
|
$this->assertInternalType("array", $result); |
|
|
|
|
148
|
|
|
$this->assertInternalType("array", $result[0]); |
|
|
|
|
149
|
|
|
$this->assertArrayHasKey("error", $result[0]); |
150
|
|
|
$this->assertEquals("test", $result[0]["error"]); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.