Improve automatic action duplication with unit tests and improve database schema
This commit is contained in:
parent
d3f789764d
commit
aa6fdd3544
|
|
@ -1,7 +1,6 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- hhvm
|
||||
- 7.0
|
||||
- 5.6
|
||||
- 5.5
|
||||
|
|
@ -12,7 +11,6 @@ matrix:
|
|||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: 7.0
|
||||
- php: hhvm
|
||||
|
||||
before_script:
|
||||
- phpenv config-add tests/php.ini
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class Action extends Base
|
|||
'TaskAssignCategoryColor' => t('Assign automatically a category based on a color'),
|
||||
'CommentCreation' => t('Create a comment from an external provider'),
|
||||
'TaskCreation' => t('Create a task from an external provider'),
|
||||
'TaskLogMoveAnotherColumn' => t('Add a comment logging moving the task between columns'),
|
||||
'TaskLogMoveAnotherColumn' => t('Add a comment log when moving the task between columns'),
|
||||
'TaskAssignUser' => t('Change the assignee based on an external username'),
|
||||
'TaskAssignCategoryLabel' => t('Change the category based on an external label'),
|
||||
'TaskUpdateStartDate' => t('Automatically update the start date'),
|
||||
|
|
@ -176,7 +176,6 @@ class Action extends Base
|
|||
$params = array();
|
||||
|
||||
foreach ($this->getAll() as $action) {
|
||||
|
||||
$action = $this->load($action['action_name'], $action['project_id'], $action['event_name']);
|
||||
$params += $action->getActionRequiredParameters();
|
||||
}
|
||||
|
|
@ -194,7 +193,10 @@ class Action extends Base
|
|||
public function getById($action_id)
|
||||
{
|
||||
$action = $this->db->table(self::TABLE)->eq('id', $action_id)->findOne();
|
||||
$action['params'] = $this->db->table(self::TABLE_PARAMS)->eq('action_id', $action_id)->findAll();
|
||||
|
||||
if (! empty($action)) {
|
||||
$action['params'] = $this->db->table(self::TABLE_PARAMS)->eq('action_id', $action_id)->findAll();
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
|
@ -286,7 +288,7 @@ class Action extends Base
|
|||
* @param string $name Action class name
|
||||
* @param integer $project_id Project id
|
||||
* @param string $event Event name
|
||||
* @return \Core\Listener Action instance
|
||||
* @return \Action\Base
|
||||
*/
|
||||
public function load($name, $project_id, $event)
|
||||
{
|
||||
|
|
@ -295,70 +297,111 @@ class Action extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Copy Actions and related Actions Parameters from a project to another one
|
||||
* Copy actions from a project to another one (skip actions that cannot resolve parameters)
|
||||
*
|
||||
* @author Antonio Rabelo
|
||||
* @param integer $project_from Project Template
|
||||
* @return integer $project_to Project that receives the copy
|
||||
* @param integer $src_project_id Source project id
|
||||
* @return integer $dst_project_id Destination project id
|
||||
* @return boolean
|
||||
*/
|
||||
public function duplicate($project_from, $project_to)
|
||||
public function duplicate($src_project_id, $dst_project_id)
|
||||
{
|
||||
$actionTemplate = $this->action->getAllByProject($project_from);
|
||||
$actions = $this->action->getAllByProject($src_project_id);
|
||||
|
||||
foreach ($actionTemplate as $action) {
|
||||
foreach ($actions as $action) {
|
||||
|
||||
unset($action['id']);
|
||||
$action['project_id'] = $project_to;
|
||||
$actionParams = $action['params'];
|
||||
unset($action['params']);
|
||||
$this->db->startTransaction();
|
||||
|
||||
if (! $this->db->table(self::TABLE)->save($action)) {
|
||||
return false;
|
||||
$values = array(
|
||||
'project_id' => $dst_project_id,
|
||||
'event_name' => $action['event_name'],
|
||||
'action_name' => $action['action_name'],
|
||||
);
|
||||
|
||||
if (! $this->db->table(self::TABLE)->insert($values)) {
|
||||
$this->container['logger']->debug('Action::duplicate => unable to create '.$action['action_name']);
|
||||
$this->db->cancelTransaction();
|
||||
continue;
|
||||
}
|
||||
|
||||
$action_clone_id = $this->db->getConnection()->getLastId();
|
||||
$action_id = $this->db->getConnection()->getLastId();
|
||||
|
||||
foreach ($actionParams as $param) {
|
||||
unset($param['id']);
|
||||
$param['value'] = $this->resolveDuplicatedParameters($param, $project_to);
|
||||
$param['action_id'] = $action_clone_id;
|
||||
|
||||
if (! $this->db->table(self::TABLE_PARAMS)->save($param)) {
|
||||
return false;
|
||||
}
|
||||
if (! $this->duplicateParameters($dst_project_id, $action_id, $action['params'])) {
|
||||
$this->container['logger']->debug('Action::duplicate => unable to copy parameters for '.$action['action_name']);
|
||||
$this->db->cancelTransaction();
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->db->closeTransaction();
|
||||
}
|
||||
|
||||
// $this->container['fileCache']->remove('proxy_action_getAll');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve type of action value from a project to the respective value in another project
|
||||
* Duplicate action parameters
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @param integer $action_id
|
||||
* @param array $params
|
||||
* @return boolean
|
||||
*/
|
||||
public function duplicateParameters($project_id, $action_id, array $params)
|
||||
{
|
||||
foreach ($params as $param) {
|
||||
|
||||
$value = $this->resolveParameters($param, $project_id);
|
||||
|
||||
if ($value === false) {
|
||||
$this->container['logger']->debug('Action::duplicateParameters => unable to resolve '.$param['name'].'='.$param['value']);
|
||||
return false;
|
||||
}
|
||||
|
||||
$values = array(
|
||||
'action_id' => $action_id,
|
||||
'name' => $param['name'],
|
||||
'value' => $value,
|
||||
);
|
||||
|
||||
if (! $this->db->table(self::TABLE_PARAMS)->insert($values)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve action parameter values according to another project
|
||||
*
|
||||
* @author Antonio Rabelo
|
||||
* @param integer $param An action parameter
|
||||
* @return integer $project_to Project to find the corresponding values
|
||||
* @return mixed The corresponding values from $project_to
|
||||
* @access public
|
||||
* @param array $param Action parameter
|
||||
* @param integer $project_id Project to find the corresponding values
|
||||
* @return mixed
|
||||
*/
|
||||
private function resolveDuplicatedParameters($param, $project_to)
|
||||
public function resolveParameters(array $param, $project_id)
|
||||
{
|
||||
switch($param['name']) {
|
||||
switch ($param['name']) {
|
||||
case 'project_id':
|
||||
return $project_to;
|
||||
return $project_id;
|
||||
case 'category_id':
|
||||
$categoryTemplate = $this->category->getById($param['value']);
|
||||
$categoryFromNewProject = $this->db->table(Category::TABLE)->eq('project_id', $project_to)->eq('name', $categoryTemplate['name'])->findOne();
|
||||
return $categoryFromNewProject['id'];
|
||||
return $this->category->getIdByName($project_id, $this->category->getNameById($param['value'])) ?: false;
|
||||
case 'src_column_id':
|
||||
case 'dest_column_id':
|
||||
case 'dst_column_id':
|
||||
case 'column_id':
|
||||
$boardTemplate = $this->board->getColumn($param['value']);
|
||||
$boardFromNewProject = $this->db->table(Board::TABLE)->eq('project_id', $project_to)->eq('title', $boardTemplate['title'])->findOne();
|
||||
return $boardFromNewProject['id'];
|
||||
// TODO: Add user_id
|
||||
$column = $this->board->getColumn($param['value']);
|
||||
|
||||
if (empty($column)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->board->getColumnIdByTitle($project_id, $column['title']) ?: false;
|
||||
case 'user_id':
|
||||
case 'owner_id':
|
||||
return $this->projectPermission->isMember($project_id, $param['value']) ? $param['value'] : false;
|
||||
default:
|
||||
return $param['value'];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -376,6 +376,19 @@ class Board extends Base
|
|||
return $this->db->table(self::TABLE)->eq('id', $column_id)->findOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a column id by the name
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @param string $title
|
||||
* @return integer
|
||||
*/
|
||||
public function getColumnIdByTitle($project_id, $title)
|
||||
{
|
||||
return (int) $this->db->table(self::TABLE)->eq('project_id', $project_id)->eq('title', $title)->findOneColumn('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of the last column for a given project
|
||||
*
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class Category extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Get a category id by the project and the name
|
||||
* Get a category id by the category name and project id
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
|
|
|
|||
|
|
@ -6,7 +6,42 @@ use PDO;
|
|||
use Core\Security;
|
||||
use Model\Link;
|
||||
|
||||
const VERSION = 73;
|
||||
const VERSION = 74;
|
||||
|
||||
function version_74($pdo)
|
||||
{
|
||||
$pdo->exec('ALTER TABLE project_has_categories MODIFY project_id INT NOT NULL');
|
||||
$pdo->exec('ALTER TABLE project_has_categories MODIFY name VARCHAR(255) NOT NULL');
|
||||
|
||||
$pdo->exec('ALTER TABLE actions MODIFY project_id INT NOT NULL');
|
||||
$pdo->exec('ALTER TABLE actions MODIFY event_name VARCHAR(50) NOT NULL');
|
||||
$pdo->exec('ALTER TABLE actions MODIFY action_name VARCHAR(50) NOT NULL');
|
||||
|
||||
$pdo->exec('ALTER TABLE action_has_params MODIFY action_id INT NOT NULL');
|
||||
$pdo->exec('ALTER TABLE action_has_params MODIFY name VARCHAR(50) NOT NULL');
|
||||
$pdo->exec('ALTER TABLE action_has_params MODIFY value VARCHAR(50) NOT NULL');
|
||||
|
||||
$pdo->exec('ALTER TABLE files MODIFY name VARCHAR(255) NOT NULL');
|
||||
$pdo->exec('ALTER TABLE files MODIFY task_id INT NOT NULL');
|
||||
|
||||
$pdo->exec('ALTER TABLE subtasks MODIFY title VARCHAR(255) NOT NULL');
|
||||
|
||||
$pdo->exec('ALTER TABLE tasks MODIFY project_id INT NOT NULL');
|
||||
$pdo->exec('ALTER TABLE tasks MODIFY column_id INT NOT NULL');
|
||||
|
||||
$pdo->exec('ALTER TABLE columns MODIFY title VARCHAR(255) NOT NULL');
|
||||
$pdo->exec('ALTER TABLE columns MODIFY project_id INT NOT NULL');
|
||||
|
||||
$pdo->exec('ALTER TABLE project_has_users MODIFY project_id INT NOT NULL');
|
||||
$pdo->exec('ALTER TABLE project_has_users MODIFY user_id INT NOT NULL');
|
||||
|
||||
$pdo->exec('ALTER TABLE projects MODIFY name VARCHAR(255) NOT NULL UNIQUE');
|
||||
|
||||
$pdo->exec('ALTER TABLE users MODIFY username VARCHAR(50) NOT NULL');
|
||||
|
||||
$pdo->exec('ALTER TABLE user_has_notifications MODIFY project_id INT NOT NULL');
|
||||
$pdo->exec('ALTER TABLE user_has_notifications MODIFY user_id INT NOT NULL');
|
||||
}
|
||||
|
||||
function version_73($pdo)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,43 @@ use PDO;
|
|||
use Core\Security;
|
||||
use Model\Link;
|
||||
|
||||
const VERSION = 53;
|
||||
const VERSION = 54;
|
||||
|
||||
function version_54($pdo)
|
||||
{
|
||||
$pdo->exec("ALTER TABLE project_has_categories ALTER COLUMN project_id SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE project_has_categories ALTER COLUMN name SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE actions ALTER COLUMN project_id SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE actions ALTER COLUMN event_name SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE actions ALTER COLUMN action_name SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE action_has_params ALTER COLUMN action_id SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE action_has_params ALTER COLUMN name SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE action_has_params ALTER COLUMN value SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE files ALTER COLUMN name SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE files ALTER COLUMN task_id SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE subtasks ALTER COLUMN title SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE tasks ALTER COLUMN title SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE tasks ALTER COLUMN project_id SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE tasks ALTER COLUMN column_id SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE columns ALTER COLUMN title SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE columns ALTER COLUMN project_id SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE project_has_users ALTER COLUMN project_id SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE project_has_users ALTER COLUMN user_id SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE projects ALTER COLUMN name SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE users ALTER COLUMN username SET NOT NULL");
|
||||
|
||||
$pdo->exec("ALTER TABLE user_has_notifications ALTER COLUMN user_id SET NOT NULL");
|
||||
$pdo->exec("ALTER TABLE user_has_notifications ALTER COLUMN user_id SET NOT NULL");
|
||||
}
|
||||
|
||||
function version_53($pdo)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -429,10 +429,10 @@ function version_37($pdo)
|
|||
$pdo->exec("
|
||||
CREATE TABLE swimlanes (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT,
|
||||
name TEXT NOT NULL,
|
||||
position INTEGER DEFAULT 1,
|
||||
is_active INTEGER DEFAULT 1,
|
||||
project_id INTEGER,
|
||||
project_id INTEGER NOT NULL,
|
||||
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
UNIQUE (name, project_id)
|
||||
)
|
||||
|
|
@ -477,9 +477,9 @@ function version_33($pdo)
|
|||
id INTEGER PRIMARY KEY,
|
||||
date_creation INTEGER NOT NULL,
|
||||
event_name TEXT NOT NULL,
|
||||
creator_id INTEGER,
|
||||
project_id INTEGER,
|
||||
task_id INTEGER,
|
||||
creator_id INTEGE NOT NULL,
|
||||
project_id INTEGER NOT NULL,
|
||||
task_id INTEGER NOT NULL,
|
||||
data TEXT,
|
||||
FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
|
|
@ -622,8 +622,8 @@ function version_23($pdo)
|
|||
|
||||
$pdo->exec("
|
||||
CREATE TABLE user_has_notifications (
|
||||
user_id INTEGER,
|
||||
project_id INTEGER,
|
||||
user_id INTEGER NOT NULL,
|
||||
project_id INTEGER NOT NULL,
|
||||
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
UNIQUE(project_id, user_id)
|
||||
|
|
@ -659,7 +659,7 @@ function version_18($pdo)
|
|||
$pdo->exec("
|
||||
CREATE TABLE task_has_subtasks (
|
||||
id INTEGER PRIMARY KEY,
|
||||
title TEXT COLLATE NOCASE,
|
||||
title TEXT COLLATE NOCASE NOT NULL,
|
||||
status INTEGER DEFAULT 0,
|
||||
time_estimated NUMERIC DEFAULT 0,
|
||||
time_spent NUMERIC DEFAULT 0,
|
||||
|
|
@ -675,10 +675,10 @@ function version_17($pdo)
|
|||
$pdo->exec("
|
||||
CREATE TABLE task_has_files (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT COLLATE NOCASE,
|
||||
name TEXT COLLATE NOCASE NOT NULL,
|
||||
path TEXT,
|
||||
is_image INTEGER DEFAULT 0,
|
||||
task_id INTEGER,
|
||||
task_id INTEGER NOT NULL,
|
||||
FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
|
||||
)"
|
||||
);
|
||||
|
|
@ -689,8 +689,8 @@ function version_16($pdo)
|
|||
$pdo->exec("
|
||||
CREATE TABLE project_has_categories (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT COLLATE NOCASE,
|
||||
project_id INT,
|
||||
name TEXT COLLATE NOCASE NOT NULL,
|
||||
project_id INTEGER NOT NULL,
|
||||
UNIQUE (project_id, name),
|
||||
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE
|
||||
)"
|
||||
|
|
@ -721,7 +721,7 @@ function version_12($pdo)
|
|||
$pdo->exec(
|
||||
'CREATE TABLE remember_me (
|
||||
id INTEGER PRIMARY KEY,
|
||||
user_id INTEGER,
|
||||
user_id INTEGER NOT NULL,
|
||||
ip TEXT,
|
||||
user_agent TEXT,
|
||||
token TEXT,
|
||||
|
|
@ -736,7 +736,7 @@ function version_12($pdo)
|
|||
'CREATE TABLE last_logins (
|
||||
id INTEGER PRIMARY KEY,
|
||||
auth_type TEXT,
|
||||
user_id INTEGER,
|
||||
user_id INTEGER NOT NULL,
|
||||
ip TEXT,
|
||||
user_agent TEXT,
|
||||
date_creation INTEGER,
|
||||
|
|
@ -779,9 +779,9 @@ function version_10($pdo)
|
|||
$pdo->exec(
|
||||
'CREATE TABLE actions (
|
||||
id INTEGER PRIMARY KEY,
|
||||
project_id INTEGER,
|
||||
event_name TEXT,
|
||||
action_name TEXT,
|
||||
project_id INTEGER NOT NULL,
|
||||
event_name TEXT NOT NULL,
|
||||
action_name TEXT NOT NULL,
|
||||
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE
|
||||
)'
|
||||
);
|
||||
|
|
@ -789,9 +789,9 @@ function version_10($pdo)
|
|||
$pdo->exec(
|
||||
'CREATE TABLE action_has_params (
|
||||
id INTEGER PRIMARY KEY,
|
||||
action_id INTEGER,
|
||||
name TEXT,
|
||||
value TEXT,
|
||||
action_id INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
FOREIGN KEY(action_id) REFERENCES actions(id) ON DELETE CASCADE
|
||||
)'
|
||||
);
|
||||
|
|
@ -822,8 +822,8 @@ function version_7($pdo)
|
|||
$pdo->exec("
|
||||
CREATE TABLE project_has_users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
project_id INTEGER,
|
||||
user_id INTEGER,
|
||||
project_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
UNIQUE(project_id, user_id)
|
||||
|
|
@ -869,7 +869,7 @@ function version_1($pdo)
|
|||
$pdo->exec("
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
username TEXT,
|
||||
username TEXT NOT NULL,
|
||||
password TEXT,
|
||||
is_admin INTEGER DEFAULT 0,
|
||||
default_project_id INTEGER DEFAULT 0
|
||||
|
|
@ -879,7 +879,7 @@ function version_1($pdo)
|
|||
$pdo->exec("
|
||||
CREATE TABLE projects (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOCASE UNIQUE,
|
||||
name TEXT NOCASE NOT NULL UNIQUE,
|
||||
is_active INTEGER DEFAULT 1
|
||||
)
|
||||
");
|
||||
|
|
@ -887,9 +887,9 @@ function version_1($pdo)
|
|||
$pdo->exec("
|
||||
CREATE TABLE columns (
|
||||
id INTEGER PRIMARY KEY,
|
||||
title TEXT,
|
||||
title TEXT NOT NULL,
|
||||
position INTEGER,
|
||||
project_id INTEGER,
|
||||
project_id INTEGER NOT NULL,
|
||||
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
UNIQUE (title, project_id)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ class ActionTaskAssignColorCategory extends Base
|
|||
$c = new Category($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $c->create(array('name' => 'c1')));
|
||||
$this->assertEquals(2, $c->create(array('name' => 'c2')));
|
||||
$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' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green', 'category_id' => 2)));
|
||||
|
||||
// We create an event but we don't do anything
|
||||
|
|
|
|||
|
|
@ -10,10 +10,250 @@ use Model\TaskPosition;
|
|||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Category;
|
||||
use Model\User;
|
||||
use Model\ProjectPermission;
|
||||
use Integration\GithubWebhook;
|
||||
use Integration\BitbucketWebhook;
|
||||
|
||||
class ActionTest extends Base
|
||||
{
|
||||
public function testGetActions()
|
||||
{
|
||||
$a = new Action($this->container);
|
||||
|
||||
$actions = $a->getAvailableActions();
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertEquals('Add a comment log when moving the task between columns', current($actions));
|
||||
$this->assertEquals('TaskLogMoveAnotherColumn', key($actions));
|
||||
}
|
||||
|
||||
public function testGetEvents()
|
||||
{
|
||||
$a = new Action($this->container);
|
||||
|
||||
$events = $a->getAvailableEvents();
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertEquals('Bitbucket commit received', current($events));
|
||||
$this->assertEquals(BitbucketWebhook::EVENT_COMMIT, key($events));
|
||||
}
|
||||
|
||||
public function testGetCompatibleEvents()
|
||||
{
|
||||
$a = new Action($this->container);
|
||||
$events = $a->getCompatibleEvents('TaskAssignSpecificUser');
|
||||
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertCount(2, $events);
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE, $events);
|
||||
$this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events);
|
||||
}
|
||||
|
||||
public function testResolveDuplicatedParameters()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$a = new Action($this->container);
|
||||
$c = new Category($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'P2')));
|
||||
|
||||
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2)));
|
||||
$this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2)));
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest1')));
|
||||
$this->assertEquals(3, $u->create(array('username' => 'unittest2')));
|
||||
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
$this->assertTrue($pp->addMember(1, 3));
|
||||
$this->assertTrue($pp->addMember(2, 3));
|
||||
|
||||
// anything
|
||||
$this->assertEquals('blah', $a->resolveParameters(array('name' => 'foobar', 'value' => 'blah'), 2));
|
||||
|
||||
// project_id
|
||||
$this->assertEquals(2, $a->resolveParameters(array('name' => 'project_id', 'value' => 'blah'), 2));
|
||||
|
||||
// category_id
|
||||
$this->assertEquals(3, $a->resolveParameters(array('name' => 'category_id', 'value' => 1), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 0), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 5), 2));
|
||||
|
||||
// column_id
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 10), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 0), 2));
|
||||
$this->assertEquals(5, $a->resolveParameters(array('name' => 'column_id', 'value' => 1), 2));
|
||||
$this->assertEquals(6, $a->resolveParameters(array('name' => 'dest_column_id', 'value' => 2), 2));
|
||||
$this->assertEquals(7, $a->resolveParameters(array('name' => 'dst_column_id', 'value' => 3), 2));
|
||||
$this->assertEquals(8, $a->resolveParameters(array('name' => 'src_column_id', 'value' => 4), 2));
|
||||
|
||||
// user_id
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 10), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 0), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 2), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'owner_id', 'value' => 2), 2));
|
||||
$this->assertEquals(3, $a->resolveParameters(array('name' => 'user_id', 'value' => 3), 2));
|
||||
$this->assertEquals(3, $a->resolveParameters(array('name' => 'owner_id', 'value' => 3), 2));
|
||||
}
|
||||
|
||||
public function testDuplicateSuccess()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$a = new Action($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'P2')));
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest1')));
|
||||
$this->assertEquals(3, $u->create(array('username' => 'unittest2')));
|
||||
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
$this->assertTrue($pp->addMember(1, 3));
|
||||
$this->assertTrue($pp->addMember(2, 3));
|
||||
|
||||
$this->assertEquals(1, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE_UPDATE,
|
||||
'action_name' => 'TaskAssignSpecificUser',
|
||||
'params' => array(
|
||||
'column_id' => 1,
|
||||
'user_id' => 3,
|
||||
)
|
||||
)));
|
||||
|
||||
$action = $a->getById(1);
|
||||
$this->assertNotEmpty($action);
|
||||
$this->assertNotEmpty($action['params']);
|
||||
$this->assertEquals(1, $action['project_id']);
|
||||
|
||||
$this->assertTrue($a->duplicate(1, 2));
|
||||
|
||||
$action = $a->getById(2);
|
||||
$this->assertNotEmpty($action);
|
||||
$this->assertNotEmpty($action['params']);
|
||||
$this->assertEquals(2, $action['project_id']);
|
||||
$this->assertEquals(Task::EVENT_CREATE_UPDATE, $action['event_name']);
|
||||
$this->assertEquals('TaskAssignSpecificUser', $action['action_name']);
|
||||
$this->assertEquals('column_id', $action['params'][0]['name']);
|
||||
$this->assertEquals(5, $action['params'][0]['value']);
|
||||
$this->assertEquals('user_id', $action['params'][1]['name']);
|
||||
$this->assertEquals(3, $action['params'][1]['value']);
|
||||
}
|
||||
|
||||
public function testDuplicateUnableToResolveParams()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$a = new Action($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'P2')));
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest1')));
|
||||
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
$this->assertEquals(1, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE_UPDATE,
|
||||
'action_name' => 'TaskAssignSpecificUser',
|
||||
'params' => array(
|
||||
'column_id' => 1,
|
||||
'user_id' => 2,
|
||||
)
|
||||
)));
|
||||
|
||||
$action = $a->getById(1);
|
||||
$this->assertNotEmpty($action);
|
||||
$this->assertNotEmpty($action['params']);
|
||||
$this->assertEquals(1, $action['project_id']);
|
||||
$this->assertEquals('user_id', $action['params'][1]['name']);
|
||||
$this->assertEquals(2, $action['params'][1]['value']);
|
||||
|
||||
$this->assertTrue($a->duplicate(1, 2));
|
||||
|
||||
$action = $a->getById(2);
|
||||
$this->assertEmpty($action);
|
||||
}
|
||||
|
||||
public function testDuplicateMixedResults()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$a = new Action($this->container);
|
||||
$u = new User($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'P2')));
|
||||
|
||||
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
|
||||
$this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2)));
|
||||
$this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2)));
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest1')));
|
||||
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
$this->assertEquals(1, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE_UPDATE,
|
||||
'action_name' => 'TaskAssignSpecificUser',
|
||||
'params' => array(
|
||||
'column_id' => 1,
|
||||
'user_id' => 2,
|
||||
)
|
||||
)));
|
||||
|
||||
$action = $a->getById(1);
|
||||
$this->assertNotEmpty($action);
|
||||
$this->assertNotEmpty($action['params']);
|
||||
|
||||
$this->assertEquals(2, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE_UPDATE,
|
||||
'action_name' => 'TaskAssignCategoryColor',
|
||||
'params' => array(
|
||||
'color_id' => 'blue',
|
||||
'category_id' => 1,
|
||||
)
|
||||
)));
|
||||
|
||||
$action = $a->getById(2);
|
||||
$this->assertNotEmpty($action);
|
||||
$this->assertNotEmpty($action['params']);
|
||||
$this->assertEquals('category_id', $action['params'][1]['name']);
|
||||
$this->assertEquals(1, $action['params'][1]['value']);
|
||||
|
||||
$actions = $a->getAllByProject(1);
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertCount(2, $actions);
|
||||
|
||||
$this->assertTrue($a->duplicate(1, 2));
|
||||
|
||||
$actions = $a->getAllByProject(2);
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertCount(1, $actions);
|
||||
|
||||
$actions = $a->getAll();
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertCount(3, $actions);
|
||||
|
||||
$action = $a->getById($actions[2]['id']);
|
||||
$this->assertNotEmpty($action);
|
||||
$this->assertNotEmpty($action['params']);
|
||||
$this->assertEquals('color_id', $action['params'][0]['name']);
|
||||
$this->assertEquals('blue', $action['params'][0]['value']);
|
||||
$this->assertEquals('category_id', $action['params'][1]['name']);
|
||||
$this->assertEquals(3, $action['params'][1]['value']);
|
||||
}
|
||||
|
||||
public function testSingleAction()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
|
|
@ -70,12 +310,10 @@ class ActionTest extends Base
|
|||
$b = new Board($this->container);
|
||||
$p = new Project($this->container);
|
||||
$a = new Action($this->container);
|
||||
$c = new Category($this->container);
|
||||
$g = new GithubWebhook($this->container);
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'unit_test')));
|
||||
$this->assertEquals(1, $c->create(array('name' => 'unit_test')));
|
||||
|
||||
// We create a new action
|
||||
$this->assertEquals(1, $a->create(array(
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class MailgunTest extends Base
|
|||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class PostmarkTest extends Base
|
|||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
|
||||
|
|
@ -81,7 +81,7 @@ class PostmarkTest extends Base
|
|||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ class ProjectPermissionTest extends Base
|
|||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$user = new User($this->container);
|
||||
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
|
||||
$this->assertNotFalse($user->create(array('username' => 'unittest', 'password' => 'unittest')));
|
||||
|
||||
// We create project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class SendgridTest extends Base
|
|||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost')));
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
|
||||
|
|
|
|||
Loading…
Reference in New Issue