ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
HiddenInputTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../../../../vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../../Base.php");
23 require_once(__DIR__ . "/InputTest.php");
24 require_once(__DIR__ . "/CommonFieldRendering.php");
25 
28 use ILIAS\Data;
29 
31 {
33 
35  protected I\Input\Field\Hidden $input;
36 
37  public function setUp(): void
38  {
39  $this->name_source = new DefNamesource();
40  $this->input = new I\Input\Field\Hidden(
41  new Data\Factory(),
42  new Refinery(
43  new Data\Factory(),
44  $this->createMock(ILIAS\Language\Language::class)
45  )
46  );
47  }
48 
49  public function testRender(): void
50  {
51  $input = $this->input->withNameFrom($this->name_source);
52 
53  $r = $this->getDefaultRenderer();
54  $html = $this->brutallyTrimHTML($r->render($input));
55 
56  $expected = $this->brutallyTrimHTML('
57  <input id="id_1" type="hidden" name="name_0" value="" />
58  ');
59  $this->assertEquals($expected, $html);
60  }
61 
62  public function testRenderDisabled(): void
63  {
64  $input = $this->input->withNameFrom($this->name_source);
65  $input = $input->withDisabled(true);
66 
67  $r = $this->getDefaultRenderer();
68  $html = $this->brutallyTrimHTML($r->render($input));
69 
70  $expected = $this->brutallyTrimHTML('
71  <input id="id_1" type="hidden" name="name_0" value="" disabled="disabled"/>
72  ');
73  $this->assertEquals($expected, $html);
74  }
75 
76  public function testRenderValue(): void
77  {
78  $input = $this->input->withNameFrom($this->name_source);
79  $input = $input->withValue('some_value');
80 
81  $r = $this->getDefaultRenderer();
82  $html = $this->brutallyTrimHTML($r->render($input));
83 
84  $expected = $this->brutallyTrimHTML('
85  <input id="id_1" type="hidden" name="name_0" value="some_value" />
86  ');
87  $this->assertEquals($expected, $html);
88  }
89 
90  public function testCommonRendering(): void
91  {
92  $f = $this->getFieldFactory();
93  $hidden = $f->hidden()->withNameFrom($this->name_source);
94 
95  $this->testWithNoByline($hidden);
96  $this->testWithAdditionalOnloadCodeRendersId($hidden);
97  }
98 
99  public function testRenderEscaped(): void
100  {
101  $expected = $this->brutallyTrimHTML('
102  <input id="id_1" type="hidden" name="name_0" value="&lt;script&gt;alert(&quot;XSS&quot;);&lt;/script&gt;" />
103  ');
104  $actual = $this->brutallyTrimHTML(
105  $this->getDefaultRenderer()->render(
106  $this->input->withNameFrom($this->name_source)->withValue('<script>alert("XSS");</script>')
107  )
108  );
109  $this->assertEquals($expected, $actual);
110  }
111 }
DefNamesource $name_source
Interface Observer Contains several chained tasks and infos about them.
I Input Field Hidden $input
Builds data types.
Definition: Factory.php:35
$r