summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-04-10 08:15:10 -0400
committerFrederic Guillot <fred@kanboard.net>2016-04-10 08:15:10 -0400
commit38326c4ddf91ed54374775d7f7599136f3e38eea (patch)
tree7a037fe8f6c22d19622414d86b6db63d7fcdb6e5 /tests
parent7705f4c533c3db726624e639be72fc9822904e96 (diff)
Added search by task creator
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Filter/TaskCreatorFilterTest.php159
1 files changed, 159 insertions, 0 deletions
diff --git a/tests/units/Filter/TaskCreatorFilterTest.php b/tests/units/Filter/TaskCreatorFilterTest.php
new file mode 100644
index 00000000..1c344de7
--- /dev/null
+++ b/tests/units/Filter/TaskCreatorFilterTest.php
@@ -0,0 +1,159 @@
+<?php
+
+use Kanboard\Filter\TaskCreatorFilter;
+use Kanboard\Model\Project;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\User;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskCreatorFilterTest extends Base
+{
+ public function testWithIntegerAssigneeId()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'creator_id' => 1)));
+
+ $filter = new TaskCreatorFilter();
+ $filter->withQuery($query);
+ $filter->withValue(1);
+ $filter->apply();
+
+ $this->assertCount(1, $query->findAll());
+
+ $filter = new TaskCreatorFilter();
+ $filter->withQuery($query);
+ $filter->withValue(123);
+ $filter->apply();
+
+ $this->assertCount(0, $query->findAll());
+ }
+
+ public function testWithStringAssigneeId()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'creator_id' => 1)));
+
+ $filter = new TaskCreatorFilter();
+ $filter->withQuery($query);
+ $filter->withValue('1');
+ $filter->apply();
+
+ $this->assertCount(1, $query->findAll());
+
+ $filter = new TaskCreatorFilter();
+ $filter->withQuery($query);
+ $filter->withValue("123");
+ $filter->apply();
+
+ $this->assertCount(0, $query->findAll());
+ }
+
+ public function testWithUsername()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'creator_id' => 1)));
+
+ $filter = new TaskCreatorFilter();
+ $filter->withQuery($query);
+ $filter->withValue('admin');
+ $filter->apply();
+
+ $this->assertCount(1, $query->findAll());
+
+ $filter = new TaskCreatorFilter();
+ $filter->withQuery($query);
+ $filter->withValue('foobar');
+ $filter->apply();
+
+ $this->assertCount(0, $query->findAll());
+ }
+
+ public function testWithName()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $userModel = new User($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'creator_id' => 2)));
+
+ $filter = new TaskCreatorFilter();
+ $filter->withQuery($query);
+ $filter->withValue('foo bar');
+ $filter->apply();
+
+ $this->assertCount(1, $query->findAll());
+
+ $filter = new TaskCreatorFilter();
+ $filter->withQuery($query);
+ $filter->withValue('bob');
+ $filter->apply();
+
+ $this->assertCount(0, $query->findAll());
+ }
+
+ public function testWithNobody()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($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 TaskCreatorFilter();
+ $filter->withQuery($query);
+ $filter->withValue('nobody');
+ $filter->apply();
+
+ $this->assertCount(1, $query->findAll());
+ }
+
+ public function testWithCurrentUser()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'creator_id' => 1)));
+
+ $filter = new TaskCreatorFilter();
+ $filter->setCurrentUserId(1);
+ $filter->withQuery($query);
+ $filter->withValue('me');
+ $filter->apply();
+
+ $this->assertCount(1, $query->findAll());
+
+ $filter = new TaskCreatorFilter();
+ $filter->setCurrentUserId(2);
+ $filter->withQuery($query);
+ $filter->withValue('me');
+ $filter->apply();
+
+ $this->assertCount(0, $query->findAll());
+ }
+}