ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TextInputTest Class Reference
+ Inheritance diagram for TextInputTest:
+ Collaboration diagram for TextInputTest:

Public Member Functions

 setUp ()
 
 testImplementsFactoryInterface ()
 
 testRender ()
 
 testCommonRendering ()
 
 testRenderValue ()
 
 testMaxLength ()
 
 testRenderMaxValue ()
 
 testValueRequired ()
 
 testStripsTags ()
 
 testWithoutStripsTags ()
 

Protected Attributes

DefNamesource $name_source
 

Detailed Description

Definition at line 32 of file TextInputTest.php.

Member Function Documentation

◆ setUp()

TextInputTest::setUp ( )

Definition at line 38 of file TextInputTest.php.

38 : void
39 {
40 $this->name_source = new DefNamesource();
41 }

◆ testCommonRendering()

TextInputTest::testCommonRendering ( )

Definition at line 69 of file TextInputTest.php.

69 : void
70 {
71 $f = $this->getFieldFactory();
72 $label = "label";
73 $text = $f->text($label)->withNameFrom($this->name_source);
74
75 $this->testWithError($text);
76 $this->testWithNoByline($text);
77 $this->testWithRequired($text);
78 $this->testWithDisabled($text);
79 $this->testWithAdditionalOnloadCodeRendersId($text);
80 }

References Vendor\Package\$f.

◆ testImplementsFactoryInterface()

TextInputTest::testImplementsFactoryInterface ( )

Definition at line 43 of file TextInputTest.php.

43 : void
44 {
45 $f = $this->getFieldFactory();
46
47 $text = $f->text("label", "byline");
48
49 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $text);
50 $this->assertInstanceOf(Field\Text::class, $text);
51 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References Vendor\Package\$f.

◆ testMaxLength()

TextInputTest::testMaxLength ( )

Definition at line 98 of file TextInputTest.php.

98 : void
99 {
100 $f = $this->getFieldFactory();
101
102 $text = $f->text("")
103 ->withMaxLength(4);
104
105 $this->assertEquals(4, $text->getMaxLength());
106
107 $text1 = $text->withValue("1234");
108 $this->assertEquals("1234", $text1->getValue());
109
110 $this->expectException(InvalidArgumentException::class);
111 $this->expectExceptionMessage("Argument 'value': Display value does not match input type.");
112 $text->withValue("12345");
113 }

References Vendor\Package\$f.

◆ testRender()

TextInputTest::testRender ( )

Definition at line 53 of file TextInputTest.php.

53 : void
54 {
55 $f = $this->getFieldFactory();
56 $label = "label";
57 $byline = "byline";
58 $text = $f->text($label, $byline)->withNameFrom($this->name_source);
59 $expected = $this->getFormWrappedHtml(
60 'text-field-input',
61 $label,
62 '<input id="id_1" type="text" name="name_0" class="c-field-text" />',
63 $byline,
64 'id_1'
65 );
66 $this->assertEquals($expected, $this->render($text));
67 }

References Vendor\Package\$f.

◆ testRenderMaxValue()

TextInputTest::testRenderMaxValue ( )

Definition at line 115 of file TextInputTest.php.

115 : void
116 {
117 $f = $this->getFieldFactory();
118 $label = "label";
119 $text = $f->text($label)->withNameFrom($this->name_source)->withMaxLength(8);
120 $expected = $this->getFormWrappedHtml(
121 'text-field-input',
122 $label,
123 '<input id="id_1" type="text" name="name_0" maxlength="8" class="c-field-text" />',
124 null,
125 'id_1'
126 );
127 $this->assertEquals($expected, $this->render($text));
128 }

References Vendor\Package\$f.

◆ testRenderValue()

TextInputTest::testRenderValue ( )

Definition at line 82 of file TextInputTest.php.

82 : void
83 {
84 $f = $this->getFieldFactory();
85 $label = "label";
86 $value = "value";
87 $text = $f->text($label)->withValue($value)->withNameFrom($this->name_source);
88 $expected = $this->getFormWrappedHtml(
89 'text-field-input',
90 $label,
91 '<input id="id_1" type="text" value="value" name="name_0" class="c-field-text" />',
92 null,
93 'id_1'
94 );
95 $this->assertEquals($expected, $this->render($text));
96 }

References Vendor\Package\$f.

◆ testStripsTags()

TextInputTest::testStripsTags ( )

Definition at line 147 of file TextInputTest.php.

147 : void
148 {
149 $f = $this->getFieldFactory();
150 $name = "name_0";
151 $text = $f->text("")
152 ->withNameFrom($this->name_source)
153 ->withInput(new DefInputData([$name => "<script>alert()</script>"]));
154
155 $content = $text->getContent();
156 $this->assertEquals("alert()", $content->value());
157 }

References Vendor\Package\$f.

◆ testValueRequired()

TextInputTest::testValueRequired ( )

Definition at line 130 of file TextInputTest.php.

130 : void
131 {
132 $f = $this->getFieldFactory();
133 $label = "label";
134 $name = "name_0";
135 $text = $f->text($label)->withNameFrom($this->name_source)->withRequired(true);
136
137 $text1 = $text->withInput(new DefInputData([$name => "0"]));
138 $value1 = $text1->getContent();
139 $this->assertTrue($value1->isOk());
140 $this->assertEquals("0", $value1->value());
141
142 $text2 = $text->withInput(new DefInputData([$name => ""]));
143 $value2 = $text2->getContent();
144 $this->assertTrue($value2->isError());
145 }

References Vendor\Package\$f.

◆ testWithoutStripsTags()

TextInputTest::testWithoutStripsTags ( )

Definition at line 159 of file TextInputTest.php.

159 : void
160 {
161 $f = $this->getFieldFactory();
162 $name = "name_0";
163 $text = $f->text("")
164 ->withNameFrom($this->name_source)
165 ->withoutStripTags()
166 ->withInput(new DefInputData([$name => "<script>alert()</script>"]));
167
168 $content = $text->getContent();
169 $this->assertEquals("<script>alert()</script>", $content->value());
170 }

References Vendor\Package\$f.

Field Documentation

◆ $name_source

DefNamesource TextInputTest::$name_source
protected

Definition at line 36 of file TextInputTest.php.


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