Skip to content

Commit e74dd8d

Browse files
authored
Merge pull request #77 from ADmad/2.x
2.x
2 parents be1e5d1 + 6f5748c commit e74dd8d

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/Validation/Validator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ protected function _processRules(string $field, ValidationSet $rules, array $dat
9090
protected function _translateArgs(array $args): array
9191
{
9292
foreach ($args as $k => $arg) {
93-
if (is_string($arg)) {
94-
$args[$k] = __d($this->_validationDomain, $arg);
93+
if (is_array($arg)) {
94+
$arg = implode(', ', $arg);
9595
}
96+
97+
$args[$k] = __d($this->_validationDomain, (string)$arg);
9698
}
9799

98100
return $args;

tests/TestCase/Validation/ValidatorTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Cake\Core\Configure;
1010
use Cake\I18n\I18n;
1111
use Cake\TestSuite\TestCase;
12+
use Laminas\Diactoros\UploadedFile;
1213

1314
/**
1415
* Tests for Validator.
@@ -83,6 +84,15 @@ public function setUp(): void
8384
'value_0' => 'Message from validation_non_default',
8485
'value_1' => '',
8586
],
87+
[
88+
'domain' => 'validation',
89+
'locale' => I18n::getLocale(),
90+
'context' => '',
91+
'singular' => 'mimeType',
92+
'plural' => '',
93+
'value_0' => 'Valid mime types: {0}',
94+
'value_1' => '',
95+
],
8696
];
8797
foreach ($messages as $row) {
8898
$I18nMessages->save($I18nMessages->newEntity($row));
@@ -92,7 +102,8 @@ public function setUp(): void
92102

93103
$this->validator
94104
->add('email', 'email', ['rule' => 'email'])
95-
->add('field', 'comparison', ['rule' => ['comparison', '<', 50]]);
105+
->add('field', 'comparison', ['rule' => ['comparison', '<', 50]])
106+
->add('file', 'mimeType', ['rule' => ['mimeType', ['image/jpeg, image/png']]]);
96107
}
97108

98109
/**
@@ -102,14 +113,18 @@ public function setUp(): void
102113
*/
103114
public function testErrors()
104115
{
116+
$file = new UploadedFile(__FILE__, 1, UPLOAD_ERR_OK, 'foo.txt', 'text/plain');
117+
105118
$errors = $this->validator->validate([
106119
'email' => 'foo',
107120
'field' => '100',
121+
'file' => $file,
108122
]);
109123

110124
$expected = [
111125
'email' => ['email' => 'Enter a valid email'],
112126
'field' => ['comparison' => 'This value must be less than 50'],
127+
'file' => ['mimeType' => 'Valid mime types: image/jpeg, image/png'],
113128
];
114129
$this->assertEquals($expected, $errors);
115130
}

0 commit comments

Comments
 (0)