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