Skip to content

Commit

Permalink
Adding additional tests for FormHelper::input() and checkbox generati…
Browse files Browse the repository at this point in the history
…on and checked attribute being set for truthy values. Close #806
  • Loading branch information
markstory committed Jun 10, 2010
1 parent d5ddd8e commit 9ee4a12
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -1952,6 +1979,7 @@ function testInputDatetime() {
));
$this->assertPattern('/for\="created-month"/', $result);
}

/**
* Test generating checkboxes in a loop.
*
Expand All @@ -1972,6 +2000,7 @@ function testInputCheckboxesInLoop() {
$this->assertTags($result, $expected);
}
}

/**
* test form->input() with select type inputs.
*
Expand Down Expand Up @@ -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'));
Expand Down

0 comments on commit 9ee4a12

Please sign in to comment.