@@ -3773,27 +3773,6 @@ function testCheckbox() {
3773
3773
);
3774
3774
$ this ->assertTags ($ result , $ expected );
3775
3775
3776
- $ result = $ this ->Form ->checkbox ('Model.field ' , array ('checked ' => 'checked ' ));
3777
- $ expected = array (
3778
- 'input ' => array ('type ' => 'hidden ' , 'name ' => 'data[Model][field] ' , 'value ' => '0 ' , 'id ' => 'ModelField_ ' ),
3779
- array ('input ' => array ('type ' => 'checkbox ' , 'name ' => 'data[Model][field] ' , 'value ' => '1 ' , 'id ' => 'ModelField ' , 'checked ' => 'checked ' ))
3780
- );
3781
- $ this ->assertTags ($ result , $ expected );
3782
-
3783
- $ result = $ this ->Form ->checkbox ('Model.field ' , array ('checked ' => 1 ));
3784
- $ expected = array (
3785
- 'input ' => array ('type ' => 'hidden ' , 'name ' => 'data[Model][field] ' , 'value ' => '0 ' , 'id ' => 'ModelField_ ' ),
3786
- array ('input ' => array ('type ' => 'checkbox ' , 'name ' => 'data[Model][field] ' , 'value ' => '1 ' , 'id ' => 'ModelField ' , 'checked ' => 'checked ' ))
3787
- );
3788
- $ this ->assertTags ($ result , $ expected );
3789
-
3790
- $ result = $ this ->Form ->checkbox ('Model.field ' , array ('checked ' => true ));
3791
- $ expected = array (
3792
- 'input ' => array ('type ' => 'hidden ' , 'name ' => 'data[Model][field] ' , 'value ' => '0 ' , 'id ' => 'ModelField_ ' ),
3793
- array ('input ' => array ('type ' => 'checkbox ' , 'name ' => 'data[Model][field] ' , 'value ' => '1 ' , 'id ' => 'ModelField ' , 'checked ' => 'checked ' ))
3794
- );
3795
- $ this ->assertTags ($ result , $ expected );
3796
-
3797
3776
$ this ->Form ->validationErrors ['Model ' ]['field ' ] = 1 ;
3798
3777
$ this ->Form ->data ['Contact ' ]['published ' ] = 1 ;
3799
3778
$ result = $ this ->Form ->checkbox ('Contact.published ' , array ('id ' => 'theID ' ));
@@ -3834,6 +3813,49 @@ function testCheckbox() {
3834
3813
$ this ->assertTags ($ result , $ expected );
3835
3814
}
3836
3815
3816
+ /**
3817
+ * test the checked option for checkboxes.
3818
+ *
3819
+ * @return void
3820
+ */
3821
+ function testCheckboxCheckedOption () {
3822
+ $ result = $ this ->Form ->checkbox ('Model.field ' , array ('checked ' => 'checked ' ));
3823
+ $ expected = array (
3824
+ 'input ' => array ('type ' => 'hidden ' , 'name ' => 'data[Model][field] ' , 'value ' => '0 ' , 'id ' => 'ModelField_ ' ),
3825
+ array ('input ' => array ('type ' => 'checkbox ' , 'name ' => 'data[Model][field] ' , 'value ' => '1 ' , 'id ' => 'ModelField ' , 'checked ' => 'checked ' ))
3826
+ );
3827
+ $ this ->assertTags ($ result , $ expected );
3828
+
3829
+ $ result = $ this ->Form ->checkbox ('Model.field ' , array ('checked ' => 1 ));
3830
+ $ expected = array (
3831
+ 'input ' => array ('type ' => 'hidden ' , 'name ' => 'data[Model][field] ' , 'value ' => '0 ' , 'id ' => 'ModelField_ ' ),
3832
+ array ('input ' => array ('type ' => 'checkbox ' , 'name ' => 'data[Model][field] ' , 'value ' => '1 ' , 'id ' => 'ModelField ' , 'checked ' => 'checked ' ))
3833
+ );
3834
+ $ this ->assertTags ($ result , $ expected );
3835
+
3836
+ $ result = $ this ->Form ->checkbox ('Model.field ' , array ('checked ' => true ));
3837
+ $ expected = array (
3838
+ 'input ' => array ('type ' => 'hidden ' , 'name ' => 'data[Model][field] ' , 'value ' => '0 ' , 'id ' => 'ModelField_ ' ),
3839
+ array ('input ' => array ('type ' => 'checkbox ' , 'name ' => 'data[Model][field] ' , 'value ' => '1 ' , 'id ' => 'ModelField ' , 'checked ' => 'checked ' ))
3840
+ );
3841
+ $ this ->assertTags ($ result , $ expected );
3842
+
3843
+ $ result = $ this ->Form ->checkbox ('Model.field ' , array ('checked ' => false ));
3844
+ $ expected = array (
3845
+ 'input ' => array ('type ' => 'hidden ' , 'name ' => 'data[Model][field] ' , 'value ' => '0 ' , 'id ' => 'ModelField_ ' ),
3846
+ array ('input ' => array ('type ' => 'checkbox ' , 'name ' => 'data[Model][field] ' , 'value ' => '1 ' , 'id ' => 'ModelField ' ))
3847
+ );
3848
+ $ this ->assertTags ($ result , $ expected );
3849
+
3850
+ $ this ->Form ->data ['Model ' ]['field ' ] = 1 ;
3851
+ $ result = $ this ->Form ->checkbox ('Model.field ' , array ('checked ' => false ));
3852
+ $ expected = array (
3853
+ 'input ' => array ('type ' => 'hidden ' , 'name ' => 'data[Model][field] ' , 'value ' => '0 ' , 'id ' => 'ModelField_ ' ),
3854
+ array ('input ' => array ('type ' => 'checkbox ' , 'name ' => 'data[Model][field] ' , 'value ' => '1 ' , 'id ' => 'ModelField ' ))
3855
+ );
3856
+ $ this ->assertTags ($ result , $ expected );
3857
+ }
3858
+
3837
3859
/**
3838
3860
* Test that disabling a checkbox also disables the hidden input so no value is submitted
3839
3861
*
0 commit comments