ILIAS  release_8 Revision v8.24
HiddenInputTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23require_once(__DIR__ . "/InputTest.php");
24
26use ILIAS\Refinery\Factory as Refinery;
27use ILIAS\Data;
28
30{
32 protected I\Input\Field\Hidden $input;
33
34 public function setUp(): void
35 {
36 $this->name_source = new DefNamesource();
37 $this->input = new I\Input\Field\Hidden(
38 new Data\Factory(),
39 new Refinery(
40 new Data\Factory(),
41 $this->createMock(ilLanguage::class)
42 )
43 );
44 }
45
46 public function test_render(): void
47 {
48 $input = $this->input->withNameFrom($this->name_source);
49
50 $r = $this->getDefaultRenderer();
51 $html = $this->brutallyTrimHTML($r->render($input));
52
53 $expected = $this->brutallyTrimHTML('
54 <input id="id_1" type="hidden" name="name_0" value="" />
55 ');
56 $this->assertEquals($expected, $html);
57 }
58
59 public function test_render_disabled(): void
60 {
61 $input = $this->input->withNameFrom($this->name_source);
62 $input = $input->withDisabled(true);
63
64 $r = $this->getDefaultRenderer();
65 $html = $this->brutallyTrimHTML($r->render($input));
66
67 $expected = $this->brutallyTrimHTML('
68 <input id="id_1" type="hidden" name="name_0" value="" disabled="disabled"/>
69 ');
70 $this->assertEquals($expected, $html);
71 }
72
73 public function test_render_value(): void
74 {
75 $input = $this->input->withNameFrom($this->name_source);
76 $input = $input->withValue('some_value');
77
78 $r = $this->getDefaultRenderer();
79 $html = $this->brutallyTrimHTML($r->render($input));
80
81 $expected = $this->brutallyTrimHTML('
82 <input id="id_1" type="hidden" name="name_0" value="some_value" />
83 ');
84 $this->assertEquals($expected, $html);
85 }
86
87 public function test_render_escape(): void
88 {
89 $expected = $this->brutallyTrimHTML('
90 <input id="id_1" type="hidden" name="name_0" value="&lt;script&gt;alert(&quot;XSS&quot;);&lt;/script&gt;" />
91 ');
92 $actual = $this->brutallyTrimHTML(
93 $this->getDefaultRenderer()->render(
94 $this->input->withNameFrom($this->name_source)->withValue('<script>alert("XSS");</script>')
95 )
96 );
97 $this->assertEquals($expected, $actual);
98 }
99}
I Input Field Hidden $input
DefNamesource $name_source
Builds data types.
Definition: Factory.php:21
Provides common functionality for UI tests.
Definition: Base.php:299
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...