ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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;
35 
36 class PresentationHeaderTest extends TestCase
37 {
38  public function testConstruct(): void
39  {
40  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
41  $head = new PresentationHeader($container, 'Some class.');
42  $this->assertInstanceOf(PresentationHeader::class, $head);
43  }
44 
45  #[DataProvider('showProvider')]
46  public function testShow(bool $additional = false): void
47  {
48  $mode = $this->getMockBuilder(Mode::class)->disableOriginalConstructor()->getMock();
49  $mode->expects($this->once())->method('withActive')->with('tile_view')->willReturn($mode);
50 
51  $view_control = $this->getMockBuilder(ViewControl::class)->disableOriginalConstructor()->getMock();
52  $view_control->expects($this->once())->method('mode')->with([
53  'tile_view' => 'list URL',
54  'table_view' => 'manage URL',
55  ])->willReturn($mode);
56 
57  $additional_component = [];
58  $consecutive_expected = [$mode];
59  if ($additional) {
60  $mock = $this->getMockBuilder(Component::class)->getMock();
61  $additional_component[] = [$mock];
62  $consecutive_expected[] = $mock;
63  }
64 
65  $toolbar = $this->getMockBuilder(ilToolbarGUI::class)->disableOriginalConstructor()->getMock();
66  $toolbar
67  ->expects($this->exactly($additional + 1))
68  ->method('addStickyItem')
69  ->willReturnCallback(
70  function ($component) use (&$consecutive_expected) {
71  $expected = array_shift($consecutive_expected);
72  $this->assertEquals($expected, $component);
73  }
74  );
75 
76 
77  $factory = $this->getMockBuilder(UI::class)->disableOriginalConstructor()->getMock();
78  $factory->expects($this->once())->method('viewControl')->willReturn($view_control);
79 
80  $ui = $this->getMockBuilder(UIServices::class)->disableOriginalConstructor()->getMock();
81  $ui->method('factory')->willReturn($factory);
82 
83  $consecutive = [
84  ['Some class.', 'listBadges', 'list URL'],
85  ['Some class.', 'manageBadges', 'manage URL'],
86  ];
87  $ctrl = $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock();
88  $ctrl
89  ->expects($this->exactly(2))
90  ->method('getLinkTargetByClass')
91  ->willReturnCallback(
92  function ($class, $cmd) use (&$consecutive) {
93  list($expected_class, $expected_cmd, $ret) = array_shift($consecutive);
94  $this->assertEquals($class, $expected_class);
95  $this->assertEquals($cmd, $expected_cmd);
96  return $ret;
97  }
98  );
99 
100  $language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
101  $language->method('txt')->willReturnCallback(static fn(string $name): string => $name);
102 
103  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
104  $container->expects($this->once())->method('toolbar')->willReturn($toolbar);
105  $container->method('ui')->willReturn($ui);
106  $container->method('ctrl')->willReturn($ctrl);
107  $container->method('language')->willReturn($language);
108 
109  $head = new PresentationHeader($container, 'Some class.');
110  $head->show('tile_view', $additional_component[0][0] ?? null);
111  }
112 
113  public static function showProvider(): array
114  {
115  return [
116  'Without additional component' => [],
117  'With additional component' => [true],
118  ];
119  }
120 }
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...
$container
Definition: wac.php:36
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This is how the factory for UI elements looks.
Definition: Factory.php:30