-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFormTest.php
More file actions
47 lines (43 loc) · 1.7 KB
/
FormTest.php
File metadata and controls
47 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require 'Form.php';
class FormTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$basicFields = array(
'first_name' =>
function ($value) {
if (!empty($value)) {
Form::check(mb_strlen($value, 'UTF-8') < 40, 'First name must not exceed 40 characters');
}
},
'multiple[]' =>
function ($values) {
Form::check(count($values) >= 3, 'Please choose at least 3 options');
},
'image' =>
function ($value) {
Form::check($value['size'] < 3000, 'Please upload a file less than 300k');
},
);
$basicValues = array('first_name' => 'Bob', 'image' => array('size' => 999999), 'foo' => 'bar');
$this->emptyForm = new Form(array());
$this->basicForm = new Form($basicValues, $basicFields);
}
public function testEmptyForm()
{
$this->assertEmpty($this->emptyForm->values);
$this->assertEmpty($this->emptyForm->errors);
$this->assertEmpty($this->emptyForm->fields);
}
public function testBasicForm()
{
$this->assertEquals('Bob', $this->basicForm->first_name);
$this->assertNull($this->basicForm->foo);
$this->assertNull($this->basicForm->multiple);
$this->assertEquals('Please upload a file less than 300k', $this->basicForm->error('image'));
$this->assertEquals('error', $this->basicForm->error('image', 'error'));
$this->assertNull($this->basicForm->error('first_name'));
$this->assertNull($this->basicForm->error('first_name', 'error'));
}
}