diff options
Diffstat (limited to 'tests/units/Job')
-rw-r--r-- | tests/units/Job/CommentEventJobTest.php | 52 | ||||
-rw-r--r-- | tests/units/Job/ProjectFileEventJobTest.php | 43 | ||||
-rw-r--r-- | tests/units/Job/ProjectMetricJobTest.php | 47 | ||||
-rw-r--r-- | tests/units/Job/SubtaskEventJobTest.php | 52 | ||||
-rw-r--r-- | tests/units/Job/TaskEventJobTest.php | 189 | ||||
-rw-r--r-- | tests/units/Job/TaskFileEventJobTest.php | 46 | ||||
-rw-r--r-- | tests/units/Job/TaskLinkEventJobTest.php | 65 |
7 files changed, 494 insertions, 0 deletions
diff --git a/tests/units/Job/CommentEventJobTest.php b/tests/units/Job/CommentEventJobTest.php new file mode 100644 index 00000000..8571af8e --- /dev/null +++ b/tests/units/Job/CommentEventJobTest.php @@ -0,0 +1,52 @@ +<?php + +use Kanboard\Job\CommentEventJob; +use Kanboard\Model\CommentModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; + +require_once __DIR__.'/../Base.php'; + +class CommentEventJobTest extends Base +{ + public function testJobParams() + { + $commentEventJob = new CommentEventJob($this->container); + $commentEventJob->withParams(123, 'foobar'); + + $this->assertSame(array(123, 'foobar'), $commentEventJob->getJobParams()); + } + + public function testWithMissingComment() + { + $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {}); + + $commentEventJob = new CommentEventJob($this->container); + $commentEventJob->execute(42, CommentModel::EVENT_CREATE); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertEmpty($called); + } + + public function testTriggerEvents() + { + $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {}); + $this->container['dispatcher']->addListener(CommentModel::EVENT_UPDATE, function() {}); + $this->container['dispatcher']->addListener(CommentModel::EVENT_DELETE, function() {}); + + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'foobar', 'user_id' => 1))); + $this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'test'))); + $this->assertTrue($commentModel->remove(1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(CommentModel::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(CommentModel::EVENT_UPDATE.'.closure', $called); + $this->assertArrayHasKey(CommentModel::EVENT_DELETE.'.closure', $called); + } +} diff --git a/tests/units/Job/ProjectFileEventJobTest.php b/tests/units/Job/ProjectFileEventJobTest.php new file mode 100644 index 00000000..f266d293 --- /dev/null +++ b/tests/units/Job/ProjectFileEventJobTest.php @@ -0,0 +1,43 @@ +<?php + +use Kanboard\Job\ProjectFileEventJob; +use Kanboard\Model\ProjectFileModel; +use Kanboard\Model\ProjectModel; + +require_once __DIR__.'/../Base.php'; + +class ProjectFileEventJobTest extends Base +{ + public function testJobParams() + { + $projectFileEventJob = new ProjectFileEventJob($this->container); + $projectFileEventJob->withParams(123, 'foobar'); + + $this->assertSame(array(123, 'foobar'), $projectFileEventJob->getJobParams()); + } + + public function testWithMissingFile() + { + $this->container['dispatcher']->addListener(ProjectFileModel::EVENT_CREATE, function() {}); + + $projectFileEventJob = new ProjectFileEventJob($this->container); + $projectFileEventJob->execute(42, ProjectFileModel::EVENT_CREATE); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertEmpty($called); + } + + public function testTriggerEvents() + { + $this->container['dispatcher']->addListener(ProjectFileModel::EVENT_CREATE, function() {}); + + $projectModel = new ProjectModel($this->container); + $projectFileModel = new ProjectFileModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $projectFileModel->create(1, 'Test', '/tmp/test', 123)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(ProjectFileModel::EVENT_CREATE.'.closure', $called); + } +} diff --git a/tests/units/Job/ProjectMetricJobTest.php b/tests/units/Job/ProjectMetricJobTest.php new file mode 100644 index 00000000..e5b0474d --- /dev/null +++ b/tests/units/Job/ProjectMetricJobTest.php @@ -0,0 +1,47 @@ +<?php + +use Kanboard\Job\ProjectMetricJob; + +require_once __DIR__.'/../Base.php'; + +class ProjectMetricJobTest extends Base +{ + public function testJobParams() + { + $projectMetricJob = new ProjectMetricJob($this->container); + $projectMetricJob->withParams(123); + + $this->assertSame( + array(123), + $projectMetricJob->getJobParams() + ); + } + + public function testJob() + { + $this->container['projectDailyColumnStatsModel'] = $this + ->getMockBuilder('\Kanboard\Model\ProjectDailyColumnStatsModel') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('updateTotals')) + ->getMock(); + + $this->container['projectDailyStatsModel'] = $this + ->getMockBuilder('\Kanboard\Model\ProjectDailyStatsModel') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('updateTotals')) + ->getMock(); + + $this->container['projectDailyColumnStatsModel'] + ->expects($this->once()) + ->method('updateTotals') + ->with(42, date('Y-m-d')); + + $this->container['projectDailyStatsModel'] + ->expects($this->once()) + ->method('updateTotals') + ->with(42, date('Y-m-d')); + + $job = new ProjectMetricJob($this->container); + $job->execute(42); + } +} diff --git a/tests/units/Job/SubtaskEventJobTest.php b/tests/units/Job/SubtaskEventJobTest.php new file mode 100644 index 00000000..bdc30b51 --- /dev/null +++ b/tests/units/Job/SubtaskEventJobTest.php @@ -0,0 +1,52 @@ +<?php + +use Kanboard\Job\SubtaskEventJob; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; + +require_once __DIR__.'/../Base.php'; + +class SubtaskEventJobTest extends Base +{ + public function testJobParams() + { + $subtaskEventJob = new SubtaskEventJob($this->container); + $subtaskEventJob->withParams(123, 'foobar', array('k' => 'v')); + + $this->assertSame(array(123, 'foobar', array('k' => 'v')), $subtaskEventJob->getJobParams()); + } + + public function testWithMissingSubtask() + { + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {}); + + $subtaskEventJob = new SubtaskEventJob($this->container); + $subtaskEventJob->execute(42, SubtaskModel::EVENT_CREATE); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertEmpty($called); + } + + public function testTriggerEvents() + { + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {}); + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, function() {}); + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, function() {}); + + $subtaskModel = new SubtaskModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'before'))); + $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'title' => 'after'))); + $this->assertTrue($subtaskModel->remove(1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(SubtaskModel::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(SubtaskModel::EVENT_UPDATE.'.closure', $called); + $this->assertArrayHasKey(SubtaskModel::EVENT_DELETE.'.closure', $called); + } +} diff --git a/tests/units/Job/TaskEventJobTest.php b/tests/units/Job/TaskEventJobTest.php new file mode 100644 index 00000000..c399faad --- /dev/null +++ b/tests/units/Job/TaskEventJobTest.php @@ -0,0 +1,189 @@ +<?php + +use Kanboard\Job\TaskEventJob; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\SwimlaneModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskModificationModel; +use Kanboard\Model\TaskPositionModel; +use Kanboard\Model\TaskProjectMoveModel; +use Kanboard\Model\TaskStatusModel; + +require_once __DIR__.'/../Base.php'; + +class TaskEventJobTest extends Base +{ + public function testJobParams() + { + $taskEventJob = new TaskEventJob($this->container); + $taskEventJob->withParams(123, array('foobar'), array('k' => 'v'), array('k1' => 'v1'), array('k2' => 'v2')); + + $this->assertSame( + array(123, array('foobar'), array('k' => 'v'), array('k1' => 'v1'), array('k2' => 'v2')), + $taskEventJob->getJobParams() + ); + } + + public function testWithMissingTask() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function() {}); + + $taskEventJob = new TaskEventJob($this->container); + $taskEventJob->execute(42, array(TaskModel::EVENT_CREATE)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertEmpty($called); + } + + public function testTriggerCreateEvent() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function() {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + } + + public function testTriggerUpdateEvent() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, function() {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $taskModificationModel = new TaskModificationModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'new title'))); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + } + + public function testTriggerAssigneeChangeEvent() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_ASSIGNEE_CHANGE, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $taskModificationModel = new TaskModificationModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + $this->assertTrue($taskModificationModel->update(array('id' => 1, 'owner_id' => 1))); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_ASSIGNEE_CHANGE.'.closure', $called); + } + + public function testTriggerCloseEvent() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_CLOSE, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $taskStatusModel = new TaskStatusModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + $this->assertTrue($taskStatusModel->close(1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_CLOSE.'.closure', $called); + } + + public function testTriggerOpenEvent() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_OPEN, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $taskStatusModel = new TaskStatusModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + $this->assertTrue($taskStatusModel->close(1)); + $this->assertTrue($taskStatusModel->open(1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_OPEN.'.closure', $called); + } + + public function testTriggerMovePositionEvent() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_POSITION, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $taskPositionModel = new TaskPositionModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1))); + $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 2)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.closure', $called); + } + + public function testTriggerMoveColumnEvent() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_COLUMN, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $taskPositionModel = new TaskPositionModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 2)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.closure', $called); + } + + public function testTriggerMoveSwimlaneEvent() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_SWIMLANE, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $taskPositionModel = new TaskPositionModel($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $swimlaneModel->create(array('name' => 'S1', 'project_id' => 1))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 1, 1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.closure', $called); + } + + public function testTriggerMoveProjectEvent() + { + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskProjectMoveModel = new TaskProjectMoveModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + $this->assertTrue($taskProjectMoveModel->moveToProject(1, 1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.closure', $called); + } +} diff --git a/tests/units/Job/TaskFileEventJobTest.php b/tests/units/Job/TaskFileEventJobTest.php new file mode 100644 index 00000000..921fe801 --- /dev/null +++ b/tests/units/Job/TaskFileEventJobTest.php @@ -0,0 +1,46 @@ +<?php + +use Kanboard\Job\TaskFileEventJob; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFileModel; + +require_once __DIR__.'/../Base.php'; + +class TaskFileEventJobTest extends Base +{ + public function testJobParams() + { + $taskFileEventJob = new TaskFileEventJob($this->container); + $taskFileEventJob->withParams(123, 'foobar'); + + $this->assertSame(array(123, 'foobar'), $taskFileEventJob->getJobParams()); + } + + public function testWithMissingFile() + { + $this->container['dispatcher']->addListener(TaskFileModel::EVENT_CREATE, function() {}); + + $taskFileEventJob = new TaskFileEventJob($this->container); + $taskFileEventJob->execute(42, TaskFileModel::EVENT_CREATE); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertEmpty($called); + } + + public function testTriggerEvents() + { + $this->container['dispatcher']->addListener(TaskFileModel::EVENT_CREATE, function() {}); + + $taskFileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + $this->assertEquals(1, $taskFileModel->create(1, 'Test', '/tmp/test', 123)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskFileModel::EVENT_CREATE.'.closure', $called); + } +} diff --git a/tests/units/Job/TaskLinkEventJobTest.php b/tests/units/Job/TaskLinkEventJobTest.php new file mode 100644 index 00000000..1949316a --- /dev/null +++ b/tests/units/Job/TaskLinkEventJobTest.php @@ -0,0 +1,65 @@ +<?php + +use Kanboard\Job\TaskLinkEventJob; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskLinkModel; + +require_once __DIR__.'/../Base.php'; + +class TaskLinkEventJobTest extends Base +{ + public function testJobParams() + { + $taskLinkEventJob = new TaskLinkEventJob($this->container); + $taskLinkEventJob->withParams(123, 'foobar'); + + $this->assertSame(array(123, 'foobar'), $taskLinkEventJob->getJobParams()); + } + + public function testWithMissingLink() + { + $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {}); + + $taskLinkEventJob = new TaskLinkEventJob($this->container); + $taskLinkEventJob->execute(42, TaskLinkModel::EVENT_CREATE_UPDATE); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertEmpty($called); + } + + public function testTriggerCreationEvents() + { + $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskLinkModel = new TaskLinkModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1))); + $this->assertEquals(1, $taskLinkModel->create(1, 2, 1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskLinkModel::EVENT_CREATE_UPDATE.'.closure', $called); + } + + public function testTriggerDeleteEvents() + { + $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_DELETE, function() {}); + + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskLinkModel = new TaskLinkModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1))); + $this->assertEquals(1, $taskLinkModel->create(1, 2, 1)); + $this->assertTrue($taskLinkModel->remove(1)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskLinkModel::EVENT_DELETE.'.closure', $called); + } +} |