/** * @covers sortKanbanColumnItems * @covers checkKanbanTypeByStatusAndUpdateIfRequired */ public function testSortKanbanColumnItems() { Yii::app()->user->userModel = User::getByUsername('super'); $project = ProjectTestHelper::createProjectByNameForOwner('MyKanbanProject', Yii::app()->user->userModel); $dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000); //First kanban task $task = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyFirstKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS); $kanbanItem1 = KanbanItem::getByTask($task->id); $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem1->type); $this->assertEquals($task->project->id, $kanbanItem1->kanbanRelatedItem->id); $task2 = TaskTestHelper::createTaskByNameWithProjectAndStatus('MySecondKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS); $kanbanItem2 = KanbanItem::getByTask($task2->id); $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem2->type); $this->assertEquals($task2->project->id, $kanbanItem2->kanbanRelatedItem->id); $task3 = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyThirdKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS); $kanbanItem3 = KanbanItem::getByTask($task3->id); $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem3->type); $this->assertEquals($task3->project->id, $kanbanItem3->kanbanRelatedItem->id); $sourceKanbanType = TasksUtil::resolveKanbanItemTypeForTaskStatus(Task::STATUS_IN_PROGRESS); TasksUtil::sortKanbanColumnItems($sourceKanbanType, $task->project); $kanbanItem = KanbanItem::getByTask($task->id); $kanbanItem2 = KanbanItem::getByTask($task2->id); $kanbanItem3 = KanbanItem::getByTask($task3->id); $this->assertEquals($task->id, $kanbanItem->task->id); $this->assertEquals(1, $kanbanItem->sortOrder); $this->assertEquals($task2->id, $kanbanItem2->task->id); $this->assertEquals(2, $kanbanItem2->sortOrder); $this->assertEquals($task3->id, $kanbanItem3->task->id); $this->assertEquals(3, $kanbanItem3->sortOrder); //Update status and check checkKanbanTypeByStatusAndUpdateIfRequired $task->status = Task::STATUS_NEW; $this->assertTrue($task->save()); TasksUtil::checkKanbanTypeByStatusAndUpdateIfRequired($task); $kanbanItem = KanbanItem::getByTask($task->id); $this->assertEquals(KanbanItem::TYPE_SOMEDAY, $kanbanItem->type); $kanbanItem2 = KanbanItem::getByTask($task2->id); $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem2->type); $kanbanItem3 = KanbanItem::getByTask($task3->id); $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem3->type); $this->assertEquals($task->id, $kanbanItem->task->id); $this->assertEquals(1, $kanbanItem->sortOrder); $this->assertEquals($task2->id, $kanbanItem2->task->id); $this->assertEquals(1, $kanbanItem2->sortOrder); $this->assertEquals($task3->id, $kanbanItem3->task->id); $this->assertEquals(2, $kanbanItem3->sortOrder); }
/** * Check kanban type for status and update if it is required, it is required * when user is changing the status from modal detail view * @param $task Task */ public static function checkKanbanTypeByStatusAndUpdateIfRequired(Task $task) { $kanbanItem = KanbanItem::getByTask($task->id); //It should be created here but check for create as well here if ($kanbanItem == null) { TasksUtil::createKanbanItemFromTask($task); } else { if (!TasksUtil::isKanbanItemTypeValidBasedOnTaskStatus($kanbanItem->type, $task->status)) { $kanbanTypeByStatus = TasksUtil::resolveKanbanItemTypeForTaskStatus($task->status); if ($kanbanItem->type != $kanbanTypeByStatus) { $sourceKanbanItemType = $kanbanItem->type; //put the item at the end $kanbanItem->sortOrder = TasksUtil::resolveAndGetSortOrderForTaskOnKanbanBoard($kanbanTypeByStatus, $task); $kanbanItem->type = $kanbanTypeByStatus; $kanbanItem->save(); //Resort the source column if ($task->project->id > 0) { TasksUtil::sortKanbanColumnItems($sourceKanbanItemType, $task->project); } elseif ($task->activityItems->count() > 0) { TasksUtil::sortKanbanColumnItems($sourceKanbanItemType, $task->activityItems->offsetGet(0)); } } } } }