ILIAS  release_7 Revision v7.30-3-g800a261c036
ilGlobalCacheSetupAgentTest.php
Go to the documentation of this file.
1<?php
2
20
21use PHPUnit\Framework\TestCase;
22use ILIAS\Refinery\Factory as Refinery;
23use ILIAS\Data\Factory as DataFactory;
25
27{
28 public function getMServer(array $node)
29 {
30 return $this->getMemcachedServer($node);
31 }
32}
33
34class ilGlobalCacheSetupAgentTest extends TestCase
35{
39 protected $obj;
40
41 public function setUp() : void
42 {
43 $this->refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
44
45 $this->obj = new TestObj($this->refinery);
46 }
47
48 public function testCreate() : void
49 {
50 $this->assertInstanceOf(\ilGlobalCacheSetupAgent::class, $this->obj);
51 }
52
53 public function testHasConfig() : void
54 {
55 $this->assertTrue($this->obj->hasConfig());
56 }
57
59 {
60 $fnc = $this->obj->getArrayToConfigTransformation();
61
62 $settings = $fnc(null);
63
64 $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
65 $this->assertFalse($settings->isActive());
66 }
67
69 {
70 $fnc = $this->obj->getArrayToConfigTransformation();
71
72 $settings = $fnc([]);
73
74 $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
75 $this->assertFalse($settings->isActive());
76 }
77
79 {
80 $fnc = $this->obj->getArrayToConfigTransformation();
81
82 $settings = $fnc(["components" => null]);
83
84 $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
85 $this->assertFalse($settings->isActive());
86 }
87
89 {
90 $fnc = $this->obj->getArrayToConfigTransformation();
91
92 $settings = $fnc(["service" => "memcached"]);
93
94 $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
95 $this->assertFalse($settings->isActive());
96 }
97
99 {
100 $fnc = $this->obj->getArrayToConfigTransformation();
101
102 $settings = $fnc(["service" => "memcached", "memcached_nodes" => null]);
103
104 $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
105 $this->assertFalse($settings->isActive());
106 }
107
109 {
110 $fnc = $this->obj->getArrayToConfigTransformation();
111
112 $settings = $fnc(["service" => "memcached", "memcached_nodes" => []]);
113
114 $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
115 $this->assertFalse($settings->isActive());
116 }
117
119 {
120 $fnc = $this->obj->getArrayToConfigTransformation();
121
122 $services = [
123 "static",
124 "xcache",
125 "memcached",
126 "apc"
127 ];
128
129 $node = [
130 "active" => "1",
131 "host" => "test.de",
132 "port" => "9874",
133 "weight" => "10"
134 ];
135
136 foreach ($services as $key => $service) {
137 $settings = $fnc(
138 [
139 "service" => $service,
140 "memcached_nodes" => [$node],
141 "components" => ["dummy"]
142 ]
143 );
144 $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
145 $this->assertEquals($key, $settings->getService());
146 }
147 }
148
150 {
151 $fnc = $this->obj->getArrayToConfigTransformation();
152
153 $node = [
154 "active" => "1",
155 "host" => "test.de",
156 "port" => "9874",
157 "weight" => "10"
158 ];
159
160 $this->expectException(\InvalidArgumentException::class);
161 $this->expectExceptionMessage("Unknown caching service: 'non_existing_service'");
162
163 $fnc(
164 [
165 "service" => "non_existing_service",
166 "memcached_nodes" => [$node],
167 "components" => ["dummy"]
168 ]
169 );
170 }
171
173 {
174 $fnc = $this->obj->getArrayToConfigTransformation();
175
176 $node = [
177 "active" => "1",
178 "host" => "test.de",
179 "port" => "9874",
180 "weight" => "10"
181 ];
182
183 $settings = $fnc(
184 [
185 "service" => "memcached",
186 "memcached_nodes" => [$node],
187 "components" => ["dummy"]
188 ]
189 );
190
191 $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
192 $memcached_nodes = $settings->getMemcachedNodes();
193
194 $this->assertIsArray($memcached_nodes);
195
196 $node = array_shift($memcached_nodes);
197
198 $this->assertEquals("1", $node->getStatus());
199 $this->assertEquals("test.de", $node->getHost());
200 $this->assertEquals("9874", $node->getPort());
201 $this->assertEquals("10", $node->getWeight());
202 }
203
204 public function testGetMemcachedServerActive() : void
205 {
206 $node = $node = [
207 "active" => "1",
208 "host" => "my.test.de",
209 "port" => "1111",
210 "weight" => "20"
211 ];
212
213 $result = $this->obj->getMServer($node);
214
215 $this->assertEquals(\ilMemcacheServer::STATUS_ACTIVE, $result->getStatus());
216 $this->assertEquals("my.test.de", $result->getHost());
217 $this->assertEquals("1111", $result->getPort());
218 $this->assertEquals("20", $result->getWeight());
219 }
220
221 public function testGetMemcachedServerInactive() : void
222 {
223 $node = $node = [
224 "active" => "0",
225 "host" => "my.test.de",
226 "port" => "1111",
227 "weight" => "20"
228 ];
229
230 $result = $this->obj->getMServer($node);
231
232 $this->assertEquals(\ilMemcacheServer::STATUS_INACTIVE, $result->getStatus());
233 $this->assertEquals("my.test.de", $result->getHost());
234 $this->assertEquals("1111", $result->getPort());
235 $this->assertEquals("20", $result->getWeight());
236 }
237
238 public function testGetInstallObjectives() : void
239 {
240 $setup_conf_mock = $this->createMock(\ilGlobalCacheSettings::class);
241 $objective_collection = $this->obj->getInstallObjective($setup_conf_mock);
242
243 $this->assertEquals('Store configuration of Services/GlobalCache', $objective_collection->getLabel());
244 $this->assertFalse($objective_collection->isNotable());
245 }
246
247 public function testGetUpdateObjective() : void
248 {
249 $setup_conf_mock = $this->createMock(\ilGlobalCacheSettings::class);
250 $objective_collection = $this->obj->getUpdateObjective($setup_conf_mock);
251
252 $this->assertEquals('Store configuration of Services/GlobalCache', $objective_collection->getLabel());
253 $this->assertFalse($objective_collection->isNotable());
254 }
255
256 public function testGetUpdateObjectiveWithoutConfig() : void
257 {
258 $objective_collection = $this->obj->getUpdateObjective();
259
260 $this->assertInstanceOf(NullObjective::class, $objective_collection);
261 }
262
263
264 public function testGetBuildArtifactObjective() : void
265 {
266 $objective_collection = $this->obj->getBuildArtifactObjective();
267
268 $this->assertInstanceOf(NullObjective::class, $objective_collection);
269 }
270}
$result
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
A non-objective, nothing to do to achieve it...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$service
Definition: result.php:17