ILIAS  release_8 Revision v8.24
ExamplesTest Class Reference

Class ExamplesTest Checks if all examples are implemented and properly returning strings. More...

+ Inheritance diagram for ExamplesTest:
+ Collaboration diagram for ExamplesTest:

Public Member Functions

 setUp ()
 
 testAllNonAbstractComponentsShowcaseExamples ()
 
 testAllExamplesRenderAString (string $example_function_name, string $example_path)
 @dataProvider provideExampleFullFunctionNamesAndPath More...
 
 provideExampleFullFunctionNamesAndPath ()
 
 testFullscreenModeExamples (string $example_function_name, string $example_path)
 @dataProvider provideListOfFullscreenExamples More...
 
 provideListOfFullscreenExamples ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDataFactory ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML (string $html)
 
 assertHTMLEquals (string $expected_html_as_string, string $html_as_string)
 

Protected Member Functions

 setUpMockDependencies ()
 Some wiring up of dependencies to get all the examples running. More...
 
 getEntriesFromCrawler ()
 
- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML (string $html)
 A more radical version of normalizeHTML. More...
 
 brutallyTrimSignals (string $html)
 A naive replacement of all il_signal-ids with dots to ease comparisons of rendered output. More...
 

Protected Attributes

string $path_to_base_factory = "src/UI/Factory.php"
 
Container $dic
 

Detailed Description

Class ExamplesTest Checks if all examples are implemented and properly returning strings.

Definition at line 32 of file ExamplesTest.php.

Member Function Documentation

◆ getEntriesFromCrawler()

ExamplesTest::getEntriesFromCrawler ( )
protected
Exceptions
Crawler

Exception\CrawlerException

Definition at line 132 of file ExamplesTest.php.

132 : Crawler\Entry\ComponentEntries
133 {
134 $crawler = new Crawler\FactoriesCrawler();
135 return $crawler->crawlFactory($this->path_to_base_factory);
136 }

Referenced by provideExampleFullFunctionNamesAndPath(), and testAllNonAbstractComponentsShowcaseExamples().

+ Here is the caller graph for this function:

◆ provideExampleFullFunctionNamesAndPath()

ExamplesTest::provideExampleFullFunctionNamesAndPath ( )

Definition at line 138 of file ExamplesTest.php.

138 : array
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 }
if($format !==null) $name
Definition: metadata.php:247

References $name, and getEntriesFromCrawler().

+ Here is the call graph for this function:

◆ provideListOfFullscreenExamples()

ExamplesTest::provideListOfFullscreenExamples ( )

Definition at line 168 of file ExamplesTest.php.

168 : 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 }

◆ setUp()

ExamplesTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 37 of file ExamplesTest.php.

37 : 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 }
setUpMockDependencies()
Some wiring up of dependencies to get all the examples running.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10

References $_SERVER, and setUpMockDependencies().

+ Here is the call graph for this function:

◆ setUpMockDependencies()

ExamplesTest::setUpMockDependencies ( )
protected

Some wiring up of dependencies to get all the examples running.

If you examples needs additional dependencies, please add them here. However, please check carefully if those deps are really needed. Even if the examples, we try to keep them minimal. Note the most deps are wired up here as mocks only.

Definition at line 54 of file ExamplesTest.php.

54 : 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 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
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.
Class ChatMainBarProvider \MainMenu\Provider.

References ILIAS_UI_TestBase\getLanguage(), and ILIAS_UI_TestBase\getTemplateFactory().

Referenced by setUp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testAllExamplesRenderAString()

ExamplesTest::testAllExamplesRenderAString ( string  $example_function_name,
string  $example_path 
)

@dataProvider provideExampleFullFunctionNamesAndPath

Definition at line 116 of file ExamplesTest.php.

116 : 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 }
Container $dic
This exception indicates that an UI component was accepted by the JF but is not backed by a real impl...
global $DIC
Definition: feed.php:28

References $DIC, $dic, and Vendor\Package\$e.

◆ testAllNonAbstractComponentsShowcaseExamples()

ExamplesTest::testAllNonAbstractComponentsShowcaseExamples ( )
Exceptions
Crawler

Exception\CrawlerException

Definition at line 96 of file ExamplesTest.php.

96 : void
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 }

References $DIC, $dic, and getEntriesFromCrawler().

+ Here is the call graph for this function:

◆ testFullscreenModeExamples()

ExamplesTest::testFullscreenModeExamples ( string  $example_function_name,
string  $example_path 
)

@dataProvider provideListOfFullscreenExamples

Definition at line 155 of file ExamplesTest.php.

155 : 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 }

References $DIC, $dic, and Vendor\Package\$e.

Field Documentation

◆ $dic

◆ $path_to_base_factory

string ExamplesTest::$path_to_base_factory = "src/UI/Factory.php"
protected

Definition at line 34 of file ExamplesTest.php.


The documentation for this class was generated from the following file: