ILIAS  release_7 Revision v7.30-3-g800a261c036
SelectTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../Base.php");
6
7use \ILIAS\Data;
10
12{
13 public function _isClientSideValueOk($value)
14 {
15 return $this->isClientSideValueOk($value);
16 }
17}
18
20{
21 public function setUp() : void
22 {
23 $this->name_source = new DefNamesource();
24 }
25
26 protected function buildFactory()
27 {
28 $df = new Data\Factory();
29 $language = $this->createMock(\ilLanguage::class);
31 new SignalGenerator(),
32 $df,
33 new Refinery\Factory($df, $language),
34 $language
35 );
36 }
37
39 {
40 $options = ["one" => "Eins", "two" => "Zwei", "three" => "Drei"];
41 $select = new SelectForTest(
42 $this->createMock(ILIAS\Data\Factory::class),
43 $this->createMock(ILIAS\Refinery\Factory::class),
44 "",
45 $options,
46 ""
47 );
48
49 $this->assertTrue($select->_isClientSideValueOk("one"));
50 $this->assertTrue($select->_isClientSideValueOk("two"));
51 $this->assertTrue($select->_isClientSideValueOk("three"));
52 $this->assertFalse($select->_isClientSideValueOk("four"));
53 }
54
56 {
57 $options = [];
58 $select = new SelectForTest(
59 $this->createMock(ILIAS\Data\Factory::class),
60 $this->createMock(ILIAS\Refinery\Factory::class),
61 "",
62 $options,
63 ""
64 );
65
66 $this->assertTrue($select->_isClientSideValueOk(""));
67 }
68
70 {
71 $options = [];
72 $select = (new SelectForTest(
73 $this->createMock(ILIAS\Data\Factory::class),
74 $this->createMock(ILIAS\Refinery\Factory::class),
75 "",
76 $options,
77 ""
78 ))->withRequired(true);
79
80 $this->assertTrue($select->_isClientSideValueOk(""));
81 }
82
83 public function test_render()
84 {
85 $f = $this->buildFactory();
86 $label = "label";
87 $byline = "byline";
88 $options = ["one" => "One", "two" => "Two", "three" => "Three"];
89 $select = $f->select($label, $options, $byline)->withNameFrom($this->name_source);
90
91 $r = $this->getDefaultRenderer();
92 $html = $this->brutallyTrimHTML($r->render($select));
93
94 $expected = $this->brutallyTrimHTML('
95<div class="form-group row">
96 <label for="id_1" class="control-label col-sm-3">label</label>
97 <div class="col-sm-9">
98 <select id="id_1" name="name_0">
99 <option selected="selected" value="">-</option>
100 <option value="one">One</option>
101 <option value="two">Two</option>
102 <option value="three">Three</option>
103 </select>
104 <div class="help-block">byline</div>
105 </div>
106</div>
107');
108 $this->assertEquals($expected, $html);
109 }
110
111
112 public function test_render_value()
113 {
114 $f = $this->buildFactory();
115 $label = "label";
116 $byline = "byline";
117 $options = ["one" => "One", "two" => "Two", "three" => "Three"];
118 $select = $f->select($label, $options, $byline)->withNameFrom($this->name_source)->withValue("one");
119
120 $r = $this->getDefaultRenderer();
121 $html = $this->brutallyTrimHTML($r->render($select));
122
123 $expected = $this->brutallyTrimHTML('
124<div class="form-group row">
125 <label for="id_1" class="control-label col-sm-3">label</label>
126 <div class="col-sm-9">
127 <select id="id_1" name="name_0">
128 <option value="">-</option>
129 <option selected="selected" value="one">One</option>
130 <option value="two">Two</option>
131 <option value="three">Three</option>
132 </select>
133 <div class="help-block">byline</div>
134 </div>
135</div>
136');
137 $this->assertEquals($expected, $html);
138 }
139
140 public function test_render_disabled()
141 {
142 $f = $this->buildFactory();
143 $label = "label";
144 $byline = "byline";
145 $options = ["one" => "One", "two" => "Two", "three" => "Three"];
146 $select = $f->select($label, $options, $byline)->withNameFrom($this->name_source)->withDisabled(true);
147
148 $r = $this->getDefaultRenderer();
149 $html = $this->brutallyTrimHTML($r->render($select));
150
151 $expected = $this->brutallyTrimHTML('
152<div class="form-group row">
153 <label for="id_1" class="control-label col-sm-3">label</label>
154 <div class="col-sm-9">
155 <select id="id_1" name="name_0" disabled="disabled">
156 <option selected="selected" value="">-</option>
157 <option value="one">One</option>
158 <option value="two">Two</option>
159 <option value="three">Three</option>
160 </select>
161 <div class="help-block">byline</div>
162 </div>
163</div>
164');
165 $this->assertEquals($expected, $html);
166 }
167}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
Provides common functionality for UI tests.
Definition: Base.php:263
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
_isClientSideValueOk($value)
Definition: SelectTest.php:13
testEmptyStringIsAcceptableClientSideValueIfSelectIsNotRequired()
Definition: SelectTest.php:55
testEmptyStringIsAnAcceptableClientSideValueEvenIfSelectIsRequired()
Definition: SelectTest.php:69
testOnlyValuesFromOptionsAreAcceptableClientSideValues()
Definition: SelectTest.php:38
This describes select field.
Definition: Select.php:11
Class ChatMainBarProvider \MainMenu\Provider.