ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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)
 
 testAllExamplesHaveExpectedOutcomeInDocs (string $example_function_name, string $example_path)
 
 testFullscreenModeExamples (string $example_function_name, string $example_path)
 

Static Public Member Functions

static getFullFunctionNamesAndPathExample ()
 
static getListOfFullscreenExamples ()
 

Protected Member Functions

 setUpMockDependencies ()
 Some wiring up of dependencies to get all the examples running. More...
 

Static Protected Member Functions

static getEntriesFromCrawler ()
 

Protected Attributes

const MAY_NOT_HAVE_EXAMPLES
 
Container $dic
 
Crawler ExamplesYamlParser $example_parser
 

Static Protected Attributes

static string $path_to_base_factory = "components/ILIAS/UI/src/Factory.php"
 

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()

static ExamplesTest::getEntriesFromCrawler ( )
staticprotected
Exceptions
Crawler

Exception\CrawlerException

Definition at line 160 of file ExamplesTest.php.

160 : Crawler\Entry\ComponentEntries
161 {
162 $crawler = new Crawler\FactoriesCrawler();
163 return $crawler->crawlFactory(self::$path_to_base_factory);
164 }

Referenced by testAllNonAbstractComponentsShowcaseExamples().

+ Here is the caller graph for this function:

◆ getFullFunctionNamesAndPathExample()

static ExamplesTest::getFullFunctionNamesAndPathExample ( )
static

Definition at line 166 of file ExamplesTest.php.

166 : array
167 {
168 $function_names = [];
169 foreach (static::getEntriesFromCrawler() as $entry) {
170 foreach ($entry->getExamples() as $name => $example_path) {
171 $function_names[$entry->getExamplesNamespace() . "\\" . $name] = [
172 $entry->getExamplesNamespace() . "\\" . $name,
173 $example_path
174 ];
175 }
176 }
177 return $function_names;
178 }

◆ getListOfFullscreenExamples()

static ExamplesTest::getListOfFullscreenExamples ( )
static

Definition at line 194 of file ExamplesTest.php.

194 : array
195 {
196 return [
197 ['ILIAS\UI\examples\MainControls\Footer\base', "components/ILIAS/UI/src/examples/MainControls/Footer/base.php"],
198 ['ILIAS\UI\examples\MainControls\MetaBar\renderMetaBarInFullscreenMode', "components/ILIAS/UI/src/examples/MainControls/MetaBar/base_metabar.php"],
199 ['ILIAS\UI\examples\Layout\Page\Standard\getUIMainbarExampleCondensed', "components/ILIAS/UI/src/examples/Layout/Page/Standard/ui_mainbar.php"],
200 ['ILIAS\UI\examples\Layout\Page\Standard\getUIMainbarExampleFull', "components/ILIAS/UI/src/examples/Layout/Page/Standard/ui_mainbar.php"],
201 ['ILIAS\UI\examples\Layout\Page\Standard\ui', "components/ILIAS/UI/src/examples/Layout/Page/Standard/ui.php"],
202 ['ILIAS\UI\examples\MainControls\ModeInfo\renderModeInfoFullscreenMode', "components/ILIAS/UI/src/examples/MainControls/ModeInfo/modeinfo.php"]
203 ];
204 }

◆ setUp()

ExamplesTest::setUp ( )

Definition at line 50 of file ExamplesTest.php.

50 : void
51 {
52 //This avoids various index not set warnings, which are only relevant in test context.
53 $_SERVER["REQUEST_SCHEME"] = "http";
54 $_SERVER["SERVER_NAME"] = "localhost";
55 $_SERVER["SERVER_PORT"] = "80";
56 $_SERVER["REQUEST_URI"] = "";
57 $_SERVER['SCRIPT_NAME'] = "";
58 $_SERVER['QUERY_STRING'] = "param=1";
59
60 //This avoids Undefined index: ilfilehash for the moment
61 $_POST["ilfilehash"] = "";
62 $this->setUpMockDependencies();
63 $this->example_parser = new Crawler\ExamplesYamlParser();
64 }
setUpMockDependencies()
Some wiring up of dependencies to get all the examples running.
$_POST['cmd']
Definition: lti.php:27
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26

References $_POST, $_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 71 of file ExamplesTest.php.

71 : void
72 {
73 $this->dic = new Container();
74 $this->dic["tpl"] = $this->getTemplateFactory()->getTemplate("tpl.main.html", false, false);
75 $this->dic["lng"] = $this->getLanguage();
76 $this->dic["refinery"] = new \ILIAS\Refinery\Factory(
77 new ILIAS\Data\Factory(),
78 $this->getLanguage()
79 );
80
81 (new InitUIFramework())->init($this->dic);
82
83 $this->dic["ui.template_factory"] = $this->getTemplateFactory();
84
85 $this->dic["ilCtrl"] = $this->getMockBuilder(\ilCtrl::class)->disableOriginalConstructor()->onlyMethods([
86 "getFormActionByClass","setParameterByClass","saveParameterByClass","getLinkTargetByClass", "isAsynch"
87 ])->getMock();
88 $this->dic["ilCtrl"]->method("getFormActionByClass")->willReturn("Testing");
89 $this->dic["ilCtrl"]->method("getLinkTargetByClass")->willReturn("2");
90 $this->dic["ilCtrl"]->method("isAsynch")->willReturn(false);
91
92 $this->dic["upload"] = $this->getMockBuilder(FileUpload::class)->getMock();
93
94 $this->dic["tree"] = $this->getMockBuilder(ilTree::class)
95 ->disableOriginalConstructor()
96 ->onlyMethods(["getNodeData"])->getMock();
97
98 $this->dic["tree"]->method("getNodeData")->willReturn([
99 "ref_id" => "1",
100 "title" => "mock root node",
101 "type" => "crs"
102 ]);
103
104 $component_factory = $this->createMock(ilComponentFactory::class);
105 $component_factory->method("getActivePluginsInSlot")->willReturn(new ArrayIterator());
106 $this->dic["component.factory"] = $component_factory;
107
108 $this->dic["help.text_retriever"] = new ILIAS\UI\Help\TextRetriever\Echoing();
109
110 (new InitHttpServices())->init($this->dic);
111 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
This HelpTextRetriever simply echo the purpose and the topics for debugging and development purpose.
Definition: Echoing.php:31
Responsible for loading the HTTP Service into the dependency injection container of ILIAS.
This is more or less a copy of the removed InitUIFramework file inside the Init component.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
getLanguage()

References getLanguage(), and init().

Referenced by setUp().

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

◆ testAllExamplesHaveExpectedOutcomeInDocs()

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

Definition at line 151 of file ExamplesTest.php.

152 {
153 $docs = $this->example_parser->parseYamlStringArrayFromFile($example_path);
154 $this->assertArrayHasKey('expected output', $docs);
155 }

◆ testAllExamplesRenderAString()

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

Definition at line 137 of file ExamplesTest.php.

137 : void
138 {
139 global $DIC;
141
142 include_once $example_path;
143 try {
144 $this->assertIsString($example_function_name(), " Example $example_function_name does not render a string");
145 } catch (NotImplementedException $e) {
146 $this->assertTrue(true);
147 }
148 }
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: shib_login.php:26

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

◆ testAllNonAbstractComponentsShowcaseExamples()

ExamplesTest::testAllNonAbstractComponentsShowcaseExamples ( )
Exceptions
Crawler

Exception\CrawlerException

Definition at line 116 of file ExamplesTest.php.

116 : void
117 {
118 global $DIC;
120
121 foreach ($this->getEntriesFromCrawler() as $entry) {
122 if (in_array(trim($entry->getNamespace(), '\\'), self::MAY_NOT_HAVE_EXAMPLES, true)) {
123 continue;
124 }
125 if (!$entry->isAbstract()) {
126 $this->assertGreaterThan(
127 0,
128 count($entry->getExamples()),
129 "Non abstract Component " . $entry->getNamespace()
130 . " does not provide any example. Please provide at least one in " . $entry->getExamplesNamespace() . " at " . $entry->getExamplesPath()
131 );
132 }
133 }
134 }
static getEntriesFromCrawler()

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

+ Here is the call graph for this function:

◆ testFullscreenModeExamples()

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

Definition at line 181 of file ExamplesTest.php.

181 : void
182 {
183 global $DIC;
185
186 include_once $example_path;
187 try {
188 $this->assertIsString($example_function_name($DIC), " Example $example_function_name does not render a string");
189 } catch (NotImplementedException $e) {
190 $this->assertTrue(true);
191 }
192 }

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

Field Documentation

◆ $dic

◆ $example_parser

Crawler ExamplesYamlParser ExamplesTest::$example_parser
protected

Definition at line 48 of file ExamplesTest.php.

◆ $path_to_base_factory

string ExamplesTest::$path_to_base_factory = "components/ILIAS/UI/src/Factory.php"
staticprotected

Definition at line 46 of file ExamplesTest.php.

◆ MAY_NOT_HAVE_EXAMPLES

const ExamplesTest::MAY_NOT_HAVE_EXAMPLES
protected
Initial value:
= [
\ILIAS\UI\Help\Topic::class,
\ILIAS\UI\Component\Progress\State\Bar\State::class,
\ILIAS\UI\Component\Input\Field\Node\Node::class,
\ILIAS\UI\Component\Input\Field\Node\Async::class,
\ILIAS\UI\Component\Input\Field\Node\Leaf::class,
]

Definition at line 38 of file ExamplesTest.php.


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