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