ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 165 of file ExamplesTest.php.

165 : Crawler\Entry\ComponentEntries
166 {
167 $crawler = new Crawler\FactoriesCrawler();
168 return $crawler->crawlFactory(self::$path_to_base_factory);
169 }

Referenced by testAllNonAbstractComponentsShowcaseExamples().

+ Here is the caller graph for this function:

◆ getFullFunctionNamesAndPathExample()

static ExamplesTest::getFullFunctionNamesAndPathExample ( )
static

Definition at line 171 of file ExamplesTest.php.

171 : array
172 {
173 $function_names = [];
174 foreach (static::getEntriesFromCrawler() as $entry) {
175 foreach ($entry->getExamples() as $name => $example_path) {
176 $function_names[$entry->getExamplesNamespace() . "\\" . $name] = [
177 $entry->getExamplesNamespace() . "\\" . $name,
178 $example_path
179 ];
180 }
181 }
182 return $function_names;
183 }

◆ getListOfFullscreenExamples()

static ExamplesTest::getListOfFullscreenExamples ( )
static

Definition at line 199 of file ExamplesTest.php.

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

◆ 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 // allows example Unit Tests to find resources like additional data or css
61 if (!defined('ILIAS_ABSOLUTE_PATH')) {
62 define('ILIAS_ABSOLUTE_PATH', realpath(__DIR__ . '/../../../../../'));
63 }
64
65 //This avoids Undefined index: ilfilehash for the moment
66 $_POST["ilfilehash"] = "";
67 $this->setUpMockDependencies();
68 $this->example_parser = new Crawler\ExamplesYamlParser();
69 }
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 76 of file ExamplesTest.php.

76 : void
77 {
78 $this->dic = new Container();
79 $this->dic["tpl"] = $this->getTemplateFactory()->getTemplate("tpl.main.html", false, false);
80 $this->dic["lng"] = $this->getLanguage();
81 $this->dic["refinery"] = new \ILIAS\Refinery\Factory(
82 new ILIAS\Data\Factory(),
83 $this->getLanguage()
84 );
85
86 (new InitUIFramework())->init($this->dic);
87
88 $this->dic["ui.template_factory"] = $this->getTemplateFactory();
89
90 $this->dic["ilCtrl"] = $this->getMockBuilder(\ilCtrl::class)->disableOriginalConstructor()->onlyMethods([
91 "getFormActionByClass","setParameterByClass","saveParameterByClass","getLinkTargetByClass", "isAsynch"
92 ])->getMock();
93 $this->dic["ilCtrl"]->method("getFormActionByClass")->willReturn("Testing");
94 $this->dic["ilCtrl"]->method("getLinkTargetByClass")->willReturn("2");
95 $this->dic["ilCtrl"]->method("isAsynch")->willReturn(false);
96
97 $this->dic["upload"] = $this->getMockBuilder(FileUpload::class)->getMock();
98
99 $this->dic["tree"] = $this->getMockBuilder(ilTree::class)
100 ->disableOriginalConstructor()
101 ->onlyMethods(["getNodeData"])->getMock();
102
103 $this->dic["tree"]->method("getNodeData")->willReturn([
104 "ref_id" => "1",
105 "title" => "mock root node",
106 "type" => "crs"
107 ]);
108
109 $component_factory = $this->createMock(ilComponentFactory::class);
110 $component_factory->method("getActivePluginsInSlot")->willReturn(new ArrayIterator());
111 $this->dic["component.factory"] = $component_factory;
112
113 $this->dic["help.text_retriever"] = new ILIAS\UI\Help\TextRetriever\Echoing();
114
115 (new InitHttpServices())->init($this->dic);
116 }
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 156 of file ExamplesTest.php.

157 {
158 $docs = $this->example_parser->parseYamlStringArrayFromFile($example_path);
159 $this->assertArrayHasKey('expected output', $docs);
160 }

◆ testAllExamplesRenderAString()

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

Definition at line 142 of file ExamplesTest.php.

142 : void
143 {
144 global $DIC;
146
147 include_once $example_path;
148 try {
149 $this->assertIsString($example_function_name(), " Example $example_function_name does not render a string");
150 } catch (NotImplementedException $e) {
151 $this->assertTrue(true);
152 }
153 }
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 121 of file ExamplesTest.php.

121 : void
122 {
123 global $DIC;
125
126 foreach ($this->getEntriesFromCrawler() as $entry) {
127 if (in_array(trim($entry->getNamespace(), '\\'), self::MAY_NOT_HAVE_EXAMPLES, true)) {
128 continue;
129 }
130 if (!$entry->isAbstract()) {
131 $this->assertGreaterThan(
132 0,
133 count($entry->getExamples()),
134 "Non abstract Component " . $entry->getNamespace()
135 . " does not provide any example. Please provide at least one in " . $entry->getExamplesNamespace() . " at " . $entry->getExamplesPath()
136 );
137 }
138 }
139 }
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 186 of file ExamplesTest.php.

186 : void
187 {
188 global $DIC;
190
191 include_once $example_path;
192 try {
193 $this->assertIsString($example_function_name($DIC), " Example $example_function_name does not render a string");
194 } catch (NotImplementedException $e) {
195 $this->assertTrue(true);
196 }
197 }

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: