ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ExamplesTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("libs/composer/vendor/autoload.php");
22 require_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_SCHEME"] = "http";
41  $_SERVER["SERVER_NAME"] = "localhost";
42  $_SERVER["SERVER_PORT"] = "80";
43  $_SERVER["REQUEST_URI"] = "";
44  $_SERVER['SCRIPT_NAME'] = "";
45  $_SERVER['QUERY_STRING'] = "param=1";
46 
47  //This avoids Undefined index: ilfilehash for the moment
48  $_POST["ilfilehash"] = "";
49  $this->setUpMockDependencies();
50  }
51 
57  protected function setUpMockDependencies(): void
58  {
59  $this->dic = new Container();
60  $this->dic["tpl"] = $this->getTemplateFactory()->getTemplate("tpl.main.html", false, false);
61  $this->dic["lng"] = $this->getLanguage();
62  $this->dic["refinery"] = new \ILIAS\Refinery\Factory(
63  new ILIAS\Data\Factory(),
64  $this->getLanguage()
65  );
66  (new InitUIFramework())->init($this->dic);
67 
68  $this->dic["ui.template_factory"] = $this->getTemplateFactory();
69 
70  $this->dic["ilCtrl"] = $this->getMockBuilder(\ilCtrl::class)->disableOriginalConstructor()->onlyMethods([
71  "getFormActionByClass","setParameterByClass","saveParameterByClass","getLinkTargetByClass", "isAsynch"
72  ])->getMock();
73  $this->dic["ilCtrl"]->method("getFormActionByClass")->willReturn("Testing");
74  $this->dic["ilCtrl"]->method("getLinkTargetByClass")->willReturn("2");
75  $this->dic["ilCtrl"]->method("isAsynch")->willReturn(false);
76 
77  $this->dic["upload"] = $this->getMockBuilder(FileUpload::class)->getMock();
78 
79  $this->dic["tree"] = $this->getMockBuilder(ilTree::class)
80  ->disableOriginalConstructor()
81  ->onlyMethods(["getNodeData"])->getMock();
82 
83  $this->dic["tree"]->method("getNodeData")->willReturn([
84  "ref_id" => "1",
85  "title" => "mock root node",
86  "type" => "crs"
87  ]);
88 
89  $component_factory = $this->createMock(ilComponentFactory::class);
90  $component_factory->method("getActivePluginsInSlot")->willReturn(new ArrayIterator());
91  $this->dic["component.factory"] = $component_factory;
92 
93  $this->dic["help.text_retriever"] = new ILIAS\UI\Help\TextRetriever\Echoing();
94 
95  $this->dic["ilUser"] = $this->getMockBuilder(\ilObjUser::class)
96  ->disableOriginalConstructor()
97  ->onlyMethods(["getDateFormat"])
98  ->getMock();
99 
100  (new InitHttpServices())->init($this->dic);
101  }
102 
107  {
108  global $DIC;
109  $DIC = $this->dic;
110 
111  foreach ($this->getEntriesFromCrawler() as $entry) {
112  if ($entry->getNamespace() === "\ILIAS\UI\Help\Topic[]") {
113  continue;
114  }
115  if (!$entry->isAbstract()) {
116  $this->assertGreaterThan(
117  0,
118  count($entry->getExamples()),
119  "Non abstract Component " . $entry->getNamespace()
120  . " does not provide any example. Please provide at least one in " . $entry->getExamplesNamespace() . " at " . $entry->getExamplesPath()
121  );
122  }
123  }
124  }
125 
129  public function testAllExamplesRenderAString(string $example_function_name, string $example_path): void
130  {
131  global $DIC;
132  $DIC = $this->dic;
133 
134  include_once $example_path;
135  try {
136  $this->assertIsString($example_function_name(), " Example $example_function_name does not render a string");
137  } catch (NotImplementedException $e) {
138  $this->assertTrue(true);
139  }
140  }
141 
145  protected function getEntriesFromCrawler(): Crawler\Entry\ComponentEntries
146  {
147  $crawler = new Crawler\FactoriesCrawler();
148  return $crawler->crawlFactory($this->path_to_base_factory);
149  }
150 
151  public function getFullFunctionNamesAndPathExample(): array
152  {
153  $function_names = [];
154  foreach ($this->getEntriesFromCrawler() as $entry) {
155  foreach ($entry->getExamples() as $name => $example_path) {
156  $function_names[$entry->getExamplesNamespace() . "\\" . $name] = [
157  $entry->getExamplesNamespace() . "\\" . $name,
158  $example_path
159  ];
160  }
161  }
162  return $function_names;
163  }
164 
168  public function testFullscreenModeExamples(string $example_function_name, string $example_path): void
169  {
170  global $DIC;
171  $DIC = $this->dic;
172 
173  include_once $example_path;
174  try {
175  $this->assertIsString($example_function_name($DIC), " Example $example_function_name does not render a string");
176  } catch (NotImplementedException $e) {
177  $this->assertTrue(true);
178  }
179  }
180 
181  public function getListOfFullscreenExamples(): array
182  {
183  return [
184  ['ILIAS\UI\examples\MainControls\Footer\renderFooterInFullscreenMode', "src/UI/examples/MainControls/Footer/footer.php"],
185  ['ILIAS\UI\examples\MainControls\Footer\renderFooterWithModalsInFullscreenMode', "src/UI/examples/MainControls/Footer/footer_with_modals.php"],
186  ['ILIAS\UI\examples\MainControls\MetaBar\renderMetaBarInFullscreenMode', "src/UI/examples/MainControls/MetaBar/base_metabar.php"],
187  ['ILIAS\UI\examples\Layout\Page\Standard\getUIMainbarExampleCondensed', "src/UI/examples/Layout/Page/Standard/ui_mainbar.php"],
188  ['ILIAS\UI\examples\Layout\Page\Standard\getUIMainbarExampleFull', "src/UI/examples/Layout/Page/Standard/ui_mainbar.php"],
189  ['ILIAS\UI\examples\Layout\Page\Standard\ui', "src/UI/examples/Layout/Page/Standard/ui.php"],
190  ['ILIAS\UI\examples\MainControls\ModeInfo\renderModeInfoFullscreenMode', "src/UI/examples/MainControls/ModeInfo/modeinfo.php"]
191  ];
192  }
193 }
Class ExamplesTest Checks if all examples are implemented and properly returning strings.
Class ChatMainBarProvider .
setUpMockDependencies()
Some wiring up of dependencies to get all the examples running.
This exception indicates that an UI component was accepted by the JF but is not backed by a real impl...
string $path_to_base_factory
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
Responsible for loading the UI Framework into the dependency injection container of ILIAS...
global $DIC
Definition: feed.php:28
Provides common functionality for UI tests.
Definition: Base.php:310
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
testAllExamplesRenderAString(string $example_function_name, string $example_path)
getFullFunctionNamesAndPathExample
testFullscreenModeExamples(string $example_function_name, string $example_path)
getListOfFullscreenExamples
Container $dic
getListOfFullscreenExamples()
getTemplateFactory()
Definition: Base.php:327
getFullFunctionNamesAndPathExample()
testAllNonAbstractComponentsShowcaseExamples()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Crawler.php:21
Responsible for loading the HTTP Service into the dependency injection container of ILIAS...