summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-10-09 20:50:26 -0400
committerFrederic Guillot <fred@kanboard.net>2016-10-09 20:50:26 -0400
commit9eefe6a35835c763c8447621fa63c3b8147b06b8 (patch)
tree13bdce5f5d721baebb42249119516324cf136434
parent71ad04cd66531aa29d8859d7115ec47acf8b89c3 (diff)
Improve task status filter
-rw-r--r--app/Filter/TaskStatusFilter.php2
-rw-r--r--tests/units/Filter/TaskStatusFilterTest.php118
2 files changed, 119 insertions, 1 deletions
diff --git a/app/Filter/TaskStatusFilter.php b/app/Filter/TaskStatusFilter.php
index a55532cb..791ebce6 100644
--- a/app/Filter/TaskStatusFilter.php
+++ b/app/Filter/TaskStatusFilter.php
@@ -34,7 +34,7 @@ class TaskStatusFilter extends BaseFilter implements FilterInterface
{
if ($this->value === 'open' || $this->value === 'closed') {
$this->query->eq(TaskModel::TABLE.'.is_active', $this->value === 'open' ? TaskModel::STATUS_OPEN : TaskModel::STATUS_CLOSED);
- } else {
+ } elseif (is_int($this->value) || ctype_digit($this->value)) {
$this->query->eq(TaskModel::TABLE.'.is_active', $this->value);
}
diff --git a/tests/units/Filter/TaskStatusFilterTest.php b/tests/units/Filter/TaskStatusFilterTest.php
new file mode 100644
index 00000000..ea8d669b
--- /dev/null
+++ b/tests/units/Filter/TaskStatusFilterTest.php
@@ -0,0 +1,118 @@
+<?php
+
+use Kanboard\Filter\TaskStatusFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskStatusFilterTest extends Base
+{
+ public function testWithOpenValue()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue('open');
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ }
+
+ public function testWithOpenNumericValue()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue(1);
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ }
+
+ public function testWithClosedValue()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue('closed');
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test2', $tasks[0]['title']);
+ }
+
+ public function testWithClosedNumericValue()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue(0);
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test2', $tasks[0]['title']);
+ }
+
+ public function testWithAllValue()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue('all');
+ $filter->apply();
+
+ $tasks = $query->asc(TaskModel::TABLE.'.title')->findAll();
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ $this->assertEquals('test2', $tasks[1]['title']);
+ }
+}