diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index ab4edfd1426..a6cd19db6b9 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -1527,6 +1527,22 @@ protected function validateActiveUrl($attribute, $value) return false; } + /** + * Validate the given value is a valid file. + * + * @param string $attribute + * @param mixed $value + * @return bool + */ + protected function validateFile($attribute, $value) + { + if (! $this->isAValidFileInstance($value)) { + return false; + } + + return true; + } + /** * Validate the MIME type of a file is an image MIME type. * diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 589ff0f7d18..02fcfba90e8 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1690,6 +1690,24 @@ public function testValidateMime() $this->assertFalse($v->passes()); } + /** + * @requires extension fileinfo + */ + public function testValidateFile() + { + $trans = $this->getRealTranslator(); + $uploadedFile = [__FILE__, '', null, null, null, true]; + + $file = $this->getMock('Symfony\Component\HttpFoundation\File\UploadedFile', [], $uploadedFile); + + $v = new Validator($trans, ['x' => '1'], ['x' => 'file']); + $this->assertTrue($v->fails()); + + $v = new Validator($trans, [], ['x' => 'file']); + $v->setFiles(['x' => $file]); + $this->assertTrue($v->passes()); + } + public function testEmptyRulesSkipped() { $trans = $this->getRealTranslator();