ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilServicesMainMenuTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\MockObject\MockObject;
24use PHPUnit\Framework\TestCase;
44
45class ilServicesMainMenuTest extends TestCase
46{
53
54 protected function setUp(): void
55 {
56 global $DIC;
57 if (!defined('ILIAS_HTTP_PATH')) {
58 define('ILIAS_HTTP_PATH', 'https://ilias.de/');
59 }
60 if (!defined('CLIENT_ID')) {
61 define('CLIENT_ID', 'client');
62 }
63 if (!defined('SYSTEM_FOLDER_ID')) {
64 define('SYSTEM_FOLDER_ID', 0);
65 }
66 $this->dic_backup = is_object($DIC) ? clone $DIC : $DIC;
67 $this->dic_mock = $DIC = new Container();
68 $provider_factory_mock = $this->createMock(ProviderFactory::class);
69 $gs_mock = $DIC['global_screen'] = new Services($provider_factory_mock);
70 $this->db_mock = $DIC['ilDB'] = $this->createMock(ilDBInterface::class);
71 $this->dic_mock['ilUser'] = $DIC['ilUser'] = $this->createMock(ilObjUser::class);
72 $this->dic_mock['ilSetting'] = $DIC['ilSetting'] = $this->createMock(ilSetting::class);
73 $this->dic_mock['rbacsystem'] = $DIC['rbacsystem'] = $this->createMock(ilRbacSystem::class);
74 $this->dic_mock['lng'] = $DIC['lng'] = $this->createMock(ilLanguage::class);
75 $this->dic_mock['ui.factory'] = $DIC['ui.factory'] = $this->createMock(Factory::class);
76 $this->dic_mock['ui.renderer'] = $DIC['ui.renderer'] = $this->createMock(Renderer::class);
77 $this->dic_mock['objDefinition'] = $DIC['objDefinition'] = $this->createMock(ilObjectDefinition::class);
78 }
79
80 protected function tearDown(): void
81 {
82 global $DIC;
84 }
85
87 public function testTypeHandlers(): void
88 {
89 $provider = new CustomMainBarProvider($this->dic_mock, $this->createMock(ilMainMenuAccess::class));
90 $type_info = $provider->provideTypeInformation();
91 $this->assertInstanceOf(TypeInformationCollection::class, $type_info);
92
93 // TopLink Item
94 $item_type_info = $type_info->get(TopParentItem::class);
95 $renderer = $item_type_info->getRenderer();
96 $this->assertInstanceOf(TopParentItemRenderer::class, $renderer);
97 $this->assertInstanceOf(
98 Combined::class,
99 $renderer->getComponentForItem(new TopParentItem(new NullIdentification()))
100 );
101
102 // Link Item
103 $item_type_info = $type_info->get(Link::class);
104 $renderer = $item_type_info->getRenderer();
105 $this->assertInstanceOf(ilMMLinkItemRenderer::class, $renderer);
106 $this->assertInstanceOf(
107 \ILIAS\UI\Component\Link\Link::class,
108 $renderer->getComponentForItem(new Link(new NullIdentification()))
109 );
110
111 // LinkList Item
112 $item_type_info = $type_info->get(LinkList::class);
113 $renderer = $item_type_info->getRenderer();
114 $this->assertInstanceOf(LinkListItemRenderer::class, $renderer);
115 $this->assertInstanceOf(
116 Combined::class,
117 $renderer->getComponentForItem(new LinkList(new NullIdentification()))
118 );
119
120 // Separator Item
121 $item_type_info = $type_info->get(Separator::class);
122 $renderer = $item_type_info->getRenderer();
123 $this->assertInstanceOf(SeparatorItemRenderer::class, $renderer);
124 $this->assertInstanceOf(
125 Horizontal::class,
126 $renderer->getComponentForItem(new Separator(new NullIdentification()))
127 );
128
129 // RepositoryLink Item
130 $this->dic_mock['ilObjDataCache'] = $this->createMock(ilObjectDataCache::class);
131 $this->dic_mock['static_url'] = $this->createMock(\ILIAS\StaticURL\Services::class);
132 $item_type_info = $type_info->get(RepositoryLink::class);
133 $renderer = $item_type_info->getRenderer();
134 $this->assertInstanceOf(ilMMRepositoryLinkItemRenderer::class, $renderer);
135 // Cannot render this due to missing mocking of ilLink
136 // $this->assertInstanceOf(
137 // \ILIAS\UI\Component\Link\Link::class,
138 // $renderer->getComponentForItem(new RepositoryLink(new NullIdentification()))
139 // );
140 }
141
142 public function testStandardTopItems(): void
143 {
144 $this->dic_mock['lng'] = $this->createMock(ilLanguage::class);
145 $standard_top_items = new StandardTopItemsProvider($this->dic_mock);
146 $items = $standard_top_items->getStaticTopItems();
147 $item_identifications = array_map(
149 $items
150 );
151
152 $this->assertCount(7, $items); // this contains Dashboard as well
153 $this->assertCount(7, $item_identifications);
154
155 $repo = $standard_top_items->getRepositoryIdentification();
156 $this->assertContains($repo, $item_identifications);
157
158 $admin = $standard_top_items->getAdministrationIdentification();
159 $this->assertContains($admin, $item_identifications);
160
161 $achievments = $standard_top_items->getAchievementsIdentification();
162 $this->assertContains($achievments, $item_identifications);
163
164 $communication = $standard_top_items->getCommunicationIdentification();
165 $this->assertContains($communication, $item_identifications);
166
167 $organisation = $standard_top_items->getOrganisationIdentification();
168 $this->assertContains($communication, $item_identifications);
169
170 $personal = $standard_top_items->getPersonalWorkspaceIdentification();
171 $this->assertContains($personal, $item_identifications);
172 }
173}
$renderer
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
testTypeHandlers()
@noinspection PhpArrayIndexImmediatelyRewrittenInspection
This describes the Combined Slate.
Definition: Combined.php:30
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilDBInterface.
$provider
Definition: ltitoken.php:80
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26