Skip to content

Commit

Permalink
Add test showing how error translation works in FormHelper.
Browse files Browse the repository at this point in the history
Refs #5382
  • Loading branch information
markstory committed Dec 11, 2014
1 parent 48ae07a commit e6762a6
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -1865,6 +1865,60 @@ public function testEmptyInputErrorValidation() {
$this->assertHtml($expected, $result);
}

/**
* Test validation errors, when calling input() overriding validation messages
*
* @return void
*/
public function testInputErrorMessage() {
$this->article['errors'] = [
'title' => ['error message']
];
$this->Form->create($this->article);

$result = $this->Form->input('title', [
'error' => 'Custom error!'
]);
$expected = [
'div' => ['class' => 'input text required error'],
'label' => ['for' => 'title'],
'Title',
'/label',
'input' => [
'type' => 'text', 'name' => 'title',
'id' => 'title', 'class' => 'form-error',
'required' => 'required',
],
['div' => ['class' => 'error-message']],
'Custom error!',
'/div',
'/div'
];
$this->assertHtml($expected, $result);

$result = $this->Form->input('title', [
'error' => ['error message' => 'Custom error!']
]);
$expected = [
'div' => ['class' => 'input text required error'],
'label' => ['for' => 'title'],
'Title',
'/label',
'input' => [
'type' => 'text',
'name' => 'title',
'id' => 'title',
'class' => 'form-error',
'required' => 'required'
],
['div' => ['class' => 'error-message']],
'Custom error!',
'/div',
'/div'
];
$this->assertHtml($expected, $result);
}

/**
* Tests displaying errors for nested entities
*
Expand Down

0 comments on commit e6762a6

Please sign in to comment.