mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Updating more tests on FormHelperTest case
This commit is contained in:
parent
ba012ed950
commit
4ed46cf330
1 changed files with 65 additions and 58 deletions
|
@ -2700,10 +2700,11 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$result = $this->Form->text('Model.text');
|
$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->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;
|
$Contact = ClassRegistry::getObject('Contact');
|
||||||
$this->Form->request->data['Model']['text'] = 'test';
|
$Contact->validationErrors['text'] = array(true);
|
||||||
$result = $this->Form->text('Model.text', array('id' => 'theID'));
|
$this->Form->request->data['Contact']['text'] = 'test';
|
||||||
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
|
$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';
|
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
|
||||||
$result = $this->Form->text('Model.0.OtherModel.field', array('id' => 'myId'));
|
$result = $this->Form->text('Model.0.OtherModel.field', array('id' => 'myId'));
|
||||||
|
@ -2766,35 +2767,36 @@ class FormHelperTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testError() {
|
public function testError() {
|
||||||
$this->Form->validationErrors['Model']['field'] = array(1);
|
$Contact = ClassRegistry::getObject('Contact');
|
||||||
$result = $this->Form->error('Model.field');
|
$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'));
|
$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->assertEqual($result, 'Error in field Field');
|
||||||
|
|
||||||
$this->Form->validationErrors['Model']['field'] = array("This field contains invalid input");
|
$Contact->validationErrors['field'] = array("This field contains invalid input");
|
||||||
$result = $this->Form->error('Model.field', null, array('wrap' => false));
|
$result = $this->Form->error('Contact.field', null, array('wrap' => false));
|
||||||
$this->assertEqual($result, 'This field contains invalid input');
|
$this->assertEqual($result, 'This field contains invalid input');
|
||||||
|
|
||||||
$this->Form->validationErrors['Model']['field'] = array("This field contains invalid input");
|
$Contact->validationErrors['field'] = array("This field contains invalid input");
|
||||||
$result = $this->Form->error('Model.field', null, array('wrap' => 'span'));
|
$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'));
|
$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'));
|
$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, '<strong>Badness!</strong>');
|
$this->assertEqual($result, '<strong>Badness!</strong>');
|
||||||
|
|
||||||
$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, '<strong>Badness!</strong>');
|
$this->assertEqual($result, '<strong>Badness!</strong>');
|
||||||
|
|
||||||
$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->assertEqual($result, '<strong>Badness!</strong>');
|
||||||
|
|
||||||
$this->Form->validationErrors['Model']['field'] = array("email");
|
$Contact->validationErrors['field'] = array("email");
|
||||||
$result = $this->Form->error('Model.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
|
$result = $this->Form->error('Contact.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'div' => array('class' => 'field-error'),
|
'div' => array('class' => 'field-error'),
|
||||||
'No good!',
|
'No good!',
|
||||||
|
@ -2802,8 +2804,8 @@ class FormHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$this->Form->validationErrors['Model']['field'] = array('notEmpty', 'email', 'Something else');
|
$Contact->validationErrors['field'] = array('notEmpty', 'email', 'Something else');
|
||||||
$result = $this->Form->error('Model.field', array(
|
$result = $this->Form->error('Contact.field', array(
|
||||||
'notEmpty' => 'Cannot be empty',
|
'notEmpty' => 'Cannot be empty',
|
||||||
'email' => 'No good!'
|
'email' => 'No good!'
|
||||||
));
|
));
|
||||||
|
@ -2819,9 +2821,9 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
/** Testing error messages list options **/
|
/** 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(
|
$expected = array(
|
||||||
'div' => array('class' => 'error-message'),
|
'div' => array('class' => 'error-message'),
|
||||||
'ol' => array(),
|
'ol' => array(),
|
||||||
|
@ -2832,7 +2834,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$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(
|
$expected = array(
|
||||||
'div' => array('class' => 'error-message'),
|
'div' => array('class' => 'error-message'),
|
||||||
'ol' => array(),
|
'ol' => array(),
|
||||||
|
@ -2843,7 +2845,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$result = $this->Form->error('Model.field', null, array(
|
$result = $this->Form->error('Contact.field', null, array(
|
||||||
'listOptions' => array(
|
'listOptions' => array(
|
||||||
'class' => 'ul-class',
|
'class' => 'ul-class',
|
||||||
'itemOptions' => array(
|
'itemOptions' => array(
|
||||||
|
@ -2869,7 +2871,8 @@ class FormHelperTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testInputErrorEscape() {
|
public function testInputErrorEscape() {
|
||||||
$this->Form->create('ValidateProfile');
|
$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))));
|
$result = $this->Form->input('city',array('error' => array('attributes' => array('escape' => true))));
|
||||||
$this->assertPattern('/required<br>/', $result);
|
$this->assertPattern('/required<br>/', $result);
|
||||||
|
|
||||||
|
@ -2886,13 +2889,14 @@ class FormHelperTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testPassword() {
|
public function testPassword() {
|
||||||
$result = $this->Form->password('Model.field');
|
$Contact = ClassRegistry::getObject('Contact');
|
||||||
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
|
$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;
|
$Contact->validationErrors['passwd'] = 1;
|
||||||
$this->Form->request->data['Model']['passwd'] = 'test';
|
$this->Form->request->data['Contact']['passwd'] = 'test';
|
||||||
$result = $this->Form->password('Model.passwd', array('id' => 'theID'));
|
$result = $this->Form->password('Contact.passwd', array('id' => 'theID'));
|
||||||
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
|
$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->assertTags($result, $expected);
|
||||||
|
|
||||||
$this->Form->validationErrors['Model']['tags'] = 'Select atleast one option';
|
$Contact = ClassRegistry::getObject('Contact');
|
||||||
$result = $this->Form->input('Model.tags', array(
|
$Contact->validationErrors['tags'] = 'Select atleast one option';
|
||||||
|
$result = $this->Form->input('Contact.tags', array(
|
||||||
'options' => array('one'),
|
'options' => array('one'),
|
||||||
'multiple' => 'checkbox',
|
'multiple' => 'checkbox',
|
||||||
'label' => false,
|
'label' => false,
|
||||||
'div' => false
|
'div' => false
|
||||||
));
|
));
|
||||||
$expected = array(
|
$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('div' => array('class' => 'checkbox form-error')),
|
||||||
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '0', 'id' => 'ModelTags0')),
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
|
||||||
array('label' => array('for' => 'ModelTags0')),
|
array('label' => array('for' => 'ContactTags0')),
|
||||||
'one',
|
'one',
|
||||||
'/label',
|
'/label',
|
||||||
'/div'
|
'/div'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$result = $this->Form->input('Model.tags', array(
|
$result = $this->Form->input('Contact.tags', array(
|
||||||
'options' => array('one'),
|
'options' => array('one'),
|
||||||
'multiple' => 'checkbox',
|
'multiple' => 'checkbox',
|
||||||
'class' => 'mycheckbox',
|
'class' => 'mycheckbox',
|
||||||
|
@ -3835,10 +3840,10 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'div' => false
|
'div' => false
|
||||||
));
|
));
|
||||||
$expected = array(
|
$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('div' => array('class' => 'mycheckbox form-error')),
|
||||||
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '0', 'id' => 'ModelTags0')),
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
|
||||||
array('label' => array('for' => 'ModelTags0')),
|
array('label' => array('for' => 'ContactTags0')),
|
||||||
'one',
|
'one',
|
||||||
'/label',
|
'/label',
|
||||||
'/div'
|
'/div'
|
||||||
|
@ -4128,35 +4133,36 @@ class FormHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$this->Form->validationErrors['Model']['field'] = 1;
|
$Contact = ClassRegistry::getObject('Contact');
|
||||||
$this->Form->request->data['Model']['field'] = 'myvalue';
|
$Contact->validationErrors['field'] = 1;
|
||||||
$result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
|
$this->Form->request->data['Contact']['field'] = 'myvalue';
|
||||||
|
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID', 'value' => 'myvalue'));
|
||||||
$expected = array(
|
$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'))
|
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'theID', 'checked' => 'checked', 'class' => 'form-error'))
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$result = $this->Form->checkbox('Model.field', array('value' => 'myvalue'));
|
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
|
||||||
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'ModelField', 'checked' => 'checked', 'class' => 'form-error'))
|
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'ContactField', 'checked' => 'checked', 'class' => 'form-error'))
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$this->Form->request->data['Model']['field'] = '';
|
$this->Form->request->data['Contact']['field'] = '';
|
||||||
$result = $this->Form->checkbox('Model.field', array('id' => 'theID'));
|
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID'));
|
||||||
$expected = array(
|
$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('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error'))
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error'))
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
unset($this->Form->validationErrors['Model']['field']);
|
$Contact->validationErrors = array();
|
||||||
$result = $this->Form->checkbox('Model.field', array('value' => 'myvalue'));
|
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
|
||||||
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'ModelField'))
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => 'myvalue', 'id' => 'ContactField'))
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
@ -5532,11 +5538,12 @@ class FormHelperTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testHiddenField() {
|
public function testHiddenField() {
|
||||||
$this->Form->validationErrors['Model']['field'] = 1;
|
$Contact = ClassRegistry::getObject('Contact');
|
||||||
$this->Form->request->data['Model']['field'] = 'test';
|
$Contact->validationErrors['field'] = 1;
|
||||||
$result = $this->Form->hidden('Model.field', array('id' => 'theID'));
|
$this->Form->request->data['Contact']['field'] = 'test';
|
||||||
|
$result = $this->Form->hidden('Contact.field', array('id' => 'theID'));
|
||||||
$this->assertTags($result, array(
|
$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'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue