Skip to content

Commit

Permalink
Adding test for form input templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 28, 2010
1 parent 0ca5c11 commit b782563
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
Empty file removed app/tmp/cache/persistent/empty
Empty file.
2 changes: 1 addition & 1 deletion cake/libs/view/helpers/form.php
Expand Up @@ -883,7 +883,7 @@ function input($fieldName, $options = array()) {
break;
case 'checkbox':
$input = $this->checkbox($fieldName, $options);
$format = $format ?: array('before', 'input', 'between', 'label', 'after', 'error');
$format = $format ? $format : array('before', 'input', 'between', 'label', 'after', 'error');
break;
case 'radio':
$input = $this->radio($fieldName, $radioOptions, $options);
Expand Down
64 changes: 63 additions & 1 deletion cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -6019,7 +6019,7 @@ function testMultiRecordForm() {
'/div',
'/div'
);
$this->assertTags($result, $expected,true);
$this->assertTags($result, $expected);
}

/**
Expand All @@ -6041,5 +6041,67 @@ function testMultiRecordFormValidationErrors() {
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
}

/**
* tests the ability to change the order of the form input placeholder "input", "label", "before", "between", "after", "error"
*
* @return void
*/
function testInputTemplate() {
$result = $this->Form->input('Contact.email', array(
'type' => 'text', 'format' => array('input')
));
$expected = array(
'div' => array('class' => 'input text'),
'input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
),
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Contact.email', array(
'type' => 'text', 'format' => array('input', 'label'),
'label' => '<em>Email (required)</em>'
));
$expected = array(
'div' => array('class' => 'input text'),
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
)),
'label' => array('for' => 'ContactEmail'),
'em' => array(),
'Email (required)',
'/em',
'/label',
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Contact.email', array(
'type' => 'text', 'format' => array('input', 'between', 'label', 'after'),
'between' => '<div>Something in the middle</div>',
'after' => '<span>Some text at the end</span>'
));
$expected = array(
'div' => array('class' => 'input text'),
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
)),
array('div' => array()),
'Something in the middle',
'/div',
'label' => array('for' => 'ContactEmail'),
'Email',
'/label',
'span' => array(),
'Some text at the end',
'/span',
'/div'
);
$this->assertTags($result, $expected);
}
}
?>

0 comments on commit b782563

Please sign in to comment.