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
|
<?php
use Kanboard\Filter\TaskStartsWithIdFilter;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
require_once __DIR__.'/../Base.php';
class TaskStartsWithIdFilterTest extends Base
{
public function testManyResults()
{
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$query = $taskFinderModel->getExtendedQuery();
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
for ($i = 1; $i <= 20; $i++) {
$this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i)));
}
$filter = new TaskStartsWithIdFilter();
$filter->withQuery($query);
$filter->withValue(1);
$filter->apply();
$tasks = $query->findAll();
$this->assertCount(11, $tasks);
$this->assertEquals('Task #1', $tasks[0]['title']);
$this->assertEquals('Task #19', $tasks[10]['title']);
}
public function testOneResult()
{
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$query = $taskFinderModel->getExtendedQuery();
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
for ($i = 1; $i <= 20; $i++) {
$this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i)));
}
$filter = new TaskStartsWithIdFilter();
$filter->withQuery($query);
$filter->withValue(3);
$filter->apply();
$tasks = $query->findAll();
$this->assertCount(1, $tasks);
$this->assertEquals('Task #3', $tasks[0]['title']);
}
public function testEmptyResult()
{
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$query = $taskFinderModel->getExtendedQuery();
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
for ($i = 1; $i <= 20; $i++) {
$this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i)));
}
$filter = new TaskStartsWithIdFilter();
$filter->withQuery($query);
$filter->withValue(30);
$filter->apply();
$tasks = $query->findAll();
$this->assertCount(0, $tasks);
}
public function testWithTwoDigits()
{
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$query = $taskFinderModel->getExtendedQuery();
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
for ($i = 1; $i <= 20; $i++) {
$this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i)));
}
$filter = new TaskStartsWithIdFilter();
$filter->withQuery($query);
$filter->withValue(11);
$filter->apply();
$tasks = $query->findAll();
$this->assertCount(1, $tasks);
$this->assertEquals('Task #11', $tasks[0]['title']);
}
}
|