From f7384bca87c973f58be76ba41986461deed73417 Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Sat, 26 Apr 2008 18:44:01 +0000 Subject: [PATCH] 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 --- .../cases/libs/view/helpers/form.test.php | 698 +++++++++++++----- cake/tests/lib/cake_test_case.php | 5 +- 2 files changed, 522 insertions(+), 181 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 031e5a488..f8bbf8c48 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -496,7 +496,7 @@ class FormHelperTest extends CakeTestCase { 'input' => array('type' => 'password', 'name' => 'data[Contact][password]', 'value' => '', 'id' => 'ContactPassword', 'class' => 'form-error'), array('div' => array('class' => 'error-message')), 'Please provide a password', - array('!div'), + '!div', '!div' ); $this->assertTags($result, $expected); @@ -607,7 +607,7 @@ class FormHelperTest extends CakeTestCase { 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), array('div' => array('class' => 'error-message')), 'This field cannot be left blank', - array('!div'), + '!div', '!div' ); $this->assertTags($result, $expected); @@ -623,7 +623,7 @@ class FormHelperTest extends CakeTestCase { 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), array('div' => array('class' => 'error-message')), 'You must provide a URL', - array('!div'), + '!div', '!div' ); $this->assertTags($result, $expected); @@ -644,7 +644,7 @@ class FormHelperTest extends CakeTestCase { 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), array('div' => array('class' => 'error-message')), 'This field cannot be empty', - array('!div'), + '!div', '!div' ); $this->assertTags($result, $expected); @@ -658,7 +658,7 @@ class FormHelperTest extends CakeTestCase { 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), array('div' => array('class' => 'error-message')), 'This field cannot be empty', - array('!div'), + '!div', '!div' ); $this->assertTags($result, $expected); @@ -683,7 +683,7 @@ class FormHelperTest extends CakeTestCase { 'input' => array('type' => 'text', 'name' => 'preg:/.+/', 'value' => '', 'id' => 'preg:/.+/', 'class' => 'form-error'), array('div' => array('class' => 'error-message')), 'You must have a last name', - array('!div'), + '!div', '!div' ); $this->assertTags($result, $expected); @@ -748,13 +748,13 @@ class FormHelperTest extends CakeTestCase { '!label', array('select' => array('name' => 'data[email]', 'id' => 'email')), array('option' => array('value' => '')), - array('!option'), + '!option', array('option' => array('value' => '0')), 'First', - array('!option'), + '!option', array('option' => array('value' => '1')), 'Second', - array('!option'), + '!option', '!select', '!div' ); @@ -819,7 +819,7 @@ class FormHelperTest extends CakeTestCase { 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), array('div' => array('class' => 'error-message')), 'Badness!', - array('!div'), + '!div', '!div' ); $this->assertTags($result, $expected); @@ -834,7 +834,7 @@ class FormHelperTest extends CakeTestCase { 'A message to you, Rudy', array('div' => array('class' => 'error-message')), 'Badness!', - array('!div'), + '!div', '!div' ); $this->assertTags($result, $expected); @@ -877,13 +877,13 @@ class FormHelperTest extends CakeTestCase { '!label', 'select' => array('name' => 'data[Model][user_id]', 'id' => 'ModelUserId'), array('option' => array('value' => '')), - array('!option'), + '!option', array('option' => array('value' => 'value', 'selected' => 'selected')), 'good', - array('!option'), + '!option', array('option' => array('value' => 'other')), 'bad', - array('!option'), + '!option', '!select', '!div' ); @@ -901,13 +901,13 @@ class FormHelperTest extends CakeTestCase { 'input' => array('type' => 'hidden', 'name' => 'data[User][User]', 'value' => ''), 'select' => array('name' => 'data[User][User][]', 'id' => 'UserUser', 'multiple' => 'multiple'), array('option' => array('value' => '')), - array('!option'), + '!option', array('option' => array('value' => 'value', 'selected' => 'selected')), 'good', - array('!option'), + '!option', array('option' => array('value' => 'other')), 'bad', - array('!option'), + '!option', '!select', '!div' ); @@ -917,162 +917,328 @@ class FormHelperTest extends CakeTestCase { function testFormInputs() { $this->Form->create('Contact'); $result = $this->Form->inputs('The Legend'); - $this->assertPattern('/The Legend<\/legend>/', $result); + $expected = array( + 'fieldset' => array(), + 'legend' => array(), + 'The Legend', + '!legend', + 'preg:/.+/', + '!fieldset' + ); + $this->assertTags($result, $expected); $View = ClassRegistry::getObject('view'); $this->Form->create('Contact'); $this->Form->params['prefix'] = 'admin'; $this->Form->action = 'admin_edit'; $result = $this->Form->inputs(); - $this->assertPattern('/Edit Contact<\/legend>/', $result); + $expected = array( + 'fieldset' => array(), + 'legend' => array(), + 'Edit Contact', + '!legend', + 'preg:/.+/', + '!fieldset' + ); + $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs(false); - $this->assertNoPattern('/]*>/', $result); - $this->assertNoPattern('/[^<>]*<\/legend>/', $result); + $expected = 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' + ); + $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs(array('fieldset' => false, 'legend' => false)); - $this->assertNoPattern('/]*>/', $result); - $this->assertNoPattern('/[^<>]*<\/legend>/', $result); + $expected = 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' + ); + $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs(array('fieldset' => true, 'legend' => false)); - $this->assertPattern('/]*>/', $result); - $this->assertNoPattern('/[^<>]*<\/legend>/', $result); + $expected = array( + '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'); $result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello')); - $this->assertNoPattern('/]*>/', $result); - $this->assertNoPattern('/[^<>]*<\/legend>/', $result); + $expected = 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' + ); + $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs('Hello'); - $this->assertPattern('/^
]*>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'); $result = $this->Form->inputs(array('legend' => 'Hello')); - $this->assertPattern('/^
]*>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() { $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => 'checkbox')); - $this->assertPattern('/^]+ \/>\s*(]+>\]+>\s*]*>\w+<\/label><\/div>\s*){3}$/', $result); - $this->assertNoPattern('/]*>[^(first|second)]<\/label>/', $result); - - $this->assertPattern('/^]+type="hidden"[^<>]+\/>/', $result); - $this->assertPattern('/^]+name="data\[Model\]\[multi_field\]"[^<>]+\/>/', $result); - $this->assertPattern('/^]+value=""[^<>]+\/>/', $result); - - $this->assertPattern('/]+type="checkbox"[^<>]+\/>]+>first<\/label>/', $result); - $this->assertPattern('/]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/>]+>first<\/label>/', $result); - $this->assertPattern('/]+checked="checked"[^<>]+\/>]+>first<\/label>/', $result); - $this->assertPattern('/]+value="0"[^<>]+\/>]+>first<\/label>/', $result); - $this->assertPattern('/]+id="ModelMultiField0"[^<>]+\/>]+>first<\/label>/', $result); - $this->assertPattern('/]+\/>]+for="ModelMultiField0"[^<>]*>first<\/label>/', $result); - $this->assertPattern('/]+\/>]+class="selected"[^<>]*>first<\/label>/', $result); - - $this->assertPattern('/]+type="checkbox"[^<>]+\/>]+>second<\/label>/', $result); - $this->assertPattern('/]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/>]+>second<\/label>/', $result); - $this->assertPattern('/]+checked="checked"[^<>]+\/>]+>second<\/label>/', $result); - $this->assertPattern('/]+value="1"[^<>]+\/>]+>second<\/label>/', $result); - $this->assertPattern('/]+id="ModelMultiField1"[^<>]+\/>]+>second<\/label>/', $result); - $this->assertPattern('/]+\/>]+for="ModelMultiField1"[^<>]*>second<\/label>/', $result); - $this->assertPattern('/]+\/>]+class="selected"[^<>]*>second<\/label>/', $result); - - $this->assertPattern('/]+type="checkbox"[^<>]+\/>]+>third<\/label>/', $result); - $this->assertPattern('/]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/>]+>third<\/label>/', $result); - $this->assertPattern('/]+value="2"[^<>]+\/>]+>third<\/label>/', $result); - $this->assertPattern('/]+id="ModelMultiField2"[^<>]+\/>]+>third<\/label>/', $result); - $this->assertPattern('/]+\/>]+for="ModelMultiField2"[^<>]*>third<\/label>/', $result); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), + array('div' => array('class' => 'checkbox')), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')), + array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')), + 'first', + '!label', + '!div', + 'preg:/.+/' + ); + $this->assertTags($result, $expected); + $expected = array( + 'preg:/.+/', + array('div' => array('class' => 'checkbox')), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')), + array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')), + 'second', + '!label', + '!div', + 'preg:/.+/' + ); + $this->assertTags($result, $expected); + $expected = array( + 'preg:/.+/', + array('div' => array('class' => 'checkbox')), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')), + array('label' => array('for' => 'ModelMultiField2')), + 'third', + '!label', + '!div' + ); + $this->assertTags($result, $expected); } function testLabel() { $this->Form->text('Person/name'); $result = $this->Form->label(); - $this->assertEqual($result, ''); + $this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '!label')); $this->Form->text('Person.name'); $result = $this->Form->label(); - $this->assertEqual($result, ''); - - $this->Form->text('Person.Name'); - $result = $this->Form->label(); - $this->assertEqual($result, ''); + $this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '!label')); $result = $this->Form->label('Person.first_name'); - $this->assertEqual($result, ''); + $this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'First Name', '!label')); $result = $this->Form->label('Person.first_name', 'Your first name'); - $this->assertEqual($result, ''); + $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')); - $this->assertPattern('/^]+>Your first name<\/label>$/', $result); - $this->assertPattern('/^]+for="PersonFirstName"[^<>]*>/', $result); - $this->assertPattern('/^]+class="my-class"[^<>]*>/', $result); + $this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class'), 'Your first name', '!label')); $result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID')); - $this->assertEqual($result, ''); + $this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '!label')); $result = $this->Form->label('Person.first_name', ''); - $this->assertEqual($result, ''); + $this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), '!label')); $result = $this->Form->label('Person.2.name', ''); - $this->assertEqual($result, ''); + $this->assertTags($result, array('label' => array('for' => 'Person2Name'), '!label')); } function testTextbox() { $result = $this->Form->text('Model.field'); - $this->assertPattern('/^]+name="data\[Model\]\[field\]"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+type="text"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+value=""[^<>]+\/>$/', $result); - $this->assertPattern('/^]+id="ModelField"[^<>]+\/>$/', $result); - $this->assertNoPattern('/^]+name="[^<>]+name="[^<>]+\/>$/', $result); - $this->assertNoPattern('/]+[^type|name|id|value]=[^<>]*>/', $result); + $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField'))); $result = $this->Form->text('Model.field', array('type' => 'password')); - $this->assertPattern('/^]+name="data\[Model\]\[field\]"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+type="password"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+value=""[^<>]+\/>$/', $result); - $this->assertPattern('/^]+id="ModelField"[^<>]+\/>$/', $result); - $this->assertNoPattern('/^]+name="[^<>]+name="[^<>]+\/>$/', $result); - $this->assertNoPattern('/]+[^type|name|id|value]=[^<>]*>/', $result); + $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField'))); $result = $this->Form->text('Model.field', array('id' => 'theID')); - $expected = ''; - $this->assertEqual($result, $expected); + $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'theID'))); $this->Form->data['Model']['text'] = 'test HTML values'; $result = $this->Form->text('Model/text'); - $this->assertPattern('/^]+type="text"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+name="data\[Model\]\[text\]"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+value="test <strong>HTML<\/strong> values"[^<>]+\/>$/', $result); - $this->assertNoPattern('/^]+name="[^<>]+name="[^<>]+\/>$/', $result); - $this->assertNoPattern('/]+[^type|name|id|value|class]=[^<>]*>/', $result); + $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test <strong>HTML</strong> values', 'id' => 'ModelText'))); $this->Form->validationErrors['Model']['text'] = 1; $this->Form->data['Model']['text'] = 'test'; $result = $this->Form->text('Model/text', array('id' => 'theID')); - $this->assertPattern('/^]+name="data\[Model\]\[text\]"[^<>]+id="theID"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+value="test"[^<>]+class="form-error"[^<>]+\/>$/', $result); - $this->assertNoPattern('/^]+name="[^<>]+name="[^<>]+\/>$/', $result); - $this->assertNoPattern('/]+[^type|name|id|value|class]=[^<>]*>/', $result); + $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error'))); } function testDefaultValue() { $this->Form->data['Model']['field'] = 'test'; $result = $this->Form->text('Model.field', array('default' => 'default value')); - $this->assertPattern('/^]+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']); $result = $this->Form->text('Model.field', array('default' => 'default value')); - $this->assertPattern('/^]+value="default value"[^<>]+\/>$/', $result); + $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'default value', 'id' => 'ModelField'))); } function testFieldError() { $this->Form->validationErrors['Model']['field'] = 1; $result = $this->Form->error('Model.field'); - $this->assertEqual($result, '
Error in field Field
'); + $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '!div')); $result = $this->Form->error('Model.field', null, array('wrap' => false)); $this->assertEqual($result, 'Error in field Field'); @@ -1093,132 +1259,310 @@ class FormHelperTest extends CakeTestCase { function testPassword() { $result = $this->Form->password('Model.field'); - $expected = ''; - $this->assertPattern('/^]+name="data\[Model\]\[field\]"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+type="password"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+value=""[^<>]+\/>$/', $result); - $this->assertPattern('/^]+id="ModelField"[^<>]+\/>$/', $result); - $this->assertNoPattern('/^]+name="[^<>]+name="[^<>]+\/>$/', $result); - $this->assertNoPattern('/]+[^type|name|id|value]=[^<>]*>/', $result); + $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField'))); $this->Form->validationErrors['Model']['passwd'] = 1; $this->Form->data['Model']['passwd'] = 'test'; $result = $this->Form->password('Model/passwd', array('id' => 'theID')); - $this->assertPattern('/^]+name="data\[Model\]\[passwd\]"[^<>]+id="theID"[^<>]+\/>$/', $result); - $this->assertPattern('/^]+value="test"[^<>]+class="form-error"[^<>]+\/>$/', $result); - $this->assertNoPattern('/^]+name="[^<>]+name="[^<>]+\/>$/', $result); - $this->assertNoPattern('/]+[^type|name|id|value|class]=[^<>]*>/', $result); + $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error'))); } function testRadio() { $result = $this->Form->radio('Model.field', array('option A')); - $this->assertPattern('/id="ModelField0"/', $result); - $this->assertNoPattern('/^
Field<\/legend>$/', $result); - $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){1}/', $result); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), + 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')); - $this->assertPattern('/id="ModelField0"/', $result); - $this->assertPattern('/id="ModelField1"/', $result); - $this->assertNoPattern('/checked="checked"/', $result); - $this->assertPattern('/^
Field<\/legend>]+>(]+>]+>option [AB]<\/label>)+<\/fieldset>$/', $result); - $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); + $expected = array( + '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' => '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' => '
')); - $this->assertPattern('/id="ModelField0"/', $result); - $this->assertPattern('/id="ModelField1"/', $result); - $this->assertNoPattern('/checked="checked"/', $result); - $this->assertPattern('/^
Field<\/legend>]+>]+>]+>option A<\/label>+]>]+>]+>option B<\/label><\/fieldset>$/', $result); - $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); + $expected = array( + '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' => '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')); - $this->assertPattern('/id="ModelField1".*checked="checked"/', $result); - $this->assertPattern('/id="ModelField0"/', $result); - $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); + $expected = array( + 'fieldset' => array(), + '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')); - $this->assertPattern('/id="ModelField1"/', $result); - $this->assertPattern('/id="ModelField0".*checked="checked"/', $result); - $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); + $expected = array( + 'fieldset' => array(), + '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)); - $this->assertPattern('/id="ModelField1"/', $result); - $this->assertPattern('/id="ModelField0"\svalue="0"\s(?!checked="checked")/', $result); + $expected = array( + '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')); - $this->assertPattern('/id="ModelField1"/', $result); - $this->assertPattern('/id="ModelField0"\svalue="0"\s(?!checked="checked")/', $result); + $expected = array( + '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'))); - $expected = '
Legend title
'; - $this->assertEqual($result, $expected); + $expected = array( + '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'))); - $expected = '
'; - $this->assertEqual($result, $expected); + $expected = array( + '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'))); - $expected = '
Legend titleUnsubscribeSubscribe
'; - $this->assertEqual($result, $expected); + $expected = array( + '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'))); - $expected = '
UnsubscribeSubscribe
'; - $this->assertEqual($result, $expected); + $expected = array( + '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')); - $expected = '
Gender
'; - $this->assertEqual($result, $expected); + $expected = array( + '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')); - $expected = '
Gender
'; - $this->assertEqual($result, $expected); + $expected = array( + '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() { $result = $this->Form->select('Model.field', array()); - $this->assertPattern('/^