mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding test cases for FormHelper::error()
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4662 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f8023ff0dc
commit
88563ebe46
2 changed files with 31 additions and 1 deletions
|
@ -215,6 +215,7 @@ class FormHelper extends AppHelper {
|
||||||
*/
|
*/
|
||||||
function error($field, $text = null, $options = array()) {
|
function error($field, $text = null, $options = array()) {
|
||||||
$this->setFormTag($field);
|
$this->setFormTag($field);
|
||||||
|
$options = am(array('wrap' => true, 'class' => 'error-message', 'escape' => true), $options);
|
||||||
|
|
||||||
if ($error = $this->tagIsInvalid()) {
|
if ($error = $this->tagIsInvalid()) {
|
||||||
if ($text != null) {
|
if ($text != null) {
|
||||||
|
@ -222,7 +223,14 @@ class FormHelper extends AppHelper {
|
||||||
} elseif (is_numeric($error)) {
|
} elseif (is_numeric($error)) {
|
||||||
$error = 'Error in field ' . Inflector::humanize($this->field());
|
$error = 'Error in field ' . Inflector::humanize($this->field());
|
||||||
}
|
}
|
||||||
return $this->Html->div('error-message', $error);
|
if ($options['escape']) {
|
||||||
|
$error = h($error);
|
||||||
|
}
|
||||||
|
if ($options['wrap'] === true) {
|
||||||
|
return $this->Html->div($options['class'], $error);
|
||||||
|
} else {
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,6 +144,28 @@ class FormHelperTest extends UnitTestCase {
|
||||||
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
|
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testFieldError() {
|
||||||
|
$this->Form->validationErrors['Model']['field'] = 1;
|
||||||
|
$result = $this->Form->error('Model.field');
|
||||||
|
$this->assertEqual($result, '<div 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');
|
||||||
|
|
||||||
|
$this->Form->validationErrors['Model']['field'] = "This field contains invalid input";
|
||||||
|
$result = $this->Form->error('Model.field', null, array('wrap' => false));
|
||||||
|
$this->assertEqual($result, 'This field contains invalid input');
|
||||||
|
|
||||||
|
$result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false));
|
||||||
|
$this->assertEqual($result, '<strong>Badness!</strong>');
|
||||||
|
|
||||||
|
$result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
|
||||||
|
$this->assertEqual($result, '<strong>Badness!</strong>');
|
||||||
|
|
||||||
|
$result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
|
||||||
|
$this->assertEqual($result, '<strong>Badness!</strong>');
|
||||||
|
}
|
||||||
|
|
||||||
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" />';
|
$expected = '<input name="data[Model][field]" type="password" value="" id="ModelField" />';
|
||||||
|
|
Loading…
Add table
Reference in a new issue