From b782563daf50c6c9a26e580e592be3972f4583ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Sat, 27 Feb 2010 23:18:21 -0430 Subject: [PATCH] Adding test for form input templates --- app/tmp/cache/persistent/empty | 0 cake/libs/view/helpers/form.php | 2 +- .../cases/libs/view/helpers/form.test.php | 64 ++++++++++++++++++- 3 files changed, 64 insertions(+), 2 deletions(-) delete mode 100755 app/tmp/cache/persistent/empty diff --git a/app/tmp/cache/persistent/empty b/app/tmp/cache/persistent/empty deleted file mode 100755 index e69de29bb2d..00000000000 diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 4ec6961cde4..167d9232ea9 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -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); diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 0a826d2619f..189d3040637 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -6019,7 +6019,7 @@ function testMultiRecordForm() { '/div', '/div' ); - $this->assertTags($result, $expected,true); + $this->assertTags($result, $expected); } /** @@ -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' => 'Email (required)' + )); + $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' => '
Something in the middle
', + 'after' => 'Some text at the end' + )); + $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); + } } ?> \ No newline at end of file