Skip to content
Permalink
Browse files

Adding additional tests for FormHelper::input() and checkbox generati…

…on and checked attribute being set for truthy values. Close #806
  • Loading branch information...
markstory committed Jun 10, 2010
1 parent d5ddd8e commit 9ee4a12a9d8ba32da80d73aafc47659b8a3815fc
Showing with 43 additions and 0 deletions.
  1. +43 −0 cake/tests/cases/libs/view/helpers/form.test.php
@@ -313,6 +313,7 @@ class UserForm extends CakeTestModel {
'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null),
'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10),
'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255),
'active' => array('type' => 'boolean', 'null' => false, 'default' => false),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
);
@@ -1829,6 +1830,32 @@ function testInput() {
);
$this->assertTags($result, $expected);
}
/**
* test input() with checkbox creation
*
* @return void
*/
function testInputCheckbox() {
$result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test form->input() with datetime, date and time types
*
@@ -1952,6 +1979,7 @@ function testInputDatetime() {
));
$this->assertPattern('/for\="created-month"/', $result);
}
/**
* Test generating checkboxes in a loop.
*
@@ -1972,6 +2000,7 @@ function testInputCheckboxesInLoop() {
$this->assertTags($result, $expected);
}
}
/**
* test form->input() with select type inputs.
*
@@ -3545,6 +3574,20 @@ function testCheckbox() {
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => 1));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('checked' => true));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
);
$this->assertTags($result, $expected);
$this->Form->validationErrors['Model']['field'] = 1;
$this->Form->data['Contact']['published'] = 1;
$result = $this->Form->checkbox('Contact.published', array('id' => 'theID'));

0 comments on commit 9ee4a12

Please sign in to comment.
You can’t perform that action at this time.