public function testMoveTaskAnotherSwimlane() { $tp = new TaskPosition($this->container); $tc = new TaskCreation($this->container); $p = new Project($this->container); $tf = new TaskFinder($this->container); $s = new Swimlane($this->container); $this->container['dispatcher'] = new EventDispatcher(); $this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container)); $now = time(); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1'))); $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals($now, $task['date_moved'], '', 1); $this->assertEquals(1, $task['column_id']); $this->assertEquals(0, $task['swimlane_id']); sleep(1); $this->assertTrue($tp->movePosition(1, 1, 2, 1, 2)); $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertNotEquals($now, $task['date_moved']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(2, $task['swimlane_id']); }
public function testSingleAction() { $tp = new TaskPosition($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $board = new Board($this->container); $project = new Project($this->container); $action = new Action($this->container); // We create a project $this->assertEquals(1, $project->create(array('name' => 'unit_test'))); // We create a new action $this->assertEquals(1, $action->create(array('project_id' => 1, 'event_name' => Task::EVENT_MOVE_COLUMN, 'action_name' => 'TaskClose', 'params' => array('column_id' => 4)))); // We create a task $this->assertEquals(1, $tc->create(array('title' => 'unit_test', 'project_id' => 1, 'owner_id' => 1, 'color_id' => 'red', 'column_id' => 1))); // We attach events $action->attachEvents(); // Our task should be open $t1 = $tf->getById(1); $this->assertEquals(1, $t1['is_active']); $this->assertEquals(1, $t1['column_id']); // We move our task $tp->movePosition(1, 1, 4, 1); // Our task should be closed $t1 = $tf->getById(1); $this->assertEquals(4, $t1['column_id']); $this->assertEquals(0, $t1['is_active']); }
public function testEvents() { $tp = new TaskPosition($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $s = new Swimlane($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $s->create(1, 'test 1')); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2))); $this->container['dispatcher']->addListener(Task::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn')); $this->container['dispatcher']->addListener(Task::EVENT_MOVE_POSITION, array($this, 'onMovePosition')); $this->container['dispatcher']->addListener(Task::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane')); // We move the task 1 to the column 2 $this->assertTrue($tp->movePosition(1, 1, 2, 1)); $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(1, $task['position']); $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(2, $task['position']); $called = $this->container['dispatcher']->getCalledListeners(); $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN . '.TaskPositionTest::onMoveColumn', $called); $this->assertEquals(1, count($called)); // We move the task 1 to the position 2 $this->assertTrue($tp->movePosition(1, 1, 2, 2)); $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(2, $task['position']); $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(1, $task['position']); $called = $this->container['dispatcher']->getCalledListeners(); $this->assertArrayHasKey(Task::EVENT_MOVE_POSITION . '.TaskPositionTest::onMovePosition', $called); $this->assertEquals(2, count($called)); // Move to another swimlane $this->assertTrue($tp->movePosition(1, 1, 3, 1, 1)); $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(3, $task['column_id']); $this->assertEquals(1, $task['position']); $this->assertEquals(1, $task['swimlane_id']); $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(1, $task['position']); $this->assertEquals(0, $task['swimlane_id']); $called = $this->container['dispatcher']->getCalledListeners(); $this->assertArrayHasKey(Task::EVENT_MOVE_SWIMLANE . '.TaskPositionTest::onMoveSwimlane', $called); $this->assertEquals(3, count($called)); }
#!/usr/bin/env php <?php require __DIR__ . '/../app/common.php'; use Model\ProjectDailySummary; use Model\TaskCreation; use Model\TaskPosition; $pds = new ProjectDailySummary($container); $taskCreation = new TaskCreation($container); $taskPosition = new TaskPosition($container); for ($i = 1; $i <= 15; $i++) { $task = array('title' => 'Task #' . $i, 'project_id' => 1, 'column_id' => 1); $taskCreation->create($task); } $pds->updateTotals(1, date('Y-m-d', strtotime('-7 days'))); $taskPosition->movePosition(1, 1, 2, 1); $taskPosition->movePosition(1, 2, 2, 1); $taskPosition->movePosition(1, 3, 2, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-6 days'))); $taskPosition->movePosition(1, 3, 3, 1); $taskPosition->movePosition(1, 4, 3, 1); $taskPosition->movePosition(1, 5, 3, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-5 days'))); $taskPosition->movePosition(1, 5, 4, 1); $taskPosition->movePosition(1, 6, 4, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-4 days'))); $taskPosition->movePosition(1, 7, 4, 1); $taskPosition->movePosition(1, 8, 4, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-3 days'))); $taskPosition->movePosition(1, 9, 3, 1); $taskPosition->movePosition(1, 10, 2, 1); $pds->updateTotals(1, date('Y-m-d', strtotime('-2 days')));
public function testEvents() { $tp = new TaskPosition($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2))); // We move the task 1 to the column 2 $this->assertTrue($tp->movePosition(1, 1, 2, 1)); $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(1, $task['position']); $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(2, $task['position']); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN)); $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION)); $event_data = $this->container['event']->getEventData(Task::EVENT_MOVE_COLUMN); $this->assertNotEmpty($event_data); $this->assertEquals(1, $event_data['task_id']); $this->assertEquals(1, $event_data['position']); $this->assertEquals(2, $event_data['column_id']); $this->assertEquals(1, $event_data['project_id']); $this->container['event']->clearTriggeredEvents(); // We move the task 1 to the position 2 $this->assertTrue($tp->movePosition(1, 1, 2, 2)); $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(2, $task['position']); $task = $tf->getById(2); $this->assertEquals(2, $task['id']); $this->assertEquals(2, $task['column_id']); $this->assertEquals(1, $task['position']); $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN)); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION)); $event_data = $this->container['event']->getEventData(Task::EVENT_MOVE_POSITION); $this->assertNotEmpty($event_data); $this->assertEquals(1, $event_data['task_id']); $this->assertEquals(2, $event_data['position']); $this->assertEquals(2, $event_data['column_id']); $this->assertEquals(1, $event_data['project_id']); }
public function testExecuteMultipleActions() { $tp = new TaskPosition($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $board = new Board($this->container); $project = new Project($this->container); $action = new Action($this->container); // We create 2 projects $this->assertEquals(1, $project->create(array('name' => 'unit_test1'))); $this->assertEquals(2, $project->create(array('name' => 'unit_test2'))); // We create a task $this->assertEquals(1, $tc->create(array('title' => 'unit_test', 'project_id' => 1, 'owner_id' => 1, 'color_id' => 'red', 'column_id' => 1))); // We create 2 actions $this->assertTrue($action->create(array('project_id' => 1, 'event_name' => Task::EVENT_CLOSE, 'action_name' => 'TaskDuplicateAnotherProject', 'params' => array('column_id' => 4, 'project_id' => 2)))); $this->assertTrue($action->create(array('project_id' => 1, 'event_name' => Task::EVENT_MOVE_COLUMN, 'action_name' => 'TaskClose', 'params' => array('column_id' => 4)))); // We bind events $action->attachEvents(); // Events should be attached $this->assertTrue($this->container['event']->hasListener(Task::EVENT_CLOSE, 'Action\\TaskDuplicateAnotherProject')); $this->assertTrue($this->container['event']->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\\TaskClose')); // Our task should be open, linked to the first project and in the first column $t1 = $tf->getById(1); $this->assertEquals(1, $t1['is_active']); $this->assertEquals(1, $t1['column_id']); $this->assertEquals(1, $t1['project_id']); // We move our task $tp->movePosition(1, 1, 4, 1); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN)); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE)); // Our task should be closed $t1 = $tf->getById(1); $this->assertEquals(4, $t1['column_id']); $this->assertEquals(0, $t1['is_active']); // Our task should be duplicated to the 2nd project $t2 = $tf->getById(2); $this->assertNotEmpty($t2); $this->assertNotEquals(4, $t2['column_id']); $this->assertEquals(1, $t2['is_active']); $this->assertEquals(2, $t2['project_id']); $this->assertEquals('unit_test', $t2['title']); }