Improve automatic action duplication with unit tests and improve database schema

This commit is contained in:
Frederic Guillot
2015-06-20 14:34:47 -04:00
parent d3f789764d
commit aa6fdd3544
13 changed files with 444 additions and 81 deletions

View File

@@ -1,7 +1,6 @@
language: php language: php
php: php:
- hhvm
- 7.0 - 7.0
- 5.6 - 5.6
- 5.5 - 5.5
@@ -12,7 +11,6 @@ matrix:
fast_finish: true fast_finish: true
allow_failures: allow_failures:
- php: 7.0 - php: 7.0
- php: hhvm
before_script: before_script:
- phpenv config-add tests/php.ini - phpenv config-add tests/php.ini

View File

@@ -53,7 +53,7 @@ class Action extends Base
'TaskAssignCategoryColor' => t('Assign automatically a category based on a color'), 'TaskAssignCategoryColor' => t('Assign automatically a category based on a color'),
'CommentCreation' => t('Create a comment from an external provider'), 'CommentCreation' => t('Create a comment from an external provider'),
'TaskCreation' => t('Create a task 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'), 'TaskAssignUser' => t('Change the assignee based on an external username'),
'TaskAssignCategoryLabel' => t('Change the category based on an external label'), 'TaskAssignCategoryLabel' => t('Change the category based on an external label'),
'TaskUpdateStartDate' => t('Automatically update the start date'), 'TaskUpdateStartDate' => t('Automatically update the start date'),
@@ -176,7 +176,6 @@ class Action extends Base
$params = array(); $params = array();
foreach ($this->getAll() as $action) { foreach ($this->getAll() as $action) {
$action = $this->load($action['action_name'], $action['project_id'], $action['event_name']); $action = $this->load($action['action_name'], $action['project_id'], $action['event_name']);
$params += $action->getActionRequiredParameters(); $params += $action->getActionRequiredParameters();
} }
@@ -194,7 +193,10 @@ class Action extends Base
public function getById($action_id) public function getById($action_id)
{ {
$action = $this->db->table(self::TABLE)->eq('id', $action_id)->findOne(); $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; return $action;
} }
@@ -286,7 +288,7 @@ class Action extends Base
* @param string $name Action class name * @param string $name Action class name
* @param integer $project_id Project id * @param integer $project_id Project id
* @param string $event Event name * @param string $event Event name
* @return \Core\Listener Action instance * @return \Action\Base
*/ */
public function load($name, $project_id, $event) 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 * @author Antonio Rabelo
* @param integer $project_from Project Template * @param integer $src_project_id Source project id
* @return integer $project_to Project that receives the copy * @return integer $dst_project_id Destination project id
* @return boolean * @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']); $this->db->startTransaction();
$action['project_id'] = $project_to;
$actionParams = $action['params'];
unset($action['params']);
if (! $this->db->table(self::TABLE)->save($action)) { $values = array(
return false; '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) { if (! $this->duplicateParameters($dst_project_id, $action_id, $action['params'])) {
unset($param['id']); $this->container['logger']->debug('Action::duplicate => unable to copy parameters for '.$action['action_name']);
$param['value'] = $this->resolveDuplicatedParameters($param, $project_to); $this->db->cancelTransaction();
$param['action_id'] = $action_clone_id; continue;
if (! $this->db->table(self::TABLE_PARAMS)->save($param)) {
return false;
}
} }
$this->db->closeTransaction();
} }
// $this->container['fileCache']->remove('proxy_action_getAll');
return true; 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 * @author Antonio Rabelo
* @param integer $param An action parameter * @access public
* @return integer $project_to Project to find the corresponding values * @param array $param Action parameter
* @return mixed The corresponding values from $project_to * @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': case 'project_id':
return $project_to; return $project_id;
case 'category_id': case 'category_id':
$categoryTemplate = $this->category->getById($param['value']); return $this->category->getIdByName($project_id, $this->category->getNameById($param['value'])) ?: false;
$categoryFromNewProject = $this->db->table(Category::TABLE)->eq('project_id', $project_to)->eq('name', $categoryTemplate['name'])->findOne();
return $categoryFromNewProject['id'];
case 'src_column_id': case 'src_column_id':
case 'dest_column_id': case 'dest_column_id':
case 'dst_column_id':
case 'column_id': case 'column_id':
$boardTemplate = $this->board->getColumn($param['value']); $column = $this->board->getColumn($param['value']);
$boardFromNewProject = $this->db->table(Board::TABLE)->eq('project_id', $project_to)->eq('title', $boardTemplate['title'])->findOne();
return $boardFromNewProject['id']; if (empty($column)) {
// TODO: Add user_id 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: default:
return $param['value']; return $param['value'];
} }

View File

@@ -376,6 +376,19 @@ class Board extends Base
return $this->db->table(self::TABLE)->eq('id', $column_id)->findOne(); 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 * Get the position of the last column for a given project
* *

View File

@@ -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 * @access public
* @param integer $project_id Project id * @param integer $project_id Project id

View File

@@ -6,7 +6,42 @@ use PDO;
use Core\Security; use Core\Security;
use Model\Link; 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) function version_73($pdo)
{ {

View File

@@ -6,7 +6,43 @@ use PDO;
use Core\Security; use Core\Security;
use Model\Link; 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) function version_53($pdo)
{ {

View File

@@ -429,10 +429,10 @@ function version_37($pdo)
$pdo->exec(" $pdo->exec("
CREATE TABLE swimlanes ( CREATE TABLE swimlanes (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
name TEXT, name TEXT NOT NULL,
position INTEGER DEFAULT 1, position INTEGER DEFAULT 1,
is_active 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, FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
UNIQUE (name, project_id) UNIQUE (name, project_id)
) )
@@ -477,9 +477,9 @@ function version_33($pdo)
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
date_creation INTEGER NOT NULL, date_creation INTEGER NOT NULL,
event_name TEXT NOT NULL, event_name TEXT NOT NULL,
creator_id INTEGER, creator_id INTEGE NOT NULL,
project_id INTEGER, project_id INTEGER NOT NULL,
task_id INTEGER, task_id INTEGER NOT NULL,
data TEXT, data TEXT,
FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY(creator_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE, FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
@@ -622,8 +622,8 @@ function version_23($pdo)
$pdo->exec(" $pdo->exec("
CREATE TABLE user_has_notifications ( CREATE TABLE user_has_notifications (
user_id INTEGER, user_id INTEGER NOT NULL,
project_id INTEGER, project_id INTEGER NOT NULL,
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE, FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
UNIQUE(project_id, user_id) UNIQUE(project_id, user_id)
@@ -659,7 +659,7 @@ function version_18($pdo)
$pdo->exec(" $pdo->exec("
CREATE TABLE task_has_subtasks ( CREATE TABLE task_has_subtasks (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
title TEXT COLLATE NOCASE, title TEXT COLLATE NOCASE NOT NULL,
status INTEGER DEFAULT 0, status INTEGER DEFAULT 0,
time_estimated NUMERIC DEFAULT 0, time_estimated NUMERIC DEFAULT 0,
time_spent NUMERIC DEFAULT 0, time_spent NUMERIC DEFAULT 0,
@@ -675,10 +675,10 @@ function version_17($pdo)
$pdo->exec(" $pdo->exec("
CREATE TABLE task_has_files ( CREATE TABLE task_has_files (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
name TEXT COLLATE NOCASE, name TEXT COLLATE NOCASE NOT NULL,
path TEXT, path TEXT,
is_image INTEGER DEFAULT 0, is_image INTEGER DEFAULT 0,
task_id INTEGER, task_id INTEGER NOT NULL,
FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
)" )"
); );
@@ -689,8 +689,8 @@ function version_16($pdo)
$pdo->exec(" $pdo->exec("
CREATE TABLE project_has_categories ( CREATE TABLE project_has_categories (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
name TEXT COLLATE NOCASE, name TEXT COLLATE NOCASE NOT NULL,
project_id INT, project_id INTEGER NOT NULL,
UNIQUE (project_id, name), UNIQUE (project_id, name),
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE
)" )"
@@ -721,7 +721,7 @@ function version_12($pdo)
$pdo->exec( $pdo->exec(
'CREATE TABLE remember_me ( 'CREATE TABLE remember_me (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
user_id INTEGER, user_id INTEGER NOT NULL,
ip TEXT, ip TEXT,
user_agent TEXT, user_agent TEXT,
token TEXT, token TEXT,
@@ -736,7 +736,7 @@ function version_12($pdo)
'CREATE TABLE last_logins ( 'CREATE TABLE last_logins (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
auth_type TEXT, auth_type TEXT,
user_id INTEGER, user_id INTEGER NOT NULL,
ip TEXT, ip TEXT,
user_agent TEXT, user_agent TEXT,
date_creation INTEGER, date_creation INTEGER,
@@ -779,9 +779,9 @@ function version_10($pdo)
$pdo->exec( $pdo->exec(
'CREATE TABLE actions ( 'CREATE TABLE actions (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
project_id INTEGER, project_id INTEGER NOT NULL,
event_name TEXT, event_name TEXT NOT NULL,
action_name TEXT, action_name TEXT NOT NULL,
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE
)' )'
); );
@@ -789,9 +789,9 @@ function version_10($pdo)
$pdo->exec( $pdo->exec(
'CREATE TABLE action_has_params ( 'CREATE TABLE action_has_params (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
action_id INTEGER, action_id INTEGER NOT NULL,
name TEXT, name TEXT NOT NULL,
value TEXT, value TEXT NOT NULL,
FOREIGN KEY(action_id) REFERENCES actions(id) ON DELETE CASCADE FOREIGN KEY(action_id) REFERENCES actions(id) ON DELETE CASCADE
)' )'
); );
@@ -822,8 +822,8 @@ function version_7($pdo)
$pdo->exec(" $pdo->exec("
CREATE TABLE project_has_users ( CREATE TABLE project_has_users (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
project_id INTEGER, project_id INTEGER NOT NULL,
user_id INTEGER, user_id INTEGER NOT NULL,
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE, FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE(project_id, user_id) UNIQUE(project_id, user_id)
@@ -869,7 +869,7 @@ function version_1($pdo)
$pdo->exec(" $pdo->exec("
CREATE TABLE users ( CREATE TABLE users (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
username TEXT, username TEXT NOT NULL,
password TEXT, password TEXT,
is_admin INTEGER DEFAULT 0, is_admin INTEGER DEFAULT 0,
default_project_id INTEGER DEFAULT 0 default_project_id INTEGER DEFAULT 0
@@ -879,7 +879,7 @@ function version_1($pdo)
$pdo->exec(" $pdo->exec("
CREATE TABLE projects ( CREATE TABLE projects (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
name TEXT NOCASE UNIQUE, name TEXT NOCASE NOT NULL UNIQUE,
is_active INTEGER DEFAULT 1 is_active INTEGER DEFAULT 1
) )
"); ");
@@ -887,9 +887,9 @@ function version_1($pdo)
$pdo->exec(" $pdo->exec("
CREATE TABLE columns ( CREATE TABLE columns (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
title TEXT, title TEXT NOT NULL,
position INTEGER, position INTEGER,
project_id INTEGER, project_id INTEGER NOT NULL,
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE, FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE,
UNIQUE (title, project_id) UNIQUE (title, project_id)
) )

View File

@@ -38,8 +38,8 @@ class ActionTaskAssignColorCategory extends Base
$c = new Category($this->container); $c = new Category($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $c->create(array('name' => 'c1'))); $this->assertEquals(1, $c->create(array('name' => 'c1', 'project_id' => 1)));
$this->assertEquals(2, $c->create(array('name' => 'c2'))); $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))); $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 // We create an event but we don't do anything

View File

@@ -10,10 +10,250 @@ use Model\TaskPosition;
use Model\TaskCreation; use Model\TaskCreation;
use Model\TaskFinder; use Model\TaskFinder;
use Model\Category; use Model\Category;
use Model\User;
use Model\ProjectPermission;
use Integration\GithubWebhook; use Integration\GithubWebhook;
use Integration\BitbucketWebhook;
class ActionTest extends Base 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() public function testSingleAction()
{ {
$tp = new TaskPosition($this->container); $tp = new TaskPosition($this->container);
@@ -70,12 +310,10 @@ class ActionTest extends Base
$b = new Board($this->container); $b = new Board($this->container);
$p = new Project($this->container); $p = new Project($this->container);
$a = new Action($this->container); $a = new Action($this->container);
$c = new Category($this->container);
$g = new GithubWebhook($this->container); $g = new GithubWebhook($this->container);
// We create a project // We create a project
$this->assertEquals(1, $p->create(array('name' => 'unit_test'))); $this->assertEquals(1, $p->create(array('name' => 'unit_test')));
$this->assertEquals(1, $c->create(array('name' => 'unit_test')));
// We create a new action // We create a new action
$this->assertEquals(1, $a->create(array( $this->assertEquals(1, $a->create(array(

View File

@@ -40,7 +40,7 @@ class MailgunTest extends Base
$tc = new TaskCreation($this->container); $tc = new TaskCreation($this->container);
$tf = new TaskFinder($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(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));

View File

@@ -43,7 +43,7 @@ class PostmarkTest extends Base
$tc = new TaskCreation($this->container); $tc = new TaskCreation($this->container);
$tf = new TaskFinder($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(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
@@ -81,7 +81,7 @@ class PostmarkTest extends Base
$tc = new TaskCreation($this->container); $tc = new TaskCreation($this->container);
$tf = new TaskFinder($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->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
$this->assertTrue($pp->addMember(1, 2)); $this->assertTrue($pp->addMember(1, 2));

View File

@@ -241,7 +241,7 @@ class ProjectPermissionTest extends Base
$pp = new ProjectPermission($this->container); $pp = new ProjectPermission($this->container);
$user = new User($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 // We create project
$this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));

View File

@@ -48,7 +48,7 @@ class SendgridTest extends Base
$tc = new TaskCreation($this->container); $tc = new TaskCreation($this->container);
$tf = new TaskFinder($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(1, $p->create(array('name' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));