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

Public Member Functions

 setUp ()
 
 testImplementsFactoryInterface ()
 
 testRender ()
 
 testRenderValue ()
 
 testHandleInvalidValue ()
 
 testCommonRendering ()
 
 testTrueContent ()
 
 testFalseContent ()
 
 testDisabledContent ()
 
 testTransformation ()
 
 testNullValue ()
 

Protected Attributes

DefNamesource $name_source
 
Refinery $refinery
 

Detailed Description

Definition at line 31 of file CheckboxInputTest.php.

Member Function Documentation

◆ setUp()

CheckboxInputTest::setUp ( )

Definition at line 38 of file CheckboxInputTest.php.

38 : void
39 {
40 $this->name_source = new DefNamesource();
41 $this->refinery = new Refinery($this->createMock(Data\Factory::class), $this->createMock(ILIAS\Language\Language::class));
42 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testCommonRendering()

CheckboxInputTest::testCommonRendering ( )

Definition at line 94 of file CheckboxInputTest.php.

94 : void
95 {
96 $f = $this->getFieldFactory();
97 $label = "label";
98 $checkbox = $f->checkbox($label, null)->withNameFrom($this->name_source);
99
100 $this->testWithError($checkbox);
101 $this->testWithNoByline($checkbox);
102 $this->testWithRequired($checkbox);
103 $this->testWithDisabled($checkbox);
104 $this->testWithAdditionalOnloadCodeRendersId($checkbox);
105 }

References Vendor\Package\$f.

◆ testDisabledContent()

CheckboxInputTest::testDisabledContent ( )

Definition at line 145 of file CheckboxInputTest.php.

145 : void
146 {
147 $f = $this->getFieldFactory();
148 $label = "label";
149 $checkbox = $f->checkbox($label)
150 ->withNameFrom($this->name_source)
151 ->withDisabled(true)
152 ->withValue(true)
153 ->withInput($this->createMock(InputData::class))
154 ;
155
156 $this->assertIsBool($checkbox->getContent()->value());
157 $this->assertTrue($checkbox->getContent()->value());
158 }

References Vendor\Package\$f.

◆ testFalseContent()

CheckboxInputTest::testFalseContent ( )

Definition at line 126 of file CheckboxInputTest.php.

126 : void
127 {
128 $f = $this->getFieldFactory();
129 $label = "label";
130 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
131
132 $input_data = $this->createMock(InputData::class);
133 $input_data
134 ->expects($this->atLeastOnce())
135 ->method("getOr")
136 ->with("name_0", "")
137 ->willReturn("");
138
139 $checkbox_false = $checkbox->withInput($input_data);
140
141 $this->assertIsBool($checkbox_false->getContent()->value());
142 $this->assertFalse($checkbox_false->getContent()->value());
143 }

References Vendor\Package\$f.

◆ testHandleInvalidValue()

CheckboxInputTest::testHandleInvalidValue ( )

Definition at line 81 of file CheckboxInputTest.php.

81 : void
82 {
83 $f = $this->getFieldFactory();
84 $label = "label";
85 $value = "invalid";
86 try {
87 $f->checkbox($label)->withValue($value);
88 $this->fail();
89 } catch (InvalidArgumentException $e) {
90 $this->assertTrue(true);
91 }
92 }

References Vendor\Package\$e, and Vendor\Package\$f.

◆ testImplementsFactoryInterface()

CheckboxInputTest::testImplementsFactoryInterface ( )

Definition at line 44 of file CheckboxInputTest.php.

44 : void
45 {
46 $f = $this->getFieldFactory();
47
48 $checkbox = $f->checkbox("label", "byline");
49
50 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $checkbox);
51 $this->assertInstanceOf(Field\Checkbox::class, $checkbox);
52 }

References Vendor\Package\$f.

◆ testNullValue()

CheckboxInputTest::testNullValue ( )

Definition at line 180 of file CheckboxInputTest.php.

180 : void
181 {
182 $f = $this->getFieldFactory();
183 $checkbox = $f->checkbox("label");
184 $checkbox->withValue(null);
185 $this->assertEquals(false, $checkbox->getValue());
186 }

References Vendor\Package\$f.

◆ testRender()

CheckboxInputTest::testRender ( )

Definition at line 54 of file CheckboxInputTest.php.

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

References Vendor\Package\$f.

◆ testRenderValue()

CheckboxInputTest::testRenderValue ( )

Definition at line 70 of file CheckboxInputTest.php.

70 : void
71 {
72 $f = $this->getFieldFactory();
73 $label = "label";
74 $value = true;
75 $checkbox = $f->checkbox($label)->withValue($value)->withNameFrom($this->name_source);
76
77 $expected = '<input type="checkbox" id="id_1" value="checked" checked="checked" name="name_0" class="c-field-checkbox" />';
78 $this->assertStringContainsString($expected, $this->render($checkbox));
79 }

References Vendor\Package\$f.

◆ testTransformation()

CheckboxInputTest::testTransformation ( )

Definition at line 160 of file CheckboxInputTest.php.

160 : void
161 {
162 $f = $this->getFieldFactory();
163 $label = "label";
164 $new_value = "NEW_VALUE";
165 $checkbox = $f->checkbox($label)
166 ->withNameFrom($this->name_source)
167 ->withDisabled(true)
168 ->withValue(true)
169 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called, $new_value): string {
170 $called = $v;
171 return $new_value;
172 }))
173 ->withInput($this->createMock(InputData::class))
174 ;
175
176 $this->assertIsString($checkbox->getContent()->value());
177 $this->assertEquals($new_value, $checkbox->getContent()->value());
178 }

References Vendor\Package\$f, and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testTrueContent()

CheckboxInputTest::testTrueContent ( )

Definition at line 107 of file CheckboxInputTest.php.

107 : void
108 {
109 $f = $this->getFieldFactory();
110 $label = "label";
111 $checkbox = $f->checkbox($label)->withNameFrom($this->name_source);
112
113 $input_data = $this->createMock(InputData::class);
114 $input_data
115 ->expects($this->atLeastOnce())
116 ->method("getOr")
117 ->with("name_0", "")
118 ->willReturn("checked");
119
120 $checkbox_true = $checkbox->withInput($input_data);
121
122 $this->assertIsBool($checkbox_true->getContent()->value());
123 $this->assertTrue($checkbox_true->getContent()->value());
124 }

References Vendor\Package\$f.

Field Documentation

◆ $name_source

DefNamesource CheckboxInputTest::$name_source
protected

Definition at line 35 of file CheckboxInputTest.php.

◆ $refinery

Refinery CheckboxInputTest::$refinery
protected

Definition at line 36 of file CheckboxInputTest.php.


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