ILIAS  release_8 Revision v8.24
DurationInputTest.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");
23
27use ILIAS\Data;
28use ILIAS\Refinery\Factory as Refinery;
30
32{
35 protected I\Input\Field\Factory $factory;
36 protected ilLanguage $lng;
37
38 public function setUp(): void
39 {
40 $this->name_source = new DefNamesource();
41 $this->data_factory = new Data\Factory();
42 $this->factory = $this->buildFactory();
43 }
44
45 protected function buildLanguage(): ilLanguage
46 {
47 $this->lng = $this->createMock(ilLanguage::class);
48 $this->lng->method("txt")
49 ->will($this->returnArgument(0));
50
51 return $this->lng;
52 }
53
54 protected function buildRefinery(): Refinery
55 {
56 return new Refinery($this->data_factory, $this->buildLanguage());
57 }
58
59 protected function buildFactory(): I\Input\Field\Factory
60 {
61 return new I\Input\Field\Factory(
62 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
63 new SignalGenerator(),
64 $this->data_factory,
65 $this->buildRefinery(),
66 $this->buildLanguage()
67 );
68 }
69
70 public function getUIFactory(): NoUIFactory
71 {
72 return new class () extends NoUIFactory {
73 public function symbol(): C\Symbol\Factory
74 {
75 return new S\Factory(
76 new S\Icon\Factory(),
77 new S\Glyph\Factory(),
78 new S\Avatar\Factory()
79 );
80 }
81 };
82 }
83
84 public function test_withFormat(): void
85 {
86 $format = $this->data_factory->dateFormat()->germanShort();
87 $duration = $this->factory->duration('label', 'byline')
88 ->withFormat($format);
89
90 $this->assertEquals(
91 $format,
92 $duration->getFormat()
93 );
94 }
95
96 public function test_withMinValue(): void
97 {
98 $dat = new DateTimeImmutable('2019-01-09');
99 $duration = $this->factory->duration('label', 'byline')
100 ->withMinValue($dat);
101
102 $this->assertEquals(
103 $dat,
104 $duration->getMinValue()
105 );
106 }
107
108 public function test_withMaxValue(): void
109 {
110 $dat = new DateTimeImmutable('2019-01-09');
111 $duration = $this->factory->duration('label', 'byline')
112 ->withMaxValue($dat);
113
114 $this->assertEquals(
115 $dat,
116 $duration->getMaxValue()
117 );
118 }
119
120 public function test_withUseTime(): void
121 {
122 $datetime = $this->factory->duration('label', 'byline');
123 $this->assertFalse($datetime->getUseTime());
124 $this->assertTrue($datetime->withUseTime(true)->getUseTime());
125 }
126
127 public function test_withTimeOnly(): void
128 {
129 $datetime = $this->factory->duration('label', 'byline');
130 $this->assertFalse($datetime->getTimeOnly());
131 $this->assertTrue($datetime->withTimeOnly(true)->getTimeOnly());
132 }
133
134 public function test_withTimeZone(): void
135 {
136 $datetime = $this->factory->duration('label', 'byline');
137 $this->assertNull($datetime->getTimeZone());
138 $tz = 'Europe/Moscow';
139 $this->assertEquals(
140 $tz,
141 $datetime->withTimeZone($tz)->getTimeZone()
142 );
143 }
144
145 public function test_withInvalidTimeZone(): void
146 {
147 $this->expectException(InvalidArgumentException::class);
148 $datetime = $this->factory->duration('label', 'byline');
149 $tz = 'NOT/aValidTZ';
150 $datetime->withTimeZone($tz);
151 }
152
153 public function testWithoutByline(): void
154 {
155 $datetime = $this->factory->duration('label');
156 $this->assertInstanceOf(C\Input\Field\Duration::class, $datetime);
157 }
158
159 public function test_render(): \ILIAS\UI\Component\Input\Field\Duration
160 {
161 $datetime = $this->factory->duration('label', 'byline');
162 $r = $this->getDefaultRenderer();
163 $html = $this->brutallyTrimHTML($r->render($datetime));
164 $label_start = 'duration_default_label_start';
165 $label_end = 'duration_default_label_end';
166
167
168 $expected = $this->brutallyTrimHTML('
169 <div class="form-group row">
170 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
171 <div class="col-sm-8 col-md-9 col-lg-10">
172 <div class="il-input-duration" id="id_1">
173 <div class="form-group row">
174 <label for="id_2" class="control-label col-sm-4 col-md-3 col-lg-2">' . $label_start . '</label>
175 <div class="col-sm-8 col-md-9 col-lg-10">
176 <div class="input-group date il-input-datetime" id="id_2"><input type="text" name="" placeholder="YYYY-MM-DD" class="form-control form-control-sm" /><span class="input-group-addon"><a tabindex="0" class="glyph" href="#" aria-label="calendar"><span class="glyphicon glyphicon-calendar" aria-hidden="true"></span></a></span></div>
177 </div>
178 </div>
179 <div class="form-group row">
180 <label for="id_3" class="control-label col-sm-4 col-md-3 col-lg-2">' . $label_end . '</label>
181 <div class="col-sm-8 col-md-9 col-lg-10">
182 <div class="input-group date il-input-datetime" id="id_3"><input type="text" name="" placeholder="YYYY-MM-DD" class="form-control form-control-sm" /><span class="input-group-addon"><a tabindex="0" class="glyph" href="#" aria-label="calendar"><span class="glyphicon glyphicon-calendar" aria-hidden="true"></span></a></span></div>
183 </div>
184 </div>
185 </div>
186 <div class="help-block">byline</div>
187 </div>
188 </div>
189 ');
190 $this->assertEquals($expected, $html);
191
192 return $datetime;
193 }
194
198 public function testRenderwithDifferentLabels($datetime): void
199 {
200 $other_start_label = 'other startlabel';
201 $other_end_label = 'other endlabel';
202 $datetime = $datetime->withLabels($other_start_label, $other_end_label);
203
204 $r = $this->getDefaultRenderer();
205 $html = $this->brutallyTrimHTML($r->render($datetime));
206
207 $expected = $this->brutallyTrimHTML('
208 <div class="form-group row">
209 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
210 <div class="col-sm-8 col-md-9 col-lg-10">
211 <div class="il-input-duration" id="id_1">
212 <div class="form-group row">
213 <label for="id_2" class="control-label col-sm-4 col-md-3 col-lg-2">' . $other_start_label . '</label>
214 <div class="col-sm-8 col-md-9 col-lg-10">
215 <div class="input-group date il-input-datetime" id="id_2"><input type="text" name="" placeholder="YYYY-MM-DD" class="form-control form-control-sm" /><span class="input-group-addon"><a tabindex="0" class="glyph" href="#" aria-label="calendar"><span class="glyphicon glyphicon-calendar" aria-hidden="true"></span></a></span></div>
216 </div>
217 </div>
218 <div class="form-group row">
219 <label for="id_3" class="control-label col-sm-4 col-md-3 col-lg-2">' . $other_end_label . '</label>
220 <div class="col-sm-8 col-md-9 col-lg-10">
221 <div class="input-group date il-input-datetime" id="id_3"><input type="text" name="" placeholder="YYYY-MM-DD" class="form-control form-control-sm" /><span class="input-group-addon"><a tabindex="0" class="glyph" href="#" aria-label="calendar"><span class="glyphicon glyphicon-calendar" aria-hidden="true"></span></a></span></div>
222 </div>
223 </div>
224 </div>
225 <div class="help-block">byline</div>
226 </div>
227 </div>
228 ');
229 $this->assertEquals($expected, $html);
230 }
231}
DefNamesource $name_source
I Input Field Factory $factory
Data Factory $data_factory
testRenderwithDifferentLabels($datetime)
@depends test_render
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
language handling
$format
Definition: metadata.php:235
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.