ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilGlobalCacheSetupAgentTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2020 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
11 
13 {
14  public function getMServer(array $node)
15  {
16  return $this->getMemcachedServer($node);
17  }
18 }
19 
20 class ilGlobalCacheSetupAgentTest extends TestCase
21 {
25  protected $obj;
26 
27  public function setUp(): void
28  {
29  $this->refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
30 
31  $this->obj = new TestObj($this->refinery);
32  }
33 
34  public function testCreate(): void
35  {
36  $this->assertInstanceOf(\ilGlobalCacheSetupAgent::class, $this->obj);
37  }
38 
39  public function testHasConfig(): void
40  {
41  $this->assertTrue($this->obj->hasConfig());
42  }
43 
45  {
46  $fnc = $this->obj->getArrayToConfigTransformation();
47 
48  $settings = $fnc(null);
49 
50  $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
51  $this->assertFalse($settings->isActive());
52  }
53 
55  {
56  $fnc = $this->obj->getArrayToConfigTransformation();
57 
58  $settings = $fnc([]);
59 
60  $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
61  $this->assertFalse($settings->isActive());
62  }
63 
65  {
66  $fnc = $this->obj->getArrayToConfigTransformation();
67 
68  $settings = $fnc(["components" => null]);
69 
70  $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
71  $this->assertFalse($settings->isActive());
72  }
73 
75  {
76  $fnc = $this->obj->getArrayToConfigTransformation();
77 
78  $settings = $fnc(["service" => "memcached"]);
79 
80  $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
81  $this->assertFalse($settings->isActive());
82  }
83 
85  {
86  $fnc = $this->obj->getArrayToConfigTransformation();
87 
88  $settings = $fnc(["service" => "memcached", "memcached_nodes" => null]);
89 
90  $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
91  $this->assertFalse($settings->isActive());
92  }
93 
95  {
96  $fnc = $this->obj->getArrayToConfigTransformation();
97 
98  $settings = $fnc(["service" => "memcached", "memcached_nodes" => []]);
99 
100  $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
101  $this->assertFalse($settings->isActive());
102  }
103 
105  {
106  $fnc = $this->obj->getArrayToConfigTransformation();
107 
108  $services = [
109  \ilGlobalCache::TYPE_STATIC => "static",
110  \ilGlobalCache::TYPE_MEMCACHED => "memcached",
111  \ilGlobalCache::TYPE_APC => "apc"
112  ];
113 
114  $node = [
115  "active" => "1",
116  "host" => "test.de",
117  "port" => "9874",
118  "weight" => "10"
119  ];
120 
121  foreach ($services as $key => $service) {
122  $settings = $fnc(
123  [
124  "service" => $service,
125  "memcached_nodes" => [$node],
126  "components" => ["dummy"]
127  ]
128  );
129  $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
130  $this->assertEquals($key, $settings->getService());
131  }
132  }
133 
135  {
136  $fnc = $this->obj->getArrayToConfigTransformation();
137 
138  $node = [
139  "active" => "1",
140  "host" => "test.de",
141  "port" => "9874",
142  "weight" => "10"
143  ];
144 
145  $this->expectException(\InvalidArgumentException::class);
146  $this->expectExceptionMessage("Unknown caching service: 'non_existing_service'");
147 
148  $fnc(
149  [
150  "service" => "non_existing_service",
151  "memcached_nodes" => [$node],
152  "components" => ["dummy"]
153  ]
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  $settings = $fnc(
169  [
170  "service" => "memcached",
171  "memcached_nodes" => [$node],
172  "components" => ["dummy"]
173  ]
174  );
175 
176  $this->assertInstanceOf(\ilGlobalCacheSettings::class, $settings);
177  $this->assertIsArray($settings->getMemcachedNodes());
178 
179  $settings = $settings->getMemcachedNodes();
180  $node = array_shift($settings);
181 
182  $this->assertEquals("1", $node->getStatus());
183  $this->assertEquals("test.de", $node->getHost());
184  $this->assertEquals("9874", $node->getPort());
185  $this->assertEquals("10", $node->getWeight());
186  }
187 
188  public function testGetMemcachedServerActive(): void
189  {
190  $node = $node = [
191  "active" => "1",
192  "host" => "my.test.de",
193  "port" => "1111",
194  "weight" => "20"
195  ];
196 
197  $result = $this->obj->getMServer($node);
198 
199  $this->assertEquals(\ilMemcacheServer::STATUS_ACTIVE, $result->getStatus());
200  $this->assertEquals("my.test.de", $result->getHost());
201  $this->assertEquals("1111", $result->getPort());
202  $this->assertEquals("20", $result->getWeight());
203  }
204 
205  public function testGetMemcachedServerInactive(): void
206  {
207  $node = $node = [
208  "active" => "0",
209  "host" => "my.test.de",
210  "port" => "1111",
211  "weight" => "20"
212  ];
213 
214  $result = $this->obj->getMServer($node);
215 
216  $this->assertEquals(\ilMemcacheServer::STATUS_INACTIVE, $result->getStatus());
217  $this->assertEquals("my.test.de", $result->getHost());
218  $this->assertEquals("1111", $result->getPort());
219  $this->assertEquals("20", $result->getWeight());
220  }
221 
222  public function testGetInstallObjectives(): void
223  {
224  $setup_conf_mock = $this->createMock(\ilGlobalCacheSettings::class);
225  $objective_collection = $this->obj->getInstallObjective($setup_conf_mock);
226 
227  $this->assertEquals('Store configuration of Services/GlobalCache', $objective_collection->getLabel());
228  $this->assertFalse($objective_collection->isNotable());
229  }
230 
231  public function testGetUpdateObjective(): void
232  {
233  $setup_conf_mock = $this->createMock(\ilGlobalCacheSettings::class);
234  $objective_collection = $this->obj->getUpdateObjective($setup_conf_mock);
235 
236  $this->assertEquals('Store configuration of Services/GlobalCache', $objective_collection->getLabel());
237  $this->assertFalse($objective_collection->isNotable());
238  }
239 
240  public function testGetUpdateObjectiveWithoutConfig(): void
241  {
242  $objective_collection = $this->obj->getUpdateObjective();
243 
244  $this->assertInstanceOf(NullObjective::class, $objective_collection);
245  }
246 
247 
248  public function testGetBuildArtifactObjective(): void
249  {
250  $objective_collection = $this->obj->getBuildArtifactObjective();
251 
252  $this->assertInstanceOf(NullObjective::class, $objective_collection);
253  }
254 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
string $key
Consumer key/client ID value.
Definition: System.php:193
$service
Definition: ltiservices.php:43