ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilServicesMainMenuTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
45 
46 class ilServicesMainMenuTest extends TestCase
47 {
52  private ProviderFactory|\PHPUnit\Framework\MockObject\MockObject $provider_factory_mock;
53  private Services $gs_mock;
58  protected Container $dic_mock;
59 
60  protected function setUp(): void
61  {
62  global $DIC;
63  if (!defined('ILIAS_HTTP_PATH')) {
64  define('ILIAS_HTTP_PATH', 'https://ilias.de/');
65  }
66  if (!defined('CLIENT_ID')) {
67  define('CLIENT_ID', 'client');
68  }
69  if (!defined('SYSTEM_FOLDER_ID')) {
70  define('SYSTEM_FOLDER_ID', 0);
71  }
72  $this->dic_backup = is_object($DIC) ? clone $DIC : $DIC;
73  $this->dic_mock = $DIC = new Container();
74  $this->provider_factory_mock = $this->createMock(ProviderFactory::class);
75  $this->gs_mock = $DIC['global_screen'] = new Services($this->provider_factory_mock);
76  $this->db_mock = $DIC['ilDB'] = $this->createMock(ilDBInterface::class);
77  $this->dic_mock['ilUser'] = $DIC['ilUser'] = $this->createMock(ilObjUser::class);
78  $this->dic_mock['ilSetting'] = $DIC['ilSetting'] = $this->createMock(ilSetting::class);
79  $this->dic_mock['rbacsystem'] = $DIC['rbacsystem'] = $this->createMock(ilRbacSystem::class);
80  $this->dic_mock['lng'] = $DIC['lng'] = $this->createMock(ilLanguage::class);
81  $this->dic_mock['ui.factory'] = $DIC['ui.factory'] = $this->createMock(\ILIAS\UI\Factory::class);
82  $this->dic_mock['ui.renderer'] = $DIC['ui.renderer'] = $this->createMock(\ILIAS\UI\Renderer::class);
83  $this->dic_mock['objDefinition'] = $DIC['objDefinition'] = $this->createMock(ilObjectDefinition::class);
84  }
85 
86  protected function tearDown(): void
87  {
88  global $DIC;
89  $DIC = $this->dic_backup;
90  }
91 
93  public function testTypeHandlers(): void
94  {
95  $provider = new CustomMainBarProvider($this->dic_mock, $this->createMock(ilMainMenuAccess::class));
96  $type_info = $provider->provideTypeInformation();
97  $this->assertInstanceOf(TypeInformationCollection::class, $type_info);
98 
99  // TopLink Item
100  $item_type_info = $type_info->get(TopParentItem::class);
101  $renderer = $item_type_info->getRenderer();
102  $this->assertInstanceOf(TopParentItemRenderer::class, $renderer);
103  $this->assertInstanceOf(
104  Combined::class,
105  $renderer->getComponentForItem(new TopParentItem(new NullIdentification()))
106  );
107 
108  // Link Item
109  $item_type_info = $type_info->get(Link::class);
110  $renderer = $item_type_info->getRenderer();
111  $this->assertInstanceOf(ilMMLinkItemRenderer::class, $renderer);
112  $this->assertInstanceOf(
113  \ILIAS\UI\Component\Link\Link::class,
114  $renderer->getComponentForItem(new Link(new NullIdentification()))
115  );
116 
117  // LinkList Item
118  $item_type_info = $type_info->get(LinkList::class);
119  $renderer = $item_type_info->getRenderer();
120  $this->assertInstanceOf(LinkListItemRenderer::class, $renderer);
121  $this->assertInstanceOf(
122  Combined::class,
123  $renderer->getComponentForItem(new LinkList(new NullIdentification()))
124  );
125 
126  // Separator Item
127  $item_type_info = $type_info->get(Separator::class);
128  $renderer = $item_type_info->getRenderer();
129  $this->assertInstanceOf(SeparatorItemRenderer::class, $renderer);
130  $this->assertInstanceOf(
131  Horizontal::class,
132  $renderer->getComponentForItem(new Separator(new NullIdentification()))
133  );
134 
135  // RepositoryLink Item
136  $this->dic_mock['ilObjDataCache'] = $this->createMock(ilObjectDataCache::class);
137  $this->dic_mock['static_url'] = $this->createMock(\ILIAS\StaticURL\Services::class);
138  $item_type_info = $type_info->get(RepositoryLink::class);
139  $renderer = $item_type_info->getRenderer();
140  $this->assertInstanceOf(ilMMRepositoryLinkItemRenderer::class, $renderer);
141  // Cannot render this due to missing mocking of ilLink
142  // $this->assertInstanceOf(
143  // \ILIAS\UI\Component\Link\Link::class,
144  // $renderer->getComponentForItem(new RepositoryLink(new NullIdentification()))
145  // );
146  }
147 
148  public function testStandardTopItems(): void
149  {
150  $this->dic_mock['lng'] = $this->createMock(ilLanguage::class);
151  $standard_top_items = new StandardTopItemsProvider($this->dic_mock);
152  $items = $standard_top_items->getStaticTopItems();
153  $item_identifications = array_map(
155  $items
156  );
157 
158  $this->assertEquals(7, count($items)); // this contains Dashboard as well
159  $this->assertEquals(7, count($item_identifications));
160 
161  $repo = $standard_top_items->getRepositoryIdentification();
162  $this->assertTrue(in_array($repo, $item_identifications));
163 
164  $admin = $standard_top_items->getAdministrationIdentification();
165  $this->assertTrue(in_array($admin, $item_identifications));
166 
167  $achievments = $standard_top_items->getAchievementsIdentification();
168  $this->assertTrue(in_array($achievments, $item_identifications));
169 
170  $communication = $standard_top_items->getCommunicationIdentification();
171  $this->assertTrue(in_array($communication, $item_identifications));
172 
173  $organisation = $standard_top_items->getOrganisationIdentification();
174  $this->assertTrue(in_array($communication, $item_identifications));
175 
176  $personal = $standard_top_items->getPersonalWorkspaceIdentification();
177  $this->assertTrue(in_array($personal, $item_identifications));
178  }
179 }
$renderer
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
ILIAS DI Container $dic_backup
testTypeHandlers()
PhpArrayIndexImmediatelyRewrittenInspection
$provider
Definition: ltitoken.php:80
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ProviderFactory PHPUnit Framework MockObject MockObject $provider_factory_mock