diff --git a/src/Validation/Validator.php b/src/Validation/Validator.php index 54e6b8a..29e81ca 100644 --- a/src/Validation/Validator.php +++ b/src/Validation/Validator.php @@ -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; diff --git a/tests/TestCase/Validation/ValidatorTest.php b/tests/TestCase/Validation/ValidatorTest.php index 1d61c45..e3774d8 100644 --- a/tests/TestCase/Validation/ValidatorTest.php +++ b/tests/TestCase/Validation/ValidatorTest.php @@ -7,6 +7,7 @@ use Cake\Cache\Cache; use Cake\I18n\I18n; use Cake\TestSuite\TestCase; +use Laminas\Diactoros\UploadedFile; /** * Tests for Validator. @@ -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)); @@ -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']]]); } /** @@ -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); }