ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
InitUIFrameworkTest.php
Go to the documentation of this file.
1 <?php
2 
19 require_once("vendor/composer/vendor/autoload.php");
20 
22 
23 class InitUIFrameworkTest extends TestCase
24 {
28  protected $dic;
29 
33  protected function setUp(): void
34  {
35  $this->dic = new \ILIAS\DI\Container();
36 
37  $this->dic["lng"] = $this->createMock("\ilLanguage");
38  $this->dic["tpl"] = $this->createMock("\ilGlobalTemplateInterface");
39  $this->dic["refinery"] = $this->createMock("\ILIAS\Refinery\Factory");
40  $this->dic["help.text_retriever"] = $this->createMock("ILIAS\UI\Help\TextRetriever\Echoing");
41  }
42 
43  public function testUIFrameworkInitialization(): void
44  {
45  $this->assertInstanceOf("\ILIAS\DI\UIServices", $this->dic->ui());
46  $this->assertFalse(isset($this->dic['ui.factory']));
47  $this->assertFalse(isset($this->dic['ui.renderer']));
48  (new \InitUIFramework())->init($this->dic);
49  $this->assertTrue(isset($this->dic['ui.factory']));
50  $this->assertTrue(isset($this->dic['ui.renderer']));
51  $this->assertInstanceOf("\ILIAS\UI\Factory", $this->dic->ui()->factory());
52  $this->assertInstanceOf("\ILIAS\UI\Renderer", $this->dic->ui()->renderer());
53  }
54 
59  public function testByExampleThatFactoryIsLoaded(): void
60  {
61  (new \InitUIFramework())->init($this->dic);
62 
63  $this->assertInstanceOf(
64  "ILIAS\UI\Implementation\Component\Divider\Vertical",
65  $this->dic->ui()->factory()->divider()->vertical()
66  );
67  }
68 
75  {
76  (new \InitUIFramework())->init($this->dic);
77  $this->dic["tpl"]->expects($this->atLeastOnce())->method("addJavaScript");
78 
79  //Note, this dep is not properly injected ilTemplate, therefore we need to hit on the global.
80  global $DIC;
81  $initial_state = $DIC;
82  $DIC = new \ILIAS\DI\Container();
83  $DIC["component.factory"] = $this->createMock(ilComponentFactory::class);
84 
85  $example_componanent = $this->dic->ui()->factory()->divider()->vertical();
86  $example_out = $this->dic->ui()->renderer()->render($example_componanent);
87  $this->assertIsString($example_out);
88  $DIC = $initial_state;
89  }
90 }
testByExampleThatFactoryIsLoaded()
This checks only by example that the factory is loaded and ready to work.
setUp()
Several dependencies need to be wired up before the UI Framework can be initialised.
global $DIC
Definition: shib_login.php:25
testByExampleThatRendererIsReadyToWork()
This checks only by example that the renderer is all up and ready to work.