@@ -16,8 +16,8 @@ class RadioElementTest extends TestCase
1616 public function testRendersElementCorrectly ()
1717 {
1818 $ radio = new RadioElement ('test ' , [
19- 'label ' => 'Test ' ,
20- 'options ' => [
19+ 'label ' => 'Test ' ,
20+ 'options ' => [
2121 'foo ' => 'Foo ' ,
2222 'bar ' => 'Bar ' ,
2323 'yes ' => 'Yes '
@@ -35,8 +35,8 @@ public function testRendersElementCorrectly()
3535 public function testNumbersOfTypeIntOrStringAsOptionKeysAreHandledEqually ()
3636 {
3737 $ radio = new RadioElement ('test ' , [
38- 'label ' => 'Test ' ,
39- 'options ' => [
38+ 'label ' => 'Test ' ,
39+ 'options ' => [
4040 '1 ' => 'Foo ' ,
4141 2 => 'Bar ' ,
4242 3 => 'Yes '
@@ -77,13 +77,13 @@ public function testNumbersOfTypeIntOrStringAsOptionKeysAreHandledEqually()
7777 public function testSetValueAddsTheCheckedAttribute ()
7878 {
7979 $ radio = new RadioElement ('test ' , [
80- 'label ' => 'Test ' ,
81- 'options ' => [
80+ 'label ' => 'Test ' ,
81+ 'options ' => [
8282 'foo ' => 'Foo ' ,
8383 'bar ' => 'Bar ' ,
8484 'yes ' => 'Yes '
8585 ],
86- 'value ' => 'bar '
86+ 'value ' => 'bar '
8787 ]);
8888
8989 $ html = <<<'HTML'
@@ -115,9 +115,9 @@ public function testSetValueAddsTheCheckedAttribute()
115115 public function testDisabledRadioOptions ()
116116 {
117117 $ radio = new RadioElement ('test ' , [
118- 'label ' => 'Test ' ,
119- 'disabledOptions ' => ['foo ' , 'bar ' , 'yes ' ],
120- 'options ' => [
118+ 'label ' => 'Test ' ,
119+ 'disabledOptions ' => ['foo ' , 'bar ' , 'yes ' ],
120+ 'options ' => [
121121 'foo ' => 'Foo ' ,
122122 'bar ' => 'Bar ' ,
123123 'yes ' => 'Yes ' ,
@@ -134,14 +134,14 @@ public function testDisabledRadioOptions()
134134 $ this ->assertHtml ($ html , $ radio );
135135
136136 $ radio = new RadioElement ('test ' , [
137- 'label ' => 'Test ' ,
138- 'options ' => [
137+ 'label ' => 'Test ' ,
138+ 'options ' => [
139139 'foo ' => 'Foo ' ,
140140 'bar ' => 'Bar ' ,
141141 'yes ' => 'Yes ' ,
142142 'no ' => 'No '
143143 ],
144- 'value ' => 'bar '
144+ 'value ' => 'bar '
145145 ]);
146146
147147 $ radio ->getOption ('yes ' )->setDisabled ();
@@ -168,9 +168,9 @@ public function testDisabledRadioOptions()
168168 public function testNonCallbackAttributesOfTheElementAreAppliedToEachOption ()
169169 {
170170 $ radio = new RadioElement ('test ' , [
171- 'label ' => 'Test ' ,
172- 'class ' => 'blue ' ,
173- 'options ' => [
171+ 'label ' => 'Test ' ,
172+ 'class ' => 'blue ' ,
173+ 'options ' => [
174174 'foo ' => 'Foo ' ,
175175 'bar ' => 'Bar ' ,
176176 'yes ' => 'Yes ' ,
@@ -192,8 +192,8 @@ public function testNonCallbackAttributesOfTheElementAreAppliedToEachOption()
192192 public function testAddCssClassToTheLabelOfASpecificOption ()
193193 {
194194 $ radio = new RadioElement ('test ' , [
195- 'label ' => 'Test ' ,
196- 'options ' => [
195+ 'label ' => 'Test ' ,
196+ 'options ' => [
197197 'foo ' => 'Foo ' ,
198198 'bar ' => 'Bar ' ,
199199 'yes ' => 'Yes ' ,
@@ -219,9 +219,9 @@ public function testAddCssClassToTheLabelOfASpecificOption()
219219 public function testAddAttributesToASpecificOption ()
220220 {
221221 $ radio = new RadioElement ('test ' , [
222- 'label ' => 'Test ' ,
223- 'class ' => 'blue ' ,
224- 'options ' => [
222+ 'label ' => 'Test ' ,
223+ 'class ' => 'blue ' ,
224+ 'options ' => [
225225 'foo ' => 'Foo ' ,
226226 'bar ' => 'Bar ' ,
227227 'yes ' => 'Yes ' ,
@@ -245,13 +245,13 @@ public function testRadioNotValidIfCheckedValueIsInvalid()
245245 {
246246 StaticTranslator::$ instance = new NoopTranslator ();
247247 $ radio = new RadioElement ('test ' , [
248- 'label ' => 'Test ' ,
249- 'options ' => [
248+ 'label ' => 'Test ' ,
249+ 'options ' => [
250250 'foo ' => 'Foo ' ,
251251 'bar ' => 'Bar ' ,
252252 'yes ' => 'Yes '
253253 ],
254- 'value ' => 'bar '
254+ 'value ' => 'bar '
255255 ]);
256256
257257 $ this ->assertTrue ($ radio ->isValid ());
@@ -267,13 +267,13 @@ public function testRadioNotValidIfCheckedValueIsDisabled()
267267 {
268268 StaticTranslator::$ instance = new NoopTranslator ();
269269 $ radio = new RadioElement ('test ' , [
270- 'label ' => 'Test ' ,
271- 'options ' => [
270+ 'label ' => 'Test ' ,
271+ 'options ' => [
272272 'foo ' => 'Foo ' ,
273273 'bar ' => 'Bar ' ,
274274 'yes ' => 'Yes '
275275 ],
276- 'value ' => 'bar '
276+ 'value ' => 'bar '
277277 ]);
278278
279279 $ radio ->setValue ('yes ' );
@@ -287,11 +287,11 @@ public function testNullAndTheEmptyStringAreEquallyHandled()
287287 $ form = new Form ();
288288 $ form ->addElement ('radio ' , 'radio ' , [
289289 'options ' => ['' => 'Please choose ' ],
290- 'value ' => ''
290+ 'value ' => ''
291291 ]);
292292 $ form ->addElement ('radio ' , 'radio2 ' , [
293293 'options ' => [null => 'Please choose ' ],
294- 'value ' => null
294+ 'value ' => null
295295 ]);
296296
297297 /** @var RadioElement $radio */
@@ -364,12 +364,12 @@ public function testSetOptionsResetsOptions()
364364 public function testOrderOfOptionsAndDisabledOptionsDoesNotMatter ()
365365 {
366366 $ radio = new RadioElement ('test ' , [
367- 'label ' => 'Test ' ,
368- 'options ' => [
367+ 'label ' => 'Test ' ,
368+ 'options ' => [
369369 'foo ' => 'Foo ' ,
370370 'bar ' => 'Bar '
371371 ],
372- 'disabledOptions ' => ['foo ' , 'bar ' ]
372+ 'disabledOptions ' => ['foo ' , 'bar ' ]
373373 ]);
374374
375375 $ html = <<<'HTML'
@@ -379,9 +379,9 @@ public function testOrderOfOptionsAndDisabledOptionsDoesNotMatter()
379379 $ this ->assertHtml ($ html , $ radio );
380380
381381 $ radio = new RadioElement ('test ' , [
382- 'disabledOptions ' => ['foo ' , 'bar ' ],
383- 'label ' => 'Test ' ,
384- 'options ' => [
382+ 'disabledOptions ' => ['foo ' , 'bar ' ],
383+ 'label ' => 'Test ' ,
384+ 'options ' => [
385385 'foo ' => 'Foo ' ,
386386 'bar ' => 'Bar '
387387 ]
@@ -451,4 +451,42 @@ public function testGetOptionGetValueAndElementGetValueHandleNullAndTheEmptyStri
451451 $ this ->assertNull ($ radio ->getValue ());
452452 $ this ->assertNull ($ radio ->getOption (null )->getValue ());
453453 }
454+
455+ public function testCloning (): void
456+ {
457+ $ form = new Form ();
458+
459+ $ radio = new RadioElement ('radio ' , [
460+ 'options ' => [
461+ 'key1 ' => 'value1 ' ,
462+ 'key2 ' => 'value2 '
463+ ]
464+ ]);
465+
466+ $ clone = clone $ radio ;
467+ $ clone ->setName ('clone ' );
468+ $ clone ->setOptions ([
469+ 'key3 ' => 'value3 ' ,
470+ 'key4 ' => 'value4 '
471+ ]);
472+
473+ $ form
474+ ->addElement ($ radio )
475+ ->addElement ($ clone )
476+ ->populate ([
477+ 'radio ' => 'key1 ' ,
478+ 'clone ' => 'key4 '
479+ ]);
480+
481+ $ expected = <<<'HTML'
482+ <form method="POST">
483+ <label class="radio-label"><input checked="checked" name="radio" type="radio" value="key1"/>value1</label>
484+ <label class="radio-label"><input name="radio" type="radio" value="key2"/>value2</label>
485+ <label class="radio-label"><input name="clone" type="radio" value="key3"/>value3</label>
486+ <label class="radio-label"><input checked="checked" name="clone" type="radio" value="key4"/>value4</label>
487+ </form>
488+ HTML;
489+
490+ $ this ->assertHtml ($ expected , $ form );
491+ }
454492}
0 commit comments