Updating more tests on FormHelperTest case

This commit is contained in:
Jose Lorenzo Rodriguez 2011-07-14 13:53:10 -04:30
parent ba012ed950
commit 4ed46cf330

View file

@ -2700,10 +2700,11 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->text('Model.text');
$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->request->data['Model']['text'] = 'test';
$result = $this->Form->text('Model.text', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['text'] = array(true);
$this->Form->request->data['Contact']['text'] = 'test';
$result = $this->Form->text('Contact.text', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Contact][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
$result = $this->Form->text('Model.0.OtherModel.field', array('id' => 'myId'));
@ -2766,35 +2767,36 @@ class FormHelperTest extends CakeTestCase {
* @return void
*/
public function testError() {
$this->Form->validationErrors['Model']['field'] = array(1);
$result = $this->Form->error('Model.field');
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['field'] = array(1);
$result = $this->Form->error('Contact.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));
$result = $this->Form->error('Contact.field', null, array('wrap' => false));
$this->assertEqual($result, 'Error in field Field');
$this->Form->validationErrors['Model']['field'] = array("This field contains invalid input");
$result = $this->Form->error('Model.field', null, array('wrap' => false));
$Contact->validationErrors['field'] = array("This field contains invalid input");
$result = $this->Form->error('Contact.field', null, array('wrap' => false));
$this->assertEqual($result, 'This field contains invalid input');
$this->Form->validationErrors['Model']['field'] = array("This field contains invalid input");
$result = $this->Form->error('Model.field', null, array('wrap' => 'span'));
$Contact->validationErrors['field'] = array("This field contains invalid input");
$result = $this->Form->error('Contact.field', null, array('wrap' => 'span'));
$this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span'));
$result = $this->Form->error('Model.field', 'There is an error fool!', array('wrap' => 'span'));
$result = $this->Form->error('Contact.field', 'There is an error fool!', array('wrap' => 'span'));
$this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span'));
$result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false));
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false));
$this->assertEqual($result, '&lt;strong&gt;Badness!&lt;/strong&gt;');
$result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
$this->assertEqual($result, '&lt;strong&gt;Badness!&lt;/strong&gt;');
$result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
$this->assertEqual($result, '<strong>Badness!</strong>');
$this->Form->validationErrors['Model']['field'] = array("email");
$result = $this->Form->error('Model.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
$Contact->validationErrors['field'] = array("email");
$result = $this->Form->error('Contact.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
$expected = array(
'div' => array('class' => 'field-error'),
'No good!',
@ -2802,8 +2804,8 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$this->Form->validationErrors['Model']['field'] = array('notEmpty', 'email', 'Something else');
$result = $this->Form->error('Model.field', array(
$Contact->validationErrors['field'] = array('notEmpty', 'email', 'Something else');
$result = $this->Form->error('Contact.field', array(
'notEmpty' => 'Cannot be empty',
'email' => 'No good!'
));
@ -2819,9 +2821,9 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
/** Testing error messages list options **/
$this->Form->validationErrors['Model']['field'] = array('notEmpty', 'email');
$Contact->validationErrors['field'] = array('notEmpty', 'email');
$result = $this->Form->error('Model.field', null, array('listOptions' => 'ol'));
$result = $this->Form->error('Contact.field', null, array('listOptions' => 'ol'));
$expected = array(
'div' => array('class' => 'error-message'),
'ol' => array(),
@ -2832,7 +2834,7 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Form->error('Model.field', null, array('listOptions' => array('tag' => 'ol')));
$result = $this->Form->error('Contact.field', null, array('listOptions' => array('tag' => 'ol')));
$expected = array(
'div' => array('class' => 'error-message'),
'ol' => array(),
@ -2843,7 +2845,7 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Form->error('Model.field', null, array(
$result = $this->Form->error('Contact.field', null, array(
'listOptions' => array(
'class' => 'ul-class',
'itemOptions' => array(
@ -2869,7 +2871,8 @@ class FormHelperTest extends CakeTestCase {
*/
public function testInputErrorEscape() {
$this->Form->create('ValidateProfile');
$this->Form->validationErrors['ValidateProfile']['city'] = array('required<br>');
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
$ValidateProfile->validationErrors['city'] = array('required<br>');
$result = $this->Form->input('city',array('error' => array('attributes' => array('escape' => true))));
$this->assertPattern('/required&lt;br&gt;/', $result);
@ -2886,13 +2889,14 @@ class FormHelperTest extends CakeTestCase {
* @return void
*/
public function testPassword() {
$result = $this->Form->password('Model.field');
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
$Contact = ClassRegistry::getObject('Contact');
$result = $this->Form->password('Contact.field');
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][field]', 'id' => 'ContactField')));
$this->Form->validationErrors['Model']['passwd'] = 1;
$this->Form->request->data['Model']['passwd'] = 'test';
$result = $this->Form->password('Model.passwd', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
$Contact->validationErrors['passwd'] = 1;
$this->Form->request->data['Contact']['passwd'] = 'test';
$result = $this->Form->password('Contact.passwd', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
}
/**
@ -3809,25 +3813,26 @@ class FormHelperTest extends CakeTestCase {
));
$this->assertTags($result, $expected);
$this->Form->validationErrors['Model']['tags'] = 'Select atleast one option';
$result = $this->Form->input('Model.tags', array(
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['tags'] = 'Select atleast one option';
$result = $this->Form->input('Contact.tags', array(
'options' => array('one'),
'multiple' => 'checkbox',
'label' => false,
'div' => false
));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'),
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
array('div' => array('class' => 'checkbox form-error')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '0', 'id' => 'ModelTags0')),
array('label' => array('for' => 'ModelTags0')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
array('label' => array('for' => 'ContactTags0')),
'one',
'/label',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Model.tags', array(
$result = $this->Form->input('Contact.tags', array(
'options' => array('one'),
'multiple' => 'checkbox',
'class' => 'mycheckbox',
@ -3835,10 +3840,10 @@ class FormHelperTest extends CakeTestCase {
'div' => false
));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'),
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
array('div' => array('class' => 'mycheckbox form-error')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '0', 'id' => 'ModelTags0')),
array('label' => array('for' => 'ModelTags0')),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
array('label' => array('for' => 'ContactTags0')),
'one',
'/label',
'/div'
@ -4128,35 +4133,36 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$this->Form->validationErrors['Model']['field'] = 1;
$this->Form->request->data['Model']['field'] = 'myvalue';
$result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['field'] = 1;
$this->Form->request->data['Contact']['field'] = 'myvalue';
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID', 'value' => 'myvalue'));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'),
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'theID', 'checked' => 'checked', 'class' => 'form-error'))
);
$this->assertTags($result, $expected);
$result = $this->Form->checkbox('Model.field', array('value' => 'myvalue'));
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'ModelField', 'checked' => 'checked', 'class' => 'form-error'))
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'ContactField', 'checked' => 'checked', 'class' => 'form-error'))
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '';
$result = $this->Form->checkbox('Model.field', array('id' => 'theID'));
$this->Form->request->data['Contact']['field'] = '';
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID'));
$expected = array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error'))
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error'))
);
$this->assertTags($result, $expected);
unset($this->Form->validationErrors['Model']['field']);
$result = $this->Form->checkbox('Model.field', array('value' => 'myvalue'));
$Contact->validationErrors = array();
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'ModelField'))
'input' => array('type' => 'hidden', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => 'myvalue', 'id' => 'ContactField'))
);
$this->assertTags($result, $expected);
@ -5532,11 +5538,12 @@ class FormHelperTest extends CakeTestCase {
* @return void
*/
public function testHiddenField() {
$this->Form->validationErrors['Model']['field'] = 1;
$this->Form->request->data['Model']['field'] = 'test';
$result = $this->Form->hidden('Model.field', array('id' => 'theID'));
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['field'] = 1;
$this->Form->request->data['Contact']['field'] = 'test';
$result = $this->Form->hidden('Contact.field', array('id' => 'theID'));
$this->assertTags($result, array(
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Model][field]', 'id' => 'theID', 'value' => 'test'))
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'id' => 'theID', 'value' => 'test'))
);
}