Skip to content

Commit

Permalink
Closes #13301 by adding a file validation rule
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed Apr 29, 2016
1 parent e9ec0c1 commit 34c8b93
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 34c8b93

Please sign in to comment.