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