ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
PresentationHeaderTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Badge\test;
22 
26 use ilToolbarGUI;
27 use ILIAS\UI\Factory as UI;
31 use ilCtrl;
33 use ilLanguage;
34 
35 class PresentationHeaderTest extends TestCase
36 {
37  public function testConstruct(): void
38  {
39  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
40  $head = new PresentationHeader($container, 'Some class.');
41  $this->assertInstanceOf(PresentationHeader::class, $head);
42  }
43 
47  public function testShow(bool $additional = false): void
48  {
49  $mode = $this->getMockBuilder(Mode::class)->disableOriginalConstructor()->getMock();
50  $mode->expects(self::once())->method('withActive')->with('tile_view')->willReturn($mode);
51 
52  $view_control = $this->getMockBuilder(ViewControl::class)->disableOriginalConstructor()->getMock();
53  $view_control->expects(self::once())->method('mode')->with([
54  'tile_view' => 'list URL',
55  'table_view' => 'manage URL',
56  ])->willReturn($mode);
57 
58  $additional_component = [];
59  if ($additional) {
60  $additional_component[] = [$this->getMockBuilder(Component::class)->getMock()];
61  }
62 
63  $toolbar = $this->getMockBuilder(ilToolbarGUI::class)->disableOriginalConstructor()->getMock();
64  $toolbar->expects(self::exactly($additional + 1))->method('addStickyItem')->withConsecutive([$mode], ...$additional_component);
65 
66  $factory = $this->getMockBuilder(UI::class)->disableOriginalConstructor()->getMock();
67  $factory->expects(self::once())->method('viewControl')->willReturn($view_control);
68 
69  $ui = $this->getMockBuilder(UIServices::class)->disableOriginalConstructor()->getMock();
70  $ui->method('factory')->willReturn($factory);
71 
72  $ctrl = $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock();
73  $ctrl->expects(self::exactly(2))->method('getLinkTargetByClass')->withConsecutive(
74  ['Some class.', 'listBadges'],
75  ['Some class.', 'manageBadges'],
76  )->willReturnOnConsecutiveCalls('list URL', 'manage URL');
77 
78  $language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
79  $language->method('txt')->willReturnCallback(static fn(string $name): string => $name);
80 
81  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
82  $container->expects(self::once())->method('toolbar')->willReturn($toolbar);
83  $container->method('ui')->willReturn($ui);
84  $container->method('ctrl')->willReturn($ctrl);
85  $container->method('language')->willReturn($language);
86 
87  $head = new PresentationHeader($container, 'Some class.');
88  $head->show('tile_view', ...($additional_component[0] ?? []));
89  }
90 
91  public function showProvider(): array
92  {
93  return [
94  'Without additional component' => [],
95  'With additional component' => [true],
96  ];
97  }
98 }
testShow(bool $additional=false)
showProvider
$container
Definition: wac.php:14
This is how the factory for UI elements looks.
Definition: Factory.php:30