Create TaskPosition model
This commit is contained in:
parent
4d007ec39f
commit
9ae83c639e
|
|
@ -347,7 +347,7 @@ class Board extends Base
|
|||
|
||||
$values = $this->request->getJson();
|
||||
|
||||
if ($this->task->movePosition($project_id, $values['task_id'], $values['column_id'], $values['position'])) {
|
||||
if ($this->taskPosition->movePosition($project_id, $values['task_id'], $values['column_id'], $values['position'])) {
|
||||
|
||||
$this->response->html(
|
||||
$this->template->load('board/show', array(
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class Event
|
|||
{
|
||||
if (! $this->isEventTriggered($eventName)) {
|
||||
|
||||
$this->events[] = $eventName;
|
||||
$this->events[$eventName] = $data;
|
||||
|
||||
if (isset($this->listeners[$eventName])) {
|
||||
|
||||
|
|
@ -118,6 +118,17 @@ class Event
|
|||
return $this->events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of triggered events
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getEventData($eventName)
|
||||
{
|
||||
return isset($this->events[$eventName]) ? $this->events[$eventName] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an event have been triggered
|
||||
*
|
||||
|
|
@ -127,7 +138,7 @@ class Event
|
|||
*/
|
||||
public function isEventTriggered($eventName)
|
||||
{
|
||||
return in_array($eventName, $this->events);
|
||||
return isset($this->events[$eventName]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -109,12 +109,6 @@ class Task extends Base
|
|||
if (isset($updated_task['owner_id']) && $original_task['owner_id'] != $updated_task['owner_id']) {
|
||||
$events[] = self::EVENT_ASSIGNEE_CHANGE;
|
||||
}
|
||||
else if (isset($updated_task['column_id']) && $original_task['column_id'] != $updated_task['column_id']) {
|
||||
$events[] = self::EVENT_MOVE_COLUMN;
|
||||
}
|
||||
else if (isset($updated_task['position']) && $original_task['position'] != $updated_task['position']) {
|
||||
$events[] = self::EVENT_MOVE_POSITION;
|
||||
}
|
||||
else {
|
||||
$events[] = self::EVENT_CREATE_UPDATE;
|
||||
$events[] = self::EVENT_UPDATE;
|
||||
|
|
@ -146,93 +140,6 @@ class Task extends Base
|
|||
return $this->db->table(self::TABLE)->eq('id', $task_id)->remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a task to another column or to another position
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param integer $task_id Task id
|
||||
* @param integer $column_id Column id
|
||||
* @param integer $position Position (must be >= 1)
|
||||
* @return boolean
|
||||
*/
|
||||
public function movePosition($project_id, $task_id, $column_id, $position)
|
||||
{
|
||||
// The position can't be lower than 1
|
||||
if ($position < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$board = $this->db->table(Board::TABLE)->eq('project_id', $project_id)->asc('position')->findAllByColumn('id');
|
||||
$columns = array();
|
||||
|
||||
// Prepare the columns
|
||||
foreach ($board as $board_column_id) {
|
||||
|
||||
$columns[$board_column_id] = $this->db->table(self::TABLE)
|
||||
->eq('is_active', 1)
|
||||
->eq('project_id', $project_id)
|
||||
->eq('column_id', $board_column_id)
|
||||
->neq('id', $task_id)
|
||||
->asc('position')
|
||||
->findAllByColumn('id');
|
||||
}
|
||||
|
||||
// The column must exists
|
||||
if (! isset($columns[$column_id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We put our task to the new position
|
||||
array_splice($columns[$column_id], $position - 1, 0, $task_id); // print_r($columns);
|
||||
|
||||
// We save the new positions for all tasks
|
||||
return $this->savePositions($task_id, $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save task positions
|
||||
*
|
||||
* @access private
|
||||
* @param integer $moved_task_id Id of the moved task
|
||||
* @param array $columns Sorted tasks
|
||||
* @return boolean
|
||||
*/
|
||||
private function savePositions($moved_task_id, array $columns)
|
||||
{
|
||||
foreach ($columns as $column_id => $column) {
|
||||
|
||||
$position = 1;
|
||||
|
||||
foreach ($column as $task_id) {
|
||||
|
||||
if ($task_id == $moved_task_id) {
|
||||
|
||||
// Events will be triggered only for that task
|
||||
$result = $this->update(array(
|
||||
'id' => $task_id,
|
||||
'position' => $position,
|
||||
'column_id' => $column_id
|
||||
));
|
||||
}
|
||||
else {
|
||||
$result = $this->db->table(self::TABLE)->eq('id', $task_id)->update(array(
|
||||
'position' => $position,
|
||||
'column_id' => $column_id
|
||||
));
|
||||
}
|
||||
|
||||
$position++;
|
||||
|
||||
if (! $result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a task to another project
|
||||
*
|
||||
|
|
|
|||
|
|
@ -21,7 +21,10 @@ class TaskCreation extends Base
|
|||
{
|
||||
$this->prepare($values);
|
||||
$task_id = $this->persist(Task::TABLE, $values);
|
||||
$this->fireEvents($task_id, $values);
|
||||
|
||||
if ($task_id) {
|
||||
$this->fireEvents($task_id, $values);
|
||||
}
|
||||
|
||||
return (int) $task_id;
|
||||
}
|
||||
|
|
@ -60,10 +63,8 @@ class TaskCreation extends Base
|
|||
*/
|
||||
private function fireEvents($task_id, array $values)
|
||||
{
|
||||
if ($task_id) {
|
||||
$values['task_id'] = $task_id;
|
||||
$this->event->trigger(Task::EVENT_CREATE_UPDATE, $values);
|
||||
$this->event->trigger(Task::EVENT_CREATE, $values);
|
||||
}
|
||||
$values['task_id'] = $task_id;
|
||||
$this->event->trigger(Task::EVENT_CREATE_UPDATE, $values);
|
||||
$this->event->trigger(Task::EVENT_CREATE, $values);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace Model;
|
||||
|
||||
/**
|
||||
* Task Position
|
||||
*
|
||||
* @package model
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskPosition extends Base
|
||||
{
|
||||
/**
|
||||
* Move a task to another column or to another position
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param integer $task_id Task id
|
||||
* @param integer $column_id Column id
|
||||
* @param integer $position Position (must be >= 1)
|
||||
* @return boolean
|
||||
*/
|
||||
public function movePosition($project_id, $task_id, $column_id, $position)
|
||||
{
|
||||
$original_task = $this->taskFinder->getById($task_id);
|
||||
$positions = $this->calculatePositions($project_id, $task_id, $column_id, $position);
|
||||
|
||||
if ($positions === false || ! $this->savePositions($positions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->fireEvents($original_task, $column_id, $position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the new position of all tasks
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param integer $task_id Task id
|
||||
* @param integer $column_id Column id
|
||||
* @param integer $position Position (must be >= 1)
|
||||
* @return array|boolean
|
||||
*/
|
||||
public function calculatePositions($project_id, $task_id, $column_id, $position)
|
||||
{
|
||||
// The position can't be lower than 1
|
||||
if ($position < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$board = $this->db->table(Board::TABLE)->eq('project_id', $project_id)->asc('position')->findAllByColumn('id');
|
||||
$columns = array();
|
||||
|
||||
// For each column fetch all tasks ordered by position
|
||||
foreach ($board as $board_column_id) {
|
||||
|
||||
$columns[$board_column_id] = $this->db->table(Task::TABLE)
|
||||
->eq('is_active', 1)
|
||||
->eq('project_id', $project_id)
|
||||
->eq('column_id', $board_column_id)
|
||||
->neq('id', $task_id)
|
||||
->asc('position')
|
||||
->findAllByColumn('id');
|
||||
}
|
||||
|
||||
// The column must exists
|
||||
if (! isset($columns[$column_id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We put our task to the new position
|
||||
array_splice($columns[$column_id], $position - 1, 0, $task_id);
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save task positions
|
||||
*
|
||||
* @access private
|
||||
* @param array $columns Sorted tasks
|
||||
* @return boolean
|
||||
*/
|
||||
private function savePositions(array $columns)
|
||||
{
|
||||
return $this->db->transaction(function ($db) use ($columns) {
|
||||
|
||||
foreach ($columns as $column_id => $column) {
|
||||
|
||||
$position = 1;
|
||||
|
||||
foreach ($column as $task_id) {
|
||||
|
||||
$result = $this->db->table(Task::TABLE)->eq('id', $task_id)->update(array(
|
||||
'position' => $position,
|
||||
'column_id' => $column_id
|
||||
));
|
||||
|
||||
if (! $result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$position++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function fireEvents(array $task, $new_column_id, $new_position)
|
||||
{
|
||||
$event_data = array(
|
||||
'task_id' => $task['id'],
|
||||
'project_id' => $task['project_id'],
|
||||
'position' => $new_position,
|
||||
'column_id' => $new_column_id,
|
||||
);
|
||||
|
||||
if ($task['column_id'] != $new_column_id) {
|
||||
$this->event->trigger(Task::EVENT_MOVE_COLUMN, $event_data);
|
||||
}
|
||||
else if ($task['position'] != $new_position) {
|
||||
$this->event->trigger(Task::EVENT_MOVE_POSITION, $event_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ $models = array(
|
|||
'Task',
|
||||
'TaskCreation',
|
||||
'TaskFinder',
|
||||
'TaskPosition',
|
||||
'TaskStatus',
|
||||
'TaskValidator',
|
||||
'User',
|
||||
|
|
@ -109,7 +110,7 @@ $server->bind('getAllTasks', $taskFinderModel, 'getAll');
|
|||
$server->bind('openTask', $taskStatusModel, 'open');
|
||||
$server->bind('closeTask', $taskStatusModel, 'close');
|
||||
$server->bind('removeTask', $taskModel, 'remove');
|
||||
$server->bind('moveTaskPosition', $taskModel, 'movePosition');
|
||||
$server->bind('moveTaskPosition', $taskPositionModel, 'movePosition');
|
||||
|
||||
$server->register('createTask', function($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, $date_due = '', $description = '', $category_id = 0, $score = 0) use ($taskCreationModel, $taskValidatorModel) {
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@ use Model\Action;
|
|||
use Model\Project;
|
||||
use Model\Board;
|
||||
use Model\Task;
|
||||
use Model\TaskPosition;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Category;
|
||||
|
||||
class ActionTest extends Base
|
||||
{
|
||||
{/*
|
||||
public function testFetchActions()
|
||||
{
|
||||
$action = new Action($this->container);
|
||||
|
|
@ -50,7 +51,7 @@ class ActionTest extends Base
|
|||
|
||||
public function testEventMoveColumn()
|
||||
{
|
||||
$t = new Task($this->container);
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$board = new Board($this->container);
|
||||
|
|
@ -88,7 +89,7 @@ class ActionTest extends Base
|
|||
$this->assertEquals(1, $t1['column_id']);
|
||||
|
||||
// We move our task
|
||||
$t->movePosition(1, 1, 4, 1);
|
||||
$tp->movePosition(1, 1, 4, 1);
|
||||
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_UPDATE));
|
||||
|
|
@ -98,10 +99,10 @@ class ActionTest extends Base
|
|||
$this->assertEquals(4, $t1['column_id']);
|
||||
$this->assertEquals(0, $t1['is_active']);
|
||||
}
|
||||
|
||||
*/
|
||||
public function testExecuteMultipleActions()
|
||||
{
|
||||
$t = new Task($this->container);
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$board = new Board($this->container);
|
||||
|
|
@ -155,10 +156,10 @@ class ActionTest extends Base
|
|||
$this->assertEquals(1, $t1['project_id']);
|
||||
|
||||
// We move our task
|
||||
$t->movePosition(1, 1, 4, 1);
|
||||
$tp->movePosition(1, 1, 4, 1);
|
||||
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));
|
||||
$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);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,446 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__.'/Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskPosition;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Project;
|
||||
|
||||
class TaskPositionTest extends Base
|
||||
{
|
||||
public function testCalculatePositionBadPosition()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($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)));
|
||||
|
||||
$this->assertFalse($tp->calculatePositions(1, 1, 2, 0));
|
||||
}
|
||||
|
||||
public function testCalculatePositionBadColumn()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($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)));
|
||||
|
||||
$this->assertFalse($tp->calculatePositions(1, 1, 10, 1));
|
||||
}
|
||||
|
||||
public function testCalculatePositions()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($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)));
|
||||
|
||||
$positions = $tp->calculatePositions(1, 1, 2, 1);
|
||||
$this->assertNotFalse($positions);
|
||||
$this->assertNotEmpty($positions);
|
||||
$this->assertEmpty($positions[1]);
|
||||
$this->assertEmpty($positions[3]);
|
||||
$this->assertEmpty($positions[4]);
|
||||
$this->assertEquals(array(1), $positions[2]);
|
||||
}
|
||||
|
||||
public function testMoveTaskWithColumnThatNotChange()
|
||||
{
|
||||
$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' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertEquals(7, $tc->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
|
||||
$this->assertEquals(8, $tc->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// We move the task 3 to the column 3
|
||||
$this->assertTrue($tp->movePosition(1, 3, 3, 2));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
$this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(6);
|
||||
$this->assertEquals(6, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$task = $tf->getById(7);
|
||||
$this->assertEquals(7, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(8);
|
||||
$this->assertEquals(8, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskWithBadPreviousPosition()
|
||||
{
|
||||
$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, $this->container['db']->table('tasks')->insert(array('title' => 'A', 'column_id' => 1, 'project_id' => 1, 'position' => 1)));
|
||||
|
||||
// Both tasks have the same position
|
||||
$this->assertEquals(2, $this->container['db']->table('tasks')->insert(array('title' => 'B', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
|
||||
$this->assertEquals(3, $this->container['db']->table('tasks')->insert(array('title' => 'C', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
|
||||
|
||||
// Move the first column to the last position of the 2nd column
|
||||
$this->assertTrue($tp->movePosition(1, 1, 2, 3));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskTop()
|
||||
{
|
||||
$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' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// Move the last task to the top
|
||||
$this->assertTrue($tp->movePosition(1, 4, 1, 1));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskBottom()
|
||||
{
|
||||
$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' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// Move the last task to hte top
|
||||
$this->assertTrue($tp->movePosition(1, 1, 1, 4));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
}
|
||||
|
||||
public function testMovePosition()
|
||||
{
|
||||
$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')));
|
||||
$counter = 1;
|
||||
$task_per_column = 5;
|
||||
|
||||
foreach (array(1, 2, 3, 4) as $column_id) {
|
||||
|
||||
for ($i = 1; $i <= $task_per_column; $i++, $counter++) {
|
||||
|
||||
$task = array(
|
||||
'title' => 'Task #'.$i.'-'.$column_id,
|
||||
'project_id' => 1,
|
||||
'column_id' => $column_id,
|
||||
'owner_id' => 0,
|
||||
);
|
||||
|
||||
$this->assertEquals($counter, $tc->create($task));
|
||||
|
||||
$task = $tf->getById($counter);
|
||||
$this->assertNotFalse($task);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals($i, $task['position']);
|
||||
}
|
||||
}
|
||||
|
||||
// We move task id #4, column 1, position 4 to the column 2, position 3
|
||||
$this->assertTrue($tp->movePosition(1, 4, 2, 3));
|
||||
|
||||
// We check the new position of the task
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
// The tasks before have the correct position
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$task = $tf->getById(7);
|
||||
$this->assertEquals(7, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
// The tasks after have the correct position
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
$task = $tf->getById(8);
|
||||
$this->assertEquals(8, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
// The number of tasks per column
|
||||
$this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 4));
|
||||
|
||||
// We move task id #1, column 1, position 1 to the column 4, position 6 (last position)
|
||||
$this->assertTrue($tp->movePosition(1, 1, 4, $task_per_column + 1));
|
||||
|
||||
// We check the new position of the task
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(4, $task['column_id']);
|
||||
$this->assertEquals($task_per_column + 1, $task['position']);
|
||||
|
||||
// The tasks before have the correct position
|
||||
$task = $tf->getById(20);
|
||||
$this->assertEquals(20, $task['id']);
|
||||
$this->assertEquals(4, $task['column_id']);
|
||||
$this->assertEquals($task_per_column, $task['position']);
|
||||
|
||||
// The tasks after have the correct position
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
// The number of tasks per column
|
||||
$this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
|
||||
|
||||
// Our previous moved task should stay at the same place
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
// Test wrong position number
|
||||
$this->assertFalse($tp->movePosition(1, 2, 3, 0));
|
||||
$this->assertFalse($tp->movePosition(1, 2, 3, -2));
|
||||
|
||||
// Wrong column
|
||||
$this->assertFalse($tp->movePosition(1, 2, 22, 2));
|
||||
|
||||
// Test position greater than the last position
|
||||
$this->assertTrue($tp->movePosition(1, 11, 1, 22));
|
||||
|
||||
$task = $tf->getById(11);
|
||||
$this->assertEquals(11, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals($tf->countByColumnId(1, 1), $task['position']);
|
||||
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
|
||||
|
||||
// Our previous moved task should stay at the same place
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
// Test moving task to position 1
|
||||
$this->assertTrue($tp->movePosition(1, 14, 1, 1));
|
||||
|
||||
$task = $tf->getById(14);
|
||||
$this->assertEquals(14, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
|
@ -27,335 +27,6 @@ class TaskTest extends Base
|
|||
$this->assertFalse($t->remove(1234));
|
||||
}
|
||||
|
||||
public function testMoveTaskWithColumnThatNotChange()
|
||||
{
|
||||
$t = new Task($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' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertEquals(7, $tc->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
|
||||
$this->assertEquals(8, $tc->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// We move the task 3 to the column 3
|
||||
$this->assertTrue($t->movePosition(1, 3, 3, 2));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(6);
|
||||
$this->assertEquals(6, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$task = $tf->getById(7);
|
||||
$this->assertEquals(7, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(8);
|
||||
$this->assertEquals(8, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskWithBadPreviousPosition()
|
||||
{
|
||||
$t = new Task($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, $this->container['db']->table('tasks')->insert(array('title' => 'A', 'column_id' => 1, 'project_id' => 1, 'position' => 1)));
|
||||
|
||||
// Both tasks have the same position
|
||||
$this->assertEquals(2, $this->container['db']->table('tasks')->insert(array('title' => 'B', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
|
||||
$this->assertEquals(3, $this->container['db']->table('tasks')->insert(array('title' => 'C', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
|
||||
|
||||
// Move the first column to the last position of the 2nd column
|
||||
$this->assertTrue($t->movePosition(1, 1, 2, 3));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskTop()
|
||||
{
|
||||
$t = new Task($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' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// Move the last task to the top
|
||||
$this->assertTrue($t->movePosition(1, 4, 1, 1));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskBottom()
|
||||
{
|
||||
$t = new Task($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' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// Move the last task to hte top
|
||||
$this->assertTrue($t->movePosition(1, 1, 1, 4));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
}
|
||||
|
||||
public function testMovePosition()
|
||||
{
|
||||
$t = new Task($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')));
|
||||
$counter = 1;
|
||||
$task_per_column = 5;
|
||||
|
||||
foreach (array(1, 2, 3, 4) as $column_id) {
|
||||
|
||||
for ($i = 1; $i <= $task_per_column; $i++, $counter++) {
|
||||
|
||||
$task = array(
|
||||
'title' => 'Task #'.$i.'-'.$column_id,
|
||||
'project_id' => 1,
|
||||
'column_id' => $column_id,
|
||||
'owner_id' => 0,
|
||||
);
|
||||
|
||||
$this->assertEquals($counter, $tc->create($task));
|
||||
|
||||
$task = $tf->getById($counter);
|
||||
$this->assertNotFalse($task);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals($i, $task['position']);
|
||||
}
|
||||
}
|
||||
|
||||
// We move task id #4, column 1, position 4 to the column 2, position 3
|
||||
$this->assertTrue($t->movePosition(1, 4, 2, 3));
|
||||
|
||||
// We check the new position of the task
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
// The tasks before have the correct position
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$task = $tf->getById(7);
|
||||
$this->assertEquals(7, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
// The tasks after have the correct position
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
$task = $tf->getById(8);
|
||||
$this->assertEquals(8, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
// The number of tasks per column
|
||||
$this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 4));
|
||||
|
||||
// We move task id #1, column 1, position 1 to the column 4, position 6 (last position)
|
||||
$this->assertTrue($t->movePosition(1, 1, 4, $task_per_column + 1));
|
||||
|
||||
// We check the new position of the task
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(4, $task['column_id']);
|
||||
$this->assertEquals($task_per_column + 1, $task['position']);
|
||||
|
||||
// The tasks before have the correct position
|
||||
$task = $tf->getById(20);
|
||||
$this->assertEquals(20, $task['id']);
|
||||
$this->assertEquals(4, $task['column_id']);
|
||||
$this->assertEquals($task_per_column, $task['position']);
|
||||
|
||||
// The tasks after have the correct position
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
// The number of tasks per column
|
||||
$this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
|
||||
|
||||
// Our previous moved task should stay at the same place
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
// Test wrong position number
|
||||
$this->assertFalse($t->movePosition(1, 2, 3, 0));
|
||||
$this->assertFalse($t->movePosition(1, 2, 3, -2));
|
||||
|
||||
// Wrong column
|
||||
$this->assertFalse($t->movePosition(1, 2, 22, 2));
|
||||
|
||||
// Test position greater than the last position
|
||||
$this->assertTrue($t->movePosition(1, 11, 1, 22));
|
||||
|
||||
$task = $tf->getById(11);
|
||||
$this->assertEquals(11, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals($tf->countByColumnId(1, 1), $task['position']);
|
||||
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
|
||||
|
||||
// Our previous moved task should stay at the same place
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
// Test moving task to position 1
|
||||
$this->assertTrue($t->movePosition(1, 14, 1, 1));
|
||||
|
||||
$task = $tf->getById(14);
|
||||
$this->assertEquals(14, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
|
||||
}
|
||||
|
||||
public function testDuplicateToTheSameProject()
|
||||
{
|
||||
$t = new Task($this->container);
|
||||
|
|
@ -488,34 +159,12 @@ class TaskTest extends Base
|
|||
|
||||
// We create task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
|
||||
|
||||
// We update a task
|
||||
$this->assertTrue($t->update(array('title' => 'test2', 'id' => 1)));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_UPDATE));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
|
||||
|
||||
// We close our task
|
||||
$this->assertTrue($ts->close(1));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));
|
||||
|
||||
// We open our task
|
||||
$this->assertTrue($ts->open(1));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_OPEN));
|
||||
|
||||
// We change the column of our task
|
||||
$this->assertTrue($t->movePosition(1, 1, 2, 1));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
|
||||
// We change the position of our task
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertTrue($t->movePosition(1, 1, 2, 2));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION));
|
||||
|
||||
// We change the column and the position of our task
|
||||
$this->assertTrue($t->movePosition(1, 1, 1, 1));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||
|
||||
// We change the assignee
|
||||
$this->assertTrue($t->update(array('owner_id' => 1, 'id' => 1)));
|
||||
$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE));
|
||||
|
|
|
|||
Loading…
Reference in New Issue