Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Splitting a long test for FormHelper up into smaller test cases.

  • Loading branch information...
commit 604b7e0a100b64ddeef7988e416645279f57ddaa 1 parent a4d09a8
@markstory markstory authored
Showing with 193 additions and 179 deletions.
  1. +193 −179 cake/tests/cases/libs/view/helpers/form.test.php
View
372 cake/tests/cases/libs/view/helpers/form.test.php
@@ -1499,50 +1499,6 @@ function testFormInput() {
);
$this->assertTags($result, $expected);
- $result = $this->Form->input('email', array(
- 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true)
- );
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'email'),
- 'Email',
- '/label',
- array('select' => array('name' => 'data[email]', 'id' => 'email')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => 'è')),
- 'Firést',
- '/option',
- array('option' => array('value' => 'é')),
- 'Secoènd',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
-
- $result = $this->Form->input('email', array(
- 'options' => array('First', 'Second'), 'empty' => true)
- );
- $expected = array(
- 'div' => array('class' => 'input select'),
- 'label' => array('for' => 'email'),
- 'Email',
- '/label',
- array('select' => array('name' => 'data[email]', 'id' => 'email')),
- array('option' => array('value' => '')),
- '/option',
- array('option' => array('value' => '0')),
- 'First',
- '/option',
- array('option' => array('value' => '1')),
- 'Second',
- '/option',
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
-
$result = $this->Form->input('Contact.email', array(
'type' => 'file', 'class' => 'textbox'
));
@@ -1559,84 +1515,6 @@ function testFormInput() {
);
$this->assertTags($result, $expected);
- $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
- $result = explode(':', $result);
- $this->assertPattern('/option value="23"/', $result[0]);
- $this->assertNoPattern('/option value="24"/', $result[0]);
-
- $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
- $result = explode(':', $result);
- $this->assertPattern('/option value="23"/', $result[0]);
- $this->assertNoPattern('/option value="24"/', $result[0]);
-
- $result = $this->Form->input('Model.field', array(
- 'type' => 'time', 'timeFormat' => 24, 'interval' => 15
- ));
- $result = explode(':', $result);
- $this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
- $this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
- $this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
-
- $result = $this->Form->input('Model.field', array(
- 'type' => 'time', 'timeFormat' => 12, 'interval' => 15
- ));
- $result = explode(':', $result);
- $this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
- $this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
- $this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
-
- $result = $this->Form->input('prueba', array(
- 'type' => 'time', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008,
- 'maxYear' => date('Y') + 1 ,'interval' => 15
- ));
- $result = explode(':', $result);
- $this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
- $this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
- $this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
- $this->assertPattern('#<option value="30"[^>]*>30</option>#', $result[1]);
-
- $result = $this->Form->input('prueba', array(
- 'type' => 'datetime', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008,
- 'maxYear' => date('Y') + 1 ,'interval' => 15
- ));
- $result = explode(':', $result);
- $this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
- $this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
- $this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
- $this->assertPattern('#<option value="30"[^>]*>30</option>#', $result[1]);
-
- //related to ticket #5013
- $result = $this->Form->input('Contact.date', array(
- 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
- ));
- $this->assertPattern('/class="customClass"/', $result);
- $this->assertPattern('/onChange="function\(\)\{\}"/', $result);
-
- $result = $this->Form->input('Contact.date', array(
- 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
- ));
- $this->assertPattern('/id="customIdDay"/', $result);
- $this->assertPattern('/id="customIdMonth"/', $result);
- $this->assertPattern('/onChange="function\(\)\{\}"/', $result);
-
- $result = $this->Form->input('Model.field', array(
- 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
- ));
- $this->assertPattern('/id="customIDDay"/', $result);
- $this->assertPattern('/id="customIDHour"/', $result);
- $result = explode('</select><select', $result);
- $result = explode(':', $result[1]);
- $this->assertPattern('/option value="23"/', $result[0]);
- $this->assertNoPattern('/option value="24"/', $result[0]);
-
- $result = $this->Form->input('Model.field', array(
- 'type' => 'datetime', 'timeFormat' => 12
- ));
- $result = explode('</select><select', $result);
- $result = explode(':', $result[1]);
- $this->assertPattern('/option value="12"/', $result[0]);
- $this->assertNoPattern('/option value="13"/', $result[0]);
-
$this->Form->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
$result = $this->Form->input('Contact.phone');
$expected = array(
@@ -1653,7 +1531,6 @@ function testFormInput() {
);
$this->assertTags($result, $expected);
-
$this->Form->data['Model']['0']['OtherModel']['field'] = 'My value';
$result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId'));
$expected = array(
@@ -1770,6 +1647,199 @@ function testFormInput() {
);
$this->assertTags($result, $expected);
+ $this->Form->validationErrors['Model']['field'] = 'minLength';
+ $result = $this->Form->input('Model.field', array('error' => array('minLength' => __('Le login doit contenir au moins 2 caractères', true))));
+ $expected = array(
+ 'div' => array('class' => 'input text error'),
+ 'label' => array('for' => 'ModelField'),
+ 'Field',
+ '/label',
+ 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'),
+ array('div' => array('class' => 'error-message')),
+ 'Le login doit contenir au moins 2 caractères',
+ '/div',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+ }
+/**
+ * test form->input() with datetime, date and time types
+ *
+ * @return void
+ **/
+ function testInputDatetime() {
+ extract($this->dateRegex);
+ $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
+ $result = explode(':', $result);
+ $this->assertPattern('/option value="23"/', $result[0]);
+ $this->assertNoPattern('/option value="24"/', $result[0]);
+
+ $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
+ $result = explode(':', $result);
+ $this->assertPattern('/option value="23"/', $result[0]);
+ $this->assertNoPattern('/option value="24"/', $result[0]);
+
+ $result = $this->Form->input('Model.field', array(
+ 'type' => 'time', 'timeFormat' => 24, 'interval' => 15
+ ));
+ $result = explode(':', $result);
+ $this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
+ $this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
+ $this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
+
+ $result = $this->Form->input('Model.field', array(
+ 'type' => 'time', 'timeFormat' => 12, 'interval' => 15
+ ));
+ $result = explode(':', $result);
+ $this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
+ $this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
+ $this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
+
+ $result = $this->Form->input('prueba', array(
+ 'type' => 'time', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008,
+ 'maxYear' => date('Y') + 1 ,'interval' => 15
+ ));
+ $result = explode(':', $result);
+ $this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
+ $this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
+ $this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
+ $this->assertPattern('#<option value="30"[^>]*>30</option>#', $result[1]);
+
+ $result = $this->Form->input('prueba', array(
+ 'type' => 'datetime', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008,
+ 'maxYear' => date('Y') + 1 ,'interval' => 15
+ ));
+ $result = explode(':', $result);
+ $this->assertNoPattern('#<option value="12"[^>]*>12</option>#', $result[1]);
+ $this->assertNoPattern('#<option value="50"[^>]*>50</option>#', $result[1]);
+ $this->assertPattern('#<option value="15"[^>]*>15</option>#', $result[1]);
+ $this->assertPattern('#<option value="30"[^>]*>30</option>#', $result[1]);
+
+ //related to ticket #5013
+ $result = $this->Form->input('Contact.date', array(
+ 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
+ ));
+ $this->assertPattern('/class="customClass"/', $result);
+ $this->assertPattern('/onChange="function\(\)\{\}"/', $result);
+
+ $result = $this->Form->input('Contact.date', array(
+ 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
+ ));
+ $this->assertPattern('/id="customIdDay"/', $result);
+ $this->assertPattern('/id="customIdMonth"/', $result);
+ $this->assertPattern('/onChange="function\(\)\{\}"/', $result);
+
+ $result = $this->Form->input('Model.field', array(
+ 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
+ ));
+ $this->assertPattern('/id="customIDDay"/', $result);
+ $this->assertPattern('/id="customIDHour"/', $result);
+ $result = explode('</select><select', $result);
+ $result = explode(':', $result[1]);
+ $this->assertPattern('/option value="23"/', $result[0]);
+ $this->assertNoPattern('/option value="24"/', $result[0]);
+
+ $result = $this->Form->input('Model.field', array(
+ 'type' => 'datetime', 'timeFormat' => 12
+ ));
+ $result = explode('</select><select', $result);
+ $result = explode(':', $result[1]);
+ $this->assertPattern('/option value="12"/', $result[0]);
+ $this->assertNoPattern('/option value="13"/', $result[0]);
+
+ $this->Form->data = array('Contact' => array('created' => null));
+ $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
+ $expected = array(
+ 'div' => array('class' => 'input date'),
+ 'label' => array('for' => 'ContactCreatedMonth'),
+ 'Created',
+ '/label',
+ array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')),
+ array('option' => array('value' => '')), 'Date Unknown', '/option',
+ $monthsRegex,
+ '/select', '-',
+ array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')),
+ array('option' => array('value' => '')), 'Date Unknown', '/option',
+ $daysRegex,
+ '/select', '-',
+ array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')),
+ array('option' => array('value' => '')), 'Date Unknown', '/option',
+ $yearsRegex,
+ '/select',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+ }
+/**
+ * Test generating checkboxes in a loop.
+ *
+ * @return void
+ **/
+ function testInputCheckboxesInLoop() {
+ for ($i = 1; $i < 5; $i++) {
+ $result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i));
+ $expected = array(
+ 'div' => array('class' => 'input checkbox'),
+ 'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"),
+ array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")),
+ 'label' => array('for' => "Contact{$i}Email"),
+ 'Email',
+ '/label',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+ }
+ }
+/**
+ * test form->input() with select type inputs.
+ *
+ * @return void
+ **/
+ function testInputSelectType() {
+ $result = $this->Form->input('email', array(
+ 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true)
+ );
+ $expected = array(
+ 'div' => array('class' => 'input select'),
+ 'label' => array('for' => 'email'),
+ 'Email',
+ '/label',
+ array('select' => array('name' => 'data[email]', 'id' => 'email')),
+ array('option' => array('value' => '')),
+ '/option',
+ array('option' => array('value' => 'è')),
+ 'Firést',
+ '/option',
+ array('option' => array('value' => 'é')),
+ 'Secoènd',
+ '/option',
+ '/select',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+
+ $result = $this->Form->input('email', array(
+ 'options' => array('First', 'Second'), 'empty' => true)
+ );
+ $expected = array(
+ 'div' => array('class' => 'input select'),
+ 'label' => array('for' => 'email'),
+ 'Email',
+ '/label',
+ array('select' => array('name' => 'data[email]', 'id' => 'email')),
+ array('option' => array('value' => '')),
+ '/option',
+ array('option' => array('value' => '0')),
+ 'First',
+ '/option',
+ array('option' => array('value' => '1')),
+ 'Second',
+ '/option',
+ '/select',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+
$this->Form->data = array('Model' => array('user_id' => 'value'));
$view =& ClassRegistry::getObject('view');
$view->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
@@ -1841,33 +1911,6 @@ function testFormInput() {
);
$this->assertTags($result, $expected);
- extract($this->dateRegex);
-
- $this->Form->data = array('Contact' => array('created' => null));
- $view =& ClassRegistry::getObject('view');
- $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
- $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
- $expected = array(
- 'div' => array('class' => 'input date'),
- 'label' => array('for' => 'ContactCreatedMonth'),
- 'Created',
- '/label',
- array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')),
- array('option' => array('value' => '')), 'Date Unknown', '/option',
- $monthsRegex,
- '/select', '-',
- array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')),
- array('option' => array('value' => '')), 'Date Unknown', '/option',
- $daysRegex,
- '/select', '-',
- array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')),
- array('option' => array('value' => '')), 'Date Unknown', '/option',
- $yearsRegex,
- '/select',
- '/div'
- );
- $this->assertTags($result, $expected);
-
$this->Form->data = array('User' => array('User' => array('value')));
$view =& ClassRegistry::getObject('view');
$view->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
@@ -1891,35 +1934,6 @@ function testFormInput() {
'/div'
);
$this->assertTags($result, $expected);
-
- $this->Form->validationErrors['Model']['field'] = 'minLength';
- $result = $this->Form->input('Model.field', array('error' => array('minLength' => __('Le login doit contenir au moins 2 caractères', true))));
- $expected = array(
- 'div' => array('class' => 'input text error'),
- 'label' => array('for' => 'ModelField'),
- 'Field',
- '/label',
- 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'),
- array('div' => array('class' => 'error-message')),
- 'Le login doit contenir au moins 2 caractères',
- '/div',
- '/div'
- );
- $this->assertTags($result, $expected);
-
- for ($i = 1; $i < 5; $i++) {
- $result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i));
- $expected = array(
- 'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"),
- array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")),
- 'label' => array('for' => "Contact{$i}Email"),
- 'Email',
- '/label',
- '/div'
- );
- $this->assertTags($result, $expected);
- }
}
/**
* testFormInputs method
Please sign in to comment.
Something went wrong with that request. Please try again.