Add unit test for TaskAssignCategoryLink
This commit is contained in:
parent
2011c35344
commit
a42f1ea2bd
|
|
@ -1,6 +1,10 @@
|
|||
Version 1.0.21 (unreleased)
|
||||
---------------------------
|
||||
|
||||
New features:
|
||||
|
||||
* New automatic action: Assign a category based on a link
|
||||
|
||||
Improvements:
|
||||
|
||||
* Improve error handling of plugins
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ abstract class Base extends \Kanboard\Core\Base
|
|||
}
|
||||
|
||||
if (DEBUG) {
|
||||
$this->container['logger']->debug(get_called_class().' => '.($result ? 'true' : 'false'));
|
||||
$this->logger->debug(get_called_class().' => '.($result ? 'true' : 'false'));
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use Kanboard\Model\TaskLink;
|
|||
*
|
||||
* @package action
|
||||
* @author Olivier Maridat
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskAssignCategoryLink extends Base
|
||||
{
|
||||
|
|
@ -35,7 +36,7 @@ class TaskAssignCategoryLink extends Base
|
|||
{
|
||||
return array(
|
||||
'category_id' => t('Category'),
|
||||
'link_id' => t('Link id'),
|
||||
'link_id' => t('Link type'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -79,6 +80,11 @@ class TaskAssignCategoryLink extends Base
|
|||
*/
|
||||
public function hasRequiredCondition(array $data)
|
||||
{
|
||||
return $data['link_id'] == $this->getParam('link_id');
|
||||
if ($data['link_id'] == $this->getParam('link_id')) {
|
||||
$task = $this->taskFinder->getById($data['task_id']);
|
||||
return empty($task['category_id']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1066,6 +1066,7 @@ return array(
|
|||
'Duplicates are not imported' => 'Les doublons ne sont pas importés',
|
||||
'Usernames must be lowercase and unique' => 'Les noms d\'utilisateurs doivent être en minuscule et unique',
|
||||
'Passwords will be encrypted if present' => 'Les mots de passe seront chiffrés si présent',
|
||||
'Assign automatically a category based on a color' => 'Assigner automatiquement une catégorie par rapport à un lien',
|
||||
'%s attached a new file to the task %s' => '%s a attaché un nouveau fichier à la tâche %s',
|
||||
'Link type' => 'Type de lien',
|
||||
'Assign automatically a category based on a link' => 'Assigner automatiquement une catégorie en fonction d\'un lien',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Kanboard\Model\Task;
|
||||
use Kanboard\Model\TaskCreation;
|
||||
use Kanboard\Model\TaskFinder;
|
||||
use Kanboard\Model\Project;
|
||||
use Kanboard\Model\TaskLink;
|
||||
use Kanboard\Model\Category;
|
||||
use Kanboard\Event\TaskLinkEvent;
|
||||
use Kanboard\Action\TaskAssignCategoryLink;
|
||||
|
||||
class TaskAssignCategoryLinkTest extends Base
|
||||
{
|
||||
public function testAssignCategory()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
|
||||
$action->setParam('category_id', 1);
|
||||
$action->setParam('link_id', 2);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'opposite_task_id' => 2,
|
||||
'link_id' => 2,
|
||||
);
|
||||
|
||||
$this->assertTrue($action->execute(new TaskLinkEvent($event)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['category_id']);
|
||||
}
|
||||
|
||||
public function testThatLinkDontMatch()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
|
||||
$action->setParam('category_id', 1);
|
||||
$action->setParam('link_id', 1);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
|
||||
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'opposite_task_id' => 2,
|
||||
'link_id' => 2,
|
||||
);
|
||||
|
||||
$this->assertFalse($action->execute(new TaskLinkEvent($event)));
|
||||
}
|
||||
|
||||
public function testThatExistingCategoryWillNotChange()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
|
||||
$action->setParam('category_id', 2);
|
||||
$action->setParam('link_id', 2);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
|
||||
$this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
|
||||
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'opposite_task_id' => 2,
|
||||
'link_id' => 2,
|
||||
);
|
||||
|
||||
$this->assertFalse($action->execute(new TaskLinkEvent($event)));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue