Handle priority for task and project duplication
This commit is contained in:
@@ -9,6 +9,7 @@ New features:
|
|||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
* Handle priority for task and project duplication
|
||||||
* Expose task reference field to the user interface
|
* Expose task reference field to the user interface
|
||||||
* Improve ICal export
|
* Improve ICal export
|
||||||
* Added argument owner_id and identifier to project API calls
|
* Added argument owner_id and identifier to project API calls
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class ActionCreationController extends BaseController
|
|||||||
'colors_list' => $this->colorModel->getList(),
|
'colors_list' => $this->colorModel->getList(),
|
||||||
'categories_list' => $this->categoryModel->getList($project['id']),
|
'categories_list' => $this->categoryModel->getList($project['id']),
|
||||||
'links_list' => $this->linkModel->getList(0, false),
|
'links_list' => $this->linkModel->getList(0, false),
|
||||||
'priorities_list' => $this->projectModel->getPriorities($project),
|
'priorities_list' => $this->projectTaskPriorityModel->getPriorities($project),
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'available_actions' => $this->actionManager->getAvailableActions(),
|
'available_actions' => $this->actionManager->getAvailableActions(),
|
||||||
'events' => $this->actionManager->getCompatibleEvents($values['action_name']),
|
'events' => $this->actionManager->getCompatibleEvents($values['action_name']),
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ use Pimple\Container;
|
|||||||
* @property \Kanboard\Model\ProjectNotificationModel $projectNotificationModel
|
* @property \Kanboard\Model\ProjectNotificationModel $projectNotificationModel
|
||||||
* @property \Kanboard\Model\ProjectNotificationTypeModel $projectNotificationTypeModel
|
* @property \Kanboard\Model\ProjectNotificationTypeModel $projectNotificationTypeModel
|
||||||
* @property \Kanboard\Model\ProjectTaskDuplicationModel $projectTaskDuplicationModel
|
* @property \Kanboard\Model\ProjectTaskDuplicationModel $projectTaskDuplicationModel
|
||||||
|
* @property \Kanboard\Model\ProjectTaskPriorityModel $projectTaskPriorityModel
|
||||||
* @property \Kanboard\Model\RememberMeSessionModel $rememberMeSessionModel
|
* @property \Kanboard\Model\RememberMeSessionModel $rememberMeSessionModel
|
||||||
* @property \Kanboard\Model\SubtaskModel $subtaskModel
|
* @property \Kanboard\Model\SubtaskModel $subtaskModel
|
||||||
* @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel
|
* @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel
|
||||||
|
|||||||
@@ -146,6 +146,9 @@ class ProjectDuplicationModel extends Base
|
|||||||
'is_public' => 0,
|
'is_public' => 0,
|
||||||
'is_private' => $private ? 1 : $is_private,
|
'is_private' => $private ? 1 : $is_private,
|
||||||
'owner_id' => $owner_id,
|
'owner_id' => $owner_id,
|
||||||
|
'priority_default' => $project['priority_default'],
|
||||||
|
'priority_start' => $project['priority_start'],
|
||||||
|
'priority_end' => $project['priority_end'],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (! $this->db->table(ProjectModel::TABLE)->save($values)) {
|
if (! $this->db->table(ProjectModel::TABLE)->save($values)) {
|
||||||
|
|||||||
@@ -245,19 +245,6 @@ class ProjectModel extends Base
|
|||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Priority range from a project
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @param array $project
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPriorities(array $project)
|
|
||||||
{
|
|
||||||
$range = range($project['priority_start'], $project['priority_end']);
|
|
||||||
return array_combine($range, $range);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gather some task metrics for a given project
|
* Gather some task metrics for a given project
|
||||||
*
|
*
|
||||||
|
|||||||
74
app/Model/ProjectTaskPriorityModel.php
Normal file
74
app/Model/ProjectTaskPriorityModel.php
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Kanboard\Model;
|
||||||
|
|
||||||
|
use Kanboard\Core\Base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project Task Priority Model
|
||||||
|
*
|
||||||
|
* @package Kanboard\Model
|
||||||
|
* @author Frederic Guillot
|
||||||
|
*/
|
||||||
|
class ProjectTaskPriorityModel extends Base
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get Priority range from a project
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param array $project
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getPriorities(array $project)
|
||||||
|
{
|
||||||
|
$range = range($project['priority_start'], $project['priority_end']);
|
||||||
|
return array_combine($range, $range);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get task priority settings
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param int $project_id
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
public function getPrioritySettings($project_id)
|
||||||
|
{
|
||||||
|
return $this->db
|
||||||
|
->table(ProjectModel::TABLE)
|
||||||
|
->columns('priority_default', 'priority_start', 'priority_end')
|
||||||
|
->eq('id', $project_id)
|
||||||
|
->findOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default task priority
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param int $project_id
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getDefaultPriority($project_id)
|
||||||
|
{
|
||||||
|
return $this->db->table(ProjectModel::TABLE)->eq('id', $project_id)->findOneColumn('priority_default') ?: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get priority for a destination project
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $dst_project_id
|
||||||
|
* @param integer $priority
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public function getPriorityForProject($dst_project_id, $priority)
|
||||||
|
{
|
||||||
|
$settings = $this->getPrioritySettings($dst_project_id);
|
||||||
|
|
||||||
|
if ($priority >= $settings['priority_start'] && $priority <= $settings['priority_end']) {
|
||||||
|
return $priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $settings['priority_default'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ class TaskDuplicationModel extends Base
|
|||||||
* @access protected
|
* @access protected
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $fields_to_duplicate = array(
|
protected $fieldsToDuplicate = array(
|
||||||
'title',
|
'title',
|
||||||
'description',
|
'description',
|
||||||
'date_due',
|
'date_due',
|
||||||
@@ -27,6 +27,7 @@ class TaskDuplicationModel extends Base
|
|||||||
'column_id',
|
'column_id',
|
||||||
'owner_id',
|
'owner_id',
|
||||||
'score',
|
'score',
|
||||||
|
'priority',
|
||||||
'category_id',
|
'category_id',
|
||||||
'time_estimated',
|
'time_estimated',
|
||||||
'swimlane_id',
|
'swimlane_id',
|
||||||
@@ -95,6 +96,12 @@ class TaskDuplicationModel extends Base
|
|||||||
$values['column_id'] = $values['column_id'] ?: $this->columnModel->getFirstColumnId($values['project_id']);
|
$values['column_id'] = $values['column_id'] ?: $this->columnModel->getFirstColumnId($values['project_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if priority exists for destination project
|
||||||
|
$values['priority'] = $this->projectTaskPriorityModel->getPriorityForProject(
|
||||||
|
$values['project_id'],
|
||||||
|
empty($values['priority']) ? 0 : $values['priority']
|
||||||
|
);
|
||||||
|
|
||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +117,7 @@ class TaskDuplicationModel extends Base
|
|||||||
$task = $this->taskFinderModel->getById($task_id);
|
$task = $this->taskFinderModel->getById($task_id);
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
foreach ($this->fields_to_duplicate as $field) {
|
foreach ($this->fieldsToDuplicate as $field) {
|
||||||
$values[$field] = $task[$field];
|
$values[$field] = $task[$field];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class ClassProvider implements ServiceProviderInterface
|
|||||||
'ProjectMetadataModel',
|
'ProjectMetadataModel',
|
||||||
'ProjectGroupRoleModel',
|
'ProjectGroupRoleModel',
|
||||||
'ProjectTaskDuplicationModel',
|
'ProjectTaskDuplicationModel',
|
||||||
|
'ProjectTaskPriorityModel',
|
||||||
'ProjectUserRoleModel',
|
'ProjectUserRoleModel',
|
||||||
'RememberMeSessionModel',
|
'RememberMeSessionModel',
|
||||||
'SubtaskModel',
|
'SubtaskModel',
|
||||||
|
|||||||
@@ -141,6 +141,28 @@ class ProjectDuplicationModelTest extends Base
|
|||||||
$this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
|
$this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCloneProjectWithDifferentPriorities()
|
||||||
|
{
|
||||||
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
$projectDuplicationModel = new ProjectDuplicationModel($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $projectModel->create(array(
|
||||||
|
'name' => 'My project',
|
||||||
|
'priority_default' => 2,
|
||||||
|
'priority_start' => -2,
|
||||||
|
'priority_end' => 8,
|
||||||
|
)));
|
||||||
|
|
||||||
|
$this->assertEquals(2, $projectDuplicationModel->duplicate(1));
|
||||||
|
|
||||||
|
$project = $projectModel->getById(2);
|
||||||
|
$this->assertNotEmpty($project);
|
||||||
|
$this->assertEquals('My project (Clone)', $project['name']);
|
||||||
|
$this->assertEquals(2, $project['priority_default']);
|
||||||
|
$this->assertEquals(-2, $project['priority_start']);
|
||||||
|
$this->assertEquals(8, $project['priority_end']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCloneProjectWithDifferentName()
|
public function testCloneProjectWithDifferentName()
|
||||||
{
|
{
|
||||||
$projectModel = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ use Kanboard\Model\TaskCreationModel;
|
|||||||
use Kanboard\Model\ConfigModel;
|
use Kanboard\Model\ConfigModel;
|
||||||
use Kanboard\Model\CategoryModel;
|
use Kanboard\Model\CategoryModel;
|
||||||
|
|
||||||
class ProjectTest extends Base
|
class ProjectModelTest extends Base
|
||||||
{
|
{
|
||||||
public function testCreationForAllLanguages()
|
public function testCreationForAllLanguages()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
foreach ($this->container['languageModel']->getLanguages() as $locale => $language) {
|
foreach ($this->container['languageModel']->getLanguages() as $locale => $language) {
|
||||||
Translator::unload();
|
Translator::unload();
|
||||||
Translator::load($locale);
|
Translator::load($locale);
|
||||||
$this->assertNotFalse($p->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language);
|
$this->assertNotFalse($projectModel->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language);
|
||||||
}
|
}
|
||||||
|
|
||||||
Translator::unload();
|
Translator::unload();
|
||||||
@@ -28,11 +28,11 @@ class ProjectTest extends Base
|
|||||||
|
|
||||||
public function testCreation()
|
public function testCreation()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals(1, $project['is_active']);
|
$this->assertEquals(1, $project['is_active']);
|
||||||
$this->assertEquals(0, $project['is_public']);
|
$this->assertEquals(0, $project['is_public']);
|
||||||
@@ -43,19 +43,19 @@ class ProjectTest extends Base
|
|||||||
|
|
||||||
public function testCreationWithDuplicateName()
|
public function testCreationWithDuplicateName()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreationWithStartAndDate()
|
public function testCreationWithStartAndDate()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31')));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals('2015-01-01', $project['start_date']);
|
$this->assertEquals('2015-01-01', $project['start_date']);
|
||||||
$this->assertEquals('2015-12-31', $project['end_date']);
|
$this->assertEquals('2015-12-31', $project['end_date']);
|
||||||
@@ -63,19 +63,19 @@ class ProjectTest extends Base
|
|||||||
|
|
||||||
public function testCreationWithDefaultCategories()
|
public function testCreationWithDefaultCategories()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
$c = new ConfigModel($this->container);
|
$configModel = new ConfigModel($this->container);
|
||||||
$cat = new CategoryModel($this->container);
|
$categoryModel = new CategoryModel($this->container);
|
||||||
|
|
||||||
// Multiple categories correctly formatted
|
// Multiple categories correctly formatted
|
||||||
|
|
||||||
$this->assertTrue($c->save(array('project_categories' => 'Test1, Test2')));
|
$this->assertTrue($configModel->save(array('project_categories' => 'Test1, Test2')));
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1')));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
|
|
||||||
$categories = $cat->getAll(1);
|
$categories = $categoryModel->getAll(1);
|
||||||
$this->assertNotEmpty($categories);
|
$this->assertNotEmpty($categories);
|
||||||
$this->assertEquals(2, count($categories));
|
$this->assertEquals(2, count($categories));
|
||||||
$this->assertEquals('Test1', $categories[0]['name']);
|
$this->assertEquals('Test1', $categories[0]['name']);
|
||||||
@@ -83,85 +83,85 @@ class ProjectTest extends Base
|
|||||||
|
|
||||||
// Single category
|
// Single category
|
||||||
|
|
||||||
$this->assertTrue($c->save(array('project_categories' => 'Test1')));
|
$this->assertTrue($configModel->save(array('project_categories' => 'Test1')));
|
||||||
$this->container['memoryCache']->flush();
|
$this->container['memoryCache']->flush();
|
||||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
$this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2')));
|
||||||
|
|
||||||
$project = $p->getById(2);
|
$project = $projectModel->getById(2);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
|
|
||||||
$categories = $cat->getAll(2);
|
$categories = $categoryModel->getAll(2);
|
||||||
$this->assertNotEmpty($categories);
|
$this->assertNotEmpty($categories);
|
||||||
$this->assertEquals(1, count($categories));
|
$this->assertEquals(1, count($categories));
|
||||||
$this->assertEquals('Test1', $categories[0]['name']);
|
$this->assertEquals('Test1', $categories[0]['name']);
|
||||||
|
|
||||||
// Multiple categories badly formatted
|
// Multiple categories badly formatted
|
||||||
|
|
||||||
$this->assertTrue($c->save(array('project_categories' => 'ABC, , DEF 3, ')));
|
$this->assertTrue($configModel->save(array('project_categories' => 'ABC, , DEF 3, ')));
|
||||||
$this->container['memoryCache']->flush();
|
$this->container['memoryCache']->flush();
|
||||||
$this->assertEquals(3, $p->create(array('name' => 'UnitTest3')));
|
$this->assertEquals(3, $projectModel->create(array('name' => 'UnitTest3')));
|
||||||
|
|
||||||
$project = $p->getById(3);
|
$project = $projectModel->getById(3);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
|
|
||||||
$categories = $cat->getAll(3);
|
$categories = $categoryModel->getAll(3);
|
||||||
$this->assertNotEmpty($categories);
|
$this->assertNotEmpty($categories);
|
||||||
$this->assertEquals(2, count($categories));
|
$this->assertEquals(2, count($categories));
|
||||||
$this->assertEquals('ABC', $categories[0]['name']);
|
$this->assertEquals('ABC', $categories[0]['name']);
|
||||||
$this->assertEquals('DEF 3', $categories[1]['name']);
|
$this->assertEquals('DEF 3', $categories[1]['name']);
|
||||||
|
|
||||||
// No default categories
|
// No default categories
|
||||||
$this->assertTrue($c->save(array('project_categories' => ' ')));
|
$this->assertTrue($configModel->save(array('project_categories' => ' ')));
|
||||||
$this->container['memoryCache']->flush();
|
$this->container['memoryCache']->flush();
|
||||||
$this->assertEquals(4, $p->create(array('name' => 'UnitTest4')));
|
$this->assertEquals(4, $projectModel->create(array('name' => 'UnitTest4')));
|
||||||
|
|
||||||
$project = $p->getById(4);
|
$project = $projectModel->getById(4);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
|
|
||||||
$categories = $cat->getAll(4);
|
$categories = $categoryModel->getAll(4);
|
||||||
$this->assertEmpty($categories);
|
$this->assertEmpty($categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateLastModifiedDate()
|
public function testUpdateLastModifiedDate()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
|
|
||||||
$now = time();
|
$now = time();
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1);
|
$this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1);
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
$this->assertTrue($p->updateModificationDate(1));
|
$this->assertTrue($projectModel->updateModificationDate(1));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertGreaterThan($now, $project['last_modified']);
|
$this->assertGreaterThan($now, $project['last_modified']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetAllIds()
|
public function testGetAllIds()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
|
|
||||||
$this->assertEmpty($p->getAllByIds(array()));
|
$this->assertEmpty($projectModel->getAllByIds(array()));
|
||||||
$this->assertNotEmpty($p->getAllByIds(array(1, 2)));
|
$this->assertNotEmpty($projectModel->getAllByIds(array(1, 2)));
|
||||||
$this->assertCount(1, $p->getAllByIds(array(1)));
|
$this->assertCount(1, $projectModel->getAllByIds(array(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsLastModified()
|
public function testIsLastModified()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
$tc = new TaskCreationModel($this->container);
|
$taskCreationModel = new TaskCreationModel($this->container);
|
||||||
|
|
||||||
$now = time();
|
$now = time();
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals($now, $project['last_modified']);
|
$this->assertEquals($now, $project['last_modified']);
|
||||||
|
|
||||||
@@ -170,113 +170,113 @@ class ProjectTest extends Base
|
|||||||
$listener = new ProjectModificationDateSubscriber($this->container);
|
$listener = new ProjectModificationDateSubscriber($this->container);
|
||||||
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($listener, 'execute'));
|
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($listener, 'execute'));
|
||||||
|
|
||||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
|
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
|
||||||
|
|
||||||
$called = $this->container['dispatcher']->getCalledListeners();
|
$called = $this->container['dispatcher']->getCalledListeners();
|
||||||
$this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called);
|
$this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called);
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertTrue($p->isModifiedSince(1, $now));
|
$this->assertTrue($projectModel->isModifiedSince(1, $now));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemove()
|
public function testRemove()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
$this->assertTrue($p->remove(1));
|
$this->assertTrue($projectModel->remove(1));
|
||||||
$this->assertFalse($p->remove(1234));
|
$this->assertFalse($projectModel->remove(1234));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEnable()
|
public function testEnable()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
$this->assertTrue($p->disable(1));
|
$this->assertTrue($projectModel->disable(1));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals(0, $project['is_active']);
|
$this->assertEquals(0, $project['is_active']);
|
||||||
|
|
||||||
$this->assertFalse($p->disable(1111));
|
$this->assertFalse($projectModel->disable(1111));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDisable()
|
public function testDisable()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
$this->assertTrue($p->disable(1));
|
$this->assertTrue($projectModel->disable(1));
|
||||||
$this->assertTrue($p->enable(1));
|
$this->assertTrue($projectModel->enable(1));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals(1, $project['is_active']);
|
$this->assertEquals(1, $project['is_active']);
|
||||||
|
|
||||||
$this->assertFalse($p->enable(1234567));
|
$this->assertFalse($projectModel->enable(1234567));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEnablePublicAccess()
|
public function testEnablePublicAccess()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
$this->assertTrue($p->enablePublicAccess(1));
|
$this->assertTrue($projectModel->enablePublicAccess(1));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals(1, $project['is_public']);
|
$this->assertEquals(1, $project['is_public']);
|
||||||
$this->assertNotEmpty($project['token']);
|
$this->assertNotEmpty($project['token']);
|
||||||
|
|
||||||
$this->assertFalse($p->enablePublicAccess(123));
|
$this->assertFalse($projectModel->enablePublicAccess(123));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDisablePublicAccess()
|
public function testDisablePublicAccess()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
|
||||||
$this->assertTrue($p->enablePublicAccess(1));
|
$this->assertTrue($projectModel->enablePublicAccess(1));
|
||||||
$this->assertTrue($p->disablePublicAccess(1));
|
$this->assertTrue($projectModel->disablePublicAccess(1));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals(0, $project['is_public']);
|
$this->assertEquals(0, $project['is_public']);
|
||||||
$this->assertEmpty($project['token']);
|
$this->assertEmpty($project['token']);
|
||||||
|
|
||||||
$this->assertFalse($p->disablePublicAccess(123));
|
$this->assertFalse($projectModel->disablePublicAccess(123));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIdentifier()
|
public function testIdentifier()
|
||||||
{
|
{
|
||||||
$p = new ProjectModel($this->container);
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
|
||||||
// Creation
|
// Creation
|
||||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
|
||||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
$this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2')));
|
||||||
|
|
||||||
$project = $p->getById(1);
|
$project = $projectModel->getById(1);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals('TEST1', $project['identifier']);
|
$this->assertEquals('TEST1', $project['identifier']);
|
||||||
|
|
||||||
$project = $p->getById(2);
|
$project = $projectModel->getById(2);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals('', $project['identifier']);
|
$this->assertEquals('', $project['identifier']);
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
$this->assertTrue($p->update(array('id' => '2', 'identifier' => 'test2')));
|
$this->assertTrue($projectModel->update(array('id' => '2', 'identifier' => 'test2')));
|
||||||
|
|
||||||
$project = $p->getById(2);
|
$project = $projectModel->getById(2);
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals('TEST2', $project['identifier']);
|
$this->assertEquals('TEST2', $project['identifier']);
|
||||||
|
|
||||||
$project = $p->getByIdentifier('test1');
|
$project = $projectModel->getByIdentifier('test1');
|
||||||
$this->assertNotEmpty($project);
|
$this->assertNotEmpty($project);
|
||||||
$this->assertEquals('TEST1', $project['identifier']);
|
$this->assertEquals('TEST1', $project['identifier']);
|
||||||
|
|
||||||
$project = $p->getByIdentifier('');
|
$project = $projectModel->getByIdentifier('');
|
||||||
$this->assertFalse($project);
|
$this->assertFalse($project);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,34 +303,4 @@ class ProjectTest extends Base
|
|||||||
$this->assertEquals('', $project['owner_username']);
|
$this->assertEquals('', $project['owner_username']);
|
||||||
$this->assertEquals(0, $project['owner_id']);
|
$this->assertEquals(0, $project['owner_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPriority()
|
|
||||||
{
|
|
||||||
$projectModel = new ProjectModel($this->container);
|
|
||||||
$this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
|
|
||||||
|
|
||||||
$project = $projectModel->getById(1);
|
|
||||||
$this->assertNotEmpty($project);
|
|
||||||
$this->assertEquals(0, $project['priority_default']);
|
|
||||||
$this->assertEquals(0, $project['priority_start']);
|
|
||||||
$this->assertEquals(3, $project['priority_end']);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
array(0 => 0, 1 => 1, 2 => 2, 3 => 3),
|
|
||||||
$projectModel->getPriorities($project)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4)));
|
|
||||||
|
|
||||||
$project = $projectModel->getById(1);
|
|
||||||
$this->assertNotEmpty($project);
|
|
||||||
$this->assertEquals(4, $project['priority_default']);
|
|
||||||
$this->assertEquals(2, $project['priority_start']);
|
|
||||||
$this->assertEquals(5, $project['priority_end']);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
array(2 => 2, 3 => 3, 4 => 4, 5 => 5),
|
|
||||||
$projectModel->getPriorities($project)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
84
tests/units/Model/ProjectTaskPriorityModelTest.php
Normal file
84
tests/units/Model/ProjectTaskPriorityModelTest.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Kanboard\Model\ProjectModel;
|
||||||
|
use Kanboard\Model\ProjectTaskPriorityModel;
|
||||||
|
|
||||||
|
require_once __DIR__.'/../Base.php';
|
||||||
|
|
||||||
|
class ProjectTaskPriorityModelTest extends Base
|
||||||
|
{
|
||||||
|
public function testPriority()
|
||||||
|
{
|
||||||
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
$projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
|
||||||
|
$this->assertEquals(0, $projectTaskPriorityModel->getDefaultPriority(1));
|
||||||
|
|
||||||
|
$project = $projectModel->getById(1);
|
||||||
|
$this->assertNotEmpty($project);
|
||||||
|
$this->assertEquals(0, $project['priority_default']);
|
||||||
|
$this->assertEquals(0, $project['priority_start']);
|
||||||
|
$this->assertEquals(3, $project['priority_end']);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(0 => 0, 1 => 1, 2 => 2, 3 => 3),
|
||||||
|
$projectTaskPriorityModel->getPriorities($project)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4)));
|
||||||
|
|
||||||
|
$project = $projectModel->getById(1);
|
||||||
|
$this->assertNotEmpty($project);
|
||||||
|
$this->assertEquals(4, $project['priority_default']);
|
||||||
|
$this->assertEquals(2, $project['priority_start']);
|
||||||
|
$this->assertEquals(5, $project['priority_end']);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(2 => 2, 3 => 3, 4 => 4, 5 => 5),
|
||||||
|
$projectTaskPriorityModel->getPriorities($project)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(4, $projectTaskPriorityModel->getDefaultPriority(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPrioritySettings()
|
||||||
|
{
|
||||||
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
$projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
'priority_default' => 0,
|
||||||
|
'priority_start' => 0,
|
||||||
|
'priority_end' => 3,
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $projectTaskPriorityModel->getPrioritySettings(1));
|
||||||
|
$this->assertNull($projectTaskPriorityModel->getPrioritySettings(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPriorityForProject()
|
||||||
|
{
|
||||||
|
$projectModel = new ProjectModel($this->container);
|
||||||
|
$projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $projectModel->create(array(
|
||||||
|
'name' => 'My project 1',
|
||||||
|
'priority_default' => 2,
|
||||||
|
'priority_start' => -2,
|
||||||
|
'priority_end' => 8,
|
||||||
|
)));
|
||||||
|
|
||||||
|
$this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, 42));
|
||||||
|
$this->assertEquals(0, $projectTaskPriorityModel->getPriorityForProject(1, 0));
|
||||||
|
$this->assertEquals(1, $projectTaskPriorityModel->getPriorityForProject(1, 1));
|
||||||
|
$this->assertEquals(-2, $projectTaskPriorityModel->getPriorityForProject(1, -2));
|
||||||
|
$this->assertEquals(-1, $projectTaskPriorityModel->getPriorityForProject(1, -1));
|
||||||
|
$this->assertEquals(8, $projectTaskPriorityModel->getPriorityForProject(1, 8));
|
||||||
|
$this->assertEquals(5, $projectTaskPriorityModel->getPriorityForProject(1, 5));
|
||||||
|
$this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, 9));
|
||||||
|
$this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, -3));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user