Skip to content

Commit

Permalink
Moving tests around to be closer in the file to similar tests.
Browse files Browse the repository at this point in the history
Reformatting tests.
Adding/updating doc blocks for test methods.
  • Loading branch information
markstory committed Oct 31, 2009
1 parent adea104 commit 15da4a7
Showing 1 changed file with 87 additions and 73 deletions.
160 changes: 87 additions & 73 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -2699,6 +2699,38 @@ function testRadio() {
$this->assertTags($result, $expected);
}

/**
* test disabling the hidden input for radio buttons
*
* @return void
**/
function testRadioHiddenInputDisabling() {
$result = $this->Form->input('Model.1.field', array(
'type' => 'radio',
'options' => array('option A'),
'hiddenField' => false
)
);
$expected = array(
'div' => array('class' => 'input radio'),
'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
'label' => array('for' => 'Model1Field0'),
'option A',
'/label',
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false));
$expected = array(
'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
'label' => array('for' => 'Model1Field0'),
'option A',
'/label'
);
$this->assertTags($result, $expected);
}

/**
* testSelect method
*
Expand Down Expand Up @@ -3313,6 +3345,31 @@ function testCheckboxHiddenDisabling() {
$this->assertTags($result, $expected);
}

/**
* Test that the hidden input for checkboxes can be removed/omitted from the output.
*
* @return void
*/
function testCheckboxHiddenFieldOmission() {
$result = $this->Form->input('UserForm.something', array(
'type' => 'checkbox',
'hiddenField' => false
)
);
$expected = array(
'div' => array('class' => 'input checkbox'),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
'value' => '1', 'id' => 'UserFormSomething'
)),
'label' => array('for' => 'UserFormSomething'),
'Something',
'/label',
'/div'
);
$this->assertTags($result, $expected);
}

/**
* testDateTime method
*
Expand Down Expand Up @@ -4792,6 +4849,28 @@ function testCreateWithInputDefaults() {
$this->assertTags($result, $expected);
}

/**
* test automatic accept-charset overriding
*
* @return void
**/
function testCreateWithAcceptCharset() {
$result = $this->Form->create('UserForm', array(
'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1'
)
);
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm',
'accept-charset' => 'iso-8859-1'
),
'fieldset' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/fieldset'
);
$this->assertTags($result, $expected);
}

/**
* Test base form url when url param is passed with multiple parameters (&)
*
Expand Down Expand Up @@ -4822,7 +4901,7 @@ function testFormCreateQuerystringParams() {
}

/**
* testGetFormCreate method
* test creating a get form, and get form inputs.
*
* @access public
* @return void
Expand Down Expand Up @@ -4862,10 +4941,10 @@ function testGetFormCreate() {
*/
function testEditFormWithData() {
$this->Form->data = array('Person' => array(
'id' => 1,
'first_name' => 'Nate',
'last_name' => 'Abele',
'email' => 'nate@example.com'
'id' => 1,
'first_name' => 'Nate',
'last_name' => 'Abele',
'email' => 'nate@example.com'
));
$this->Form->params = array('models' => array('Person'), 'controller' => 'people', 'action' => 'add');
$options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
Expand All @@ -4877,15 +4956,9 @@ function testEditFormWithData() {
'select' => array(
'name' => 'data[People][People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople'
),
array('option' => array('value' => 1)),
'Nate',
'/option',
array('option' => array('value' => 2)),
'Garrett',
'/option',
array('option' => array('value' => 3)),
'Larry',
'/option',
array('option' => array('value' => 1)), 'Nate', '/option',
array('option' => array('value' => 2)), 'Garrett', '/option',
array('option' => array('value' => 3)), 'Larry', '/option',
'/select'
);
$this->assertTags($result, $expected);
Expand Down Expand Up @@ -5627,64 +5700,5 @@ function testMultiRecordFormValidationErrors() {
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
}

function testInputErrorEscape() {
$this->Form->create('ValidateProfile');
$this->Form->validationErrors['ValidateProfile']['city'] = 'required<br>';
$result = $this->Form->input('city',array('error' => array('escape' => true)));
$this->assertPattern('/required&lt;br&gt;/', $result);

$result = $this->Form->input('city',array('error' => array('escape' => false)));
$this->assertPattern('/required<br>/', $result);
}

function testFormEncoding() {
$result = $this->Form->create('UserForm', array(
'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1'
)
);
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm',
'accept-charset' => 'iso-8859-1'
),
'fieldset' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/fieldset'
);
$this->assertTags($result, $expected);
}

function testDisableHiddenField() {
$result = $this->Form->input('UserForm.something', array(
'type' => 'checkbox', 'hiddenField' => false
)
);
$expected = array(
'div' => array('class' => 'input checkbox'),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
'value' => '1', 'id' => 'UserFormSomething'
)),
'label' => array('for' => 'UserFormSomething'),
'Something',
'/label',
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Model.1.field', array(
'type' => 'radio','options' => 'option A', 'hiddenField' => false
)
);
$expected = array(
'div' => array('class' => 'input radio'),
'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
'label' => array('for' => 'Model1Field0'),
'option A',
'/label',
'/div'
);
$this->assertTags($result, $expected,true);
}
}
?>

0 comments on commit 15da4a7

Please sign in to comment.