From 1731211908f949e501b43262985e07f7cde785e2 Mon Sep 17 00:00:00 2001 From: Rafael de Camargo Date: Sun, 25 Aug 2019 01:50:09 -0300 Subject: Add tests for task link and subtask assignee filters --- tests/units/Filter/TaskLinkFilterTest.php | 69 ++++++ .../units/Filter/TaskSubtaskAssigneeFilterTest.php | 238 +++++++++++++++++++++ 2 files changed, 307 insertions(+) create mode 100644 tests/units/Filter/TaskLinkFilterTest.php create mode 100644 tests/units/Filter/TaskSubtaskAssigneeFilterTest.php (limited to 'tests') diff --git a/tests/units/Filter/TaskLinkFilterTest.php b/tests/units/Filter/TaskLinkFilterTest.php new file mode 100644 index 00000000..c0710fb6 --- /dev/null +++ b/tests/units/Filter/TaskLinkFilterTest.php @@ -0,0 +1,69 @@ +container); + $taskCreation = new TaskCreationModel($this->container); + $linkModel = new LinkModel($this->container); + $taskLinkModel = new TaskLinkModel($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 1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1))); + + $links = $linkModel->getMergedList(); + + $this->assertNotFalse(1, $taskLinkModel->create(1, 2, $links[1]['id'])); + + $filter = new TaskLinkFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue($links[1]["label"]); + $filter->apply(); + + $result = $query->findAll(); + $this->assertCount(1, $result); + $this->assertEquals(1, $result[0]["id"]); + } + + public function testMatchOppositeLabel() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $linkModel = new LinkModel($this->container); + $taskLinkModel = new TaskLinkModel($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 1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1))); + + $links = $linkModel->getMergedList(); + + $this->assertNotFalse(1, $taskLinkModel->create(1, 2, $links[1]['id'])); + + $filter = new TaskLinkFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue($links[1]["opposite_label"]); + $filter->apply(); + + $result = $query->findAll(); + $this->assertCount(1, $result); + $this->assertEquals(2, $result[0]["id"]); + } +} diff --git a/tests/units/Filter/TaskSubtaskAssigneeFilterTest.php b/tests/units/Filter/TaskSubtaskAssigneeFilterTest.php new file mode 100644 index 00000000..b8d500db --- /dev/null +++ b/tests/units/Filter/TaskSubtaskAssigneeFilterTest.php @@ -0,0 +1,238 @@ +container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask', 'task_id' => 1, 'user_id' => 1))); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue(1); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue(123); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithStringAssigneeId() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask', 'task_id' => 1, 'user_id' => 1))); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue('1'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue("123"); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithUsername() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask', 'task_id' => 1, 'user_id' => 1))); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue('admin'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue('foobar'); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithName() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $userModel = new UserModel($this->container); + + $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))); + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask', 'task_id' => 1, 'user_id' => 2))); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue('foo bar'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue('bob'); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithNobody() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask', 'task_id' => 1))); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue('nobody'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + } + + public function testWithCurrentUser() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask', 'task_id' => 1, 'user_id' => 1))); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->setCurrentUserId(1); + $filter->withQuery($query); + $filter->withValue('me'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->setCurrentUserId(2); + $filter->withQuery($query); + $filter->withValue('me'); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithMultiple() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $userModel = new UserModel($this->container); + + $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))); + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 2))); + $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1))); + + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1))); + $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 2))); + $this->assertEquals(4, $subtaskModel->create(array('title' => 'subtask #4', 'task_id' => 2, 'user_id' => 1))); + + $this->assertEquals(3, $taskCreation->create(array('title' => 'Test 3', 'project_id' => 1))); + $this->assertEquals(5, $subtaskModel->create(array('title' => 'subtask #5', 'task_id' => 3))); + $this->assertEquals(6, $subtaskModel->create(array('title' => 'subtask #6', 'task_id' => 3, 'user_id' => 2))); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue('foo bar'); + $filter->apply(); + + $this->assertCount(2, $query->findAll()); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue('nobody'); + $filter->apply(); + $result = $query->findAll(); + $this->assertCount(2, $result); + + $query = $taskFinder->getExtendedQuery(); + $filter = new TaskSubtaskAssigneeFilter(); + $filter->setDatabase($this->container['db']); + $filter->withQuery($query); + $filter->withValue('admin'); + $filter->apply(); + + $this->assertCount(2, $query->findAll()); + } +} -- cgit v1.2.3