14
14
*/
15
15
namespace Cake \Test \TestCase \View \Helper ;
16
16
17
+ use Cake \Collection \Collection ;
17
18
use Cake \Controller \Controller ;
18
19
use Cake \Core \App ;
19
20
use Cake \Core \Configure ;
@@ -3060,6 +3061,9 @@ public function testRadio() {
3060
3061
);
3061
3062
$ this ->assertTags ($ result , $ expected );
3062
3063
3064
+ $ result = $ this ->Form ->radio ('Model.field ' , new Collection (['option A ' ]));
3065
+ $ this ->assertTags ($ result , $ expected );
3066
+
3063
3067
$ result = $ this ->Form ->radio ('Model.field ' , array ('option A ' , 'option B ' ));
3064
3068
$ expected = array (
3065
3069
'input ' => array ('type ' => 'hidden ' , 'name ' => 'Model[field] ' , 'value ' => '' ),
@@ -3192,6 +3196,9 @@ public function testSelect() {
3192
3196
);
3193
3197
$ this ->assertTags ($ result , $ expected );
3194
3198
3199
+ $ result = $ this ->Form ->select ('Model.field ' , new Collection (['value ' => 'good ' , 'other ' => 'bad ' ]));
3200
+ $ this ->assertTags ($ result , $ expected );
3201
+
3195
3202
$ this ->Form ->request ->data = array ();
3196
3203
$ result = $ this ->Form ->select ('Model.field ' , array ('value ' => 'good ' , 'other ' => 'bad ' ));
3197
3204
$ expected = array (
@@ -3206,39 +3213,6 @@ public function testSelect() {
3206
3213
);
3207
3214
$ this ->assertTags ($ result , $ expected );
3208
3215
3209
- $ result = $ this ->Form ->select (
3210
- 'Model.field ' , array ('first ' => 'first "html" <chars> ' , 'second ' => 'value ' ),
3211
- array ('empty ' => false )
3212
- );
3213
- $ expected = array (
3214
- 'select ' => array ('name ' => 'Model[field] ' ),
3215
- array ('option ' => array ('value ' => 'first ' )),
3216
- 'first "html" <chars> ' ,
3217
- '/option ' ,
3218
- array ('option ' => array ('value ' => 'second ' )),
3219
- 'value ' ,
3220
- '/option ' ,
3221
- '/select '
3222
- );
3223
- $ this ->assertTags ($ result , $ expected );
3224
-
3225
- $ result = $ this ->Form ->select (
3226
- 'Model.field ' ,
3227
- array ('first ' => 'first "html" <chars> ' , 'second ' => 'value ' ),
3228
- array ('escape ' => false , 'empty ' => false )
3229
- );
3230
- $ expected = array (
3231
- 'select ' => array ('name ' => 'Model[field] ' ),
3232
- array ('option ' => array ('value ' => 'first ' )),
3233
- 'first "html" <chars> ' ,
3234
- '/option ' ,
3235
- array ('option ' => array ('value ' => 'second ' )),
3236
- 'value ' ,
3237
- '/option ' ,
3238
- '/select '
3239
- );
3240
- $ this ->assertTags ($ result , $ expected );
3241
-
3242
3216
$ options = array (
3243
3217
array ('value ' => 'first ' , 'text ' => 'First ' ),
3244
3218
array ('value ' => 'first ' , 'text ' => 'Another First ' ),
@@ -3288,6 +3262,46 @@ public function testSelect() {
3288
3262
$ this ->assertTags ($ result , $ expected );
3289
3263
}
3290
3264
3265
+ /**
3266
+ * Test that select() escapes HTML.
3267
+ *
3268
+ * @return void
3269
+ */
3270
+ public function testSelectEscapeHtml () {
3271
+ $ result = $ this ->Form ->select (
3272
+ 'Model.field ' , array ('first ' => 'first "html" <chars> ' , 'second ' => 'value ' ),
3273
+ array ('empty ' => false )
3274
+ );
3275
+ $ expected = array (
3276
+ 'select ' => array ('name ' => 'Model[field] ' ),
3277
+ array ('option ' => array ('value ' => 'first ' )),
3278
+ 'first "html" <chars> ' ,
3279
+ '/option ' ,
3280
+ array ('option ' => array ('value ' => 'second ' )),
3281
+ 'value ' ,
3282
+ '/option ' ,
3283
+ '/select '
3284
+ );
3285
+ $ this ->assertTags ($ result , $ expected );
3286
+
3287
+ $ result = $ this ->Form ->select (
3288
+ 'Model.field ' ,
3289
+ array ('first ' => 'first "html" <chars> ' , 'second ' => 'value ' ),
3290
+ array ('escape ' => false , 'empty ' => false )
3291
+ );
3292
+ $ expected = array (
3293
+ 'select ' => array ('name ' => 'Model[field] ' ),
3294
+ array ('option ' => array ('value ' => 'first ' )),
3295
+ 'first "html" <chars> ' ,
3296
+ '/option ' ,
3297
+ array ('option ' => array ('value ' => 'second ' )),
3298
+ 'value ' ,
3299
+ '/option ' ,
3300
+ '/select '
3301
+ );
3302
+ $ this ->assertTags ($ result , $ expected );
3303
+ }
3304
+
3291
3305
/**
3292
3306
* test select() with required and disabled attributes.
3293
3307
*
0 commit comments