ILIAS  release_8 Revision v8.24
RadioInputTest.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;
29
31{
33
34 public function setUp(): void
35 {
36 $this->name_source = new DefNamesource();
37 }
38
39 protected function buildFactory(): I\Input\Field\Factory
40 {
41 $df = new Data\Factory();
42 $language = $this->createMock(\ilLanguage::class);
43 return new I\Input\Field\Factory(
44 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
45 new SignalGenerator(),
46 $df,
47 new Refinery($df, $language),
48 $language
49 );
50 }
51
52 protected function buildRadio(): \ILIAS\UI\Component\Input\Container\Form\FormInput
53 {
54 $f = $this->buildFactory();
55 $label = "label";
56 $byline = "byline";
57 return $f
58 ->radio($label, $byline)
59 ->withOption('value0', 'label0', 'byline0')
60 ->withOption('1', 'label1', 'byline1')
61 ->withNameFrom($this->name_source);
62 }
63
64 public function test_implements_factory_interface(): void
65 {
66 $f = $this->buildFactory();
67 $radio = $f->radio("label", "byline");
68 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $radio);
69 $this->assertInstanceOf(Field\Radio::class, $radio);
70 }
71
72 public function test_render(): void
73 {
74 $r = $this->getDefaultRenderer();
75 $radio = $this->buildRadio();
76 $name = $radio->getName();
77 $label = $radio->getLabel();
78 $byline = $radio->getByline();
79 $options = $radio->getOptions();
80
81 $expected = ""
82 . "<div class=\"form-group row\">"
83 . "<label class=\"control-label col-sm-4 col-md-3 col-lg-2\">$label</label>"
84 . "<div class=\"col-sm-8 col-md-9 col-lg-10\">"
85 . "<div id=\"id_1\" class=\"il-input-radio\">";
86
87 foreach ($options as $opt_value => $opt_label) {
88 $expected .= ""
89 . "<div class=\"form-control form-control-sm il-input-radiooption\">"
90 . "<input type=\"radio\" id=\"id_1_" . $opt_value . "_opt\" name=\"$name\" value=\"$opt_value\" />"
91 . "<label for=\"id_1_" . $opt_value . "_opt\">$opt_label</label>"
92 . "<div class=\"help-block\">{$radio->getBylineFor((string) $opt_value)}</div>"
93 . "</div>";
94 }
95
96 $expected .= ""
97 . "</div>"
98 . "<div class=\"help-block\">$byline</div>"
99 . "</div>"
100 . "</div>";
101 $this->assertHTMLEquals($expected, $r->render($radio));
102 }
103
104 public function test_render_value(): void
105 {
106 $r = $this->getDefaultRenderer();
107 $radio = $this->buildRadio();
108 $name = $radio->getName();
109 $label = $radio->getLabel();
110 $byline = $radio->getByline();
111 $options = $radio->getOptions();
112 $value = '1';
113 $radio = $radio->withValue($value);
114 $expected = ""
115 . "<div class=\"form-group row\">"
116 . "<label class=\"control-label col-sm-4 col-md-3 col-lg-2\">$label</label>"
117 . "<div class=\"col-sm-8 col-md-9 col-lg-10\">"
118 . "<div id=\"id_1\" class=\"il-input-radio\">";
119
120 foreach ($options as $opt_value => $opt_label) {
121 $expected .= "<div class=\"form-control form-control-sm il-input-radiooption\">";
122 if ($opt_value == $value) {
123 $expected .= "<input type=\"radio\" id=\"id_1_" . $opt_value . "_opt\" name=\"$name\" value=\"$opt_value\" checked=\"checked\"/>";
124 } else {
125 $expected .= "<input type=\"radio\" id=\"id_1_" . $opt_value . "_opt\" name=\"$name\" value=\"$opt_value\" />";
126 }
127 $expected .= ""
128 . "<label for=\"id_1_" . $opt_value . "_opt\">$opt_label</label>"
129 . "<div class=\"help-block\">{$radio->getBylineFor((string) $opt_value)}</div>"
130 . "</div>";
131 }
132
133 $expected .= ""
134 . "</div>"
135 . "<div class=\"help-block\">$byline</div>"
136 . "</div>"
137 . "</div>";
138
139 $this->assertHTMLEquals($expected, $r->render($radio));
140 }
141
142 public function test_render_disabled(): void
143 {
144 $r = $this->getDefaultRenderer();
145 $radio = $this->buildRadio()->withDisabled(true);
146 $name = $radio->getName();
147 $label = $radio->getLabel();
148 $byline = $radio->getByline();
149 $options = $radio->getOptions();
150
151 $expected = ""
152 . "<div class=\"form-group row\">"
153 . "<label class=\"control-label col-sm-4 col-md-3 col-lg-2\">$label</label>"
154 . "<div class=\"col-sm-8 col-md-9 col-lg-10\">"
155 . "<div id=\"id_1\" class=\"il-input-radio\">";
156
157 foreach ($options as $opt_value => $opt_label) {
158 $expected .= ""
159 . "<div class=\"form-control form-control-sm il-input-radiooption\">"
160 . "<input type=\"radio\" id=\"id_1_" . $opt_value . "_opt\" name=\"$name\" value=\"$opt_value\" disabled=\"disabled\"/>"
161 . "<label for=\"id_1_" . $opt_value . "_opt\">$opt_label</label>"
162 . "<div class=\"help-block\">{$radio->getBylineFor((string) $opt_value)}</div>"
163 . "</div>";
164 }
165
166 $expected .= ""
167 . "</div>"
168 . "<div class=\"help-block\">$byline</div>"
169 . "</div>"
170 . "</div>";
171 $this->assertHTMLEquals($expected, $r->render($radio));
172 }
173}
Builds data types.
Definition: Factory.php:21
Provides common functionality for UI tests.
Definition: Base.php:299
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
test_implements_factory_interface()
DefNamesource $name_source
This describes inputs that can be used in forms.
Definition: FormInput.php:32
This is a legacy support of Component\Input\Field\Input that has been moved to Component\Input\Contai...
Definition: Input.php:32
if($format !==null) $name
Definition: metadata.php:247
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
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.