ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilPluginsOverviewTableTest.php
Go to the documentation of this file.
1 <?php
2 
20 declare(strict_types=1);
21 
29 
30 class ilPluginsOverviewTableTest extends TestCase
31 {
33  protected ilCtrl $ctrl;
34  protected Factory $ui;
35  protected Renderer $renderer;
36  protected ilLanguage $lng;
37 
38  protected function setUp(): void
39  {
40  $this->parent_gui = $this->createMock(ilObjComponentSettingsGUI::class);
41  $this->ctrl = $this->createMock(ilCtrl::class);
42  $this->ui = $this->createMock(Factory::class);
43  $this->renderer = $this->createMock(Renderer::class);
44  $this->lng = $this->createMock(ilLanguage::class);
45  $this->lng->method("txt")
46  ->willReturnCallback(fn($id) => $id);
47  }
48 
49  public function testCreateObject(): void
50  {
51  $obj = new ilPluginsOverviewTable($this->parent_gui, $this->ctrl, $this->ui, $this->renderer, $this->lng, []);
52  $this->assertInstanceOf(ilPluginsOverviewTable::class, $obj);
53  }
54 
55  public static function getImportantFieldData(): array
56  {
57  return [
58  [true, true],
59  [true, false],
60  [false, true],
61  [false, false]
62  ];
63  }
64 
68  public function testGetImportantFields(bool $installed, bool $active): void
69  {
71  public function getImportantFields(ilPluginInfo $plugin_info): array
72  {
73  return parent::getImportantFields($plugin_info);
74  }
75  };
76 
77  $plugin_info = $this->createMock(ilPluginInfo::class);
78  $plugin_info
79  ->expects($this->once())
80  ->method("isInstalled")
81  ->willReturn($installed)
82  ;
83  $plugin_info
84  ->expects($this->once())
85  ->method("isActive")
86  ->willReturn($active)
87  ;
88 
89  $result1 = "not_installed";
90  if ($installed) {
91  $result1 = "installed";
92  }
93 
94  $result2 = "inactive";
95  if ($active) {
96  $result2 = "cmps_active";
97  }
98 
99  $result = $obj->getImportantFields($plugin_info);
100 
101  $this->assertEquals($result1, $result[0]);
102  $this->assertEquals($result2, $result[1]);
103  }
104 
105  public function testGetContent(): void
106  {
108  public function getContent(ilPluginInfo $plugin_info): array
109  {
110  return parent::getContent($plugin_info);
111  }
112  };
113 
114  $plugin_info = $this->createMock(ilPluginInfo::class);
115  $plugin_info
116  ->expects($this->once())
117  ->method("isInstalled")
118  ->willReturn(true)
119  ;
120  $plugin_info
121  ->expects($this->once())
122  ->method("isActive")
123  ->willReturn(true)
124  ;
125  $plugin_info
126  ->expects($this->once())
127  ->method("isUpdateRequired")
128  ->willReturn(true)
129  ;
130 
131  $result = $obj->getContent($plugin_info);
132 
133  $this->assertIsArray($result);
134  }
135 
136  public function testBoolToString(): void
137  {
139  public function boolToString(bool $value): string
140  {
141  return parent::boolToString($value);
142  }
143  };
144 
145  $result = $obj->boolToString(true);
146  $this->assertEquals("yes", $result);
147 
148  $result = $obj->boolToString(false);
149  $this->assertEquals("no", $result);
150  }
151 
152  public function testFilterData(): void
153  {
155  public function setFilter(array $filter): void
156  {
157  $this->filter = $filter;
158  }
159 
160  public function filterData(array $data): array
161  {
162  return parent::filterData($data);
163  }
164  };
165 
166  $plugin_slot = $this->createMock(ilPluginSlotInfo::class);
167  $plugin_slot
168  ->method("getName")
169  ->willReturn("Repository")
170  ;
171 
172  $component = $this->createMock(ilComponentInfo::class);
173  $component
174  ->method("getQualifiedName")
175  ->willReturn("QualifiedName")
176  ;
177 
178  $plugin_info = $this->createMock(ilPluginInfo::class);
179  $plugin_info
180  ->method("getName")
181  ->willReturn("TestRepo")
182  ;
183  $plugin_info
184  ->method("getId")
185  ->willReturn("xvw")
186  ;
187  $plugin_info
188  ->method("isActive")
189  ->willReturn(true)
190  ;
191  $plugin_info
192  ->method("getPluginSlot")
193  ->willReturn($plugin_slot)
194  ;
195  $plugin_info
196  ->method("getComponent")
197  ->willReturn($component)
198  ;
199 
200  $obj->setFilter(["plugin_name" => "TestRepo"]);
201  $result = $obj->filterData([$plugin_info]);
202  $this->assertEquals($plugin_info, $result[0]);
203 
204  $obj->setFilter(["plugin_name" => "TestRepoFAIL"]);
205  $result = $obj->filterData([$plugin_info]);
206  $this->assertCount(0, $result);
207 
208  $obj->setFilter(["plugin_id" => "xvw"]);
209  $result = $obj->filterData([$plugin_info]);
210  $this->assertEquals($plugin_info, $result[0]);
211 
212  $obj->setFilter(["plugin_id" => "xvwFAIL"]);
213  $result = $obj->filterData([$plugin_info]);
214  $this->assertCount(0, $result);
215 
216  $obj->setFilter(["plugin_active" => "1"]);
217  $result = $obj->filterData([$plugin_info]);
218  $this->assertEquals($plugin_info, $result[0]);
219 
220  $obj->setFilter(["plugin_active" => "-1"]);
221  $result = $obj->filterData([$plugin_info]);
222  $this->assertCount(0, $result);
223 
224  $obj->setFilter(["slot_name" => ["Repository"]]);
225  $result = $obj->filterData([$plugin_info]);
226  $this->assertEquals($plugin_info, $result[0]);
227 
228  $obj->setFilter(["slot_name" => ["RepositoryFAILQualifiedNameFAIL"]]);
229  $result = $obj->filterData([$plugin_info]);
230  $this->assertCount(0, $result);
231 
232  $obj->setFilter(["component_name" => ["QualifiedName"]]);
233  $result = $obj->filterData([$plugin_info]);
234  $this->assertEquals($plugin_info, $result[0]);
235 
236  $obj->setFilter(["component_name" => ["QualifiedNameFAIL"]]);
237  $result = $obj->filterData([$plugin_info]);
238  $this->assertCount(0, $result);
239  }
240 
241  public function testGetData(): void
242  {
244  public function getData(): array
245  {
246  return parent::getData();
247  }
248  };
249 
250  $result = $obj->getData();
251 
252  $this->assertIsArray($result);
253  $this->assertEmpty($result);
254  }
255 
256  public function testWithData(): void
257  {
259  public function getData(): array
260  {
261  return parent::getData();
262  }
263  public function withDataWrapper(array $data)
264  {
265  return parent::withData($data);
266  }
267  };
268 
269  $obj = $obj->withDataWrapper(["data1", "data2"]);
270  $result = $obj->getData();
271 
272  $this->assertIsArray($result);
273  $this->assertEquals("data1", $result[0]);
274  $this->assertEquals("data2", $result[1]);
275  }
276 
277  public function testGetActionsPluginNotInstalled(): void
278  {
279  $shy = $this->createMock(Shy::class);
280 
281  $standard = $this->createMock(Standard::class);
282  $standard
283  ->expects($this->once())
284  ->method("getItems")
285  ->willReturn([$shy])
286  ;
287 
288  $dropdown = $this->createMock(\ILIAS\UI\Component\Dropdown\Factory::class);
289  $dropdown
290  ->expects($this->once())
291  ->method("standard")
292  ->willReturn($standard)
293  ;
294 
295  $this->ui
296  ->expects($this->once())
297  ->method("dropdown")
298  ->willReturn($dropdown)
299  ;
300 
302  protected Shy $shy;
303 
304  public function __construct(
305  ilObjComponentSettingsGUI $parent_gui,
306  ilCtrl $ctrl,
307  Factory $ui,
308  Renderer $renderer,
309  ilLanguage $lng,
310  array $filter,
311  Shy $shy
312  ) {
313  parent::__construct($parent_gui, $ctrl, $ui, $renderer, $lng, $filter);
314  $this->shy = $shy;
315  }
316 
317  public function getActions(ilPluginInfo $plugin_info): Dropdown
318  {
319  return parent::getActions($plugin_info);
320  }
321  protected function setParameter(ilPluginInfo $plugin): void
322  {
323  }
324  protected function clearParameter(): void
325  {
326  }
327  protected function getDropdownButton(string $caption, string $command): Shy
328  {
329  return $this->shy;
330  }
331  };
332 
333  $plugin_info = $this->createMock(ilPluginInfo::class);
334  $plugin_info
335  ->expects($this->once())
336  ->method("isInstalled")
337  ->willReturn(false)
338  ;
339 
340  $result = $obj->getActions($plugin_info);
341 
342  $this->assertInstanceOf(Shy::class, $result->getItems()[0]);
343  }
344 
345  public function testGetActionsPluginInstalled(): void
346  {
347  $shy = $this->createMock(Shy::class);
348 
349  $standard = $this->createMock(Standard::class);
350  $standard
351  ->expects($this->once())
352  ->method("getItems")
353  ->willReturn([$shy])
354  ;
355 
356  $dropdown = $this->createMock(\ILIAS\UI\Component\Dropdown\Factory::class);
357  $dropdown
358  ->expects($this->once())
359  ->method("standard")
360  ->willReturn($standard)
361  ;
362 
363  $this->ui
364  ->expects($this->once())
365  ->method("dropdown")
366  ->willReturn($dropdown)
367  ;
368 
370  protected Shy $shy;
371 
372  public function __construct(
373  ilObjComponentSettingsGUI $parent_gui,
374  ilCtrl $ctrl,
375  Factory $ui,
376  Renderer $renderer,
377  ilLanguage $lng,
378  array $filter,
379  Shy $shy
380  ) {
381  parent::__construct($parent_gui, $ctrl, $ui, $renderer, $lng, $filter);
382  $this->shy = $shy;
383  }
384 
385  public function getActions(ilPluginInfo $plugin_info): Dropdown
386  {
387  return parent::getActions($plugin_info);
388  }
389  protected function setParameter(ilPluginInfo $plugin): void
390  {
391  }
392  protected function clearParameter(): void
393  {
394  }
395  protected function hasLang(ilPluginInfo $plugin_info): bool
396  {
397  return false;
398  }
399  protected function getDropdownButton(string $caption, string $command): Shy
400  {
401  return $this->shy;
402  }
403  };
404 
405  $plugin_info = $this->createMock(ilPluginInfo::class);
406  $plugin_info
407  ->expects($this->once())
408  ->method("isInstalled")
409  ->willReturn(true)
410  ;
411  $plugin_info
412  ->expects($this->once())
413  ->method("isActive")
414  ->willReturn(false)
415  ;
416  $plugin_info
417  ->expects($this->once())
418  ->method("isActivationPossible")
419  ->willReturn(false)
420  ;
421  $plugin_info
422  ->expects($this->once())
423  ->method("isUpdateRequired")
424  ->willReturn(false)
425  ;
426 
427  $result = $obj->getActions($plugin_info);
428 
429  $this->assertInstanceOf(Shy::class, $result->getItems()[0]);
430  }
431 }
testGetImportantFields(bool $installed, bool $active)
getImportantFieldData
ilObjComponentSettingsGUI $parent_gui
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes commonalities between all types of Dropdowns.
Definition: Dropdown.php:34
This is how the factory for UI elements looks.
Definition: Factory.php:37
Simple value class for information about a plugin.
ilObjComponentSettingsGUI: ilPermissionGUI
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)