Handle tags and tasks move/duplication to another project

This commit is contained in:
Frederic Guillot
2016-07-02 14:44:26 -04:00
parent 853189a43f
commit 3fcc0cb918
19 changed files with 1121 additions and 777 deletions

View File

@@ -76,7 +76,7 @@ class TaskDuplicateAnotherProject extends Base
public function doAction(array $data) public function doAction(array $data)
{ {
$destination_column_id = $this->columnModel->getFirstColumnId($this->getParam('project_id')); $destination_column_id = $this->columnModel->getFirstColumnId($this->getParam('project_id'));
return (bool) $this->taskDuplicationModel->duplicateToProject($data['task_id'], $this->getParam('project_id'), null, $destination_column_id); return (bool) $this->taskProjectDuplicationModel->duplicateToProject($data['task_id'], $this->getParam('project_id'), null, $destination_column_id);
} }
/** /**

View File

@@ -75,7 +75,7 @@ class TaskMoveAnotherProject extends Base
*/ */
public function doAction(array $data) public function doAction(array $data)
{ {
return $this->taskDuplicationModel->moveToProject($data['task_id'], $this->getParam('project_id')); return $this->taskProjectMoveModel->moveToProject($data['task_id'], $this->getParam('project_id'));
} }
/** /**

View File

@@ -77,13 +77,13 @@ class TaskProcedure extends BaseProcedure
public function moveTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) public function moveTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null)
{ {
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'moveTaskToProject', $project_id); ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'moveTaskToProject', $project_id);
return $this->taskDuplicationModel->moveToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); return $this->taskProjectMoveModel->moveToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id);
} }
public function duplicateTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) public function duplicateTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null)
{ {
ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'duplicateTaskToProject', $project_id); ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'duplicateTaskToProject', $project_id);
return $this->taskDuplicationModel->duplicateToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); return $this->taskProjectDuplicationModel->duplicateToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id);
} }
public function createTask($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, public function createTask($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0,

View File

@@ -50,7 +50,7 @@ class TaskDuplicationController extends BaseController
$values = $this->request->getValues(); $values = $this->request->getValues();
list($valid, ) = $this->taskValidator->validateProjectModification($values); list($valid, ) = $this->taskValidator->validateProjectModification($values);
if ($valid && $this->taskDuplicationModel->moveToProject($task['id'], if ($valid && $this->taskProjectMoveModel->moveToProject($task['id'],
$values['project_id'], $values['project_id'],
$values['swimlane_id'], $values['swimlane_id'],
$values['column_id'], $values['column_id'],
@@ -80,7 +80,7 @@ class TaskDuplicationController extends BaseController
list($valid, ) = $this->taskValidator->validateProjectModification($values); list($valid, ) = $this->taskValidator->validateProjectModification($values);
if ($valid) { if ($valid) {
$task_id = $this->taskDuplicationModel->duplicateToProject( $task_id = $this->taskProjectDuplicationModel->duplicateToProject(
$task['id'], $values['project_id'], $values['swimlane_id'], $task['id'], $values['project_id'], $values['swimlane_id'],
$values['column_id'], $values['category_id'], $values['owner_id'] $values['column_id'], $values['category_id'], $values['owner_id']
); );

View File

@@ -90,11 +90,15 @@ use Pimple\Container;
* @property \Kanboard\Model\SubtaskModel $subtaskModel * @property \Kanboard\Model\SubtaskModel $subtaskModel
* @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel * @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel
* @property \Kanboard\Model\SwimlaneModel $swimlaneModel * @property \Kanboard\Model\SwimlaneModel $swimlaneModel
* @property \Kanboard\Model\TagDuplicationModel $tagDuplicationModel
* @property \Kanboard\Model\TagModel $tagModel * @property \Kanboard\Model\TagModel $tagModel
* @property \Kanboard\Model\TaskModel $taskModel * @property \Kanboard\Model\TaskModel $taskModel
* @property \Kanboard\Model\TaskAnalyticModel $taskAnalyticModel * @property \Kanboard\Model\TaskAnalyticModel $taskAnalyticModel
* @property \Kanboard\Model\TaskCreationModel $taskCreationModel * @property \Kanboard\Model\TaskCreationModel $taskCreationModel
* @property \Kanboard\Model\TaskDuplicationModel $taskDuplicationModel * @property \Kanboard\Model\TaskDuplicationModel $taskDuplicationModel
* @property \Kanboard\Model\TaskProjectDuplicationModel $taskProjectDuplicationModel
* @property \Kanboard\Model\TaskProjectMoveModel $taskProjectMoveModel
* @property \Kanboard\Model\TaskRecurrenceModel $taskRecurrenceModel
* @property \Kanboard\Model\TaskExternalLinkModel $taskExternalLinkModel * @property \Kanboard\Model\TaskExternalLinkModel $taskExternalLinkModel
* @property \Kanboard\Model\TaskFinderModel $taskFinderModel * @property \Kanboard\Model\TaskFinderModel $taskFinderModel
* @property \Kanboard\Model\TaskLinkModel $taskLinkModel * @property \Kanboard\Model\TaskLinkModel $taskLinkModel

View File

@@ -0,0 +1,67 @@
<?php
namespace Kanboard\Model;
use Kanboard\Core\Base;
/**
* Tag Duplication
*
* @package Kanboard\Model
* @author Frederic Guillot
*/
class TagDuplicationModel extends Base
{
/**
* Link tags to the new tasks
*
* @access public
* @param integer $src_task_id
* @param integer $dst_task_id
* @param integer $dst_project_id
*/
public function duplicateTaskTagsToAnotherProject($src_task_id, $dst_task_id, $dst_project_id)
{
$tags = $this->taskTagModel->getTagsByTask($src_task_id);
foreach ($tags as $tag) {
$tag_id = $this->tagModel->getIdByName($dst_project_id, $tag['name']);
if ($tag_id) {
$this->taskTagModel->associateTag($dst_task_id, $tag_id);
}
}
}
/**
* Duplicate tags to the new task
*
* @access public
* @param integer $src_task_id
* @param integer $dst_task_id
*/
public function duplicateTaskTags($src_task_id, $dst_task_id)
{
$tags = $this->taskTagModel->getTagsByTask($src_task_id);
foreach ($tags as $tag) {
$this->taskTagModel->associateTag($dst_task_id, $tag['id']);
}
}
/**
* Remove tags that are not available in destination project
*
* @access public
* @param integer $task_id
* @param integer $dst_project_id
*/
public function syncTaskTagsToAnotherProject($task_id, $dst_project_id)
{
$tag_ids = $this->taskTagModel->getTagIdsByTaskNotAvailableInProject($task_id, $dst_project_id);
foreach ($tag_ids as $tag_id) {
$this->taskTagModel->dissociateTag($task_id, $tag_id);
}
}
}

View File

@@ -2,10 +2,7 @@
namespace Kanboard\Model; namespace Kanboard\Model;
use DateTime;
use DateInterval;
use Kanboard\Core\Base; use Kanboard\Core\Base;
use Kanboard\Event\TaskEvent;
/** /**
* Task Duplication * Task Duplication
@@ -18,10 +15,10 @@ class TaskDuplicationModel extends Base
/** /**
* Fields to copy when duplicating a task * Fields to copy when duplicating a task
* *
* @access private * @access protected
* @var array * @var string[]
*/ */
private $fields_to_duplicate = array( protected $fields_to_duplicate = array(
'title', 'title',
'description', 'description',
'date_due', 'date_due',
@@ -49,106 +46,13 @@ class TaskDuplicationModel extends Base
*/ */
public function duplicate($task_id) public function duplicate($task_id)
{ {
return $this->save($task_id, $this->copyFields($task_id)); $new_task_id = $this->save($task_id, $this->copyFields($task_id));
}
/** if ($new_task_id !== false) {
* Duplicate recurring task $this->tagDuplicationModel->duplicateTaskTags($task_id, $new_task_id);
*
* @access public
* @param integer $task_id Task id
* @return boolean|integer Recurrence task id
*/
public function duplicateRecurringTask($task_id)
{
$values = $this->copyFields($task_id);
if ($values['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) {
$values['recurrence_parent'] = $task_id;
$values['column_id'] = $this->columnModel->getFirstColumnId($values['project_id']);
$this->calculateRecurringTaskDueDate($values);
$recurring_task_id = $this->save($task_id, $values);
if ($recurring_task_id > 0) {
$parent_update = $this->db
->table(TaskModel::TABLE)
->eq('id', $task_id)
->update(array(
'recurrence_status' => TaskModel::RECURRING_STATUS_PROCESSED,
'recurrence_child' => $recurring_task_id,
));
if ($parent_update) {
return $recurring_task_id;
}
}
} }
return false; return $new_task_id;
}
/**
* Duplicate a task to another project
*
* @access public
* @param integer $task_id
* @param integer $project_id
* @param integer $swimlane_id
* @param integer $column_id
* @param integer $category_id
* @param integer $owner_id
* @return boolean|integer
*/
public function duplicateToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null)
{
$values = $this->copyFields($task_id);
$values['project_id'] = $project_id;
$values['column_id'] = $column_id !== null ? $column_id : $values['column_id'];
$values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $values['swimlane_id'];
$values['category_id'] = $category_id !== null ? $category_id : $values['category_id'];
$values['owner_id'] = $owner_id !== null ? $owner_id : $values['owner_id'];
$this->checkDestinationProjectValues($values);
return $this->save($task_id, $values);
}
/**
* Move a task to another project
*
* @access public
* @param integer $task_id
* @param integer $project_id
* @param integer $swimlane_id
* @param integer $column_id
* @param integer $category_id
* @param integer $owner_id
* @return boolean
*/
public function moveToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null)
{
$task = $this->taskFinderModel->getById($task_id);
$values = array();
$values['is_active'] = 1;
$values['project_id'] = $project_id;
$values['column_id'] = $column_id !== null ? $column_id : $task['column_id'];
$values['position'] = $this->taskFinderModel->countByColumnId($project_id, $values['column_id']) + 1;
$values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $task['swimlane_id'];
$values['category_id'] = $category_id !== null ? $category_id : $task['category_id'];
$values['owner_id'] = $owner_id !== null ? $owner_id : $task['owner_id'];
$this->checkDestinationProjectValues($values);
if ($this->db->table(TaskModel::TABLE)->eq('id', $task['id'])->update($values)) {
$this->container['dispatcher']->dispatch(
TaskModel::EVENT_MOVE_PROJECT,
new TaskEvent(array_merge($task, $values, array('task_id' => $task['id'])))
);
}
return true;
} }
/** /**
@@ -194,50 +98,14 @@ class TaskDuplicationModel extends Base
return $values; return $values;
} }
/**
* Calculate new due date for new recurrence task
*
* @access public
* @param array $values Task fields
*/
public function calculateRecurringTaskDueDate(array &$values)
{
if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) {
if ($values['recurrence_basedate'] == TaskModel::RECURRING_BASEDATE_TRIGGERDATE) {
$values['date_due'] = time();
}
$factor = abs($values['recurrence_factor']);
$subtract = $values['recurrence_factor'] < 0;
switch ($values['recurrence_timeframe']) {
case TaskModel::RECURRING_TIMEFRAME_MONTHS:
$interval = 'P' . $factor . 'M';
break;
case TaskModel::RECURRING_TIMEFRAME_YEARS:
$interval = 'P' . $factor . 'Y';
break;
default:
$interval = 'P' . $factor . 'D';
}
$date_due = new DateTime();
$date_due->setTimestamp($values['date_due']);
$subtract ? $date_due->sub(new DateInterval($interval)) : $date_due->add(new DateInterval($interval));
$values['date_due'] = $date_due->getTimestamp();
}
}
/** /**
* Duplicate fields for the new task * Duplicate fields for the new task
* *
* @access private * @access protected
* @param integer $task_id Task id * @param integer $task_id Task id
* @return array * @return array
*/ */
private function copyFields($task_id) protected function copyFields($task_id)
{ {
$task = $this->taskFinderModel->getById($task_id); $task = $this->taskFinderModel->getById($task_id);
$values = array(); $values = array();
@@ -252,16 +120,16 @@ class TaskDuplicationModel extends Base
/** /**
* Create the new task and duplicate subtasks * Create the new task and duplicate subtasks
* *
* @access private * @access protected
* @param integer $task_id Task id * @param integer $task_id Task id
* @param array $values Form values * @param array $values Form values
* @return boolean|integer * @return boolean|integer
*/ */
private function save($task_id, array $values) protected function save($task_id, array $values)
{ {
$new_task_id = $this->taskCreationModel->create($values); $new_task_id = $this->taskCreationModel->create($values);
if ($new_task_id) { if ($new_task_id !== false) {
$this->subtaskModel->duplicate($task_id, $new_task_id); $this->subtaskModel->duplicate($task_id, $new_task_id);
} }

View File

@@ -215,7 +215,7 @@ class TaskModel extends Base
$task_ids = $this->taskFinderModel->getAllIds($src_project_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED)); $task_ids = $this->taskFinderModel->getAllIds($src_project_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED));
foreach ($task_ids as $task_id) { foreach ($task_ids as $task_id) {
if (! $this->taskDuplicationModel->duplicateToProject($task_id, $dst_project_id)) { if (! $this->taskProjectDuplicationModel->duplicateToProject($task_id, $dst_project_id)) {
return false; return false;
} }
} }

View File

@@ -0,0 +1,60 @@
<?php
namespace Kanboard\Model;
/**
* Task Project Duplication
*
* @package Kanboard\Model
* @author Frederic Guillot
*/
class TaskProjectDuplicationModel extends TaskDuplicationModel
{
/**
* Duplicate a task to another project
*
* @access public
* @param integer $task_id
* @param integer $project_id
* @param integer $swimlane_id
* @param integer $column_id
* @param integer $category_id
* @param integer $owner_id
* @return boolean|integer
*/
public function duplicateToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null)
{
$values = $this->prepare($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id);
$this->checkDestinationProjectValues($values);
$new_task_id = $this->save($task_id, $values);
if ($new_task_id !== false) {
$this->tagDuplicationModel->duplicateTaskTagsToAnotherProject($task_id, $new_task_id, $project_id);
}
return $new_task_id;
}
/**
* Prepare values before duplication
*
* @access protected
* @param integer $task_id
* @param integer $project_id
* @param integer $swimlane_id
* @param integer $column_id
* @param integer $category_id
* @param integer $owner_id
* @return array
*/
protected function prepare($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id)
{
$values = $this->copyFields($task_id);
$values['project_id'] = $project_id;
$values['column_id'] = $column_id !== null ? $column_id : $values['column_id'];
$values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $values['swimlane_id'];
$values['category_id'] = $category_id !== null ? $category_id : $values['category_id'];
$values['owner_id'] = $owner_id !== null ? $owner_id : $values['owner_id'];
return $values;
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Kanboard\Model;
use Kanboard\Event\TaskEvent;
/**
* Task Project Move
*
* @package Kanboard\Model
* @author Frederic Guillot
*/
class TaskProjectMoveModel extends TaskDuplicationModel
{
/**
* Move a task to another project
*
* @access public
* @param integer $task_id
* @param integer $project_id
* @param integer $swimlane_id
* @param integer $column_id
* @param integer $category_id
* @param integer $owner_id
* @return boolean
*/
public function moveToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null)
{
$task = $this->taskFinderModel->getById($task_id);
$values = $this->prepare($project_id, $swimlane_id, $column_id, $category_id, $owner_id, $task);
$this->checkDestinationProjectValues($values);
$this->tagDuplicationModel->syncTaskTagsToAnotherProject($task_id, $project_id);
if ($this->db->table(TaskModel::TABLE)->eq('id', $task['id'])->update($values)) {
$event = new TaskEvent(array_merge($task, $values, array('task_id' => $task['id'])));
$this->dispatcher->dispatch(TaskModel::EVENT_MOVE_PROJECT, $event);
}
return true;
}
/**
* Prepare new task values
*
* @access protected
* @param integer $project_id
* @param integer $swimlane_id
* @param integer $column_id
* @param integer $category_id
* @param integer $owner_id
* @param array $task
* @return array
*/
protected function prepare($project_id, $swimlane_id, $column_id, $category_id, $owner_id, array $task)
{
$values = array();
$values['is_active'] = 1;
$values['project_id'] = $project_id;
$values['column_id'] = $column_id !== null ? $column_id : $task['column_id'];
$values['position'] = $this->taskFinderModel->countByColumnId($project_id, $values['column_id']) + 1;
$values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $task['swimlane_id'];
$values['category_id'] = $category_id !== null ? $category_id : $task['category_id'];
$values['owner_id'] = $owner_id !== null ? $owner_id : $task['owner_id'];
return $values;
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace Kanboard\Model;
use DateInterval;
use DateTime;
/**
* Task Recurrence
*
* @package Kanboard\Model
* @author Frederic Guillot
*/
class TaskRecurrenceModel extends TaskDuplicationModel
{
/**
* Duplicate recurring task
*
* @access public
* @param integer $task_id Task id
* @return boolean|integer Recurrence task id
*/
public function duplicateRecurringTask($task_id)
{
$values = $this->copyFields($task_id);
if ($values['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) {
$values['recurrence_parent'] = $task_id;
$values['column_id'] = $this->columnModel->getFirstColumnId($values['project_id']);
$this->calculateRecurringTaskDueDate($values);
$recurring_task_id = $this->save($task_id, $values);
if ($recurring_task_id > 0) {
$parent_update = $this->db
->table(TaskModel::TABLE)
->eq('id', $task_id)
->update(array(
'recurrence_status' => TaskModel::RECURRING_STATUS_PROCESSED,
'recurrence_child' => $recurring_task_id,
));
if ($parent_update) {
return $recurring_task_id;
}
}
}
return false;
}
/**
* Calculate new due date for new recurrence task
*
* @access public
* @param array $values Task fields
*/
public function calculateRecurringTaskDueDate(array &$values)
{
if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) {
if ($values['recurrence_basedate'] == TaskModel::RECURRING_BASEDATE_TRIGGERDATE) {
$values['date_due'] = time();
}
$factor = abs($values['recurrence_factor']);
$subtract = $values['recurrence_factor'] < 0;
switch ($values['recurrence_timeframe']) {
case TaskModel::RECURRING_TIMEFRAME_MONTHS:
$interval = 'P' . $factor . 'M';
break;
case TaskModel::RECURRING_TIMEFRAME_YEARS:
$interval = 'P' . $factor . 'Y';
break;
default:
$interval = 'P' . $factor . 'D';
}
$date_due = new DateTime();
$date_due->setTimestamp($values['date_due']);
$subtract ? $date_due->sub(new DateInterval($interval)) : $date_due->add(new DateInterval($interval));
$values['date_due'] = $date_due->getTimestamp();
}
}
}

View File

@@ -19,6 +19,23 @@ class TaskTagModel extends Base
*/ */
const TABLE = 'task_has_tags'; const TABLE = 'task_has_tags';
/**
* Get all tags not available in a project
*
* @access public
* @param integer $task_id
* @param integer $project_id
* @return array
*/
public function getTagIdsByTaskNotAvailableInProject($task_id, $project_id)
{
return $this->db->table(TagModel::TABLE)
->eq(self::TABLE.'.task_id', $task_id)
->notIn(TagModel::TABLE.'.project_id', array(0, $project_id))
->join(self::TABLE, 'tag_id', 'id')
->findAllByColumn(TagModel::TABLE.'.id');
}
/** /**
* Get all tags associated to a task * Get all tags associated to a task
* *

View File

@@ -60,11 +60,15 @@ class ClassProvider implements ServiceProviderInterface
'SubtaskModel', 'SubtaskModel',
'SubtaskTimeTrackingModel', 'SubtaskTimeTrackingModel',
'SwimlaneModel', 'SwimlaneModel',
'TagDuplicationModel',
'TagModel', 'TagModel',
'TaskModel', 'TaskModel',
'TaskAnalyticModel', 'TaskAnalyticModel',
'TaskCreationModel', 'TaskCreationModel',
'TaskDuplicationModel', 'TaskDuplicationModel',
'TaskProjectDuplicationModel',
'TaskProjectMoveModel',
'TaskRecurrenceModel',
'TaskExternalLinkModel', 'TaskExternalLinkModel',
'TaskFinderModel', 'TaskFinderModel',
'TaskFileModel', 'TaskFileModel',

View File

@@ -22,9 +22,9 @@ class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberI
if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) { if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) {
if ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_FIRST_COLUMN && $this->columnModel->getFirstColumnId($event['project_id']) == $event['src_column_id']) { if ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_FIRST_COLUMN && $this->columnModel->getFirstColumnId($event['project_id']) == $event['src_column_id']) {
$this->taskDuplicationModel->duplicateRecurringTask($event['task_id']); $this->taskRecurrenceModel->duplicateRecurringTask($event['task_id']);
} elseif ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_LAST_COLUMN && $this->columnModel->getLastColumnId($event['project_id']) == $event['dst_column_id']) { } elseif ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_LAST_COLUMN && $this->columnModel->getLastColumnId($event['project_id']) == $event['dst_column_id']) {
$this->taskDuplicationModel->duplicateRecurringTask($event['task_id']); $this->taskRecurrenceModel->duplicateRecurringTask($event['task_id']);
} }
} }
} }
@@ -34,7 +34,7 @@ class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberI
$this->logger->debug('Subscriber executed: '.__METHOD__); $this->logger->debug('Subscriber executed: '.__METHOD__);
if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING && $event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_CLOSE) { if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING && $event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_CLOSE) {
$this->taskDuplicationModel->duplicateRecurringTask($event['task_id']); $this->taskRecurrenceModel->duplicateRecurringTask($event['task_id']);
} }
} }
} }

View File

@@ -2,31 +2,27 @@
require_once __DIR__.'/../Base.php'; require_once __DIR__.'/../Base.php';
use Kanboard\Core\DateParser;
use Kanboard\Model\TaskModel; use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskCreationModel; use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskDuplicationModel; use Kanboard\Model\TaskDuplicationModel;
use Kanboard\Model\TaskFinderModel; use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel; use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Model\CategoryModel; use Kanboard\Model\CategoryModel;
use Kanboard\Model\UserModel; use Kanboard\Model\TaskTagModel;
use Kanboard\Model\SwimlaneModel;
use Kanboard\Core\Security\Role;
class TaskDuplicationTest extends Base class TaskDuplicationTest extends Base
{ {
public function testThatDuplicateDefineCreator() public function testThatDuplicateDefineCreator()
{ {
$td = new TaskDuplicationModel($this->container); $taskDuplicationModel = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container); $taskCreationModel = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container); $taskFinderModel = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container); $projectModel = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
$task = $tf->getById(1); $task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task); $this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']); $this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['project_id']); $this->assertEquals(1, $task['project_id']);
@@ -35,37 +31,41 @@ class TaskDuplicationTest extends Base
$this->container['sessionStorage']->user = array('id' => 1); $this->container['sessionStorage']->user = array('id' => 1);
// We duplicate our task // We duplicate our task
$this->assertEquals(2, $td->duplicate(1)); $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
// Check the values of the duplicated task // Check the values of the duplicated task
$task = $tf->getById(2); $task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task); $this->assertNotEmpty($task);
$this->assertEquals(1, $task['creator_id']); $this->assertEquals(1, $task['creator_id']);
} }
public function testDuplicateSameProject() public function testDuplicateSameProject()
{ {
$td = new TaskDuplicationModel($this->container); $taskDuplicationModel = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container); $taskCreationModel = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container); $taskFinderModel = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container); $projectModel = new ProjectModel($this->container);
$c = new CategoryModel($this->container); $categoryModel = new CategoryModel($this->container);
// We create a task and a project // We create a task and a project
$this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
// Some categories // Some categories
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1))); $this->assertNotFalse($categoryModel->create(array('name' => 'Category #2', 'project_id' => 1)));
$this->assertTrue($c->exists(1)); $this->assertTrue($categoryModel->exists(1));
$this->assertTrue($c->exists(2)); $this->assertTrue($categoryModel->exists(2));
$this->assertEquals( $this->assertEquals(1, $taskCreationModel->create(array(
1, 'title' => 'test',
$tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2, 'time_spent' => 4.4) 'project_id' => 1,
)); 'column_id' => 3,
'owner_id' => 1,
'category_id' => 2,
'time_spent' => 4.4
)));
$task = $tf->getById(1); $task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task); $this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']); $this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['project_id']); $this->assertEquals(1, $task['project_id']);
@@ -77,14 +77,14 @@ class TaskDuplicationTest extends Base
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {});
// We duplicate our task // We duplicate our task
$this->assertEquals(2, $td->duplicate(1)); $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
$called = $this->container['dispatcher']->getCalledListeners(); $called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
$this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
// Check the values of the duplicated task // Check the values of the duplicated task
$task = $tf->getById(2); $task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task); $this->assertNotEmpty($task);
$this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']);
$this->assertEquals(1, $task['project_id']); $this->assertEquals(1, $task['project_id']);
@@ -97,604 +97,25 @@ class TaskDuplicationTest extends Base
$this->assertEquals(0, $task['time_spent']); $this->assertEquals(0, $task['time_spent']);
} }
public function testDuplicateAnotherProject() public function testDuplicateSameProjectWitTags()
{ {
$td = new TaskDuplicationModel($this->container); $taskDuplicationModel = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container); $taskCreationModel = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container); $projectModel = new ProjectModel($this->container);
$p = new ProjectModel($this->container); $taskTagModel = new TaskTagModel($this->container);
$c = new CategoryModel($this->container);
// We create 2 projects $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array(
$this->assertEquals(2, $p->create(array('name' => 'test2')));
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertTrue($c->exists(1));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {});
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
$this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testDuplicateAnotherProjectWithCategory()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$c = new CategoryModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
$this->assertTrue($c->exists(1));
$this->assertTrue($c->exists(2));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(2, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testDuplicateAnotherProjectWithPredefinedCategory()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$c = new CategoryModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
$this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 2)));
$this->assertTrue($c->exists(1));
$this->assertTrue($c->exists(2));
$this->assertTrue($c->exists(3));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
// We duplicate our task to the 2nd project with no category
$this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, 0));
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['category_id']);
// We duplicate our task to the 2nd project with a different category
$this->assertEquals(3, $td->duplicateToProject(1, 2, null, null, 3));
// Check the values of the duplicated task
$task = $tf->getById(3);
$this->assertNotEmpty($task);
$this->assertEquals(3, $task['category_id']);
}
public function testDuplicateAnotherProjectWithSwimlane()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$s = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(2, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testDuplicateAnotherProjectWithoutSwimlane()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$s = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testDuplicateAnotherProjectWithPredefinedSwimlane()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$s = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2, 3));
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(3, $task['swimlane_id']);
}
public function testDuplicateAnotherProjectWithPredefinedColumn()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2)));
// We duplicate our task to the 2nd project with a different column
$this->assertEquals(2, $td->duplicateToProject(1, 2, null, 7));
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(7, $task['column_id']);
}
public function testDuplicateAnotherProjectWithUser()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$pp = new ProjectUserRoleModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
// We create a new user for our project
$user = new UserModel($this->container);
$this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
$this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
$this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER));
// We duplicate our task to the 2nd project
$this->assertEquals(3, $td->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $tf->getById(3);
$this->assertNotEmpty($task);
$this->assertEquals(2, $task['position']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(2, $task['owner_id']);
$this->assertEquals(2, $task['project_id']);
// We duplicate a task with a not allowed user
$this->assertEquals(4, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3)));
$this->assertEquals(5, $td->duplicateToProject(4, 2));
$task = $tf->getById(5);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals(5, $task['column_id']);
}
public function testDuplicateAnotherProjectWithPredefinedUser()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$pr = new ProjectUserRoleModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
$this->assertTrue($pr->addUser(2, 1, Role::PROJECT_MEMBER));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, null, 1));
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['owner_id']);
}
public function onMoveProject($event)
{
$this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals('test', $event_data['title']);
}
public function testMoveAnotherProject()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$user = new UserModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333)));
$this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, array($this, 'onMoveProject'));
// We duplicate our task to the 2nd project
$this->assertTrue($td->moveToProject(1, 2));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called);
// Check the values of the moved task
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals(5, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals('test', $task['title']);
}
public function testMoveAnotherProjectWithCategory()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$c = new CategoryModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
$this->assertTrue($c->exists(1));
$this->assertTrue($c->exists(2));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
// We move our task to the 2nd project
$this->assertTrue($td->moveToProject(1, 2));
// Check the values of the duplicated task
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(2, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testMoveAnotherProjectWithUser()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$pp = new ProjectUserRoleModel($this->container);
$user = new UserModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
// We create a new user for our project
$this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
$this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
$this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
// We move our task to the 2nd project
$this->assertTrue($td->moveToProject(1, 2));
// Check the values of the moved task
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['owner_id']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals(6, $task['column_id']);
}
public function testMoveAnotherProjectWithForbiddenUser()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$pp = new ProjectUserRoleModel($this->container);
$user = new UserModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
// We create a new user for our project
$this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
$this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
$this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3)));
// We move our task to the 2nd project
$this->assertTrue($td->moveToProject(1, 2));
// Check the values of the moved task
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals(6, $task['column_id']);
}
public function testMoveAnotherProjectWithSwimlane()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$s = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We move our task to the 2nd project
$this->assertTrue($td->moveToProject(1, 2));
// Check the values of the moved task
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(2, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testMoveAnotherProjectWithoutSwimlane()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$s = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2')));
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
// We create a task
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We move our task to the 2nd project
$this->assertTrue($td->moveToProject(1, 2));
// Check the values of the moved task
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testCalculateRecurringTaskDueDate()
{
$td = new TaskDuplicationModel($this->container);
$values = array('date_due' => 0);
$td->calculateRecurringTaskDueDate($values);
$this->assertEquals(0, $values['date_due']);
$values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$td->calculateRecurringTaskDueDate($values);
$this->assertEquals(0, $values['date_due']);
$values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$td->calculateRecurringTaskDueDate($values);
$this->assertEquals(time() + 86400, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$td->calculateRecurringTaskDueDate($values);
$this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$td->calculateRecurringTaskDueDate($values);
$this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$td->calculateRecurringTaskDueDate($values);
$this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS);
$td->calculateRecurringTaskDueDate($values);
$this->assertEquals(1436561776, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS);
$td->calculateRecurringTaskDueDate($values);
$this->assertEquals(1494449776, $values['date_due'], '', 1);
}
public function testDuplicateRecurringTask()
{
$td = new TaskDuplicationModel($this->container);
$tc = new TaskCreationModel($this->container);
$tf = new TaskFinderModel($this->container);
$p = new ProjectModel($this->container);
$dp = new DateParser($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(1, $tc->create(array(
'title' => 'test', 'title' => 'test',
'project_id' => 1, 'project_id' => 1,
'date_due' => 1436561776, 'tags' => array('T1', 'T2')
'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
'recurrence_factor' => 2,
'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS,
'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE,
))); )));
$this->assertEquals(2, $td->duplicateRecurringTask(1)); $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
$task = $tf->getById(1); $tags = $taskTagModel->getList(2);
$this->assertNotEmpty($task); $this->assertCount(2, $tags);
$this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); $this->assertArrayHasKey(1, $tags);
$this->assertEquals(2, $task['recurrence_child']); $this->assertArrayHasKey(2, $tags);
$this->assertEquals(1436486400, $task['date_due'], '', 2);
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']);
$this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']);
$this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
$this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']);
$this->assertEquals(1, $task['recurrence_parent']);
$this->assertEquals(2, $task['recurrence_factor']);
$this->assertEquals($dp->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2);
} }
} }

View File

@@ -0,0 +1,369 @@
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Core\Security\Role;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Model\SwimlaneModel;
use Kanboard\Model\TagModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskProjectDuplicationModel;
use Kanboard\Model\TaskTagModel;
use Kanboard\Model\UserModel;
class TaskProjectDuplicationModelTest extends Base
{
public function testDuplicateAnotherProject()
{
$taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$categoryModel = new CategoryModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertTrue($categoryModel->exists(1));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {});
// We duplicate our task to the 2nd project
$this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
$this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
// Check the values of the duplicated task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testDuplicateAnotherProjectWithCategory()
{
$taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$categoryModel = new CategoryModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2)));
$this->assertTrue($categoryModel->exists(1));
$this->assertTrue($categoryModel->exists(2));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(2, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testDuplicateAnotherProjectWithPredefinedCategory()
{
$taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$categoryModel = new CategoryModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2)));
$this->assertNotFalse($categoryModel->create(array('name' => 'Category #2', 'project_id' => 2)));
$this->assertTrue($categoryModel->exists(1));
$this->assertTrue($categoryModel->exists(2));
$this->assertTrue($categoryModel->exists(3));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
// We duplicate our task to the 2nd project with no category
$this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, 0));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['category_id']);
// We duplicate our task to the 2nd project with a different category
$this->assertEquals(3, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, 3));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(3);
$this->assertNotEmpty($task);
$this->assertEquals(3, $task['category_id']);
}
public function testDuplicateAnotherProjectWithSwimlane()
{
$taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$swimlaneModel = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(2, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testDuplicateAnotherProjectWithoutSwimlane()
{
$taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$swimlaneModel = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testDuplicateAnotherProjectWithPredefinedSwimlane()
{
$taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$swimlaneModel = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, 3));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(3, $task['swimlane_id']);
}
public function testDuplicateAnotherProjectWithPredefinedColumn()
{
$taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2)));
// We duplicate our task to the 2nd project with a different column
$this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, 7));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(7, $task['column_id']);
}
public function testDuplicateAnotherProjectWithUser()
{
$taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$projectUserRoleModel = new ProjectUserRoleModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
// We create a new user for our project
$user = new UserModel($this->container);
$this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
$this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
$this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
// We duplicate our task to the 2nd project
$this->assertEquals(3, $taskProjectDuplicationModel->duplicateToProject(1, 2));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(3);
$this->assertNotEmpty($task);
$this->assertEquals(2, $task['position']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(2, $task['owner_id']);
$this->assertEquals(2, $task['project_id']);
// We duplicate a task with a not allowed user
$this->assertEquals(4, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3)));
$this->assertEquals(5, $taskProjectDuplicationModel->duplicateToProject(4, 2));
$task = $taskFinderModel->getById(5);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals(5, $task['column_id']);
}
public function testDuplicateAnotherProjectWithPredefinedUser()
{
$taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$projectUserRoleModel = new ProjectUserRoleModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
$this->assertTrue($projectUserRoleModel->addUser(2, 1, Role::PROJECT_MEMBER));
// We duplicate our task to the 2nd project
$this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, null, 1));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['owner_id']);
}
public function testDuplicateAnotherProjectWithDifferentTags()
{
$taskProjectMoveModel = new TaskProjectDuplicationModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$tagModel = new TagModel($this->container);
$taskTagModel = new TaskTagModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
// We create our tags for each projects
$this->assertEquals(1, $tagModel->create(1, 'T1'));
$this->assertEquals(2, $tagModel->create(1, 'T2'));
$this->assertEquals(3, $tagModel->create(2, 'T2'));
$this->assertEquals(4, $tagModel->create(2, 'T3'));
$this->assertEquals(5, $tagModel->create(0, 'T4'));
$this->assertEquals(6, $tagModel->create(0, 'T5'));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('T1', 'T2', 'T5'))));
// We move our task to the 2nd project
$this->assertEquals(2, $taskProjectMoveModel->duplicateToProject(1, 2));
// Check the values of the moved task
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['project_id']);
// Check tags
$tags = $taskTagModel->getList(2);
$this->assertCount(2, $tags);
$this->assertArrayHasKey(3, $tags);
$this->assertArrayHasKey(6, $tags);
}
}

View File

@@ -0,0 +1,269 @@
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Core\Security\Role;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Model\SwimlaneModel;
use Kanboard\Model\TagModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskProjectMoveModel;
use Kanboard\Model\TaskTagModel;
use Kanboard\Model\UserModel;
class TaskProjectMoveModelTest extends Base
{
public function onMoveProject($event)
{
$this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
$this->assertEquals('test', $event_data['title']);
}
public function testMoveAnotherProject()
{
$taskProjectMoveModel = new TaskProjectMoveModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333)));
$this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, array($this, 'onMoveProject'));
// We duplicate our task to the 2nd project
$this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.TaskProjectMoveModelTest::onMoveProject', $called);
// Check the values of the moved task
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals(5, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals('test', $task['title']);
}
public function testMoveAnotherProjectWithCategory()
{
$taskProjectMoveModel = new TaskProjectMoveModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$categoryModel = new CategoryModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2)));
$this->assertTrue($categoryModel->exists(1));
$this->assertTrue($categoryModel->exists(2));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
// We move our task to the 2nd project
$this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
// Check the values of the duplicated task
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(2, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testMoveAnotherProjectWithUser()
{
$taskProjectMoveModel = new TaskProjectMoveModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$projectUserRoleModel = new ProjectUserRoleModel($this->container);
$userModel = new UserModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
// We create a new user for our project
$this->assertNotFalse($userModel->create(array('username' => 'unittest#1', 'password' => 'unittest')));
$this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
$this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
// We move our task to the 2nd project
$this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
// Check the values of the moved task
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['owner_id']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals(6, $task['column_id']);
}
public function testMoveAnotherProjectWithForbiddenUser()
{
$taskProjectMoveModel = new TaskProjectMoveModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$projectUserRoleModel = new ProjectUserRoleModel($this->container);
$userModel = new UserModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
// We create a new user for our project
$this->assertNotFalse($userModel->create(array('username' => 'unittest#1', 'password' => 'unittest')));
$this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
$this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3)));
// We move our task to the 2nd project
$this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
// Check the values of the moved task
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals(6, $task['column_id']);
}
public function testMoveAnotherProjectWithSwimlane()
{
$taskProjectMoveModel = new TaskProjectMoveModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$swimlaneModel = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We move our task to the 2nd project
$this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
// Check the values of the moved task
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(2, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testMoveAnotherProjectWithoutSwimlane()
{
$taskProjectMoveModel = new TaskProjectMoveModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$swimlaneModel = new SwimlaneModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
// We move our task to the 2nd project
$this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
// Check the values of the moved task
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(0, $task['swimlane_id']);
$this->assertEquals(6, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
}
public function testMoveAnotherProjectWithDifferentTags()
{
$taskProjectMoveModel = new TaskProjectMoveModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$tagModel = new TagModel($this->container);
$taskTagModel = new TaskTagModel($this->container);
// We create 2 projects
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
// We create our tags for each projects
$this->assertEquals(1, $tagModel->create(1, 'T1'));
$this->assertEquals(2, $tagModel->create(1, 'T2'));
$this->assertEquals(3, $tagModel->create(2, 'T3'));
$this->assertEquals(4, $tagModel->create(2, 'T4'));
$this->assertEquals(5, $tagModel->create(0, 'T5'));
$this->assertEquals(6, $tagModel->create(0, 'T6'));
// We create a task
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('T1', 'T5', 'T6'))));
// We move our task to the 2nd project
$this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
// Check the values of the moved task
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(2, $task['project_id']);
// Check tags
$tags = $taskTagModel->getList(1);
$this->assertCount(2, $tags);
$this->assertArrayHasKey(5, $tags);
$this->assertArrayHasKey(6, $tags);
}
}

View File

@@ -0,0 +1,90 @@
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Core\DateParser;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskRecurrenceModel;
class TaskRecurrenceModelTest extends Base
{
public function testCalculateRecurringTaskDueDate()
{
$taskRecurrenceModel = new TaskRecurrenceModel($this->container);
$values = array('date_due' => 0);
$taskRecurrenceModel->calculateRecurringTaskDueDate($values);
$this->assertEquals(0, $values['date_due']);
$values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$taskRecurrenceModel->calculateRecurringTaskDueDate($values);
$this->assertEquals(0, $values['date_due']);
$values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$taskRecurrenceModel->calculateRecurringTaskDueDate($values);
$this->assertEquals(time() + 86400, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$taskRecurrenceModel->calculateRecurringTaskDueDate($values);
$this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$taskRecurrenceModel->calculateRecurringTaskDueDate($values);
$this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
$taskRecurrenceModel->calculateRecurringTaskDueDate($values);
$this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS);
$taskRecurrenceModel->calculateRecurringTaskDueDate($values);
$this->assertEquals(1436561776, $values['date_due'], '', 1);
$values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS);
$taskRecurrenceModel->calculateRecurringTaskDueDate($values);
$this->assertEquals(1494449776, $values['date_due'], '', 1);
}
public function testDuplicateRecurringTask()
{
$taskRecurrenceModel = new TaskRecurrenceModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$projectModel = new ProjectModel($this->container);
$dateParser = new DateParser($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array(
'title' => 'test',
'project_id' => 1,
'date_due' => 1436561776,
'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
'recurrence_factor' => 2,
'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS,
'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE,
)));
$this->assertEquals(2, $taskRecurrenceModel->duplicateRecurringTask(1));
$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']);
$this->assertEquals(2, $task['recurrence_child']);
$this->assertEquals(1436486400, $task['date_due'], '', 2);
$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']);
$this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']);
$this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
$this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']);
$this->assertEquals(1, $task['recurrence_parent']);
$this->assertEquals(2, $task['recurrence_factor']);
$this->assertEquals($dateParser->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2);
}
}

View File

@@ -124,4 +124,25 @@ class TaskTagModelTest extends Base
$tags = $taskTagModel->getTagsByTasks(array()); $tags = $taskTagModel->getTagsByTasks(array());
$this->assertEquals(array(), $tags); $this->assertEquals(array(), $tags);
} }
public function testGetTagIdNotAvailableInDestinationProject()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskTagModel = new TaskTagModel($this->container);
$tagModel = new TagModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'P2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
$this->assertEquals(1, $tagModel->create(0, 'T0'));
$this->assertEquals(2, $tagModel->create(2, 'T1'));
$this->assertEquals(3, $tagModel->create(2, 'T3'));
$this->assertEquals(4, $tagModel->create(1, 'T2'));
$this->assertEquals(5, $tagModel->create(1, 'T3'));
$this->assertTrue($taskTagModel->save(1, 1, array('T0', 'T2', 'T3')));
$this->assertEquals(array(4, 5), $taskTagModel->getTagIdsByTaskNotAvailableInProject(1, 2));
}
} }