ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
UrlInputTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../../Base.php");
23 require_once(__DIR__ . "/InputTest.php");
24 
28 use ILIAS\Data;
30 
32 {
34 
35  public function setUp(): void
36  {
37  $this->name_source = new DefNamesource();
38  }
39 
40  protected function buildFactory(): I\Input\Field\Factory
41  {
42  $data_factory = new Data\Factory();
43  $language = $this->createMock(ilLanguage::class);
44  return new I\Input\Field\Factory(
45  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
46  new SignalGenerator(),
47  $data_factory,
48  new Refinery($data_factory, $language),
49  $language
50  );
51  }
52 
53  public function test_implements_factory_interface(): void
54  {
55  $factory = $this->buildFactory();
56  $url = $factory->url("Test Label", "Test Byline");
57 
58  $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $url);
59  $this->assertInstanceOf(Field\Url::class, $url);
60  }
61 
62  public function test_rendering(): void
63  {
64  $factory = $this->buildFactory();
65  $renderer = $this->getDefaultRenderer();
66  $label = "Test Label";
67  $byline = "Test Byline";
68  $id = "id_1";
69  $name = "name_0";
70  $url = $factory->url($label, $byline)->withNameFrom($this->name_source);
71  $html = $this->normalizeHTML($renderer->render($url));
72 
73  $expected = "<div class=\"form-group row\">
74  <label for=\"$id\" class=\"control-label col-sm-4 col-md-3 col-lg-2\">$label</label>
75  <div class=\"col-sm-8 col-md-9 col-lg-10\">
76  <input id=\"$id\" type=\"url\" name=\"$name\" class=\"form-control form-control-sm\" />
77  <div class=\"help-block\">$byline</div>
78  </div>
79  </div>";
80  $this->assertEquals(
81  $this->brutallyTrimHTML($expected),
82  $this->brutallyTrimHTML($html)
83  );
84  }
85 
86  public function test_render_error(): void
87  {
88  $factory = $this->buildFactory();
89  $renderer = $this->getDefaultRenderer();
90  $label = "Test Label";
91  $byline = "Test Byline";
92  $id = "id_1";
93  $name = "name_0";
94  $error = "test_error";
95  $url = $factory->url($label, $byline)->withNameFrom($this->name_source)
96  ->withError($error);
97  $html = $this->normalizeHTML($renderer->render($url));
98 
99  $expected = "<div class=\"form-group row\">
100  <label for=\"$id\" class=\"control-label col-sm-4 col-md-3 col-lg-2\">$label</label>
101  <div class=\"col-sm-8 col-md-9 col-lg-10\">
102  <div class=\"help-block alert alert-danger\" aria-describedby=\"id_1\" role=\"alert\">$error</div>
103  <input id=\"$id\" type=\"url\" name=\"$name\" class=\"form-control form-control-sm\" />
104  <div class=\"help-block\">$byline</div>
105  </div>
106  </div>";
107 
108  $this->assertEquals(
109  $this->brutallyTrimHTML($expected),
110  $this->brutallyTrimHTML($html)
111  );
112  }
113 
114  public function test_render_no_byline(): void
115  {
116  $factory = $this->buildFactory();
117  $renderer = $this->getDefaultRenderer();
118  $label = "Test Label";
119  $id = "id_1";
120  $name = "name_0";
121  $url = $factory->url($label)->withNameFrom($this->name_source);
122  $html = $this->normalizeHTML($renderer->render($url));
123 
124  $expected = "<div class=\"form-group row\">
125  <label for=\"$id\" class=\"control-label col-sm-4 col-md-3 col-lg-2\">$label</label>
126  <div class=\"col-sm-8 col-md-9 col-lg-10\">
127  <input id=\"$id\" type=\"url\" name=\"$name\" class=\"form-control form-control-sm\" />
128  </div>
129  </div>";
130  $this->assertEquals(
131  $this->brutallyTrimHTML($expected),
132  $this->brutallyTrimHTML($html)
133  );
134  }
135 
136  public function test_render_value(): void
137  {
138  $factory = $this->buildFactory();
139  $renderer = $this->getDefaultRenderer();
140  $label = "Test Label";
141  $value = "https://www.ilias.de/";
142  $id = "id_1";
143  $name = "name_0";
144  $url = $factory->url($label)->withValue($value)
145  ->withNameFrom($this->name_source);
146  $html = $this->normalizeHTML($renderer->render($url));
147 
148  $expected = "<div class=\"form-group row\">
149  <label for=\"$id\" class=\"control-label col-sm-4 col-md-3 col-lg-2\">$label</label>
150  <div class=\"col-sm-8 col-md-9 col-lg-10\">
151  <input id=\"$id\" type=\"url\" value=\"$value\" name=\"$name\" class=\"form-control form-control-sm\" />
152  </div>
153  </div>";
154  $this->assertEquals(
155  $this->brutallyTrimHTML($expected),
156  $this->brutallyTrimHTML($html)
157  );
158  }
159 
160  public function test_render_required(): void
161  {
162  $factory = $this->buildFactory();
163  $renderer = $this->getDefaultRenderer();
164  $label = "Test Label";
165  $id = "id_1";
166  $name = "name_0";
167  $url = $factory->url($label)->withNameFrom($this->name_source)
168  ->withRequired(true);
169  $html = $this->normalizeHTML($renderer->render($url));
170 
171  $expected = "<div class=\"form-group row\">
172  <label for=\"$id\" class=\"control-label col-sm-4 col-md-3 col-lg-2\">$label<span class=\"asterisk\">*</span></label>
173  <div class=\"col-sm-8 col-md-9 col-lg-10\">
174  <input id=\"$id\" type=\"url\" name=\"$name\" class=\"form-control form-control-sm\" />
175  </div>
176  </div>";
177  $this->assertEquals(
178  $this->brutallyTrimHTML($expected),
179  $this->brutallyTrimHTML($html)
180  );
181  }
182 
183  public function test_render_disabled(): void
184  {
185  $factory = $this->buildFactory();
186  $renderer = $this->getDefaultRenderer();
187  $label = "Test Label";
188  $id = "id_1";
189  $name = "name_0";
190  $url = $factory->url($label)->withNameFrom($this->name_source)
191  ->withDisabled(true);
192  $html = $this->normalizeHTML($renderer->render($url));
193 
194  $expected = "<div class=\"form-group row\">
195  <label for=\"$id\" class=\"control-label col-sm-4 col-md-3 col-lg-2\">$label</label>
196  <div class=\"col-sm-8 col-md-9 col-lg-10\">
197  <input id=\"$id\" type=\"url\" name=\"$name\" disabled=\"disabled\" class=\"form-control form-control-sm\" />
198  </div>
199  </div>";
200 
201  $this->assertEquals(
202  $this->brutallyTrimHTML($expected),
203  $this->brutallyTrimHTML($html)
204  );
205  }
206 }
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...
Class Factory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
DefNamesource $name_source
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
if($format !==null) $name
Definition: metadata.php:247
Provides common functionality for UI tests.
Definition: Base.php:298
test_implements_factory_interface()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$url
normalizeHTML(string $html)
Definition: Base.php:422
$factory
Definition: metadata.php:75