mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-01 20:19:42 +08:00
Fixes #15417: Added yii\validators\FileValidator::$minFiles
This commit is contained in:
committed by
Alexander Makarov
parent
5e3776e482
commit
72b69e359a
@ -235,6 +235,85 @@ class FileValidatorTest extends TestCase
|
||||
$this->assertFalse($m->validate());
|
||||
}
|
||||
|
||||
public function testValidateAttribute_minFilesGreaterThanOneMaxFilesUnlimited_notError()
|
||||
{
|
||||
$validator = new FileValidator(['minFiles' => 2, 'maxFiles' => 0]);
|
||||
$model = FakedValidationModel::createWithAttributes(
|
||||
[
|
||||
'attr_images' => $this->createTestFiles(
|
||||
[
|
||||
[
|
||||
'name' => 'image.png',
|
||||
'size' => 1024,
|
||||
'type' => 'image/png',
|
||||
],
|
||||
[
|
||||
'name' => 'image.png',
|
||||
'size' => 1024,
|
||||
'type' => 'image/png',
|
||||
],
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$validator->validateAttribute($model, 'attr_images');
|
||||
|
||||
$this->assertFalse($model->hasErrors('attr_images'));
|
||||
}
|
||||
|
||||
public function testValidateAttribute_minFilesTwoMaxFilesFour_notError()
|
||||
{
|
||||
$validator = new FileValidator(['minFiles' => 2, 'maxFiles' => 4]);
|
||||
$model = FakedValidationModel::createWithAttributes(
|
||||
[
|
||||
'attr_images' => $this->createTestFiles(
|
||||
[
|
||||
[
|
||||
'name' => 'image.png',
|
||||
'size' => 1024,
|
||||
'type' => 'image/png',
|
||||
],
|
||||
[
|
||||
'name' => 'image.png',
|
||||
'size' => 1024,
|
||||
'type' => 'image/png',
|
||||
],
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$validator->validateAttribute($model, 'attr_images');
|
||||
|
||||
$this->assertFalse($model->hasErrors('attr_images'));
|
||||
}
|
||||
|
||||
public function testValidateAttribute_minFilesTwoMaxFilesUnlimited_hasError()
|
||||
{
|
||||
$validator = new FileValidator(['minFiles' => 2, 'maxFiles' => 0]);
|
||||
$model = FakedValidationModel::createWithAttributes(
|
||||
[
|
||||
'attr_images' => $this->createTestFiles(
|
||||
[
|
||||
[
|
||||
'name' => 'image.png',
|
||||
'size' => 1024,
|
||||
'type' => 'image/png',
|
||||
],
|
||||
[
|
||||
'error' => UPLOAD_ERR_NO_FILE,
|
||||
],
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$validator->validateAttribute($model, 'attr_images');
|
||||
|
||||
$this->assertTrue($model->hasErrors('attr_images'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return UploadedFile[]
|
||||
|
||||
Reference in New Issue
Block a user