ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ExamplesTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../Base.php");
23
28
33{
34 protected string $path_to_base_factory = "src/UI/Factory.php";
35 protected Container $dic;
36
37 public function setUp(): void
38 {
39 //This avoids various index not set warnings, which are only relevant in test context.
40 $_SERVER["REQUEST_URI"] = "";
41 $_SERVER['SCRIPT_NAME'] = "";
42 $_SERVER['QUERY_STRING'] = "param=1";
43
44 //This avoids Undefined index: ilfilehash for the moment
45 $_POST["ilfilehash"] = "";
46 $this->setUpMockDependencies();
47 }
48
54 protected function setUpMockDependencies(): void
55 {
56 $this->dic = new Container();
57 $this->dic["tpl"] = $this->getTemplateFactory()->getTemplate("tpl.main.html", false, false);
58 $this->dic["lng"] = $this->getLanguage();
59 $this->dic["refinery"] = new \ILIAS\Refinery\Factory(
60 new ILIAS\Data\Factory(),
61 $this->getLanguage()
62 );
63 (new InitUIFramework())->init($this->dic);
64
65 $this->dic["ui.template_factory"] = $this->getTemplateFactory();
66
67 $this->dic["ilCtrl"] = $this->getMockBuilder(\ilCtrl::class)->disableOriginalConstructor()->onlyMethods([
68 "getFormActionByClass","setParameterByClass","saveParameterByClass","getLinkTargetByClass", "isAsynch"
69 ])->getMock();
70 $this->dic["ilCtrl"]->method("getFormActionByClass")->willReturn("Testing");
71 $this->dic["ilCtrl"]->method("getLinkTargetByClass")->willReturn("2");
72 $this->dic["ilCtrl"]->method("isAsynch")->willReturn(false);
73
74 $this->dic["upload"] = $this->getMockBuilder(FileUpload::class)->getMock();
75
76 $this->dic["tree"] = $this->getMockBuilder(ilTree::class)
77 ->disableOriginalConstructor()
78 ->onlyMethods(["getNodeData"])->getMock();
79
80 $this->dic["tree"]->method("getNodeData")->willReturn([
81 "ref_id" => "1",
82 "title" => "mock root node",
83 "type" => "crs"
84 ]);
85
86 $component_factory = $this->createMock(ilComponentFactory::class);
87 $component_factory->method("getActivePluginsInSlot")->willReturn(new ArrayIterator());
88 $this->dic["component.factory"] = $component_factory;
89
90 (new InitHttpServices())->init($this->dic);
91 }
92
97 {
98 global $DIC;
100
101 foreach ($this->getEntriesFromCrawler() as $entry) {
102 if (!$entry->isAbstract()) {
103 $this->assertGreaterThan(
104 0,
105 count($entry->getExamples()),
106 "Non abstract Component " . $entry->getNamespace()
107 . " does not provide any example. Please provide at least one in " . $entry->getExamplesNamespace() . " at " . $entry->getExamplesPath()
108 );
109 }
110 }
111 }
112
116 public function testAllExamplesRenderAString(string $example_function_name, string $example_path): void
117 {
118 global $DIC;
120
121 include_once $example_path;
122 try {
123 $this->assertIsString($example_function_name(), " Example $example_function_name does not render a string");
124 } catch (NotImplementedException $e) {
125 $this->assertTrue(true);
126 }
127 }
128
132 protected function getEntriesFromCrawler(): Crawler\Entry\ComponentEntries
133 {
134 $crawler = new Crawler\FactoriesCrawler();
135 return $crawler->crawlFactory($this->path_to_base_factory);
136 }
137
139 {
140 $function_names = [];
141 foreach ($this->getEntriesFromCrawler() as $entry) {
142 foreach ($entry->getExamples() as $name => $example_path) {
143 $function_names[$entry->getExamplesNamespace() . "\\" . $name] = [
144 $entry->getExamplesNamespace() . "\\" . $name,
145 $example_path
146 ];
147 }
148 }
149 return $function_names;
150 }
151
155 public function testFullscreenModeExamples(string $example_function_name, string $example_path): void
156 {
157 global $DIC;
159
160 include_once $example_path;
161 try {
162 $this->assertIsString($example_function_name($DIC), " Example $example_function_name does not render a string");
163 } catch (NotImplementedException $e) {
164 $this->assertTrue(true);
165 }
166 }
167
168 public function provideListOfFullscreenExamples(): array
169 {
170 return [
171 ['ILIAS\UI\examples\MainControls\Footer\renderFooterInFullscreenMode', "src/UI/examples/MainControls/Footer/footer.php"],
172 ['ILIAS\UI\examples\MainControls\Footer\renderFooterWithModalsInFullscreenMode', "src/UI/examples/MainControls/Footer/footer_with_modals.php"],
173 ['ILIAS\UI\examples\MainControls\MetaBar\renderMetaBarInFullscreenMode', "src/UI/examples/MainControls/MetaBar/base_metabar.php"],
174 ['ILIAS\UI\examples\Layout\Page\Standard\getUIMainbarExampleCondensed', "src/UI/examples/Layout/Page/Standard/ui_mainbar.php"],
175 ['ILIAS\UI\examples\Layout\Page\Standard\getUIMainbarExampleFull', "src/UI/examples/Layout/Page/Standard/ui_mainbar.php"],
176 ['ILIAS\UI\examples\Layout\Page\Standard\renderFooterInFullscreenMode', "src/UI/examples/Layout/Page/Standard/ui.php"]
177 ];
178 }
179}
Class ExamplesTest Checks if all examples are implemented and properly returning strings.
provideExampleFullFunctionNamesAndPath()
testAllNonAbstractComponentsShowcaseExamples()
provideListOfFullscreenExamples()
testAllExamplesRenderAString(string $example_function_name, string $example_path)
@dataProvider provideExampleFullFunctionNamesAndPath
string $path_to_base_factory
testFullscreenModeExamples(string $example_function_name, string $example_path)
@dataProvider provideListOfFullscreenExamples
Container $dic
setUpMockDependencies()
Some wiring up of dependencies to get all the examples running.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
This exception indicates that an UI component was accepted by the JF but is not backed by a real impl...
Provides common functionality for UI tests.
Definition: Base.php:299
getTemplateFactory()
Definition: Base.php:315
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Responsible for loading the UI Framework into the dependency injection container of ILIAS.
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
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...
Definition: Crawler.php:21
Class ChatMainBarProvider \MainMenu\Provider.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10