ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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)
 getFullFunctionNamesAndPathExample More...
 
 testAllExamplesHaveExpectedOutcomeInDocs (string $example_function_name, string $example_path)
 getFullFunctionNamesAndPathExample More...
 
 testFullscreenModeExamples (string $example_function_name, string $example_path)
 getListOfFullscreenExamples More...
 

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

Definition at line 160 of file ExamplesTest.php.

Referenced by testAllNonAbstractComponentsShowcaseExamples().

160  : Crawler\Entry\ComponentEntries
161  {
162  $crawler = new Crawler\FactoriesCrawler();
163  return $crawler->crawlFactory(self::$path_to_base_factory);
164  }
+ 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 196 of file ExamplesTest.php.

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

◆ setUp()

ExamplesTest::setUp ( )

Definition at line 47 of file ExamplesTest.php.

References $_POST, $_SERVER, and setUpMockDependencies().

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

References getLanguage(), and init().

Referenced by setUp().

68  : void
69  {
70  $this->dic = new Container();
71  $this->dic["tpl"] = $this->getTemplateFactory()->getTemplate("tpl.main.html", false, false);
72  $this->dic["lng"] = $this->getLanguage();
73  $this->dic["refinery"] = new \ILIAS\Refinery\Factory(
74  new ILIAS\Data\Factory(),
75  $this->getLanguage()
76  );
77  (new InitUIFramework())->init($this->dic);
78 
79  $this->dic["ui.template_factory"] = $this->getTemplateFactory();
80 
81  $this->dic["ilCtrl"] = $this->getMockBuilder(\ilCtrl::class)->disableOriginalConstructor()->onlyMethods([
82  "getFormActionByClass","setParameterByClass","saveParameterByClass","getLinkTargetByClass", "isAsynch"
83  ])->getMock();
84  $this->dic["ilCtrl"]->method("getFormActionByClass")->willReturn("Testing");
85  $this->dic["ilCtrl"]->method("getLinkTargetByClass")->willReturn("2");
86  $this->dic["ilCtrl"]->method("isAsynch")->willReturn(false);
87 
88  $this->dic["upload"] = $this->getMockBuilder(FileUpload::class)->getMock();
89 
90  $this->dic["tree"] = $this->getMockBuilder(ilTree::class)
91  ->disableOriginalConstructor()
92  ->onlyMethods(["getNodeData"])->getMock();
93 
94  $this->dic["tree"]->method("getNodeData")->willReturn([
95  "ref_id" => "1",
96  "title" => "mock root node",
97  "type" => "crs"
98  ]);
99 
100  $component_factory = $this->createMock(ilComponentFactory::class);
101  $component_factory->method("getActivePluginsInSlot")->willReturn(new ArrayIterator());
102  $this->dic["component.factory"] = $component_factory;
103 
104  $this->dic["help.text_retriever"] = new ILIAS\UI\Help\TextRetriever\Echoing();
105 
106  (new InitHttpServices())->init($this->dic);
107  }
Interface Observer Contains several chained tasks and infos about them.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
Responsible for loading the UI Framework into the dependency injection container of ILIAS...
getLanguage()
Responsible for loading the HTTP Service into the dependency injection container of ILIAS...
+ 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 
)

getFullFunctionNamesAndPathExample

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 
)

getFullFunctionNamesAndPathExample

Definition at line 135 of file ExamplesTest.php.

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

135  : void
136  {
137  global $DIC;
138  $DIC = $this->dic;
139 
140  include_once $example_path;
141  try {
142  $this->assertIsString($example_function_name(), " Example $example_function_name does not render a string");
143  } catch (NotImplementedException $e) {
144  $this->assertTrue(true);
145  }
146  }
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:25
Container $dic

◆ testAllNonAbstractComponentsShowcaseExamples()

ExamplesTest::testAllNonAbstractComponentsShowcaseExamples ( )
Exceptions
Crawler

Definition at line 112 of file ExamplesTest.php.

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

112  : void
113  {
114  global $DIC;
115  $DIC = $this->dic;
116 
117  foreach ($this->getEntriesFromCrawler() as $entry) {
118  if (in_array(trim($entry->getNamespace(), '\\'), self::MAY_NOT_HAVE_EXAMPLES, true)) {
119  continue;
120  }
121  if (!$entry->isAbstract()) {
122  $this->assertGreaterThan(
123  0,
124  count($entry->getExamples()),
125  "Non abstract Component " . $entry->getNamespace()
126  . " does not provide any example. Please provide at least one in " . $entry->getExamplesNamespace() . " at " . $entry->getExamplesPath()
127  );
128  }
129  }
130  }
static getEntriesFromCrawler()
global $DIC
Definition: shib_login.php:25
Container $dic
+ Here is the call graph for this function:

◆ testFullscreenModeExamples()

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

getListOfFullscreenExamples

Definition at line 183 of file ExamplesTest.php.

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

183  : void
184  {
185  global $DIC;
186  $DIC = $this->dic;
187 
188  include_once $example_path;
189  try {
190  $this->assertIsString($example_function_name($DIC), " Example $example_function_name does not render a string");
191  } catch (NotImplementedException $e) {
192  $this->assertTrue(true);
193  }
194  }
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:25
Container $dic

Field Documentation

◆ $dic

◆ $example_parser

Crawler ExamplesYamlParser ExamplesTest::$example_parser
protected

Definition at line 45 of file ExamplesTest.php.

◆ $path_to_base_factory

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

Definition at line 43 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,
]

Definition at line 38 of file ExamplesTest.php.


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