diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-05-12 15:55:13 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-05-12 15:55:13 -0400 |
commit | 5b7e137f769e352e0dddeff6c0c9a19602a8e4d9 (patch) | |
tree | 19c38daad18475b623fc713392fc51419a3c029a /tests/units | |
parent | 630f4ee780f3a9240ae9296e73f7518f21ae23ae (diff) |
Add wildcard search for task reference field (PR #3119)
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/Filter/TaskReferenceFilterTest.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/units/Filter/TaskReferenceFilterTest.php b/tests/units/Filter/TaskReferenceFilterTest.php new file mode 100644 index 00000000..49a86454 --- /dev/null +++ b/tests/units/Filter/TaskReferenceFilterTest.php @@ -0,0 +1,65 @@ +<?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()); + } +} |