Skip to content

Commit e5d7bd3

Browse files
tfbritosrtab
authored andcommitted
Added unit tests.
1 parent b3a9776 commit e5d7bd3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Fields/FileField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function __construct(array $args = array())
3131

3232
public function validate($value)
3333
{
34-
if ((!isset($value->size) && $this->isDisabled()) || 0 == $value->size && !$this->required) {
34+
if ((!isset($value->size) || 0 == $value->size) && !$this->required) {
3535
return;
36-
} elseif (!isset($value->size) && !$this->isDisabled()) {
36+
} elseif (!isset($value->size) && $this->required) {
3737
throw new ValidationError(msg("INVALID_FILE"), 'invalid');
3838
}
3939

tests/unit/Fields/FileFieldTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ public function testValidateMaxSize()
5555
$this->field->validate((object) $data);
5656
}
5757

58+
public function testValidateNull()
59+
{
60+
$result = $this->field->validate(null);
61+
$this->assertNull($result);
62+
}
63+
64+
/**
65+
* @expectedException PHPForm\Exceptions\ValidationError
66+
* @expectedExceptionMessage Invalid file submitted.
67+
*/
68+
public function testValidateInvalid()
69+
{
70+
$field = new FileField(["max_size" => 20, 'required' => true]);
71+
$field->validate(null);
72+
}
73+
5874
public function testToNative()
5975
{
6076
$data = array(

0 commit comments

Comments
 (0)