ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TagInputTest Class Reference

Class TagInputTest. More...

+ Inheritance diagram for TagInputTest:
+ Collaboration diagram for TagInputTest:

Public Member Functions

 setUp ()
 
 test_implements_factory_interface ()
 
 test_render ()
 
 test_render_error ()
 
 test_render_no_byline ()
 
 test_render_value ()
 
 test_render_required ()
 
 test_value_required ()
 
 test_user_created_not_allowed ()
 
 test_max_tags_ok ()
 
 test_max_tags_not_ok ()
 
 test_max_taglength_tags_ok ()
 
 test_max_taglength_tags_not_ok ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Protected Member Functions

 buildFactory ()
 

Private Attributes

 $name_source
 

Detailed Description

Class TagInputTest.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 19 of file TagInputTest.php.

Member Function Documentation

◆ buildFactory()

TagInputTest::buildFactory ( )
protected

Definition at line 34 of file TagInputTest.php.

35 {
36 $df = new Data\Factory();
38 new SignalGenerator(),
39 $df,
40 new Validation\Factory($df, $this->createMock(\ilLanguage::class)),
42 );
43 }
Builds data types.
Definition: Factory.php:15
A transformation is a function from one datatype to another.

Referenced by test_implements_factory_interface(), test_max_taglength_tags_not_ok(), test_max_taglength_tags_ok(), test_max_tags_not_ok(), test_max_tags_ok(), test_render(), test_render_error(), test_render_no_byline(), test_render_required(), test_render_value(), test_user_created_not_allowed(), and test_value_required().

+ Here is the caller graph for this function:

◆ setUp()

TagInputTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 28 of file TagInputTest.php.

29 {
30 $this->name_source = new DefNamesource();
31 }

◆ test_implements_factory_interface()

TagInputTest::test_implements_factory_interface ( )

Definition at line 46 of file TagInputTest.php.

47 {
48 $f = $this->buildFactory();
49
50 $tag = $f->tag(
51 "label",
52 ["lorem", "ipsum", "dolor",],
53 "byline"
54 );
55 }
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35

References $f, $tag, and buildFactory().

+ Here is the call graph for this function:

◆ test_max_taglength_tags_not_ok()

TagInputTest::test_max_taglength_tags_not_ok ( )

Definition at line 236 of file TagInputTest.php.

237 {
238 $f = $this->buildFactory();
239
240 $this->expectException(\InvalidArgumentException::class);
241 $f->tag("label", [])->withTagMaxLength(2)->withNameFrom($this->name_source)->withInput(
242 new DefPostData(
243 ["name_0" => ["lorem", "ipsum", "dolor",],]
244 )
245 );
246 }

References $f, and buildFactory().

+ Here is the call graph for this function:

◆ test_max_taglength_tags_ok()

TagInputTest::test_max_taglength_tags_ok ( )

Definition at line 224 of file TagInputTest.php.

225 {
226 $f = $this->buildFactory();
227
228 $tag = $f->tag("label", [])->withTagMaxLength(10)->withNameFrom($this->name_source)->withInput(
229 new DefPostData(["name_0" => ["lorem", "ipsum",],])
230 );
231 $value = $tag->getContent();
232 $this->assertTrue($value->isOk());
233 }

References $f, $tag, and buildFactory().

+ Here is the call graph for this function:

◆ test_max_tags_not_ok()

TagInputTest::test_max_tags_not_ok ( )

Definition at line 211 of file TagInputTest.php.

212 {
213 $f = $this->buildFactory();
214
215 $this->expectException(\InvalidArgumentException::class);
216 $f->tag("label", [])->withMaxTags(2)->withNameFrom($this->name_source)->withInput(
217 new DefPostData(
218 ["name_0" => ["lorem", "ipsum", "dolor",],]
219 )
220 );
221 }

References $f, and buildFactory().

+ Here is the call graph for this function:

◆ test_max_tags_ok()

TagInputTest::test_max_tags_ok ( )

Definition at line 199 of file TagInputTest.php.

200 {
201 $f = $this->buildFactory();
202
203 $tag = $f->tag("label", [])->withMaxTags(3)->withNameFrom($this->name_source)->withInput(
204 new DefPostData(["name_0" => ["lorem", "ipsum",],])
205 );
206 $value = $tag->getContent();
207 $this->assertTrue($value->isOk());
208 }

References $f, $tag, and buildFactory().

+ Here is the call graph for this function:

◆ test_render()

TagInputTest::test_render ( )

Definition at line 58 of file TagInputTest.php.

59 {
60 $f = $this->buildFactory();
61 $label = "label";
62 $byline = "byline";
63 $tags = ["lorem", "ipsum", "dolor",];
64 $name = "name_0";
65 $text = $f->tag($label, $tags, $byline)->withNameFrom($this->name_source);
66
67 $r = $this->getDefaultRenderer();
68 $html = $this->normalizeHTML($r->render($text));
69
70 $expected = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label</label> <div class=\"col-sm-9\"> <div id=\"container-id_1\" class=\"form-control form-control-sm il-input-tag\"> <input type=\"text\" id=\"id_1\" value=\"\" class=\"form-control form-control-sm\"/> <input type=\"hidden\" id=\"template-id_1\" value='name_0[]'> </div> <div class=\"help-block\">byline</div> </div></div>";
71 $this->assertEquals($expected, $html);
72 }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
normalizeHTML($html)
Definition: Base.php:261
$tags
Definition: croninfo.php:19
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
$text
Definition: errorreport.php:18

References $f, $html, $name, $r, $tags, $text, buildFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_render_error()

TagInputTest::test_render_error ( )

Definition at line 75 of file TagInputTest.php.

76 {
77 $f = $this->buildFactory();
78 $label = "label";
79 $byline = "byline";
80 $name = "name_0";
81 $tags = ["lorem", "ipsum", "dolor",];
82 $error = "an_error";
83 $text = $f->tag($label, $tags, $byline)->withNameFrom($this->name_source)->withError($error);
84
85 $r = $this->getDefaultRenderer();
86 $html = $this->normalizeHTML($r->render($text));
87
88 $expected
89 = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label</label> <div class=\"col-sm-9\"> <div id=\"container-id_1\" class=\"form-control form-control-sm il-input-tag\"> <input type=\"text\" id=\"id_1\" value=\"\" class=\"form-control form-control-sm\"/> <input type=\"hidden\" id=\"template-id_1\" value='name_0[]'> </div> <div class=\"help-block\">byline</div> <div class=\"help-block alert alert-danger\" role=\"alert\"> <img border=\"0\" src=\"./templates/default/images/icon_alert.svg\" alt=\"alert\" /> an_error </div> </div></div>";
90 $this->assertEquals($expected, $html);
91 }

References $f, $html, $name, $r, $tags, $text, buildFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_render_no_byline()

TagInputTest::test_render_no_byline ( )

Definition at line 94 of file TagInputTest.php.

95 {
96 $f = $this->buildFactory();
97 $label = "label";
98 $name = "name_0";
99 $tags = ["lorem", "ipsum", "dolor",];
100 $text = $f->tag($label, $tags)->withNameFrom($this->name_source);
101
102 $r = $this->getDefaultRenderer();
103 $html = $this->normalizeHTML($r->render($text));
104
105 $expected = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label</label> <div class=\"col-sm-9\"> <div id=\"container-id_1\" class=\"form-control form-control-sm il-input-tag\"> <input type=\"text\" id=\"id_1\" value=\"\" class=\"form-control form-control-sm\"/> <input type=\"hidden\" id=\"template-id_1\" value='name_0[]'> </div> </div></div>";
106 $this->assertEquals($expected, $html);
107 }

References $f, $html, $name, $r, $tags, $text, buildFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_render_required()

TagInputTest::test_render_required ( )

Definition at line 128 of file TagInputTest.php.

129 {
130 $f = $this->buildFactory();
131 $label = "label";
132 $name = "name_0";
133 $tags = ["lorem", "ipsum", "dolor",];
134 $text = $f->tag($label, $tags)->withNameFrom($this->name_source)->withRequired(true);
135
136 $r = $this->getDefaultRenderer();
137 $html = $this->normalizeHTML($r->render($text));
138
139 $expected = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label<span class=\"asterisk\">*</span></label> <div class=\"col-sm-9\"> <div id=\"container-id_1\" class=\"form-control form-control-sm il-input-tag\"> <input type=\"text\" id=\"id_1\" value=\"\" class=\"form-control form-control-sm\"/> <input type=\"hidden\" id=\"template-id_1\" value='name_0[]'> </div> </div></div>";
140
141 $this->assertEquals($expected, $html);
142 }

References $f, $html, $name, $r, $tags, $text, buildFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_render_value()

TagInputTest::test_render_value ( )

Definition at line 110 of file TagInputTest.php.

111 {
112 $f = $this->buildFactory();
113 $label = "label";
114 $value = ["lorem", "ipsum",];
115 $name = "name_0";
116 $tags = ["lorem", "ipsum", "dolor",];
117 $text = $f->tag($label, $tags)->withValue($value)->withNameFrom($this->name_source);
118
119 $r = $this->getDefaultRenderer();
120 $html = $this->normalizeHTML($r->render($text));
121
122 $expected
123 = "<div class=\"form-group row\"> <label for=\"name_0\" class=\"control-label col-sm-3\">label</label> <div class=\"col-sm-9\"> <div id=\"container-id_1\" class=\"form-control form-control-sm il-input-tag\"> <input type=\"text\" id=\"id_1\" value=\"lorem,ipsum\" class=\"form-control form-control-sm\"/> <input type=\"hidden\" id=\"template-id_1\" value='name_0[]'> <input type=\"hidden\" id=\"tag-id_1-lorem\" name=\"name_0[]\" value='lorem'> <input type=\"hidden\" id=\"tag-id_1-ipsum\" name=\"name_0[]\" value='ipsum'> </div> </div></div>";
124 $this->assertEquals($expected, $html);
125 }

References $f, $html, $name, $r, $tags, $text, buildFactory(), ILIAS_UI_TestBase\getDefaultRenderer(), and ILIAS_UI_TestBase\normalizeHTML().

+ Here is the call graph for this function:

◆ test_user_created_not_allowed()

TagInputTest::test_user_created_not_allowed ( )

Definition at line 170 of file TagInputTest.php.

171 {
172 $f = $this->buildFactory();
173 $tags = ["lorem", "ipsum", "dolor",];
174 $tag = $f->tag("label", $tags)->withUserCreatedTagsAllowed(false)->withNameFrom($this->name_source);
175
176 $tag1 = $tag->withInput(
177 new DefPostData(
178 ["name_0" => ["lorem", "ipsum",],]
179 )
180 );
181 $value1 = $tag1->getContent();
182 $this->assertTrue($value1->isOk());
183 $value = $value1->value();
184 $this->assertEquals(
185 ["lorem", "ipsum",],
186 $value
187 );
188
189 $tag1 = $tag->withInput(
190 new DefPostData(
191 ["name_0" => ["conseptetuer", "ipsum",],]
192 )
193 );
194 $value1 = $tag1->getContent();
195 $this->assertTrue($value1->isError());
196 }

References $f, $tag, $tags, and buildFactory().

+ Here is the call graph for this function:

◆ test_value_required()

TagInputTest::test_value_required ( )

Definition at line 145 of file TagInputTest.php.

146 {
147 $f = $this->buildFactory();
148 $label = "label";
149 $name = "name_0";
150 $tags = ["lorem", "ipsum", "dolor",];
151 $tag = $f->tag($label, $tags)->withNameFrom($this->name_source)->withRequired(true);
152
153 $raw_value1 = ["lorem", "ipsum",];
154 $tag1 = $tag->withInput(new DefPostData([$name => $raw_value1]));
155 $value1 = $tag1->getContent();
156 $this->assertTrue($value1->isOk());
157 $value = $value1->value();
158 $this->assertEquals($raw_value1, $value);
159
160 $tag2 = $tag->withInput(new DefPostData([$name => []]));
161 $value2 = $tag2->getContent();
162 $this->assertTrue($value2->isError());
163
164 $tag2 = $tag->withInput(new DefPostData([$name => null]));
165 $value2 = $tag2->getContent();
166 $this->assertTrue($value2->isError());
167 }

References $f, $name, $tag, $tags, and buildFactory().

+ Here is the call graph for this function:

Field Documentation

◆ $name_source

TagInputTest::$name_source
private

Definition at line 25 of file TagInputTest.php.


The documentation for this class was generated from the following file: