Commit 0206e917 by Mark

file validator tests added

parent c52c063c
...@@ -21,7 +21,7 @@ class FileValidatorTest extends TestCase ...@@ -21,7 +21,7 @@ class FileValidatorTest extends TestCase
public function testAssureMessagesSetOnInit() public function testAssureMessagesSetOnInit()
{ {
$val = new FileValidator(); $val = new FileValidator();
foreach (['message', 'uploadRequired', 'tooMany', 'wrongType', 'tooBig', 'tooSmall'] as $attr) { foreach (['message', 'uploadRequired', 'tooMany', 'wrongType', 'tooBig', 'tooSmall', 'wrongMimeType'] as $attr) {
$this->assertTrue(is_string($val->$attr)); $this->assertTrue(is_string($val->$attr));
} }
} }
...@@ -30,18 +30,44 @@ class FileValidatorTest extends TestCase ...@@ -30,18 +30,44 @@ class FileValidatorTest extends TestCase
{ {
$val = new FileValidator(['types' => 'jpeg, jpg, gif']); $val = new FileValidator(['types' => 'jpeg, jpg, gif']);
$this->assertEquals(['jpeg', 'jpg', 'gif'], $val->types); $this->assertEquals(['jpeg', 'jpg', 'gif'], $val->types);
$val = new FileValidator(['types' => 'jpeg']); $val = new FileValidator(['types' => 'jpeg']);
$this->assertEquals(['jpeg'], $val->types); $this->assertEquals(['jpeg'], $val->types);
$val = new FileValidator(['types' => '']); $val = new FileValidator(['types' => '']);
$this->assertEquals([], $val->types); $this->assertEquals([], $val->types);
$val = new FileValidator(['types' => []]); $val = new FileValidator(['types' => []]);
$this->assertEquals([], $val->types); $this->assertEquals([], $val->types);
$val = new FileValidator(); $val = new FileValidator();
$this->assertEquals([], $val->types); $this->assertEquals([], $val->types);
$val = new FileValidator(['types' => ['jpeg', 'exe']]); $val = new FileValidator(['types' => ['jpeg', 'exe']]);
$this->assertEquals(['jpeg', 'exe'], $val->types); $this->assertEquals(['jpeg', 'exe'], $val->types);
} }
public function testMimeTypeSplitOnInit()
{
$val = new FileValidator(['mimeTypes' => 'text/plain, image/png']);
$this->assertEquals(['text/plain', 'image/png'], $val->mimeTypes);
$val = new FileValidator(['mimeTypes' => 'text/plain']);
$this->assertEquals(['text/plain'], $val->mimeTypes);
$val = new FileValidator(['mimeTypes' => '']);
$this->assertEquals([], $val->mimeTypes);
$val = new FileValidator(['mimeTypes' => []]);
$this->assertEquals([], $val->mimeTypes);
$val = new FileValidator();
$this->assertEquals([], $val->mimeTypes);
$val = new FileValidator(['mimeTypes' => ['text/plain', 'image/png']]);
$this->assertEquals(['text/plain', 'image/png'], $val->mimeTypes);
}
public function testGetSizeLimit() public function testGetSizeLimit()
{ {
$size = $this->sizeToBytes(ini_get('upload_max_filesize')); $size = $this->sizeToBytes(ini_get('upload_max_filesize'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment