|
|
@@ -8496,4 +8496,86 @@ class FormHelperTest extends TestCase
|
|
|
];
|
|
|
$this->assertHtml($expected, $result);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * testRadioAttributes method
|
|
|
+ *
|
|
|
+ * Test generation of radio widget with additional attributes.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testRadioAttributes()
|
|
|
+ {
|
|
|
+ $result = $this->Form->radio('Model.field', ['option A'], ['class' => 'my-class', 'data-ref' => 'custom-attr']);
|
|
|
+ $expected = [
|
|
|
+ 'input' => ['type' => 'hidden', 'name' => 'Model[field]', 'value' => ''],
|
|
|
+ 'label' => ['for' => 'model-field-0'],
|
|
|
+ ['input' => [
|
|
|
+ 'type' => 'radio', 'name' => 'Model[field]',
|
|
|
+ 'value' => '0', 'id' => 'model-field-0',
|
|
|
+ 'class' => 'my-class', 'data-ref' => 'custom-attr'
|
|
|
+ ]],
|
|
|
+ 'option A',
|
|
|
+ '/label'
|
|
|
+ ];
|
|
|
+ $this->assertHtml($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * testCheckboxAttributes method
|
|
|
+ *
|
|
|
+ * Test generation of checkbox widget with additional attributes.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testCheckboxAttributes()
|
|
|
+ {
|
|
|
+ $result = $this->Form->checkbox('Model.field', ['class' => 'my-class', 'data-ref' => 'custom-attr']);
|
|
|
+ $expected = [
|
|
|
+ 'input' => ['type' => 'hidden', 'name' => 'Model[field]', 'value' => '0'],
|
|
|
+ ['input' => [
|
|
|
+ 'type' => 'checkbox', 'name' => 'Model[field]',
|
|
|
+ 'value' => '1', 'class' => 'my-class',
|
|
|
+ 'data-ref' => 'custom-attr'
|
|
|
+ ]]
|
|
|
+ ];
|
|
|
+ $this->assertHtml($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * testMultiCheckboxAttributes method
|
|
|
+ *
|
|
|
+ * Test generation of multiple checkboxes with additional attributes
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testMultiCheckboxAttributes()
|
|
|
+ {
|
|
|
+ $result = $this->Form->multiCheckbox('category', ['1', '2'], ['class' => 'my-class', 'data-ref' => 'custom-attr']);
|
|
|
+
|
|
|
+ $expected = [
|
|
|
+ 'input' => ['type' => 'hidden', 'name' => 'category', 'value' => ''],
|
|
|
+ ['div' => ['class' => 'checkbox']],
|
|
|
+ ['label' => ['for' => 'category-0']],
|
|
|
+ ['input' => [
|
|
|
+ 'type' => 'checkbox', 'name' => 'category[]',
|
|
|
+ 'value' => '0', 'id' => 'category-0',
|
|
|
+ 'class' => 'my-class', 'data-ref' => 'custom-attr'
|
|
|
+ ]],
|
|
|
+ '1',
|
|
|
+ '/label',
|
|
|
+ '/div',
|
|
|
+ ['div' => ['class' => 'checkbox']],
|
|
|
+ ['label' => ['for' => 'category-1']],
|
|
|
+ ['input' => [
|
|
|
+ 'type' => 'checkbox', 'name' => 'category[]',
|
|
|
+ 'value' => '1', 'id' => 'category-1',
|
|
|
+ 'class' => 'my-class', 'data-ref' => 'custom-attr'
|
|
|
+ ]],
|
|
|
+ '2',
|
|
|
+ '/label',
|
|
|
+ '/div'
|
|
|
+ ];
|
|
|
+ $this->assertHtml($expected, $result);
|
|
|
+ }
|
|
|
}
|