Removing extra check for closing tag in assertTags().

Continuing with FormHelperTest refactoring.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6730 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-04-26 18:44:01 +00:00
parent 3180aecb95
commit f7384bca87
2 changed files with 522 additions and 181 deletions

View file

@ -496,7 +496,7 @@ class FormHelperTest extends CakeTestCase {
'input' => array('type' => 'password', 'name' => 'data[Contact][password]', 'value' => '', 'id' => 'ContactPassword', 'class' => 'form-error'), 'input' => array('type' => 'password', 'name' => 'data[Contact][password]', 'value' => '', 'id' => 'ContactPassword', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')), array('div' => array('class' => 'error-message')),
'Please provide a password', 'Please provide a password',
array('!div'), '!div',
'!div' '!div'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -607,7 +607,7 @@ class FormHelperTest extends CakeTestCase {
'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')), array('div' => array('class' => 'error-message')),
'This field cannot be left blank', 'This field cannot be left blank',
array('!div'), '!div',
'!div' '!div'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -623,7 +623,7 @@ class FormHelperTest extends CakeTestCase {
'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')), array('div' => array('class' => 'error-message')),
'You must provide a URL', 'You must provide a URL',
array('!div'), '!div',
'!div' '!div'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -644,7 +644,7 @@ class FormHelperTest extends CakeTestCase {
'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')), array('div' => array('class' => 'error-message')),
'This field cannot be empty', 'This field cannot be empty',
array('!div'), '!div',
'!div' '!div'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -658,7 +658,7 @@ class FormHelperTest extends CakeTestCase {
'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')), array('div' => array('class' => 'error-message')),
'This field cannot be empty', 'This field cannot be empty',
array('!div'), '!div',
'!div' '!div'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -683,7 +683,7 @@ class FormHelperTest extends CakeTestCase {
'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')), array('div' => array('class' => 'error-message')),
'You must have a last name', 'You must have a last name',
array('!div'), '!div',
'!div' '!div'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -748,13 +748,13 @@ class FormHelperTest extends CakeTestCase {
'!label', '!label',
array('select' => array('name' => 'data[email]', 'id' => 'email')), array('select' => array('name' => 'data[email]', 'id' => 'email')),
array('option' => array('value' => '')), array('option' => array('value' => '')),
array('!option'), '!option',
array('option' => array('value' => '0')), array('option' => array('value' => '0')),
'First', 'First',
array('!option'), '!option',
array('option' => array('value' => '1')), array('option' => array('value' => '1')),
'Second', 'Second',
array('!option'), '!option',
'!select', '!select',
'!div' '!div'
); );
@ -819,7 +819,7 @@ class FormHelperTest extends CakeTestCase {
'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')), array('div' => array('class' => 'error-message')),
'Badness!', 'Badness!',
array('!div'), '!div',
'!div' '!div'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -834,7 +834,7 @@ class FormHelperTest extends CakeTestCase {
'A message to you, Rudy', 'A message to you, Rudy',
array('div' => array('class' => 'error-message')), array('div' => array('class' => 'error-message')),
'Badness!', 'Badness!',
array('!div'), '!div',
'!div' '!div'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
@ -877,13 +877,13 @@ class FormHelperTest extends CakeTestCase {
'!label', '!label',
'select' => array('name' => 'data[Model][user_id]', 'id' => 'ModelUserId'), 'select' => array('name' => 'data[Model][user_id]', 'id' => 'ModelUserId'),
array('option' => array('value' => '')), array('option' => array('value' => '')),
array('!option'), '!option',
array('option' => array('value' => 'value', 'selected' => 'selected')), array('option' => array('value' => 'value', 'selected' => 'selected')),
'good', 'good',
array('!option'), '!option',
array('option' => array('value' => 'other')), array('option' => array('value' => 'other')),
'bad', 'bad',
array('!option'), '!option',
'!select', '!select',
'!div' '!div'
); );
@ -901,13 +901,13 @@ class FormHelperTest extends CakeTestCase {
'input' => array('type' => 'hidden', 'name' => 'data[User][User]', 'value' => ''), 'input' => array('type' => 'hidden', 'name' => 'data[User][User]', 'value' => ''),
'select' => array('name' => 'data[User][User][]', 'id' => 'UserUser', 'multiple' => 'multiple'), 'select' => array('name' => 'data[User][User][]', 'id' => 'UserUser', 'multiple' => 'multiple'),
array('option' => array('value' => '')), array('option' => array('value' => '')),
array('!option'), '!option',
array('option' => array('value' => 'value', 'selected' => 'selected')), array('option' => array('value' => 'value', 'selected' => 'selected')),
'good', 'good',
array('!option'), '!option',
array('option' => array('value' => 'other')), array('option' => array('value' => 'other')),
'bad', 'bad',
array('!option'), '!option',
'!select', '!select',
'!div' '!div'
); );
@ -917,162 +917,328 @@ class FormHelperTest extends CakeTestCase {
function testFormInputs() { function testFormInputs() {
$this->Form->create('Contact'); $this->Form->create('Contact');
$result = $this->Form->inputs('The Legend'); $result = $this->Form->inputs('The Legend');
$this->assertPattern('/<legend>The Legend<\/legend>/', $result); $expected = array(
'fieldset' => array(),
'legend' => array(),
'The Legend',
'!legend',
'preg:/.+/',
'!fieldset'
);
$this->assertTags($result, $expected);
$View = ClassRegistry::getObject('view'); $View = ClassRegistry::getObject('view');
$this->Form->create('Contact'); $this->Form->create('Contact');
$this->Form->params['prefix'] = 'admin'; $this->Form->params['prefix'] = 'admin';
$this->Form->action = 'admin_edit'; $this->Form->action = 'admin_edit';
$result = $this->Form->inputs(); $result = $this->Form->inputs();
$this->assertPattern('/<legend>Edit Contact<\/legend>/', $result); $expected = array(
'fieldset' => array(),
'legend' => array(),
'Edit Contact',
'!legend',
'preg:/.+/',
'!fieldset'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact'); $this->Form->create('Contact');
$result = $this->Form->inputs(false); $result = $this->Form->inputs(false);
$this->assertNoPattern('/<fieldset[^<>]*>/', $result); $expected = array(
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result); 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact'); $this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => false)); $result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
$this->assertNoPattern('/<fieldset[^<>]*>/', $result); $expected = array(
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result); 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact'); $this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false)); $result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
$this->assertPattern('/<fieldset[^<>]*>/', $result); $expected = array(
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result); 'fieldset' => array(),
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
'!fieldset'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact'); $this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello')); $result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
$this->assertNoPattern('/<fieldset[^<>]*>/', $result); $expected = array(
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result); 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact'); $this->Form->create('Contact');
$result = $this->Form->inputs('Hello'); $result = $this->Form->inputs('Hello');
$this->assertPattern('/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s', $result); $expected = array(
'fieldset' => array(),
'legend' => array(),
'Hello',
'!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
'!fieldset'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact'); $this->Form->create('Contact');
$result = $this->Form->inputs(array('legend' => 'Hello')); $result = $this->Form->inputs(array('legend' => 'Hello'));
$this->assertPattern('/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s', $result); $expected = array(
'fieldset' => array(),
'legend' => array(),
'Hello',
'!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
array('div' => array('class' => 'input')),
'preg:/.+/',
'!div',
'!fieldset'
);
$this->assertTags($result, $expected);
} }
function testSelectAsCheckbox() { function testSelectAsCheckbox() {
$result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => 'checkbox')); $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => 'checkbox'));
$this->assertPattern('/^<input type="hidden"[^<>]+ \/>\s*(<div[^<>]+>\<input[^<>]+>\s*<label[^<>]*>\w+<\/label><\/div>\s*){3}$/', $result); $expected = array(
$this->assertNoPattern('/<label[^<>]*>[^(first|second)]<\/label>/', $result); 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''),
array('div' => array('class' => 'checkbox')),
$this->assertPattern('/^<input[^<>]+type="hidden"[^<>]+\/>/', $result); array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[multi_field\]"[^<>]+\/>/', $result); array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),
$this->assertPattern('/^<input[^<>]+value=""[^<>]+\/>/', $result); 'first',
'!label',
$this->assertPattern('/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label>/', $result); '!div',
$this->assertPattern('/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label>/', $result); 'preg:/.+/'
$this->assertPattern('/<input[^<>]+checked="checked"[^<>]+\/><label[^<>]+>first<\/label>/', $result); );
$this->assertPattern('/<input[^<>]+value="0"[^<>]+\/><label[^<>]+>first<\/label>/', $result); $this->assertTags($result, $expected);
$this->assertPattern('/<input[^<>]+id="ModelMultiField0"[^<>]+\/><label[^<>]+>first<\/label>/', $result); $expected = array(
$this->assertPattern('/<input[^<>]+\/><label[^<>]+for="ModelMultiField0"[^<>]*>first<\/label>/', $result); 'preg:/.+/',
$this->assertPattern('/<input[^<>]+\/><label[^<>]+class="selected"[^<>]*>first<\/label>/', $result); array('div' => array('class' => 'checkbox')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),
$this->assertPattern('/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label>/', $result); array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),
$this->assertPattern('/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label>/', $result); 'second',
$this->assertPattern('/<input[^<>]+checked="checked"[^<>]+\/><label[^<>]+>second<\/label>/', $result); '!label',
$this->assertPattern('/<input[^<>]+value="1"[^<>]+\/><label[^<>]+>second<\/label>/', $result); '!div',
$this->assertPattern('/<input[^<>]+id="ModelMultiField1"[^<>]+\/><label[^<>]+>second<\/label>/', $result); 'preg:/.+/'
$this->assertPattern('/<input[^<>]+\/><label[^<>]+for="ModelMultiField1"[^<>]*>second<\/label>/', $result); );
$this->assertPattern('/<input[^<>]+\/><label[^<>]+class="selected"[^<>]*>second<\/label>/', $result); $this->assertTags($result, $expected);
$expected = array(
$this->assertPattern('/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>third<\/label>/', $result); 'preg:/.+/',
$this->assertPattern('/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>third<\/label>/', $result); array('div' => array('class' => 'checkbox')),
$this->assertPattern('/<input[^<>]+value="2"[^<>]+\/><label[^<>]+>third<\/label>/', $result); array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
$this->assertPattern('/<input[^<>]+id="ModelMultiField2"[^<>]+\/><label[^<>]+>third<\/label>/', $result); array('label' => array('for' => 'ModelMultiField2')),
$this->assertPattern('/<input[^<>]+\/><label[^<>]+for="ModelMultiField2"[^<>]*>third<\/label>/', $result); 'third',
'!label',
'!div'
);
$this->assertTags($result, $expected);
} }
function testLabel() { function testLabel() {
$this->Form->text('Person/name'); $this->Form->text('Person/name');
$result = $this->Form->label(); $result = $this->Form->label();
$this->assertEqual($result, '<label for="PersonName">Name</label>'); $this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '!label'));
$this->Form->text('Person.name'); $this->Form->text('Person.name');
$result = $this->Form->label(); $result = $this->Form->label();
$this->assertEqual($result, '<label for="PersonName">Name</label>'); $this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '!label'));
$this->Form->text('Person.Name');
$result = $this->Form->label();
$this->assertEqual($result, '<label for="PersonName">Name</label>');
$result = $this->Form->label('Person.first_name'); $result = $this->Form->label('Person.first_name');
$this->assertEqual($result, '<label for="PersonFirstName">First Name</label>'); $this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'First Name', '!label'));
$result = $this->Form->label('Person.first_name', 'Your first name'); $result = $this->Form->label('Person.first_name', 'Your first name');
$this->assertEqual($result, '<label for="PersonFirstName">Your first name</label>'); $this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'Your first name', '!label'));
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class')); $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
$this->assertPattern('/^<label[^<>]+>Your first name<\/label>$/', $result); $this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class'), 'Your first name', '!label'));
$this->assertPattern('/^<label[^<>]+for="PersonFirstName"[^<>]*>/', $result);
$this->assertPattern('/^<label[^<>]+class="my-class"[^<>]*>/', $result);
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID')); $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
$this->assertEqual($result, '<label for="PersonFirstName" class="my-class" id="LabelID">Your first name</label>'); $this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '!label'));
$result = $this->Form->label('Person.first_name', ''); $result = $this->Form->label('Person.first_name', '');
$this->assertEqual($result, '<label for="PersonFirstName"></label>'); $this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), '!label'));
$result = $this->Form->label('Person.2.name', ''); $result = $this->Form->label('Person.2.name', '');
$this->assertEqual($result, '<label for="Person2Name"></label>'); $this->assertTags($result, array('label' => array('for' => 'Person2Name'), '!label'));
} }
function testTextbox() { function testTextbox() {
$result = $this->Form->text('Model.field'); $result = $this->Form->text('Model.field');
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/', $result); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField')));
$this->assertPattern('/^<input[^<>]+type="text"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+value=""[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+id="ModelField"[^<>]+\/>$/', $result);
$this->assertNoPattern('/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value]=[^<>]*>/', $result);
$result = $this->Form->text('Model.field', array('type' => 'password')); $result = $this->Form->text('Model.field', array('type' => 'password'));
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/', $result); $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField')));
$this->assertPattern('/^<input[^<>]+type="password"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+value=""[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+id="ModelField"[^<>]+\/>$/', $result);
$this->assertNoPattern('/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value]=[^<>]*>/', $result);
$result = $this->Form->text('Model.field', array('id' => 'theID')); $result = $this->Form->text('Model.field', array('id' => 'theID'));
$expected = '<input name="data[Model][field]" type="text" id="theID" value="" />'; $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'theID')));
$this->assertEqual($result, $expected);
$this->Form->data['Model']['text'] = 'test <strong>HTML</strong> values'; $this->Form->data['Model']['text'] = 'test <strong>HTML</strong> values';
$result = $this->Form->text('Model/text'); $result = $this->Form->text('Model/text');
$this->assertPattern('/^<input[^<>]+type="text"[^<>]+\/>$/', $result); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test &lt;strong&gt;HTML&lt;/strong&gt; values', 'id' => 'ModelText')));
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[text\]"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+value="test &lt;strong&gt;HTML&lt;\/strong&gt; values"[^<>]+\/>$/', $result);
$this->assertNoPattern('/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
$this->Form->validationErrors['Model']['text'] = 1; $this->Form->validationErrors['Model']['text'] = 1;
$this->Form->data['Model']['text'] = 'test'; $this->Form->data['Model']['text'] = 'test';
$result = $this->Form->text('Model/text', array('id' => 'theID')); $result = $this->Form->text('Model/text', array('id' => 'theID'));
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[text\]"[^<>]+id="theID"[^<>]+\/>$/', $result); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
$this->assertPattern('/^<input[^<>]+value="test"[^<>]+class="form-error"[^<>]+\/>$/', $result);
$this->assertNoPattern('/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
} }
function testDefaultValue() { function testDefaultValue() {
$this->Form->data['Model']['field'] = 'test'; $this->Form->data['Model']['field'] = 'test';
$result = $this->Form->text('Model.field', array('default' => 'default value')); $result = $this->Form->text('Model.field', array('default' => 'default value'));
$this->assertPattern('/^<input[^<>]+value="test"[^<>]+\/>$/', $result); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'test', 'id' => 'ModelField')));
unset($this->Form->data['Model']['field']); unset($this->Form->data['Model']['field']);
$result = $this->Form->text('Model.field', array('default' => 'default value')); $result = $this->Form->text('Model.field', array('default' => 'default value'));
$this->assertPattern('/^<input[^<>]+value="default value"[^<>]+\/>$/', $result); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'default value', 'id' => 'ModelField')));
} }
function testFieldError() { function testFieldError() {
$this->Form->validationErrors['Model']['field'] = 1; $this->Form->validationErrors['Model']['field'] = 1;
$result = $this->Form->error('Model.field'); $result = $this->Form->error('Model.field');
$this->assertEqual($result, '<div class="error-message">Error in field Field</div>'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '!div'));
$result = $this->Form->error('Model.field', null, array('wrap' => false)); $result = $this->Form->error('Model.field', null, array('wrap' => false));
$this->assertEqual($result, 'Error in field Field'); $this->assertEqual($result, 'Error in field Field');
@ -1093,132 +1259,310 @@ class FormHelperTest extends CakeTestCase {
function testPassword() { function testPassword() {
$result = $this->Form->password('Model.field'); $result = $this->Form->password('Model.field');
$expected = '<input name="data[Model][field]" type="password" value="" id="ModelField" />'; $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField')));
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+type="password"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+value=""[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+id="ModelField"[^<>]+\/>$/', $result);
$this->assertNoPattern('/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value]=[^<>]*>/', $result);
$this->Form->validationErrors['Model']['passwd'] = 1; $this->Form->validationErrors['Model']['passwd'] = 1;
$this->Form->data['Model']['passwd'] = 'test'; $this->Form->data['Model']['passwd'] = 'test';
$result = $this->Form->password('Model/passwd', array('id' => 'theID')); $result = $this->Form->password('Model/passwd', array('id' => 'theID'));
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[passwd\]"[^<>]+id="theID"[^<>]+\/>$/', $result); $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
$this->assertPattern('/^<input[^<>]+value="test"[^<>]+class="form-error"[^<>]+\/>$/', $result);
$this->assertNoPattern('/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
} }
function testRadio() { function testRadio() {
$result = $this->Form->radio('Model.field', array('option A')); $result = $this->Form->radio('Model.field', array('option A'));
$this->assertPattern('/id="ModelField0"/', $result); $expected = array(
$this->assertNoPattern('/^<fieldset><legend>Field<\/legend>$/', $result); 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
$this->assertPattern('/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){1}/', $result); array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
'label' => array('for' => 'ModelField0'),
'option A',
'!label'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('option A', 'option B')); $result = $this->Form->radio('Model.field', array('option A', 'option B'));
$this->assertPattern('/id="ModelField0"/', $result); $expected = array(
$this->assertPattern('/id="ModelField1"/', $result); 'fieldset' => array(),
$this->assertNoPattern('/checked="checked"/', $result); 'legend' => array(),
$this->assertPattern('/^<fieldset><legend>Field<\/legend><input[^<>]+>(<input[^<>]+><label[^<>]+>option [AB]<\/label>)+<\/fieldset>$/', $result); 'Field',
$this->assertPattern('/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); '!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'option A',
'!label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'option B',
'!label',
'!fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('separator' => '<br/>')); $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('separator' => '<br/>'));
$this->assertPattern('/id="ModelField0"/', $result); $expected = array(
$this->assertPattern('/id="ModelField1"/', $result); 'fieldset' => array(),
$this->assertNoPattern('/checked="checked"/', $result); 'legend' => array(),
$this->assertPattern('/^<fieldset><legend>Field<\/legend><input[^<>]+><input[^<>]+><label[^<>]+>option A<\/label><br[^<>+]><input[^<>]+><label[^<>]+>option B<\/label><\/fieldset>$/', $result); 'Field',
$this->assertPattern('/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); '!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'option A',
'!label',
'br' => array(),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'option B',
'!label',
'!fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1')); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1'));
$this->assertPattern('/id="ModelField1".*checked="checked"/', $result); $expected = array(
$this->assertPattern('/id="ModelField0"/', $result); 'fieldset' => array(),
$this->assertPattern('/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); 'legend' => array(),
'Field',
'!legend',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'checked' => 'checked')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'!label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'!label',
'!fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0')); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0'));
$this->assertPattern('/id="ModelField1"/', $result); $expected = array(
$this->assertPattern('/id="ModelField0".*checked="checked"/', $result); 'fieldset' => array(),
$this->assertPattern('/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); 'legend' => array(),
'Field',
'!legend',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'!label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')),
array('label' => array('for' => 'ModelField0')),
'No',
'!label',
'!fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null)); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null));
$this->assertPattern('/id="ModelField1"/', $result); $expected = array(
$this->assertPattern('/id="ModelField0"\svalue="0"\s(?!checked="checked")/', $result); 'fieldset' => array(),
'legend' => array(),
'Field',
'!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'!label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'!label',
'!fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No')); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'));
$this->assertPattern('/id="ModelField1"/', $result); $expected = array(
$this->assertPattern('/id="ModelField0"\svalue="0"\s(?!checked="checked")/', $result); 'fieldset' => array(),
'legend' => array(),
'Field',
'!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'!label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'!label',
'!fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = '<div class="input"><fieldset><legend>Legend title</legend><input type="hidden" name="data[Newsletter][subscribe]" value="" id="NewsletterSubscribe_" /><input type="radio" name="data[Newsletter][subscribe]" id="NewsletterSubscribe0" value="0" /><label for="NewsletterSubscribe0">Unsubscribe</label><input type="radio" name="data[Newsletter][subscribe]" id="NewsletterSubscribe1" value="1" /><label for="NewsletterSubscribe1">Subscribe</label></fieldset></div>'; $expected = array(
$this->assertEqual($result, $expected); 'div' => array('class' => 'input'),
'fieldset' => array(),
'legend' => array(),
'Legend title',
'!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'),
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')),
array('label' => array('for' => 'NewsletterSubscribe0')),
'Unsubscribe',
'!label',
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')),
array('label' => array('for' => 'NewsletterSubscribe1')),
'Subscribe',
'!label',
'!fieldset',
'!div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = '<div class="input"><input type="hidden" name="data[Newsletter][subscribe]" value="" id="NewsletterSubscribe_" /><input type="radio" name="data[Newsletter][subscribe]" id="NewsletterSubscribe0" value="0" /><label for="NewsletterSubscribe0">Unsubscribe</label><input type="radio" name="data[Newsletter][subscribe]" id="NewsletterSubscribe1" value="1" /><label for="NewsletterSubscribe1">Subscribe</label></div>'; $expected = array(
$this->assertEqual($result, $expected); 'div' => array('class' => 'input'),
'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'),
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')),
array('label' => array('for' => 'NewsletterSubscribe0')),
'Unsubscribe',
'!label',
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')),
array('label' => array('for' => 'NewsletterSubscribe1')),
'Subscribe',
'!label',
'!div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = '<div class="input"><fieldset><legend>Legend title</legend><input type="hidden" name="data[Newsletter][subscribe]" value="" id="NewsletterSubscribe_" /><input type="radio" name="data[Newsletter][subscribe]" id="NewsletterSubscribe0" value="0" />Unsubscribe<input type="radio" name="data[Newsletter][subscribe]" id="NewsletterSubscribe1" value="1" />Subscribe</fieldset></div>'; $expected = array(
$this->assertEqual($result, $expected); 'div' => array('class' => 'input'),
'fieldset' => array(),
'legend' => array(),
'Legend title',
'!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'),
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')),
'Unsubscribe',
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')),
'Subscribe',
'!fieldset',
'!div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = '<div class="input"><input type="hidden" name="data[Newsletter][subscribe]" value="" id="NewsletterSubscribe_" /><input type="radio" name="data[Newsletter][subscribe]" id="NewsletterSubscribe0" value="0" />Unsubscribe<input type="radio" name="data[Newsletter][subscribe]" id="NewsletterSubscribe1" value="1" />Subscribe</div>'; $expected = array(
$this->assertEqual($result, $expected); 'div' => array('class' => 'input'),
'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'),
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')),
'Unsubscribe',
array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')),
'Subscribe',
'!div'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female')); $result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female'));
$expected = '<fieldset><legend>Gender</legend><input type="hidden" name="data[Employee][gender]" value="" id="EmployeeGender_" /><input type="radio" name="data[Employee][gender]" id="EmployeeGenderMale" value="male" /><label for="EmployeeGenderMale">Male</label><input type="radio" name="data[Employee][gender]" id="EmployeeGenderFemale" value="female" /><label for="EmployeeGenderFemale">Female</label></fieldset>'; $expected = array(
$this->assertEqual($result, $expected); 'fieldset' => array(),
'legend' => array(),
'Gender',
'!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_'),
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale')),
array('label' => array('for' => 'EmployeeGenderMale')),
'Male',
'!label',
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale')),
array('label' => array('for' => 'EmployeeGenderFemale')),
'Female',
'!label',
'!fieldset',
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Officer.gender', array('male' => 'Male', 'female' => 'Female')); $result = $this->Form->radio('Officer.gender', array('male' => 'Male', 'female' => 'Female'));
$expected = '<fieldset><legend>Gender</legend><input type="hidden" name="data[Officer][gender]" value="" id="OfficerGender_" /><input type="radio" name="data[Officer][gender]" id="OfficerGenderMale" value="male" /><label for="OfficerGenderMale">Male</label><input type="radio" name="data[Officer][gender]" id="OfficerGenderFemale" value="female" /><label for="OfficerGenderFemale">Female</label></fieldset>'; $expected = array(
$this->assertEqual($result, $expected); 'fieldset' => array(),
'legend' => array(),
'Gender',
'!legend',
'input' => array('type' => 'hidden', 'name' => 'data[Officer][gender]', 'value' => '', 'id' => 'OfficerGender_'),
array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'male', 'id' => 'OfficerGenderMale')),
array('label' => array('for' => 'OfficerGenderMale')),
'Male',
'!label',
array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'female', 'id' => 'OfficerGenderFemale')),
array('label' => array('for' => 'OfficerGenderFemale')),
'Female',
'!label',
'!fieldset',
);
$this->assertTags($result, $expected);
} }
function testSelect() { function testSelect() {
$result = $this->Form->select('Model.field', array()); $result = $this->Form->select('Model.field', array());
$this->assertPattern('/^<select [^<>]+>\n<option [^<>]+>/', $result); $expected = array(
$this->assertPattern('/<option value=""><\/option>/', $result); 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
$this->assertPattern('/<\/select>$/', $result); array('option' => array('value' => '')),
$this->assertPattern('/<select[^<>]+name="data\[Model\]\[field\]"[^<>]*>/', $result); '!option',
$this->assertPattern('/<select[^<>]+id="ModelField"[^<>]*>/', $result); '!select'
$this->assertNoPattern('/^<select[^<>]+name="[^<>]+name="[^<>]+>$/', $result); );
$this->assertTags($result, $expected);
$this->Form->data = array('Model' => array('field' => 'value')); $this->Form->data = array('Model' => array('field' => 'value'));
$result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad')); $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
$this->assertPattern('/option value=""/', $result); $expected = array(
$this->assertPattern('/option value="value"\s+selected="selected"/', $result); 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
$this->assertPattern('/option value="other"/', $result); array('option' => array('value' => '')),
$this->assertPattern('/<\/option>\s+<option/', $result); '!option',
$this->assertPattern('/<\/option>\s+<\/select>/', $result); array('option' => array('value' => 'value', 'selected' => 'selected')),
$this->assertNoPattern('/option value="other"\s+selected="selected"/', $result); 'good',
$this->assertNoPattern('/<select[^<>]+[^name|id]=[^<>]*>/', $result); '!option',
$this->assertNoPattern('/<option[^<>]+[^value|selected]=[^<>]*>/', $result); array('option' => array('value' => 'other')),
'bad',
'!option',
'!select'
);
$this->assertTags($result, $expected);
$this->Form->data = array(); $this->Form->data = array();
$result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad')); $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
$this->assertPattern('/option value=""/', $result); $expected = array(
$this->assertPattern('/option value="value"/', $result); 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
$this->assertPattern('/option value="other"/', $result); array('option' => array('value' => '')),
$this->assertPattern('/<\/option>\s+<option/', $result); '!option',
$this->assertPattern('/<\/option>\s+<\/select>/', $result); array('option' => array('value' => 'value')),
$this->assertNoPattern('/option value="field"\s+selected="selected"/', $result); 'good',
$this->assertNoPattern('/option value="other"\s+selected="selected"/', $result); '!option',
array('option' => array('value' => 'other')),
'bad',
'!option',
'!select'
);
$this->assertTags($result, $expected);
$result = $this->Form->select('Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'), null, array(), false); $result = $this->Form->select('Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'), null, array(), false);
$this->assertPattern('/' . $expected = array(
'<select[^>]*>\s*' . 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
'<option\s+value="first"[^>]*>first &quot;html&quot; &lt;chars&gt;<\/option>\s+'. array('option' => array('value' => 'first')),
'<option\s+value="second"[^>]*>value<\/option>\s+'. 'first &quot;html&quot; &lt;chars&gt;',
'<\/select>/i', '!option',
$result); array('option' => array('value' => 'second')),
'value',
'!option',
'!select'
);
$this->assertTags($result, $expected);
$result = $this->Form->select('Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'), null, array('escape' => false), false); $result = $this->Form->select('Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'), null, array('escape' => false), false);
$this->assertPattern('/' . $expected = array(
'<select[^>]*>\s*' . 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
'<option[^<>\/]+value="first"[^>]*>first "html" <chars><\/option>\s+'. array('option' => array('value' => 'first')),
'<option[^<>\/]+value="second"[^>]*>value<\/option>\s+'. 'first "html" <chars>',
'<\/select>'. '!option',
'/i', array('option' => array('value' => 'second')),
$result); 'value',
'!option',
'!select'
);
$this->assertTags($result, $expected);
} }
function testSelectMultiple() { function testSelectMultiple() {

View file

@ -454,10 +454,7 @@ class CakeTestCase extends UnitTestCase {
} }
} }
foreach ($normalized as $tags) { foreach ($normalized as $tags) {
if (is_string($tags) || (is_array($tags) && count($tags) == 1 && !empty($tags[0]))) { if (is_string($tags)) {
if (is_array($tags)) {
$tags = $tags[0];
}
if ($tags{0} == '!') { if ($tags{0} == '!') {
$regex[] = '<[\s]*\/[\s]*'.substr($tags, 1).'[\s]*>'; $regex[] = '<[\s]*\/[\s]*'.substr($tags, 1).'[\s]*>';
continue; continue;