summaryrefslogtreecommitdiff
path: root/tests/units/Filter/TaskReferenceFilterTest.php
blob: 016f69c4af09ef904bfbf538967cd396f68e3dcf (plain)
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
<?php

use Kanboard\Filter\TaskReferenceFilter;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;

require_once __DIR__.'/../Base.php';

class TaskReferenceFilterTest extends Base
{
    public function testWithoutMatch()
    {
        $taskFinder = new TaskFinderModel($this->container);
        $taskCreation = new TaskCreationModel($this->container);
        $projectModel = new ProjectModel($this->container);
        $query = $taskFinder->getExtendedQuery();

        $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
        $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));

        $filter = new TaskReferenceFilter();
        $filter->withQuery($query);
        $filter->withValue('aaa-bbb');
        $filter->apply();

        $this->assertCount(0, $query->findAll());
    }

    public function testWithExactMatch()
    {
        $taskFinder = new TaskFinderModel($this->container);
        $taskCreation = new TaskCreationModel($this->container);
        $projectModel = new ProjectModel($this->container);
        $query = $taskFinder->getExtendedQuery();

        $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
        $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'reference' => 'aaa-bbb')));

        $filter = new TaskReferenceFilter();
        $filter->withQuery($query);
        $filter->withValue('aaa-bbb');
        $filter->apply();

        $this->assertCount(1, $query->findAll());
    }

    public function testWithWildCard()
    {
        $taskFinder = new TaskFinderModel($this->container);
        $taskCreation = new TaskCreationModel($this->container);
        $projectModel = new ProjectModel($this->container);
        $query = $taskFinder->getExtendedQuery();

        $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
        $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'reference' => 'aaa-bbb')));

        $filter = new TaskReferenceFilter();
        $filter->withQuery($query);
        $filter->withValue('aaa-*');
        $filter->apply();

        $this->assertCount(1, $query->findAll());
    }

    public function testWithNone()
    {
        $taskFinder = new TaskFinderModel($this->container);
        $taskCreation = new TaskCreationModel($this->container);
        $projectModel = new ProjectModel($this->container);
        $query = $taskFinder->getExtendedQuery();

        $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
        $this->assertEquals(1, $taskCreation->create(array('title' => 'A', 'project_id' => 1, 'reference' => 'aaa-bbb')));
        $this->assertEquals(2, $taskCreation->create(array('title' => 'B', 'project_id' => 1)));

        $filter = new TaskReferenceFilter();
        $filter->withQuery($query);
        $filter->withValue('none');
        $filter->apply();

        $this->assertCount(1, $query->findAll());
    }
}