|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the core-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2021 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Tests\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\ServerBag; |
|
16
|
|
|
use WBW\Bundle\CoreBundle\Controller\HostController; |
|
17
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractWebTestCase; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Host controller test. |
|
21
|
|
|
* |
|
22
|
|
|
* @author webeweb <https://github.com/webeweb> |
|
23
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\Controller |
|
24
|
|
|
*/ |
|
25
|
|
|
class HostControllerTest extends AbstractWebTestCase { |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Tests cpuAction() |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testCpuAction(): void { |
|
33
|
|
|
|
|
34
|
|
|
$client = $this->client; |
|
35
|
|
|
|
|
36
|
|
|
$client->request("GET", "/host/cpu"); |
|
37
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
38
|
|
|
$this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type")); |
|
39
|
|
|
|
|
40
|
|
|
// Check the JSON response. |
|
41
|
|
|
$res = json_decode($client->getResponse()->getContent(), true); |
|
42
|
|
|
$this->assertCount(4, $res); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertArrayHasKey("success", $res); |
|
45
|
|
|
$this->assertArrayHasKey("message", $res); |
|
46
|
|
|
$this->assertArrayHasKey("errors", $res); |
|
47
|
|
|
$this->assertArrayHasKey("data", $res); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertTrue($res["success"]); |
|
50
|
|
|
$this->assertNull($res["message"]); |
|
51
|
|
|
$this->assertNull($res["errors"]); |
|
52
|
|
|
$this->assertCount(8, $res["data"]); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertArrayHasKey("us", $res["data"]); |
|
55
|
|
|
$this->assertArrayHasKey("sy", $res["data"]); |
|
56
|
|
|
$this->assertArrayHasKey("ni", $res["data"]); |
|
57
|
|
|
$this->assertArrayHasKey("id", $res["data"]); |
|
58
|
|
|
$this->assertArrayHasKey("wa", $res["data"]); |
|
59
|
|
|
$this->assertArrayHasKey("hi", $res["data"]); |
|
60
|
|
|
$this->assertArrayHasKey("si", $res["data"]); |
|
61
|
|
|
$this->assertArrayHasKey("st", $res["data"]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Tests memoryAction() |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testMemoryAction(): void { |
|
70
|
|
|
|
|
71
|
|
|
$client = $this->client; |
|
72
|
|
|
|
|
73
|
|
|
$client->request("GET", "/host/memory"); |
|
74
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
75
|
|
|
$this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type")); |
|
76
|
|
|
|
|
77
|
|
|
// Check the JSON response. |
|
78
|
|
|
$res = json_decode($client->getResponse()->getContent(), true); |
|
79
|
|
|
$this->assertCount(4, $res); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertArrayHasKey("success", $res); |
|
82
|
|
|
$this->assertArrayHasKey("message", $res); |
|
83
|
|
|
$this->assertArrayHasKey("errors", $res); |
|
84
|
|
|
$this->assertArrayHasKey("data", $res); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertTrue($res["success"]); |
|
87
|
|
|
$this->assertNull($res["message"]); |
|
88
|
|
|
$this->assertNull($res["errors"]); |
|
89
|
|
|
$this->assertNotCount(0, $res["data"]); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertArrayHasKey("MemAvailable", $res["data"]); |
|
92
|
|
|
$this->assertArrayHasKey("MemFree", $res["data"]); |
|
93
|
|
|
$this->assertArrayHasKey("MemTotal", $res["data"]); |
|
94
|
|
|
$this->assertArrayHasKey("SwapFree", $res["data"]); |
|
95
|
|
|
$this->assertArrayHasKey("SwapTotal", $res["data"]); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Tests hardDisksAction() |
|
100
|
|
|
* |
|
101
|
|
|
* @return void |
|
102
|
|
|
*/ |
|
103
|
|
|
public function testHardDisksAction(): void { |
|
104
|
|
|
|
|
105
|
|
|
$client = $this->client; |
|
106
|
|
|
|
|
107
|
|
|
$client->request("GET", "/host/hard-disks"); |
|
108
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
109
|
|
|
$this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type")); |
|
110
|
|
|
|
|
111
|
|
|
// Check the JSON response. |
|
112
|
|
|
$res = json_decode($client->getResponse()->getContent(), true); |
|
113
|
|
|
$this->assertCount(4, $res); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertArrayHasKey("success", $res); |
|
116
|
|
|
$this->assertArrayHasKey("message", $res); |
|
117
|
|
|
$this->assertArrayHasKey("errors", $res); |
|
118
|
|
|
$this->assertArrayHasKey("data", $res); |
|
119
|
|
|
|
|
120
|
|
|
$this->assertTrue($res["success"]); |
|
121
|
|
|
$this->assertNull($res["message"]); |
|
122
|
|
|
$this->assertNull($res["errors"]); |
|
123
|
|
|
$this->assertNotCount(0, $res["data"]); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertArrayHasKey("available", $res["data"][0]); |
|
126
|
|
|
$this->assertArrayHasKey("fileSystem", $res["data"][0]); |
|
127
|
|
|
$this->assertArrayHasKey("mountedOn", $res["data"][0]); |
|
128
|
|
|
$this->assertArrayHasKey("name", $res["data"][0]); |
|
129
|
|
|
$this->assertArrayHasKey("type", $res["data"][0]); |
|
130
|
|
|
$this->assertArrayHasKey("used", $res["data"][0]); |
|
131
|
|
|
$this->assertArrayHasKey("usePercent", $res["data"][0]); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Tests retrieveInformationDatabase() |
|
136
|
|
|
* |
|
137
|
|
|
* @return void |
|
138
|
|
|
*/ |
|
139
|
|
|
public function testRetrieveInformationDatabase(): void { |
|
140
|
|
|
|
|
141
|
|
|
$obj = new HostController(); |
|
142
|
|
|
$obj->setContainer(static::$kernel->getContainer()); |
|
143
|
|
|
|
|
144
|
|
|
$res = $obj->retrieveInformationDatabase(); |
|
145
|
|
|
$this->assertCount(6, $res); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertArrayHasKey("driver", $res); |
|
148
|
|
|
$this->assertArrayHasKey("dbname", $res); |
|
149
|
|
|
$this->assertArrayHasKey("host", $res); |
|
150
|
|
|
$this->assertArrayHasKey("port", $res); |
|
151
|
|
|
$this->assertArrayHasKey("user", $res); |
|
152
|
|
|
$this->assertArrayHasKey("serverVersion", $res); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Tests retrieveInformationServer() |
|
157
|
|
|
* |
|
158
|
|
|
* @return void |
|
159
|
|
|
*/ |
|
160
|
|
|
public function testRetrieveInformationServer(): void { |
|
161
|
|
|
|
|
162
|
|
|
// Set a Request mock. |
|
163
|
|
|
$request = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock(); |
|
164
|
|
|
$request->server = $this->getMockBuilder(ServerBag::class)->disableOriginalConstructor()->getMock(); |
|
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
$obj = new HostController(); |
|
167
|
|
|
$obj->setContainer(static::$kernel->getContainer()); |
|
168
|
|
|
|
|
169
|
|
|
$res = $obj->retrieveInformationServer($request); |
|
170
|
|
|
$this->assertCount(5, $res); |
|
171
|
|
|
|
|
172
|
|
|
$this->assertArrayHasKey("maxExecutionTime", $res); |
|
173
|
|
|
$this->assertArrayHasKey("memoryLimit", $res); |
|
174
|
|
|
$this->assertArrayHasKey("phpUname", $res); |
|
175
|
|
|
$this->assertArrayHasKey("phpVersion", $res); |
|
176
|
|
|
$this->assertArrayHasKey("serverSoftware", $res); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Tests __construct() |
|
181
|
|
|
* |
|
182
|
|
|
* @return void |
|
183
|
|
|
*/ |
|
184
|
|
|
public function test__construct(): void { |
|
185
|
|
|
|
|
186
|
|
|
$this->assertEquals("wbw.core.controller.host", HostController::SERVICE_NAME); |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|