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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Validator\TaskValidator;
class TaskValidatorTest extends Base
{
public function testValidationEmailCreation()
{
$taskValidator = new TaskValidator($this->container);
$result = $taskValidator->validateEmailCreation(array('emails' => 'test@localhost', 'subject' => 'test'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateEmailCreation(array('subject' => 'test'));
$this->assertFalse($result[0]);
$result = $taskValidator->validateEmailCreation(array('emails' => 'test@localhost, test@localhost'));
$this->assertFalse($result[0]);
}
public function testRequiredFields()
{
$taskValidator = new TaskValidator($this->container);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1));
$this->assertFalse($result[0]);
$result = $taskValidator->validateCreation(array('title' => 'test'));
$this->assertFalse($result[0]);
}
public function testRangeFields()
{
$taskValidator = new TaskValidator($this->container);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 2147483647));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => -2147483647));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 0));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 2147483648));
$this->assertFalse($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => -2147483648));
$this->assertFalse($result[0]);
}
public function testSwimlaneIdField()
{
$taskValidator = new TaskValidator($this->container);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'swimlane_id' => 1));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'swimlane_id' => 0));
$this->assertFalse($result[0]);
}
public function testStartAndDueDateFields()
{
$taskValidator = new TaskValidator($this->container);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '09/11/2017 10:50', 'date_started' => '09/11/2017 9:50'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '09/11/2017 10:50', 'date_started' => '09/11/2017 10:50'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '09/11/2017 10:50', 'date_started' => '09/11/2017 11:50'));
$this->assertFalse($result[0]);
// date_due
// ISO dates
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '2017-02-01'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '2017-02-01 13:15'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '2017-02-01 1:15 pm'));
$this->assertFalse($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '2017_02_01'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '2017_02_01 13:15'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '2017_02_01 1:15 am'));
$this->assertFalse($result[0]);
// d/m/Y dates
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '02/01/2017'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '02/01/2017 13:15'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_due' => '02/01/2017 1:15 pm'));
$this->assertFalse($result[0]);
// date_started
// ISO dates
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_started' => '2017-02-01'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_started' => '2017-02-01 13:15'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_started' => '2017-02-01 1:15 pm'));
$this->assertFalse($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_started' => '2017_02_01'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_started' => '2017_02_01 13:15'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_started' => '2017_02_01 1:15 pm'));
$this->assertFalse($result[0]);
// d/m/Y dates
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_started' => '02/01/2017'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_started' => '02/01/2017 13:15'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'date_started' => '02/01/2017 1:15 pm'));
$this->assertFalse($result[0]);
}
}
|