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