ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
RadioInputTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2018 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../../Base.php");
7
10use \ILIAS\UI\Component\Input\Field;
11use \ILIAS\Data;
13
15{
16 public function setUp() : void
17 {
18 $this->name_source = new DefNamesource();
19 }
20
21 protected function buildFactory()
22 {
23 $df = new Data\Factory();
24 $language = $this->createMock(\ilLanguage::class);
26 new SignalGenerator(),
27 $df,
28 new \ILIAS\Refinery\Factory($df, $language),
29 $language
30 );
31 }
32
33 protected function buildRadio() : Radio
34 {
35 $f = $this->buildFactory();
36 $label = "label";
37 $byline = "byline";
38 $radio = $f->radio($label, $byline)
39 ->withOption('value0', 'label0', 'byline0')
40 ->withOption('1', 'label1', 'byline1')
41 ->withNameFrom($this->name_source);
42 return $radio;
43 }
44
45
47 {
48 $f = $this->buildFactory();
49 $radio = $f->radio("label", "byline");
50 $this->assertInstanceOf(Field\Input::class, $radio);
51 $this->assertInstanceOf(Field\Radio::class, $radio);
52 }
53
54
55 public function test_render()
56 {
57 $r = $this->getDefaultRenderer();
58 $radio = $this->buildRadio();
59 $name = $radio->getName();
60 $label = $radio->getLabel();
61 $byline = $radio->getByline();
62 $options = $radio->getOptions();
63
64 $expected = ""
65 . "<div class=\"form-group row\">"
66 . "<label for=\"\" class=\"control-label col-sm-3\">$label</label>"
67 . "<div class=\"col-sm-9\">"
68 . "<div id=\"id_1\" class=\"il-input-radio\">";
69
70 foreach ($options as $opt_value => $opt_label) {
71 $expected .= ""
72 . "<div class=\"form-control form-control-sm il-input-radiooption\">"
73 . "<input type=\"radio\" id=\"id_1_" . $opt_value . "_opt\" name=\"$name\" value=\"$opt_value\" />"
74 . "<label for=\"id_1_" . $opt_value . "_opt\">$opt_label</label>"
75 . "<div class=\"help-block\">{$radio->getBylineFor($opt_value)}</div>"
76 . "</div>";
77 }
78
79 $expected .= ""
80 . "</div>"
81 . "<div class=\"help-block\">$byline</div>"
82 . "</div>"
83 . "</div>";
84 $this->assertHTMLEquals($expected, $r->render($radio));
85 }
86
87
88 public function test_render_value()
89 {
90 $r = $this->getDefaultRenderer();
91 $radio = $this->buildRadio();
92 $name = $radio->getName();
93 $label = $radio->getLabel();
94 $byline = $radio->getByline();
95 $options = $radio->getOptions();
96 $value = '1';
97 $radio = $radio->withValue($value);
98 $expected = ""
99 . "<div class=\"form-group row\">"
100 . "<label for=\"\" class=\"control-label col-sm-3\">$label</label>"
101 . "<div class=\"col-sm-9\">"
102 . "<div id=\"id_1\" class=\"il-input-radio\">";
103
104 foreach ($options as $opt_value => $opt_label) {
105 $expected .= "<div class=\"form-control form-control-sm il-input-radiooption\">";
106 if ($opt_value == $value) {
107 $expected .= "<input type=\"radio\" id=\"id_1_" . $opt_value . "_opt\" name=\"$name\" value=\"$opt_value\" checked=\"checked\"/>";
108 } else {
109 $expected .= "<input type=\"radio\" id=\"id_1_" . $opt_value . "_opt\" name=\"$name\" value=\"$opt_value\" />";
110 }
111 $expected .= ""
112 . "<label for=\"id_1_" . $opt_value . "_opt\">$opt_label</label>"
113 . "<div class=\"help-block\">{$radio->getBylineFor($opt_value)}</div>"
114 . "</div>";
115 }
116
117 $expected .= ""
118 . "</div>"
119 . "<div class=\"help-block\">$byline</div>"
120 . "</div>"
121 . "</div>";
122
123 $this->assertHTMLEquals($expected, $r->render($radio));
124 }
125
126
127
128 public function test_render_disabled()
129 {
130 $r = $this->getDefaultRenderer();
131 $radio = $this->buildRadio()->withDisabled(true);
132 $name = $radio->getName();
133 $label = $radio->getLabel();
134 $byline = $radio->getByline();
135 $options = $radio->getOptions();
136
137 $expected = ""
138 . "<div class=\"form-group row\">"
139 . "<label for=\"\" class=\"control-label col-sm-3\">$label</label>"
140 . "<div class=\"col-sm-9\">"
141 . "<div id=\"id_1\" class=\"il-input-radio\">";
142
143 foreach ($options as $opt_value => $opt_label) {
144 $expected .= ""
145 . "<div class=\"form-control form-control-sm il-input-radiooption\">"
146 . "<input type=\"radio\" id=\"id_1_" . $opt_value . "_opt\" name=\"$name\" value=\"$opt_value\" disabled=\"disabled\"/>"
147 . "<label for=\"id_1_" . $opt_value . "_opt\">$opt_label</label>"
148 . "<div class=\"help-block\">{$radio->getBylineFor($opt_value)}</div>"
149 . "</div>";
150 }
151
152 $expected .= ""
153 . "</div>"
154 . "<div class=\"help-block\">$byline</div>"
155 . "</div>"
156 . "</div>";
157 $this->assertHTMLEquals($expected, $r->render($radio));
158 }
159}
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:225
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
test_implements_factory_interface()
This is what a radio-input looks like.
Definition: Radio.php:11
if($format !==null) $name
Definition: metadata.php:230
Class ChatMainBarProvider \MainMenu\Provider.