ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
DefaultRendererTest Class Reference
+ Inheritance diagram for DefaultRendererTest:
+ Collaboration diagram for DefaultRendererTest:

Public Member Functions

 testGetRendererSuccessfully ()
 
 testGetRendererCaching ()
 
 getResourceRegistry ()
 
 testInvokesRegistry ()
 
 testRenderingChainAndContextStack ()
 Simulates the rendering chain and tests if the contexts are properly stacked. More...
 
 testRender ()
 
 testRenderAsyncNoJs ()
 
 testRenderAsyncWithJs ()
 
 testRenderAsyncWithJsTwice ()
 
 testRenderAsyncArray ()
 
 testPassesSelfAsRootIfNoRootExist ($render_type)
 
 testPassesOtherOnAsRoot ($render_type)
 
 testComponentListUsesRootToRender ()
 

Static Public Member Functions

static getRenderType ()
 

Data Fields

ComponentRenderer $component_renderer
 

Protected Attributes

LoggingRegistry $resource_registry
 

Detailed Description

Definition at line 37 of file DefaultRendererTest.php.

Member Function Documentation

◆ getRenderType()

static DefaultRendererTest::getRenderType ( )
static

Definition at line 249 of file DefaultRendererTest.php.

250  {
251  return [
252  ["render"],
253  ["renderAsync"]
254  ];
255  }

◆ getResourceRegistry()

DefaultRendererTest::getResourceRegistry ( )

Definition at line 58 of file DefaultRendererTest.php.

References $resource_registry.

59  {
60  $this->resource_registry = parent::getResourceRegistry();
62  }
LoggingRegistry $resource_registry

◆ testComponentListUsesRootToRender()

DefaultRendererTest::testComponentListUsesRootToRender ( )

Definition at line 257 of file DefaultRendererTest.php.

References $renderer, and $res.

258  {
259  $component = $this->createMock(C\Component::class);
260  $root = $this->createMock(Renderer::class);
261 
262  $renderer = $this->getDefaultRenderer();
263 
264  $root->expects($this->exactly(2))
265  ->method("render")
266  ->with($component)
267  ->willReturn(".");
268 
269  $res = $renderer->render([$component, $component], $root);
270  $this->assertEquals("..", $res);
271  }
$res
Definition: ltiservices.php:66
$renderer

◆ testGetRendererCaching()

DefaultRendererTest::testGetRendererCaching ( )

Definition at line 50 of file DefaultRendererTest.php.

50  : void
51  {
52  $dr = $this->getDefaultRenderer();
53  $r1 = $dr->_getRendererFor(new Glyph("up", "up"));
54  $r2 = $dr->_getRendererFor(new Glyph("up", "up"));
55  $this->assertTrue($r1 === $r2, "Instances not equal");
56  }

◆ testGetRendererSuccessfully()

DefaultRendererTest::testGetRendererSuccessfully ( )

Definition at line 42 of file DefaultRendererTest.php.

References $r.

42  : void
43  {
44  // There should be a renderer for Glyph...
45  $dr = $this->getDefaultRenderer();
46  $r = $dr->_getRendererFor(new Glyph("up", "up"));
47  $this->assertInstanceOf(ComponentRenderer::class, $r);
48  }
$r

◆ testInvokesRegistry()

DefaultRendererTest::testInvokesRegistry ( )

Definition at line 64 of file DefaultRendererTest.php.

64  : void
65  {
66  $dr = $this->getDefaultRenderer();
67  $component = new TestComponent("foo");
68 
69  $dr->render($component);
70 
71  $this->assertEquals(array("test.js"), $this->resource_registry->resources);
72  }

◆ testPassesOtherOnAsRoot()

DefaultRendererTest::testPassesOtherOnAsRoot (   $render_type)

Definition at line 231 of file DefaultRendererTest.php.

References $renderer, and getLanguage().

232  {
233  $this->component_renderer = $this->createMock(ComponentRenderer::class);
234  $component = $this->createMock(C\Component::class);
235  $root = $this->createMock(Renderer::class);
236 
237  $loader = $this->createMock(Loader::class);
238  $loader->method('getRendererFor')->willReturn($this->component_renderer);
239 
240  $renderer = new TestDefaultRenderer($loader, $this->getJavaScriptBinding(), $this->getLanguage());
241 
242  $this->component_renderer->expects($this->once())
243  ->method("render")
244  ->with($component, $root);
245 
246  $renderer->$render_type($component, $root);
247  }
$renderer
getLanguage()
+ Here is the call graph for this function:

◆ testPassesSelfAsRootIfNoRootExist()

DefaultRendererTest::testPassesSelfAsRootIfNoRootExist (   $render_type)

Definition at line 213 of file DefaultRendererTest.php.

References $renderer, and getLanguage().

214  {
215  $this->component_renderer = $this->createMock(ComponentRenderer::class);
216  $component = $this->createMock(C\Component::class);
217 
218  $loader = $this->createMock(Loader::class);
219  $loader->method('getRendererFor')->willReturn($this->component_renderer);
220 
221  $renderer = new TestDefaultRenderer($loader, $this->getJavaScriptBinding(), $this->getLanguage());
222 
223  $this->component_renderer->expects($this->once())
224  ->method("render")
225  ->with($component, $renderer);
226 
227  $renderer->$render_type($component);
228  }
$renderer
getLanguage()
+ Here is the call graph for this function:

◆ testRender()

DefaultRendererTest::testRender ( )

Definition at line 156 of file DefaultRendererTest.php.

References $renderer.

156  : void
157  {
158  $c1 = new TestComponent("foo");
159  $renderer = $this->getDefaultRenderer();
160  $html = $renderer->render($c1);
161  $this->assertEquals("foo", $html);
162  }
$renderer

◆ testRenderAsyncArray()

DefaultRendererTest::testRenderAsyncArray ( )

Definition at line 201 of file DefaultRendererTest.php.

References $renderer.

201  : void
202  {
203  $c1 = new TestComponent("foo");
204 
205  $renderer = $this->getDefaultRenderer(
206  new ilJavaScriptBinding($this->getTemplateFactory()->getTemplate("tpl.main.html", false, false))
207  );
208  $html = $renderer->renderAsync([$c1,$c1]);
209  $this->assertEquals('foofoo', $html);
210  }
$renderer
Wraps global ilTemplate to provide JavaScriptBinding.

◆ testRenderAsyncNoJs()

DefaultRendererTest::testRenderAsyncNoJs ( )

Definition at line 164 of file DefaultRendererTest.php.

References $renderer.

164  : void
165  {
166  $c1 = new TestComponent("foo");
167  $renderer = $this->getDefaultRenderer(
169  $this->getTemplateFactory()->getTemplate("tpl.main.html", false, false)
170  )
171  );
172  $html = $renderer->renderAsync($c1);
173  $this->assertEquals("foo", $html);
174  }
$renderer
Wraps global ilTemplate to provide JavaScriptBinding.

◆ testRenderAsyncWithJs()

DefaultRendererTest::testRenderAsyncWithJs ( )

Definition at line 176 of file DefaultRendererTest.php.

References $renderer.

176  : void
177  {
178  $c1 = new JSTestComponent("foo");
179  $renderer = $this->getDefaultRenderer(
180  new ilJavaScriptBinding($this->getTemplateFactory()->getTemplate("tpl.main.html", false, false))
181  );
182  $html = $renderer->renderAsync($c1);
183  $this->assertEquals('foo<script data-replace-marker="script">id:foo.id content:foo</script>', $html);
184  }
$renderer
Wraps global ilTemplate to provide JavaScriptBinding.

◆ testRenderAsyncWithJsTwice()

DefaultRendererTest::testRenderAsyncWithJsTwice ( )

Definition at line 186 of file DefaultRendererTest.php.

References $renderer.

186  : void
187  {
188  $c1 = new TestComponent("foo");
189  $c2 = new JSTestComponent("foo");
190  $renderer = $this->getDefaultRenderer(
191  new ilJavaScriptBinding($this->getTemplateFactory()->getTemplate("tpl.main.html", false, false))
192  );
193  $html = $renderer->renderAsync($c2);
194  $this->assertEquals('foo<script data-replace-marker="script">id:foo.id content:foo</script>', $html);
195  $html = $renderer->renderAsync($c1);
196  $this->assertEquals("foo", $html);
197  $html = $renderer->renderAsync($c2);
198  $this->assertEquals('foo<script data-replace-marker="script">id:foo.id content:foo</script>', $html);
199  }
$renderer
Wraps global ilTemplate to provide JavaScriptBinding.

◆ testRenderingChainAndContextStack()

DefaultRendererTest::testRenderingChainAndContextStack ( )

Simulates the rendering chain and tests if the contexts are properly stacked.

DefaultRenderer -> ConcreteRenderer -> DefaultRenderer -> ConcreteRenderer ...

Definition at line 78 of file DefaultRendererTest.php.

References $component_renderer, $renderer, ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\UI\Implementation\DefaultRenderer\render().

78  : void
79  {
80  $component1 = new TestComponent("component1");
81  $component2 = new TestComponent("component2");
82  $component3 = new TestComponent("component3");
83  $glue = '.';
84 
85  $component_renderer = $this->createMock(ComponentRenderer::class);
86  $component_renderer->method('render')->willReturnCallback(
87  static function (TestComponent $component, DefaultRenderer $renderer) use (
88  $component1,
89  $component2,
90  $component3,
91  $glue
92  ) {
93  return match ($component->text) {
94  $component1->text => $component1->text . $glue . $renderer->render($component2),
95  $component2->text => $component2->text . $glue . $renderer->render($component3),
96  $component3->text => $component3->text,
97  };
98  }
99  );
100 
101  $renderer = new class (
102  $this->createMock(Render\Loader::class),
103  $this->createMock(JavaScriptBinding::class),
104  $this->createMock(\ILIAS\Language\Language::class),
106  ) extends DefaultRenderer {
107  public array $context_history = [];
108 
109  public function __construct(
110  Render\Loader $component_renderer_loader,
111  JavaScriptBinding $java_script_binding,
112  \ILIAS\Language\Language $language,
114  ) {
115  parent::__construct($component_renderer_loader, $java_script_binding, $language);
116  }
117 
118  protected function getRendererFor(Component $component): ComponentRenderer
119  {
121  }
122 
123  protected function pushContext(Component $component): void
124  {
125  parent::pushContext($component);
126  $this->context_history[] = $this->getContexts();
127  }
128 
129  protected function popContext(): void
130  {
131  parent::popContext();
132  $this->context_history[] = $this->getContexts();
133  }
134  };
135 
136  $expected_context_history = [
137  [$component1],
138  [$component1, $component2],
139  [$component1, $component2, $component3],
140  [$component1, $component2],
141  [$component1],
142  []
143  ];
144 
145  $expected_html =
146  $component1->text . $glue .
147  $component2->text . $glue .
148  $component3->text;
149 
150  $html = $renderer->render($component1);
151 
152  $this->assertEquals($expected_context_history, $renderer->context_history);
153  $this->assertEquals($expected_html, $html);
154  }
render($component, ?Renderer $root=null)
Render given component.If an array of components is passed, this method returns a concatenated output...
$renderer
Interface Observer Contains several chained tasks and infos about them.
An entity that renders components to a string output.
ComponentRenderer $component_renderer
Provides methods to interface with javascript.
__construct(Container $dic, ilPlugin $plugin)
Loads renderers for components.
Definition: Loader.php:29
+ Here is the call graph for this function:

Field Documentation

◆ $component_renderer

ComponentRenderer DefaultRendererTest::$component_renderer

Definition at line 40 of file DefaultRendererTest.php.

Referenced by testRenderingChainAndContextStack().

◆ $resource_registry

LoggingRegistry DefaultRendererTest::$resource_registry
protected

Definition at line 39 of file DefaultRendererTest.php.

Referenced by getResourceRegistry().


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