mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-12 20:49:50 +00:00
Adding additional tests for FormHelper::input() and checkbox generation and checked attribute being set for truthy values. Close #806
This commit is contained in:
parent
d5ddd8ee5f
commit
9ee4a12a9d
1 changed files with 43 additions and 0 deletions
|
@ -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 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$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 @@ class FormHelperTest extends CakeTestCase {
|
|||
));
|
||||
$this->assertPattern('/for\="created-month"/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test generating checkboxes in a loop.
|
||||
*
|
||||
|
@ -1972,6 +2000,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test form->input() with select type inputs.
|
||||
*
|
||||
|
@ -3545,6 +3574,20 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$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'));
|
||||
|
|
Loading…
Add table
Reference in a new issue