ILIAS  release_8 Revision v8.24
SelectTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . "/../../../Base.php");
22
23use ILIAS\Data;
24use ILIAS\Refinery\Factory as Refinery;
28
30{
31 public function _isClientSideValueOk($value): bool
32 {
33 return $this->isClientSideValueOk($value);
34 }
35}
36
38{
40
41 public function setUp(): void
42 {
43 $this->name_source = new DefNamesource();
44 }
45
46 protected function buildFactory(): I\Input\Field\Factory
47 {
48 $df = new Data\Factory();
49 $language = $this->createMock(ilLanguage::class);
50 return new I\Input\Field\Factory(
51 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
52 new SignalGenerator(),
53 $df,
54 new Refinery($df, $language),
55 $language
56 );
57 }
58
60 {
61 $options = ["one" => "Eins", "two" => "Zwei", "three" => "Drei"];
62 $select = new SelectForTest(
63 $this->createMock(ILIAS\Data\Factory::class),
64 $this->createMock(ILIAS\Refinery\Factory::class),
65 "",
66 $options,
67 ""
68 );
69
70 $this->assertTrue($select->_isClientSideValueOk("one"));
71 $this->assertTrue($select->_isClientSideValueOk("two"));
72 $this->assertTrue($select->_isClientSideValueOk("three"));
73 $this->assertFalse($select->_isClientSideValueOk("four"));
74 }
75
77 {
78 $options = [];
79 $select = new SelectForTest(
80 $this->createMock(ILIAS\Data\Factory::class),
81 $this->createMock(ILIAS\Refinery\Factory::class),
82 "",
83 $options,
84 ""
85 );
86
87 $this->assertTrue($select->_isClientSideValueOk(""));
88 }
89
91 {
92 $options = [];
93 $select = $this->buildFactory()->select(
94 "",
95 $options,
96 ""
97 )
98 ->withRequired(true)
99 ->withNameFrom($this->name_source);
100
101 $data = $this->createMock(InputData::class);
102 $data->expects($this->once())
103 ->method("getOr")
104 ->willReturn(null);
105 $select = $select->withInput(
106 $data
107 );
108
109 $this->assertNotEquals(null, $select->getError());
110 }
111
113 {
114 $options = [];
115 $select = (new SelectForTest(
116 $this->createMock(ILIAS\Data\Factory::class),
117 $this->createMock(ILIAS\Refinery\Factory::class),
118 "",
119 $options,
120 ""
121 ))->withRequired(true);
122
123 $this->assertTrue($select->_isClientSideValueOk(""));
124 }
125
126 public function test_render(): void
127 {
128 $f = $this->buildFactory();
129 $label = "label";
130 $byline = "byline";
131 $options = ["one" => "One", "two" => "Two", "three" => "Three"];
132 $select = $f->select($label, $options, $byline)->withNameFrom($this->name_source);
133
134 $r = $this->getDefaultRenderer();
135 $html = $this->brutallyTrimHTML($r->render($select));
136
137 $expected = $this->brutallyTrimHTML('
138<div class="form-group row">
139 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
140 <div class="col-sm-8 col-md-9 col-lg-10">
141 <select id="id_1" name="name_0">
142 <option selected="selected" value="">-</option>
143 <option value="one">One</option>
144 <option value="two">Two</option>
145 <option value="three">Three</option>
146 </select>
147 <div class="help-block">byline</div>
148 </div>
149</div>
150');
151 $this->assertEquals($expected, $html);
152 }
153
154
155 public function test_render_value(): void
156 {
157 $f = $this->buildFactory();
158 $label = "label";
159 $byline = "byline";
160 $options = ["one" => "One", "two" => "Two", "three" => "Three"];
161 $select = $f->select($label, $options, $byline)->withNameFrom($this->name_source)->withValue("one");
162
163 $r = $this->getDefaultRenderer();
164 $html = $this->brutallyTrimHTML($r->render($select));
165
166 $expected = $this->brutallyTrimHTML('
167<div class="form-group row">
168 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
169 <div class="col-sm-8 col-md-9 col-lg-10">
170 <select id="id_1" name="name_0">
171 <option value="">-</option>
172 <option selected="selected" value="one">One</option>
173 <option value="two">Two</option>
174 <option value="three">Three</option>
175 </select>
176 <div class="help-block">byline</div>
177 </div>
178</div>
179');
180 $this->assertEquals($expected, $html);
181 }
182
183 public function test_render_disabled(): void
184 {
185 $f = $this->buildFactory();
186 $label = "label";
187 $byline = "byline";
188 $options = ["one" => "One", "two" => "Two", "three" => "Three"];
189 $select = $f->select($label, $options, $byline)->withNameFrom($this->name_source)->withDisabled(true);
190
191 $r = $this->getDefaultRenderer();
192 $html = $this->brutallyTrimHTML($r->render($select));
193
194 $expected = $this->brutallyTrimHTML('
195<div class="form-group row">
196 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
197 <div class="col-sm-8 col-md-9 col-lg-10">
198 <select id="id_1" name="name_0" disabled="disabled">
199 <option selected="selected" value="">-</option>
200 <option value="one">One</option>
201 <option value="two">Two</option>
202 <option value="three">Three</option>
203 </select>
204 <div class="help-block">byline</div>
205 </div>
206</div>
207');
208 $this->assertEquals($expected, $html);
209 }
210}
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
_isClientSideValueOk($value)
Definition: SelectTest.php:31
testEmptyStringIsAcceptableClientSideValueIfSelectIsNotRequired()
Definition: SelectTest.php:76
DefNamesource $name_source
Definition: SelectTest.php:39
testEmptyStringIsAnAcceptableClientSideValueEvenIfSelectIsRequired()
Definition: SelectTest.php:112
testEmptyStringCreatesErrorIfSelectIsRequired()
Definition: SelectTest.php:90
testOnlyValuesFromOptionsAreAcceptableClientSideValues()
Definition: SelectTest.php:59
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
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.