ILIAS  release_8 Revision v8.24
ilServicesMainMenuTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use PHPUnit\Framework\TestCase;
45
46class ilServicesMainMenuTest extends TestCase
47{
54
55 protected function setUp(): void
56 {
57 global $DIC;
58 if (!defined('ILIAS_HTTP_PATH')) {
59 define('ILIAS_HTTP_PATH', 'https://ilias.de/');
60 }
61 if (!defined('CLIENT_ID')) {
62 define('CLIENT_ID', 'client');
63 }
64 if (!defined('SYSTEM_FOLDER_ID')) {
65 define('SYSTEM_FOLDER_ID', 0);
66 }
67 $this->dic_backup = is_object($DIC) ? clone $DIC : $DIC;
68 $this->dic_mock = $DIC = new Container();
69 $this->provider_factory_mock = $this->createMock(ProviderFactory::class);
70 $this->gs_mock = $DIC['global_screen'] = new Services($this->provider_factory_mock);
71 $this->db_mock = $DIC['ilDB'] = $this->createMock(ilDBInterface::class);
72 $this->dic_mock['ilUser'] = $DIC['ilUser'] = $this->createMock(ilObjUser::class);
73 $this->dic_mock['ilSetting'] = $DIC['ilSetting'] = $this->createMock(ilSetting::class);
74 $this->dic_mock['rbacsystem'] = $DIC['rbacsystem'] = $this->createMock(ilRbacSystem::class);
75 $this->dic_mock['lng'] = $DIC['lng'] = $this->createMock(ilLanguage::class);
76 $this->dic_mock['ui.factory'] = $DIC['ui.factory'] = $this->createMock(\ILIAS\UI\Factory::class);
77 $this->dic_mock['ui.renderer'] = $DIC['ui.renderer'] = $this->createMock(\ILIAS\UI\Renderer::class);
78 $this->dic_mock['objDefinition'] = $DIC['objDefinition'] = $this->createMock(ilObjectDefinition::class);
79 }
80
81 protected function tearDown(): void
82 {
83 global $DIC;
85 }
86
88 public function testTypeHandlers(): void
89 {
90 $provider = new CustomMainBarProvider($this->dic_mock, $this->createMock(ilMainMenuAccess::class));
91 $type_info = $provider->provideTypeInformation();
92 $this->assertInstanceOf(TypeInformationCollection::class, $type_info);
93
94 // TopLink Item
95 $item_type_info = $type_info->get(TopParentItem::class);
96 $renderer = $item_type_info->getRenderer();
97 $this->assertInstanceOf(TopParentItemRenderer::class, $renderer);
98 $this->assertInstanceOf(
99 Combined::class,
100 $renderer->getComponentForItem(new TopParentItem(new NullIdentification()))
101 );
102
103 // Link Item
104 $item_type_info = $type_info->get(Link::class);
105 $renderer = $item_type_info->getRenderer();
106 $this->assertInstanceOf(ilMMLinkItemRenderer::class, $renderer);
107 $this->assertInstanceOf(
108 \ILIAS\UI\Component\Link\Link::class,
109 $renderer->getComponentForItem(new Link(new NullIdentification()))
110 );
111
112 // LinkList Item
113 $item_type_info = $type_info->get(LinkList::class);
114 $renderer = $item_type_info->getRenderer();
115 $this->assertInstanceOf(LinkListItemRenderer::class, $renderer);
116 $this->assertInstanceOf(
117 Combined::class,
118 $renderer->getComponentForItem(new LinkList(new NullIdentification()))
119 );
120
121 // Separator Item
122 $item_type_info = $type_info->get(Separator::class);
123 $renderer = $item_type_info->getRenderer();
124 $this->assertInstanceOf(SeparatorItemRenderer::class, $renderer);
125 $this->assertInstanceOf(
126 Horizontal::class,
127 $renderer->getComponentForItem(new Separator(new NullIdentification()))
128 );
129
130 // RepositoryLink Item
131 $this->dic_mock['ilObjDataCache'] = $this->createMock(ilObjectDataCache::class);
132 $item_type_info = $type_info->get(RepositoryLink::class);
133 $renderer = $item_type_info->getRenderer();
134 $this->assertInstanceOf(ilMMRepositoryLinkItemRenderer::class, $renderer);
135 $this->assertInstanceOf(
136 \ILIAS\UI\Component\Link\Link::class,
137 $renderer->getComponentForItem(new RepositoryLink(new NullIdentification()))
138 );
139 }
140
141 public function testStandardTopItems(): void
142 {
143 $this->dic_mock['lng'] = $this->createMock(ilLanguage::class);
144 $standard_top_items = new StandardTopItemsProvider($this->dic_mock);
145 $items = $standard_top_items->getStaticTopItems();
146 $item_identifications = array_map(
147 fn (isItem $i): IdentificationInterface => $i->getProviderIdentification(),
148 $items
149 );
150
151 $this->assertEquals(7, count($items)); // this contains Dashboard as well
152 $this->assertEquals(7, count($item_identifications));
153
154 $repo = $standard_top_items->getRepositoryIdentification();
155 $this->assertTrue(in_array($repo, $item_identifications));
156
157 $admin = $standard_top_items->getAdministrationIdentification();
158 $this->assertTrue(in_array($admin, $item_identifications));
159
160 $achievments = $standard_top_items->getAchievementsIdentification();
161 $this->assertTrue(in_array($achievments, $item_identifications));
162
163 $communication = $standard_top_items->getCommunicationIdentification();
164 $this->assertTrue(in_array($communication, $item_identifications));
165
166 $organisation = $standard_top_items->getOrganisationIdentification();
167 $this->assertTrue(in_array($communication, $item_identifications));
168
169 $personal = $standard_top_items->getPersonalWorkspaceIdentification();
170 $this->assertTrue(in_array($personal, $item_identifications));
171
172
173// $this->assertFalse(true);
174 }
175}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
testTypeHandlers()
@noinspection PhpArrayIndexImmediatelyRewrittenInspection
ILIAS DI Container $dic_backup
global $DIC
Definition: feed.php:28
Class TypeRenderer Every Type should have a renderer, if you won't provide on in your TypeInformation...
This describes the Combined Slate.
Definition: Combined.php:30
Interface ilDBInterface.
$provider
Definition: ltitoken.php:83
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.