Skip to content

Commit 1bf67c1

Browse files
committed
Add tests for #9105
1 parent e38cda7 commit 1bf67c1

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/TestCase/View/Helper/FormHelperTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4149,6 +4149,56 @@ public function testError()
41494149
$this->assertHtml($expected, $result);
41504150
}
41514151

4152+
/**
4153+
* test error translation can use rule names for translating.
4154+
*
4155+
* @return void
4156+
*/
4157+
public function testErrorRuleName()
4158+
{
4159+
$this->article['errors'] = [
4160+
'Article' => [
4161+
'field' => ['email' => 'Your email was not good']
4162+
]
4163+
];
4164+
$this->Form->create($this->article);
4165+
4166+
$result = $this->Form->error('Article.field');
4167+
$expected = [
4168+
['div' => ['class' => 'error-message']],
4169+
'Your email was not good',
4170+
'/div',
4171+
];
4172+
$this->assertHtml($expected, $result);
4173+
4174+
$result = $this->Form->error('Article.field', ['email' => 'Email in use']);
4175+
$expected = [
4176+
['div' => ['class' => 'error-message']],
4177+
'Email in use',
4178+
'/div',
4179+
];
4180+
$this->assertHtml($expected, $result);
4181+
4182+
$result = $this->Form->error('Article.field', ['Your email was not good' => 'Email in use']);
4183+
$expected = [
4184+
['div' => ['class' => 'error-message']],
4185+
'Email in use',
4186+
'/div',
4187+
];
4188+
$this->assertHtml($expected, $result);
4189+
4190+
$result = $this->Form->error('Article.field', [
4191+
'email' => 'Key is preferred',
4192+
'Your email was not good' => 'Email in use'
4193+
]);
4194+
$expected = [
4195+
['div' => ['class' => 'error-message']],
4196+
'Key is preferred',
4197+
'/div',
4198+
];
4199+
$this->assertHtml($expected, $result);
4200+
}
4201+
41524202
/**
41534203
* Test error with nested lists.
41544204
*

0 commit comments

Comments
 (0)