Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ protected function _processRules(string $field, ValidationSet $rules, array $dat
protected function _translateArgs(array $args): array
{
foreach ($args as $k => $arg) {
if (is_string($arg)) {
$args[$k] = __d($this->_validationDomain, $arg);
if (is_array($arg)) {
$arg = implode(', ', $arg);
}

$args[$k] = __d($this->_validationDomain, (string)$arg);
}

return $args;
Expand Down
17 changes: 16 additions & 1 deletion tests/TestCase/Validation/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Cake\Cache\Cache;
use Cake\I18n\I18n;
use Cake\TestSuite\TestCase;
use Laminas\Diactoros\UploadedFile;

/**
* Tests for Validator.
Expand Down Expand Up @@ -80,6 +81,15 @@ public function setUp(): void
'value_0' => 'Message from validation_non_default',
'value_1' => '',
],
[
'domain' => 'validation',
'locale' => I18n::getLocale(),
'context' => '',
'singular' => 'mimeType',
'plural' => '',
'value_0' => 'Valid mime types: {0}',
'value_1' => '',
],
];
foreach ($messages as $row) {
$I18nMessages->save($I18nMessages->newEntity($row));
Expand All @@ -89,7 +99,8 @@ public function setUp(): void

$this->validator
->add('email', 'email', ['rule' => 'email'])
->add('field', 'comparison', ['rule' => ['comparison', '<', 50]]);
->add('field', 'comparison', ['rule' => ['comparison', '<', 50]])
->add('file', 'mimeType', ['rule' => ['mimeType', ['image/jpeg, image/png']]]);
}

/**
Expand All @@ -99,14 +110,18 @@ public function setUp(): void
*/
public function testErrors()
{
$file = new UploadedFile(__FILE__, 1, UPLOAD_ERR_OK, 'foo.txt', 'text/plain');

$errors = $this->validator->validate([
'email' => 'foo',
'field' => '100',
'file' => $file,
]);

$expected = [
'email' => ['email' => 'Enter a valid email'],
'field' => ['comparison' => 'This value must be less than 50'],
'file' => ['mimeType' => 'Valid mime types: image/jpeg, image/png'],
];
$this->assertEquals($expected, $errors);
}
Expand Down