Improve unit tests
This commit is contained in:
293
tests/units/Model/AclTest.php
Normal file
293
tests/units/Model/AclTest.php
Normal file
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Core\Session;
|
||||
use Model\Acl;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
use Model\User;
|
||||
|
||||
class AclTest extends Base
|
||||
{
|
||||
public function testMatchAcl()
|
||||
{
|
||||
$acl_rules = array(
|
||||
'controller1' => array('action1', 'action3'),
|
||||
'controller3' => '*',
|
||||
'controller5' => '-',
|
||||
'controller6' => array(),
|
||||
);
|
||||
|
||||
$acl = new Acl($this->container);
|
||||
$this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'aCtiOn1'));
|
||||
$this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'action1'));
|
||||
$this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'action3'));
|
||||
$this->assertFalse($acl->matchAcl($acl_rules, 'controller1', 'action2'));
|
||||
$this->assertFalse($acl->matchAcl($acl_rules, 'controller2', 'action2'));
|
||||
$this->assertFalse($acl->matchAcl($acl_rules, 'controller2', 'action3'));
|
||||
$this->assertTrue($acl->matchAcl($acl_rules, 'controller3', 'anything'));
|
||||
$this->assertFalse($acl->matchAcl($acl_rules, 'controller4', 'anything'));
|
||||
$this->assertFalse($acl->matchAcl($acl_rules, 'controller5', 'anything'));
|
||||
$this->assertFalse($acl->matchAcl($acl_rules, 'controller6', 'anything'));
|
||||
}
|
||||
|
||||
public function testPublicActions()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$this->assertTrue($acl->isPublicAction('task', 'readonly'));
|
||||
$this->assertTrue($acl->isPublicAction('board', 'readonly'));
|
||||
$this->assertFalse($acl->isPublicAction('board', 'show'));
|
||||
$this->assertTrue($acl->isPublicAction('feed', 'project'));
|
||||
$this->assertTrue($acl->isPublicAction('feed', 'user'));
|
||||
$this->assertTrue($acl->isPublicAction('ical', 'project'));
|
||||
$this->assertTrue($acl->isPublicAction('ical', 'user'));
|
||||
$this->assertTrue($acl->isPublicAction('oauth', 'github'));
|
||||
$this->assertTrue($acl->isPublicAction('oauth', 'google'));
|
||||
$this->assertTrue($acl->isPublicAction('auth', 'login'));
|
||||
$this->assertTrue($acl->isPublicAction('auth', 'check'));
|
||||
$this->assertTrue($acl->isPublicAction('auth', 'captcha'));
|
||||
}
|
||||
|
||||
public function testAdminActions()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$this->assertFalse($acl->isAdminAction('board', 'show'));
|
||||
$this->assertFalse($acl->isAdminAction('task', 'show'));
|
||||
$this->assertTrue($acl->isAdminAction('config', 'api'));
|
||||
$this->assertTrue($acl->isAdminAction('config', 'anything'));
|
||||
$this->assertTrue($acl->isAdminAction('config', 'anything'));
|
||||
$this->assertTrue($acl->isAdminAction('user', 'save'));
|
||||
}
|
||||
|
||||
public function testProjectAdminActions()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$this->assertFalse($acl->isProjectAdminAction('config', 'save'));
|
||||
$this->assertFalse($acl->isProjectAdminAction('user', 'index'));
|
||||
$this->assertTrue($acl->isProjectAdminAction('project', 'remove'));
|
||||
}
|
||||
|
||||
public function testProjectManagerActions()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$this->assertFalse($acl->isProjectManagerAction('board', 'readonly'));
|
||||
$this->assertFalse($acl->isProjectManagerAction('project', 'remove'));
|
||||
$this->assertFalse($acl->isProjectManagerAction('project', 'show'));
|
||||
$this->assertTrue($acl->isProjectManagerAction('project', 'disable'));
|
||||
$this->assertTrue($acl->isProjectManagerAction('category', 'index'));
|
||||
$this->assertTrue($acl->isProjectManagerAction('project', 'users'));
|
||||
$this->assertFalse($acl->isProjectManagerAction('app', 'index'));
|
||||
}
|
||||
|
||||
public function testPageAccessNoSession()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$session = new Session;
|
||||
$session = array();
|
||||
|
||||
$this->assertFalse($acl->isAllowed('board', 'readonly'));
|
||||
$this->assertFalse($acl->isAllowed('task', 'show'));
|
||||
$this->assertFalse($acl->isAllowed('config', 'application'));
|
||||
$this->assertFalse($acl->isAllowed('project', 'users'));
|
||||
$this->assertFalse($acl->isAllowed('task', 'remove'));
|
||||
$this->assertTrue($acl->isAllowed('app', 'index'));
|
||||
}
|
||||
|
||||
public function testPageAccessEmptySession()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$session = new Session;
|
||||
$session['user'] = array();
|
||||
|
||||
$this->assertFalse($acl->isAllowed('board', 'readonly'));
|
||||
$this->assertFalse($acl->isAllowed('task', 'show'));
|
||||
$this->assertFalse($acl->isAllowed('config', 'application'));
|
||||
$this->assertFalse($acl->isAllowed('project', 'users'));
|
||||
$this->assertFalse($acl->isAllowed('task', 'remove'));
|
||||
$this->assertTrue($acl->isAllowed('app', 'index'));
|
||||
}
|
||||
|
||||
public function testPageAccessAdminUser()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$session = new Session;
|
||||
|
||||
$session['user'] = array(
|
||||
'is_admin' => true,
|
||||
);
|
||||
|
||||
$this->assertTrue($acl->isAllowed('board', 'readonly'));
|
||||
$this->assertTrue($acl->isAllowed('task', 'readonly'));
|
||||
$this->assertTrue($acl->isAllowed('webhook', 'github'));
|
||||
$this->assertTrue($acl->isAllowed('task', 'show'));
|
||||
$this->assertTrue($acl->isAllowed('task', 'update'));
|
||||
$this->assertTrue($acl->isAllowed('config', 'application'));
|
||||
$this->assertTrue($acl->isAllowed('project', 'show'));
|
||||
$this->assertTrue($acl->isAllowed('project', 'users'));
|
||||
$this->assertTrue($acl->isAllowed('project', 'remove'));
|
||||
$this->assertTrue($acl->isAllowed('category', 'edit'));
|
||||
$this->assertTrue($acl->isAllowed('task', 'remove'));
|
||||
$this->assertTrue($acl->isAllowed('app', 'index'));
|
||||
}
|
||||
|
||||
public function testPageAccessProjectAdmin()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$u = new User($this->container);
|
||||
$session = new Session;
|
||||
|
||||
// We create our user
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
|
||||
|
||||
// We create a project and set our user as project manager
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
$this->assertTrue($pp->isMember(1, 2));
|
||||
$this->assertFalse($pp->isManager(1, 2));
|
||||
|
||||
// We fake a session for him
|
||||
$session['user'] = array(
|
||||
'id' => 2,
|
||||
'is_admin' => false,
|
||||
'is_project_admin' => true,
|
||||
);
|
||||
|
||||
$this->assertTrue($acl->isAllowed('board', 'readonly', 1));
|
||||
$this->assertTrue($acl->isAllowed('task', 'readonly', 1));
|
||||
$this->assertTrue($acl->isAllowed('webhook', 'github', 1));
|
||||
$this->assertTrue($acl->isAllowed('task', 'show', 1));
|
||||
$this->assertFalse($acl->isAllowed('task', 'show', 2));
|
||||
$this->assertTrue($acl->isAllowed('task', 'update', 1));
|
||||
$this->assertTrue($acl->isAllowed('project', 'show', 1));
|
||||
$this->assertFalse($acl->isAllowed('config', 'application', 1));
|
||||
|
||||
$this->assertTrue($acl->isAllowed('project', 'users', 1));
|
||||
$this->assertFalse($acl->isAllowed('project', 'users', 2));
|
||||
|
||||
$this->assertTrue($acl->isAllowed('project', 'remove', 1));
|
||||
$this->assertFalse($acl->isAllowed('project', 'remove', 2));
|
||||
|
||||
$this->assertTrue($acl->isAllowed('category', 'edit', 1));
|
||||
$this->assertTrue($acl->isAllowed('task', 'remove', 1));
|
||||
$this->assertTrue($acl->isAllowed('app', 'index', 1));
|
||||
}
|
||||
|
||||
public function testPageAccessProjectManager()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$u = new User($this->container);
|
||||
$session = new Session;
|
||||
|
||||
// We create our user
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
|
||||
|
||||
// We create a project and set our user as project manager
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest'), 2, true));
|
||||
$this->assertTrue($pp->isMember(1, 2));
|
||||
$this->assertTrue($pp->isManager(1, 2));
|
||||
|
||||
// We fake a session for him
|
||||
$session['user'] = array(
|
||||
'id' => 2,
|
||||
'is_admin' => false,
|
||||
);
|
||||
|
||||
$this->assertTrue($acl->isAllowed('board', 'readonly', 1));
|
||||
$this->assertTrue($acl->isAllowed('task', 'readonly', 1));
|
||||
$this->assertTrue($acl->isAllowed('webhook', 'github', 1));
|
||||
$this->assertTrue($acl->isAllowed('task', 'show', 1));
|
||||
$this->assertFalse($acl->isAllowed('task', 'show', 2));
|
||||
$this->assertTrue($acl->isAllowed('task', 'update', 1));
|
||||
$this->assertTrue($acl->isAllowed('project', 'show', 1));
|
||||
$this->assertFalse($acl->isAllowed('config', 'application', 1));
|
||||
|
||||
$this->assertTrue($acl->isAllowed('project', 'users', 1));
|
||||
$this->assertFalse($acl->isAllowed('project', 'users', 2));
|
||||
|
||||
$this->assertFalse($acl->isAllowed('project', 'remove', 1));
|
||||
$this->assertFalse($acl->isAllowed('project', 'remove', 2));
|
||||
|
||||
$this->assertTrue($acl->isAllowed('category', 'edit', 1));
|
||||
$this->assertTrue($acl->isAllowed('task', 'remove', 1));
|
||||
$this->assertTrue($acl->isAllowed('app', 'index', 1));
|
||||
}
|
||||
|
||||
public function testPageAccessMember()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
// We create our user
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
|
||||
|
||||
// We create a project and set our user as member
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
$this->assertTrue($pp->isMember(1, 2));
|
||||
$this->assertFalse($pp->isManager(1, 2));
|
||||
|
||||
$session = new Session;
|
||||
|
||||
$session['user'] = array(
|
||||
'id' => 2,
|
||||
'is_admin' => false,
|
||||
);
|
||||
|
||||
$this->assertTrue($acl->isAllowed('board', 'readonly', 1));
|
||||
$this->assertTrue($acl->isAllowed('task', 'readonly', 1));
|
||||
$this->assertTrue($acl->isAllowed('webhook', 'github', 1));
|
||||
$this->assertFalse($acl->isAllowed('board', 'show', 2));
|
||||
$this->assertTrue($acl->isAllowed('board', 'show', 1));
|
||||
$this->assertFalse($acl->isAllowed('task', 'show', 2));
|
||||
$this->assertTrue($acl->isAllowed('task', 'show', 1));
|
||||
$this->assertTrue($acl->isAllowed('task', 'update', 1));
|
||||
$this->assertTrue($acl->isAllowed('project', 'show', 1));
|
||||
$this->assertFalse($acl->isAllowed('config', 'application', 1));
|
||||
$this->assertFalse($acl->isAllowed('project', 'users', 1));
|
||||
$this->assertTrue($acl->isAllowed('task', 'remove', 1));
|
||||
$this->assertFalse($acl->isAllowed('task', 'remove', 2));
|
||||
$this->assertTrue($acl->isAllowed('app', 'index', 1));
|
||||
}
|
||||
|
||||
public function testPageAccessNotMember()
|
||||
{
|
||||
$acl = new Acl($this->container);
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
// We create our user
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
|
||||
|
||||
// We create a project and set our user as member
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
||||
$this->assertFalse($pp->isMember(1, 2));
|
||||
$this->assertFalse($pp->isManager(1, 2));
|
||||
|
||||
$session = new Session;
|
||||
|
||||
$session['user'] = array(
|
||||
'id' => 2,
|
||||
'is_admin' => false,
|
||||
);
|
||||
|
||||
$this->assertFalse($acl->isAllowed('board', 'show', 2));
|
||||
$this->assertFalse($acl->isAllowed('board', 'show', 1));
|
||||
$this->assertFalse($acl->isAllowed('task', 'show', 1));
|
||||
$this->assertFalse($acl->isAllowed('task', 'update', 1));
|
||||
$this->assertFalse($acl->isAllowed('project', 'show', 1));
|
||||
$this->assertFalse($acl->isAllowed('config', 'application', 1));
|
||||
$this->assertFalse($acl->isAllowed('project', 'users', 1));
|
||||
$this->assertFalse($acl->isAllowed('task', 'remove', 1));
|
||||
$this->assertTrue($acl->isAllowed('app', 'index', 1));
|
||||
}
|
||||
}
|
||||
379
tests/units/Model/ActionTest.php
Normal file
379
tests/units/Model/ActionTest.php
Normal file
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Action;
|
||||
use Model\Project;
|
||||
use Model\Board;
|
||||
use Model\Task;
|
||||
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);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$board = new Board($this->container);
|
||||
$project = new Project($this->container);
|
||||
$action = new Action($this->container);
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
|
||||
|
||||
// We create a new action
|
||||
$this->assertEquals(1, $action->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_MOVE_COLUMN,
|
||||
'action_name' => 'TaskClose',
|
||||
'params' => array(
|
||||
'column_id' => 4,
|
||||
)
|
||||
)));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array(
|
||||
'title' => 'unit_test',
|
||||
'project_id' => 1,
|
||||
'owner_id' => 1,
|
||||
'color_id' => 'red',
|
||||
'column_id' => 1,
|
||||
)));
|
||||
|
||||
// We attach events
|
||||
$action->attachEvents();
|
||||
|
||||
// Our task should be open
|
||||
$t1 = $tf->getById(1);
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals(1, $t1['column_id']);
|
||||
|
||||
// We move our task
|
||||
$tp->movePosition(1, 1, 4, 1);
|
||||
|
||||
// Our task should be closed
|
||||
$t1 = $tf->getById(1);
|
||||
$this->assertEquals(4, $t1['column_id']);
|
||||
$this->assertEquals(0, $t1['is_active']);
|
||||
}
|
||||
|
||||
public function testMultipleActions()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$b = new Board($this->container);
|
||||
$p = new Project($this->container);
|
||||
$a = new Action($this->container);
|
||||
$g = new GithubWebhook($this->container);
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'unit_test')));
|
||||
|
||||
// We create a new action
|
||||
$this->assertEquals(1, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => GithubWebhook::EVENT_ISSUE_OPENED,
|
||||
'action_name' => 'TaskCreation',
|
||||
'params' => array()
|
||||
)));
|
||||
|
||||
$this->assertEquals(2, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
|
||||
'action_name' => 'TaskAssignCategoryLabel',
|
||||
'params' => array(
|
||||
'label' => 'bug',
|
||||
'category_id' => 1,
|
||||
)
|
||||
)));
|
||||
|
||||
$this->assertEquals(3, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE_UPDATE,
|
||||
'action_name' => 'TaskAssignColorCategory',
|
||||
'params' => array(
|
||||
'color_id' => 'red',
|
||||
'category_id' => 1,
|
||||
)
|
||||
)));
|
||||
|
||||
// We attach events
|
||||
$a->attachEvents();
|
||||
$g->setProjectId(1);
|
||||
|
||||
// We create a Github issue
|
||||
$issue = array(
|
||||
'number' => 123,
|
||||
'title' => 'Bugs everywhere',
|
||||
'body' => 'There is a bug!',
|
||||
'html_url' => 'http://localhost/',
|
||||
);
|
||||
|
||||
$this->assertTrue($g->handleIssueOpened($issue));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['is_active']);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
$this->assertEquals('yellow', $task['color_id']);
|
||||
|
||||
// We assign a label to our issue
|
||||
$label = array(
|
||||
'name' => 'bug',
|
||||
);
|
||||
|
||||
$this->assertTrue($g->handleIssueLabeled($issue, $label));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['is_active']);
|
||||
$this->assertEquals(1, $task['category_id']);
|
||||
$this->assertEquals('red', $task['color_id']);
|
||||
}
|
||||
}
|
||||
39
tests/units/Model/AuthenticationTest.php
Normal file
39
tests/units/Model/AuthenticationTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\User;
|
||||
use Model\Authentication;
|
||||
|
||||
class AuthenticationTest extends Base
|
||||
{
|
||||
public function testHasCaptcha()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$a = new Authentication($this->container);
|
||||
|
||||
$this->assertFalse($a->hasCaptcha('not_found'));
|
||||
$this->assertFalse($a->hasCaptcha('admin'));
|
||||
|
||||
$this->assertTrue($u->incrementFailedLogin('admin'));
|
||||
$this->assertTrue($u->incrementFailedLogin('admin'));
|
||||
$this->assertTrue($u->incrementFailedLogin('admin'));
|
||||
|
||||
$this->assertFalse($a->hasCaptcha('not_found'));
|
||||
$this->assertTrue($a->hasCaptcha('admin'));
|
||||
}
|
||||
|
||||
public function testHandleFailedLogin()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$a = new Authentication($this->container);
|
||||
|
||||
$this->assertFalse($u->isLocked('admin'));
|
||||
|
||||
for ($i = 0; $i <= 6; $i++) {
|
||||
$a->handleFailedLogin('admin');
|
||||
}
|
||||
|
||||
$this->assertTrue($u->isLocked('admin'));
|
||||
}
|
||||
}
|
||||
372
tests/units/Model/BoardTest.php
Normal file
372
tests/units/Model/BoardTest.php
Normal file
@@ -0,0 +1,372 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Project;
|
||||
use Model\Board;
|
||||
use Model\Config;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Swimlane;
|
||||
|
||||
class BoardTest extends Base
|
||||
{
|
||||
public function testCreation()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
$c = new Config($this->container);
|
||||
|
||||
// Default columns
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$columns = $b->getColumnsList(1);
|
||||
|
||||
$this->assertTrue(is_array($columns));
|
||||
$this->assertEquals(4, count($columns));
|
||||
$this->assertEquals('Backlog', $columns[1]);
|
||||
$this->assertEquals('Ready', $columns[2]);
|
||||
$this->assertEquals('Work in progress', $columns[3]);
|
||||
$this->assertEquals('Done', $columns[4]);
|
||||
|
||||
// Custom columns: spaces should be trimed and no empty columns
|
||||
$input = ' column #1 , column #2, ';
|
||||
|
||||
$this->assertTrue($c->save(array('board_columns' => $input)));
|
||||
$this->assertEquals($input, $c->get('board_columns'));
|
||||
|
||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
||||
$columns = $b->getColumnsList(2);
|
||||
|
||||
$this->assertTrue(is_array($columns));
|
||||
$this->assertEquals(2, count($columns));
|
||||
$this->assertEquals('column #1', $columns[5]);
|
||||
$this->assertEquals('column #2', $columns[6]);
|
||||
}
|
||||
|
||||
public function testGetBoard()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
|
||||
$board = $b->getBoard(1);
|
||||
$this->assertNotEmpty($board);
|
||||
$this->assertEquals(1, count($board));
|
||||
$this->assertEquals(5, count($board[0]));
|
||||
$this->assertTrue(array_key_exists('name', $board[0]));
|
||||
$this->assertTrue(array_key_exists('columns', $board[0]));
|
||||
$this->assertTrue(array_key_exists('tasks', $board[0]['columns'][2]));
|
||||
$this->assertTrue(array_key_exists('title', $board[0]['columns'][2]));
|
||||
}
|
||||
|
||||
public function testGetBoardWithSwimlane()
|
||||
{
|
||||
$b = new Board($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 3)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 3)));
|
||||
$this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 4)));
|
||||
$this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 4, 'swimlane_id' => 1)));
|
||||
|
||||
$board = $b->getBoard(1);
|
||||
$this->assertNotEmpty($board);
|
||||
$this->assertEquals(2, count($board));
|
||||
$this->assertEquals(5, count($board[0]));
|
||||
$this->assertTrue(array_key_exists('nb_tasks', $board[0]));
|
||||
$this->assertTrue(array_key_exists('name', $board[0]));
|
||||
$this->assertTrue(array_key_exists('columns', $board[0]));
|
||||
$this->assertTrue(array_key_exists('tasks', $board[0]['columns'][2]));
|
||||
$this->assertTrue(array_key_exists('title', $board[0]['columns'][2]));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['id']);
|
||||
$this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['column_id']);
|
||||
$this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['position']);
|
||||
$this->assertEquals(0, $board[0]['columns'][0]['tasks'][0]['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(2, $board[0]['columns'][2]['tasks'][0]['id']);
|
||||
$this->assertEquals(3, $board[0]['columns'][2]['tasks'][0]['column_id']);
|
||||
$this->assertEquals(1, $board[0]['columns'][2]['tasks'][0]['position']);
|
||||
$this->assertEquals(0, $board[0]['columns'][2]['tasks'][0]['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(1, $task['swimlane_id']);
|
||||
$this->assertEquals(3, $board[1]['columns'][1]['tasks'][0]['id']);
|
||||
$this->assertEquals(2, $board[1]['columns'][1]['tasks'][0]['column_id']);
|
||||
$this->assertEquals(1, $board[1]['columns'][1]['tasks'][0]['position']);
|
||||
$this->assertEquals(1, $board[1]['columns'][1]['tasks'][0]['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(4, $board[0]['columns'][2]['tasks'][1]['id']);
|
||||
$this->assertEquals(3, $board[0]['columns'][2]['tasks'][1]['column_id']);
|
||||
$this->assertEquals(2, $board[0]['columns'][2]['tasks'][1]['position']);
|
||||
$this->assertEquals(0, $board[0]['columns'][2]['tasks'][1]['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(4, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(5, $board[0]['columns'][3]['tasks'][0]['id']);
|
||||
$this->assertEquals(4, $board[0]['columns'][3]['tasks'][0]['column_id']);
|
||||
$this->assertEquals(1, $board[0]['columns'][3]['tasks'][0]['position']);
|
||||
$this->assertEquals(0, $board[0]['columns'][3]['tasks'][0]['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(6);
|
||||
$this->assertEquals(6, $task['id']);
|
||||
$this->assertEquals(4, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(1, $task['swimlane_id']);
|
||||
$this->assertEquals(6, $board[1]['columns'][3]['tasks'][0]['id']);
|
||||
$this->assertEquals(4, $board[1]['columns'][3]['tasks'][0]['column_id']);
|
||||
$this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['position']);
|
||||
$this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['swimlane_id']);
|
||||
}
|
||||
|
||||
public function testGetColumn()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
|
||||
$column = $b->getColumn(3);
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('Work in progress', $column['title']);
|
||||
|
||||
$column = $b->getColumn(33);
|
||||
$this->assertEmpty($column);
|
||||
}
|
||||
|
||||
public function testRemoveColumn()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertTrue($b->removeColumn(3));
|
||||
$this->assertFalse($b->removeColumn(322));
|
||||
|
||||
$columns = $b->getColumns(1);
|
||||
$this->assertTrue(is_array($columns));
|
||||
$this->assertEquals(3, count($columns));
|
||||
}
|
||||
|
||||
public function testUpdateColumn()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
|
||||
$this->assertTrue($b->updateColumn(3, 'blah', 5));
|
||||
$this->assertTrue($b->updateColumn(2, 'boo'));
|
||||
|
||||
$column = $b->getColumn(3);
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('blah', $column['title']);
|
||||
$this->assertEquals(5, $column['task_limit']);
|
||||
|
||||
$column = $b->getColumn(2);
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('boo', $column['title']);
|
||||
$this->assertEquals(0, $column['task_limit']);
|
||||
}
|
||||
|
||||
public function testAddColumn()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertNotFalse($b->addColumn(1, 'another column'));
|
||||
$this->assertNotFalse($b->addColumn(1, 'one more', 3, 'one more description'));
|
||||
|
||||
$columns = $b->getColumns(1);
|
||||
$this->assertTrue(is_array($columns));
|
||||
$this->assertEquals(6, count($columns));
|
||||
|
||||
$this->assertEquals('another column', $columns[4]['title']);
|
||||
$this->assertEquals(0, $columns[4]['task_limit']);
|
||||
$this->assertEquals(5, $columns[4]['position']);
|
||||
|
||||
$this->assertEquals('one more', $columns[5]['title']);
|
||||
$this->assertEquals(3, $columns[5]['task_limit']);
|
||||
$this->assertEquals(6, $columns[5]['position']);
|
||||
$this->assertEquals('one more description', $columns[5]['description']);
|
||||
}
|
||||
|
||||
public function testMoveColumns()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
||||
|
||||
// We get the columns of the project 2
|
||||
$columns = $b->getColumns(2);
|
||||
$columns_id = array_keys($b->getColumnsList(2));
|
||||
$this->assertNotEmpty($columns);
|
||||
|
||||
// Initial order: 5, 6, 7, 8
|
||||
|
||||
// Move the column 1 down
|
||||
$this->assertEquals(1, $columns[0]['position']);
|
||||
$this->assertEquals($columns_id[0], $columns[0]['id']);
|
||||
|
||||
$this->assertEquals(2, $columns[1]['position']);
|
||||
$this->assertEquals($columns_id[1], $columns[1]['id']);
|
||||
|
||||
$this->assertTrue($b->moveDown(2, $columns[0]['id']));
|
||||
$columns = $b->getColumns(2); // Sorted by position
|
||||
|
||||
// New order: 6, 5, 7, 8
|
||||
|
||||
$this->assertEquals(1, $columns[0]['position']);
|
||||
$this->assertEquals($columns_id[1], $columns[0]['id']);
|
||||
|
||||
$this->assertEquals(2, $columns[1]['position']);
|
||||
$this->assertEquals($columns_id[0], $columns[1]['id']);
|
||||
|
||||
// Move the column 3 up
|
||||
$this->assertTrue($b->moveUp(2, $columns[2]['id']));
|
||||
$columns = $b->getColumns(2);
|
||||
|
||||
// New order: 6, 7, 5, 8
|
||||
|
||||
$this->assertEquals(1, $columns[0]['position']);
|
||||
$this->assertEquals($columns_id[1], $columns[0]['id']);
|
||||
|
||||
$this->assertEquals(2, $columns[1]['position']);
|
||||
$this->assertEquals($columns_id[2], $columns[1]['id']);
|
||||
|
||||
$this->assertEquals(3, $columns[2]['position']);
|
||||
$this->assertEquals($columns_id[0], $columns[2]['id']);
|
||||
|
||||
// Move column 1 up (must do nothing because it's the first column)
|
||||
$this->assertFalse($b->moveUp(2, $columns[0]['id']));
|
||||
$columns = $b->getColumns(2);
|
||||
|
||||
// Order: 6, 7, 5, 8
|
||||
|
||||
$this->assertEquals(1, $columns[0]['position']);
|
||||
$this->assertEquals($columns_id[1], $columns[0]['id']);
|
||||
|
||||
// Move column 4 down (must do nothing because it's the last column)
|
||||
$this->assertFalse($b->moveDown(2, $columns[3]['id']));
|
||||
$columns = $b->getColumns(2);
|
||||
|
||||
// Order: 6, 7, 5, 8
|
||||
|
||||
$this->assertEquals(4, $columns[3]['position']);
|
||||
$this->assertEquals($columns_id[3], $columns[3]['id']);
|
||||
}
|
||||
|
||||
public function testMoveUpAndRemoveColumn()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
|
||||
// We remove the second column
|
||||
$this->assertTrue($b->removeColumn(2));
|
||||
|
||||
$columns = $b->getColumns(1);
|
||||
$this->assertNotEmpty($columns);
|
||||
$this->assertCount(3, $columns);
|
||||
|
||||
$this->assertEquals(1, $columns[0]['position']);
|
||||
$this->assertEquals(3, $columns[1]['position']);
|
||||
$this->assertEquals(4, $columns[2]['position']);
|
||||
|
||||
$this->assertEquals(1, $columns[0]['id']);
|
||||
$this->assertEquals(3, $columns[1]['id']);
|
||||
$this->assertEquals(4, $columns[2]['id']);
|
||||
|
||||
// We move up the second column
|
||||
$this->assertTrue($b->moveUp(1, $columns[1]['id']));
|
||||
|
||||
// Check the new positions
|
||||
$columns = $b->getColumns(1);
|
||||
$this->assertNotEmpty($columns);
|
||||
$this->assertCount(3, $columns);
|
||||
|
||||
$this->assertEquals(1, $columns[0]['position']);
|
||||
$this->assertEquals(2, $columns[1]['position']);
|
||||
$this->assertEquals(3, $columns[2]['position']);
|
||||
|
||||
$this->assertEquals(3, $columns[0]['id']);
|
||||
$this->assertEquals(1, $columns[1]['id']);
|
||||
$this->assertEquals(4, $columns[2]['id']);
|
||||
}
|
||||
|
||||
public function testMoveDownAndRemoveColumn()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
|
||||
// We remove the second column
|
||||
$this->assertTrue($b->removeColumn(2));
|
||||
|
||||
$columns = $b->getColumns(1);
|
||||
$this->assertNotEmpty($columns);
|
||||
$this->assertCount(3, $columns);
|
||||
|
||||
$this->assertEquals(1, $columns[0]['position']);
|
||||
$this->assertEquals(3, $columns[1]['position']);
|
||||
$this->assertEquals(4, $columns[2]['position']);
|
||||
|
||||
$this->assertEquals(1, $columns[0]['id']);
|
||||
$this->assertEquals(3, $columns[1]['id']);
|
||||
$this->assertEquals(4, $columns[2]['id']);
|
||||
|
||||
// We move up the second column
|
||||
$this->assertTrue($b->moveDown(1, $columns[0]['id']));
|
||||
|
||||
// Check the new positions
|
||||
$columns = $b->getColumns(1);
|
||||
$this->assertNotEmpty($columns);
|
||||
$this->assertCount(3, $columns);
|
||||
|
||||
$this->assertEquals(1, $columns[0]['position']);
|
||||
$this->assertEquals(2, $columns[1]['position']);
|
||||
$this->assertEquals(3, $columns[2]['position']);
|
||||
|
||||
$this->assertEquals(3, $columns[0]['id']);
|
||||
$this->assertEquals(1, $columns[1]['id']);
|
||||
$this->assertEquals(4, $columns[2]['id']);
|
||||
}
|
||||
}
|
||||
67
tests/units/Model/CategoryTest.php
Normal file
67
tests/units/Model/CategoryTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Project;
|
||||
use Model\Category;
|
||||
use Model\User;
|
||||
|
||||
class CategoryTest extends Base
|
||||
{
|
||||
public function testCreation()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
|
||||
$this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertTrue(is_array($task));
|
||||
$this->assertEquals(2, $task['category_id']);
|
||||
|
||||
$category = $c->getById(2);
|
||||
$this->assertTrue(is_array($category));
|
||||
$this->assertEquals(2, $category['id']);
|
||||
$this->assertEquals('Category #2', $category['name']);
|
||||
$this->assertEquals(1, $category['project_id']);
|
||||
|
||||
$this->assertEquals(2, $c->getIdByName(1, 'Category #2'));
|
||||
$this->assertEquals(0, $c->getIdByName(2, 'Category #2'));
|
||||
|
||||
$this->assertEquals('Category #2', $c->getNameById(2));
|
||||
$this->assertEquals('', $c->getNameById(23));
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
|
||||
$this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertTrue(is_array($task));
|
||||
$this->assertEquals(2, $task['category_id']);
|
||||
|
||||
$this->assertTrue($c->remove(1));
|
||||
$this->assertTrue($c->remove(2));
|
||||
|
||||
// Make sure tasks assigned with that category are reseted
|
||||
$task = $tf->getById(1);
|
||||
$this->assertTrue(is_array($task));
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
}
|
||||
}
|
||||
142
tests/units/Model/CommentTest.php
Normal file
142
tests/units/Model/CommentTest.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\Project;
|
||||
use Model\Comment;
|
||||
|
||||
class CommentTest extends Base
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$c = new Comment($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
|
||||
$this->assertEquals(1, $c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
|
||||
$this->assertEquals(2, $c->create(array('task_id' => 1, 'comment' => 'bla bla')));
|
||||
|
||||
$comment = $c->getById(1);
|
||||
$this->assertNotEmpty($comment);
|
||||
$this->assertEquals('bla bla', $comment['comment']);
|
||||
$this->assertEquals(1, $comment['task_id']);
|
||||
$this->assertEquals(1, $comment['user_id']);
|
||||
$this->assertEquals('admin', $comment['username']);
|
||||
$this->assertEquals(time(), $comment['date_creation'], '', 3);
|
||||
|
||||
$comment = $c->getById(2);
|
||||
$this->assertNotEmpty($comment);
|
||||
$this->assertEquals('bla bla', $comment['comment']);
|
||||
$this->assertEquals(1, $comment['task_id']);
|
||||
$this->assertEquals(0, $comment['user_id']);
|
||||
$this->assertEquals('', $comment['username']);
|
||||
$this->assertEquals(time(), $comment['date_creation'], '', 3);
|
||||
}
|
||||
|
||||
public function testGetAll()
|
||||
{
|
||||
$c = new Comment($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
|
||||
|
||||
$comments = $c->getAll(1);
|
||||
|
||||
$this->assertNotEmpty($comments);
|
||||
$this->assertEquals(3, count($comments));
|
||||
$this->assertEquals(1, $comments[0]['id']);
|
||||
$this->assertEquals(2, $comments[1]['id']);
|
||||
$this->assertEquals(3, $comments[2]['id']);
|
||||
|
||||
$this->assertEquals(3, $c->count(1));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$c = new Comment($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
|
||||
$this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla')));
|
||||
|
||||
$comment = $c->getById(1);
|
||||
$this->assertNotEmpty($comment);
|
||||
$this->assertEquals('bla', $comment['comment']);
|
||||
}
|
||||
|
||||
public function validateRemove()
|
||||
{
|
||||
$c = new Comment($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
|
||||
$this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
|
||||
|
||||
$this->assertTrue($c->remove(1));
|
||||
$this->assertFalse($c->remove(1));
|
||||
$this->assertFalse($c->remove(1111));
|
||||
}
|
||||
|
||||
public function testValidateCreation()
|
||||
{
|
||||
$c = new Comment($this->container);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla'));
|
||||
$this->assertTrue($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => ''));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 1, 'comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('task_id' => 1, 'comment' => 'bla'));
|
||||
$this->assertTrue($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array());
|
||||
$this->assertFalse($result[0]);
|
||||
}
|
||||
|
||||
public function testValidateModification()
|
||||
{
|
||||
$c = new Comment($this->container);
|
||||
|
||||
$result = $c->validateModification(array('id' => 1, 'comment' => 'bla'));
|
||||
$this->assertTrue($result[0]);
|
||||
|
||||
$result = $c->validateModification(array('id' => 1, 'comment' => ''));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateModification(array('comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateModification(array('id' => 'b', 'comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateModification(array());
|
||||
$this->assertFalse($result[0]);
|
||||
}
|
||||
}
|
||||
66
tests/units/Model/ConfigTest.php
Normal file
66
tests/units/Model/ConfigTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Config;
|
||||
use Core\Session;
|
||||
|
||||
class ConfigTest extends Base
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$c = new Config($this->container);
|
||||
|
||||
$this->assertEquals('en_US', $c->get('application_language'));
|
||||
$this->assertEquals('UTC', $c->get('application_timezone'));
|
||||
|
||||
$this->assertEmpty($c->get('webhook_url_task_modification'));
|
||||
$this->assertEmpty($c->get('webhook_url_task_creation'));
|
||||
$this->assertEmpty($c->get('board_columns'));
|
||||
$this->assertEmpty($c->get('application_url'));
|
||||
|
||||
$this->assertNotEmpty($c->get('webhook_token'));
|
||||
$this->assertNotEmpty($c->get('api_token'));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$c = new Config($this->container);
|
||||
|
||||
$this->assertEquals('', $c->get('board_columns'));
|
||||
$this->assertEquals('test', $c->get('board_columns', 'test'));
|
||||
$this->assertEquals(0, $c->get('board_columns', 0));
|
||||
}
|
||||
|
||||
public function testGetWithSession()
|
||||
{
|
||||
$this->container['session'] = new Session;
|
||||
$c = new Config($this->container);
|
||||
|
||||
session_id('test');
|
||||
|
||||
$this->assertTrue(Session::isOpen());
|
||||
|
||||
$this->assertEquals('', $c->get('board_columns'));
|
||||
$this->assertEquals('test', $c->get('board_columns', 'test'));
|
||||
|
||||
$this->container['session']['config'] = array(
|
||||
'board_columns' => 'foo',
|
||||
'empty_value' => 0
|
||||
);
|
||||
|
||||
$this->assertEquals('foo', $c->get('board_columns'));
|
||||
$this->assertEquals('foo', $c->get('board_columns', 'test'));
|
||||
$this->assertEquals('test', $c->get('empty_value', 'test'));
|
||||
|
||||
session_id('');
|
||||
unset($this->container['session']);
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
$c = new Config($this->container);
|
||||
$this->assertTrue($c->save(array('application_url' => 'http://localhost/')));
|
||||
$this->assertEquals('http://localhost/', $c->get('application_url'));
|
||||
}
|
||||
}
|
||||
84
tests/units/Model/DateParserTest.php
Normal file
84
tests/units/Model/DateParserTest.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\DateParser;
|
||||
|
||||
class DateParserTest extends Base
|
||||
{
|
||||
public function testDateRange()
|
||||
{
|
||||
$d = new DateParser($this->container);
|
||||
|
||||
$this->assertTrue($d->withinDateRange(new DateTime('2015-03-14 15:30:00'), new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00')));
|
||||
$this->assertFalse($d->withinDateRange(new DateTime('2015-03-14 15:30:00'), new DateTime('2015-03-14 16:00:00'), new DateTime('2015-03-14 17:00:00')));
|
||||
}
|
||||
|
||||
public function testRoundSeconds()
|
||||
{
|
||||
$d = new DateParser($this->container);
|
||||
$this->assertEquals('16:30', date('H:i', $d->getRoundedSeconds(strtotime('16:28'))));
|
||||
$this->assertEquals('16:00', date('H:i', $d->getRoundedSeconds(strtotime('16:02'))));
|
||||
$this->assertEquals('16:15', date('H:i', $d->getRoundedSeconds(strtotime('16:14'))));
|
||||
$this->assertEquals('17:00', date('H:i', $d->getRoundedSeconds(strtotime('16:58'))));
|
||||
}
|
||||
|
||||
public function testGetHours()
|
||||
{
|
||||
$d = new DateParser($this->container);
|
||||
|
||||
$this->assertEquals(1, $d->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00')));
|
||||
$this->assertEquals(2.5, $d->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:30:00')));
|
||||
$this->assertEquals(2.75, $d->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:45:00')));
|
||||
$this->assertEquals(3, $d->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 17:58:00')));
|
||||
$this->assertEquals(3, $d->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 11:58:00')));
|
||||
}
|
||||
|
||||
public function testValidDate()
|
||||
{
|
||||
$d = new DateParser($this->container);
|
||||
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('2014-03-05', 'Y-m-d')));
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('2014_03_05', 'Y_m_d')));
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('05/03/2014', 'd/m/Y')));
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('03/05/2014', 'm/d/Y')));
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('3/5/2014', 'm/d/Y')));
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('5/3/2014', 'd/m/Y')));
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('5/3/14', 'd/m/y')));
|
||||
$this->assertEquals(0, $d->getValidDate('5/3/14', 'd/m/Y'));
|
||||
$this->assertEquals(0, $d->getValidDate('5-3-2014', 'd/m/Y'));
|
||||
}
|
||||
|
||||
public function testGetTimestamp()
|
||||
{
|
||||
$d = new DateParser($this->container);
|
||||
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014-03-05')));
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014_03_05')));
|
||||
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('03/05/2014')));
|
||||
$this->assertEquals('2014-03-25 17:18', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 5:18 pm')));
|
||||
$this->assertEquals('2014-03-25 05:18', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 5:18 am')));
|
||||
$this->assertEquals('2014-03-25 05:18', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 5:18am')));
|
||||
$this->assertEquals('2014-03-25 23:14', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 23:14')));
|
||||
$this->assertEquals('2014-03-29 23:14', date('Y-m-d H:i', $d->getTimestamp('2014_03_29 23:14')));
|
||||
$this->assertEquals('2014-03-29 23:14', date('Y-m-d H:i', $d->getTimestamp('2014-03-29 23:14')));
|
||||
}
|
||||
|
||||
public function testConvert()
|
||||
{
|
||||
$d = new DateParser($this->container);
|
||||
|
||||
$values = array(
|
||||
'date_due' => '2015-01-25',
|
||||
'date_started' => '2015_01_25',
|
||||
);
|
||||
|
||||
$d->convert($values, array('date_due', 'date_started'));
|
||||
|
||||
$this->assertEquals(mktime(0, 0, 0, 1, 25, 2015), $values['date_due']);
|
||||
$this->assertEquals('2015-01-25', date('Y-m-d', $values['date_due']));
|
||||
|
||||
$this->assertEquals(mktime(0, 0, 0, 1, 25, 2015), $values['date_started']);
|
||||
$this->assertEquals('2015-01-25', date('Y-m-d', $values['date_started']));
|
||||
}
|
||||
}
|
||||
190
tests/units/Model/FileTest.php
Normal file
190
tests/units/Model/FileTest.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\File;
|
||||
use Model\TaskCreation;
|
||||
use Model\Project;
|
||||
|
||||
class FileTest extends Base
|
||||
{
|
||||
public function testCreation()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$f = new File($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$this->assertEquals(1, $f->create(1, 'test', '/tmp/foo', 10));
|
||||
|
||||
$file = $f->getById(1);
|
||||
$this->assertNotEmpty($file);
|
||||
$this->assertEquals('test', $file['name']);
|
||||
$this->assertEquals('/tmp/foo', $file['path']);
|
||||
$this->assertEquals(0, $file['is_image']);
|
||||
$this->assertEquals(1, $file['task_id']);
|
||||
$this->assertEquals(time(), $file['date'], '', 2);
|
||||
$this->assertEquals(0, $file['user_id']);
|
||||
$this->assertEquals(10, $file['size']);
|
||||
|
||||
$this->assertEquals(2, $f->create(1, 'test2.png', '/tmp/foobar', 10));
|
||||
|
||||
$file = $f->getById(2);
|
||||
$this->assertNotEmpty($file);
|
||||
$this->assertEquals('test2.png', $file['name']);
|
||||
$this->assertEquals('/tmp/foobar', $file['path']);
|
||||
$this->assertEquals(1, $file['is_image']);
|
||||
}
|
||||
|
||||
public function testCreationFileNameTooLong()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$f = new File($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$this->assertNotFalse($f->create(1, 'test', '/tmp/foo', 10));
|
||||
$this->assertNotFalse($f->create(1, str_repeat('a', 1000), '/tmp/foo', 10));
|
||||
|
||||
$files = $f->getAll(1);
|
||||
$this->assertNotEmpty($files);
|
||||
$this->assertCount(2, $files);
|
||||
|
||||
$this->assertEquals(str_repeat('a', 255), $files[0]['name']);
|
||||
$this->assertEquals('test', $files[1]['name']);
|
||||
}
|
||||
|
||||
public function testIsImage()
|
||||
{
|
||||
$f = new File($this->container);
|
||||
|
||||
$this->assertTrue($f->isImage('test.png'));
|
||||
$this->assertTrue($f->isImage('test.jpeg'));
|
||||
$this->assertTrue($f->isImage('test.gif'));
|
||||
$this->assertTrue($f->isImage('test.jpg'));
|
||||
$this->assertTrue($f->isImage('test.JPG'));
|
||||
|
||||
$this->assertFalse($f->isImage('test.bmp'));
|
||||
$this->assertFalse($f->isImage('test'));
|
||||
$this->assertFalse($f->isImage('test.pdf'));
|
||||
}
|
||||
|
||||
public function testGeneratePath()
|
||||
{
|
||||
$f = new File($this->container);
|
||||
|
||||
$this->assertStringStartsWith('12/34/', $f->generatePath(12, 34, 'test.png'));
|
||||
$this->assertNotEquals($f->generatePath(12, 34, 'test1.png'), $f->generatePath(12, 34, 'test2.png'));
|
||||
}
|
||||
|
||||
public function testUploadScreenshot()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$f = new File($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$this->assertEquals(1, $f->uploadScreenshot(1, 1, base64_encode('image data')));
|
||||
|
||||
$file = $f->getById(1);
|
||||
$this->assertNotEmpty($file);
|
||||
$this->assertStringStartsWith('Screenshot taken ', $file['name']);
|
||||
$this->assertStringStartsWith('1/1/', $file['path']);
|
||||
$this->assertEquals(1, $file['is_image']);
|
||||
$this->assertEquals(1, $file['task_id']);
|
||||
$this->assertEquals(time(), $file['date'], '', 2);
|
||||
$this->assertEquals(0, $file['user_id']);
|
||||
$this->assertEquals(10, $file['size']);
|
||||
}
|
||||
|
||||
public function testUploadFileContent()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$f = new File($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$this->assertEquals(1, $f->uploadContent(1, 1, 'my file.pdf', base64_encode('file data')));
|
||||
|
||||
$file = $f->getById(1);
|
||||
$this->assertNotEmpty($file);
|
||||
$this->assertEquals('my file.pdf', $file['name']);
|
||||
$this->assertStringStartsWith('1/1/', $file['path']);
|
||||
$this->assertEquals(0, $file['is_image']);
|
||||
$this->assertEquals(1, $file['task_id']);
|
||||
$this->assertEquals(time(), $file['date'], '', 2);
|
||||
$this->assertEquals(0, $file['user_id']);
|
||||
$this->assertEquals(9, $file['size']);
|
||||
}
|
||||
|
||||
public function testGetAll()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$f = new File($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10));
|
||||
$this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10));
|
||||
$this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10));
|
||||
$this->assertEquals(4, $f->create(1, 'C.JPG', '/tmp/foo', 10));
|
||||
|
||||
$files = $f->getAll(1);
|
||||
$this->assertNotEmpty($files);
|
||||
$this->assertCount(4, $files);
|
||||
$this->assertEquals('A.png', $files[0]['name']);
|
||||
$this->assertEquals('B.pdf', $files[1]['name']);
|
||||
$this->assertEquals('C.JPG', $files[2]['name']);
|
||||
$this->assertEquals('D.doc', $files[3]['name']);
|
||||
|
||||
$files = $f->getAllImages(1);
|
||||
$this->assertNotEmpty($files);
|
||||
$this->assertCount(2, $files);
|
||||
$this->assertEquals('A.png', $files[0]['name']);
|
||||
$this->assertEquals('C.JPG', $files[1]['name']);
|
||||
|
||||
$files = $f->getAllDocuments(1);
|
||||
$this->assertNotEmpty($files);
|
||||
$this->assertCount(2, $files);
|
||||
$this->assertEquals('B.pdf', $files[0]['name']);
|
||||
$this->assertEquals('D.doc', $files[1]['name']);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$f = new File($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10));
|
||||
$this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10));
|
||||
$this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10));
|
||||
|
||||
$this->assertTrue($f->remove(2));
|
||||
|
||||
$files = $f->getAll(1);
|
||||
$this->assertNotEmpty($files);
|
||||
$this->assertCount(2, $files);
|
||||
$this->assertEquals('B.pdf', $files[0]['name']);
|
||||
$this->assertEquals('D.doc', $files[1]['name']);
|
||||
|
||||
$this->assertTrue($f->removeAll(1));
|
||||
|
||||
$files = $f->getAll(1);
|
||||
$this->assertEmpty($files);
|
||||
}
|
||||
}
|
||||
43
tests/units/Model/HourlyRateTest.php
Normal file
43
tests/units/Model/HourlyRateTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\User;
|
||||
use Model\HourlyRate;
|
||||
|
||||
class HourlyRateTest extends Base
|
||||
{
|
||||
public function testCreation()
|
||||
{
|
||||
$hr = new HourlyRate($this->container);
|
||||
$this->assertEquals(1, $hr->create(1, 32.4, 'EUR', '2015-01-01'));
|
||||
$this->assertEquals(2, $hr->create(1, 42, 'CAD', '2015-02-01'));
|
||||
|
||||
$rates = $hr->getAllByUser(0);
|
||||
$this->assertEmpty($rates);
|
||||
|
||||
$rates = $hr->getAllByUser(1);
|
||||
$this->assertNotEmpty($rates);
|
||||
$this->assertCount(2, $rates);
|
||||
|
||||
$this->assertEquals(42, $rates[0]['rate']);
|
||||
$this->assertEquals('CAD', $rates[0]['currency']);
|
||||
$this->assertEquals('2015-02-01', date('Y-m-d', $rates[0]['date_effective']));
|
||||
|
||||
$this->assertEquals(32.4, $rates[1]['rate']);
|
||||
$this->assertEquals('EUR', $rates[1]['currency']);
|
||||
$this->assertEquals('2015-01-01', date('Y-m-d', $rates[1]['date_effective']));
|
||||
|
||||
$this->assertEquals(0, $hr->getCurrentRate(0));
|
||||
$this->assertEquals(42, $hr->getCurrentRate(1));
|
||||
|
||||
$this->assertTrue($hr->remove(2));
|
||||
$this->assertEquals(32.4, $hr->getCurrentRate(1));
|
||||
|
||||
$this->assertTrue($hr->remove(1));
|
||||
$this->assertEquals(0, $hr->getCurrentRate(1));
|
||||
|
||||
$rates = $hr->getAllByUser(1);
|
||||
$this->assertEmpty($rates);
|
||||
}
|
||||
}
|
||||
173
tests/units/Model/LinkTest.php
Normal file
173
tests/units/Model/LinkTest.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Link;
|
||||
|
||||
class LinkTest extends Base
|
||||
{
|
||||
public function testCreateLink()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$this->assertNotFalse($l->create('Link A'));
|
||||
$this->assertFalse($l->create('Link A'));
|
||||
$this->assertNotFalse($l->create('Link B', 'Link C'));
|
||||
|
||||
$links = $l->getAll();
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(14, $links);
|
||||
|
||||
$link = $l->getByLabel('Link A');
|
||||
$this->assertNotEmpty($link);
|
||||
$this->assertEquals('Link A', $link['label']);
|
||||
$this->assertEquals(0, $link['opposite_id']);
|
||||
|
||||
$link1 = $l->getByLabel('Link B');
|
||||
$this->assertNotEmpty($link1);
|
||||
$this->assertEquals('Link B', $link1['label']);
|
||||
$this->assertNotEmpty($link1['opposite_id']);
|
||||
|
||||
$link2 = $l->getByLabel('Link C');
|
||||
$this->assertNotEmpty($link2);
|
||||
$this->assertEquals('Link C', $link2['label']);
|
||||
$this->assertNotEmpty($link2['opposite_id']);
|
||||
|
||||
$this->assertNotEquals($link1['opposite_id'], $link2['opposite_id']);
|
||||
}
|
||||
|
||||
public function testGetOppositeLinkId()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$this->assertNotFalse($l->create('Link A'));
|
||||
$this->assertNotFalse($l->create('Link B', 'Link C'));
|
||||
|
||||
$this->assertEquals(1, $l->getOppositeLinkId(1));
|
||||
$this->assertEquals(3, $l->getOppositeLinkId(2));
|
||||
$this->assertEquals(2, $l->getOppositeLinkId(3));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$this->assertTrue($l->update(array('id' => 2, 'label' => 'test', 'opposite_id' => 0)));
|
||||
|
||||
$link = $l->getById(2);
|
||||
$this->assertNotEmpty($link);
|
||||
$this->assertEquals('test', $link['label']);
|
||||
$this->assertEquals(0, $link['opposite_id']);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$link = $l->getById(3);
|
||||
$this->assertNotEmpty($link);
|
||||
$this->assertEquals('is blocked by', $link['label']);
|
||||
$this->assertEquals(2, $link['opposite_id']);
|
||||
|
||||
$this->assertTrue($l->remove(2));
|
||||
|
||||
$link = $l->getById(2);
|
||||
$this->assertEmpty($link);
|
||||
|
||||
$link = $l->getById(3);
|
||||
$this->assertNotEmpty($link);
|
||||
$this->assertEquals('is blocked by', $link['label']);
|
||||
$this->assertEquals(0, $link['opposite_id']);
|
||||
}
|
||||
|
||||
public function testGetMergedList()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
$links = $l->getMergedList();
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(11, $links);
|
||||
$this->assertEquals('blocks', $links[1]['label']);
|
||||
$this->assertEquals('is blocked by', $links[1]['opposite_label']);
|
||||
}
|
||||
|
||||
public function testGetList()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
$links = $l->getList();
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(12, $links);
|
||||
$this->assertEquals('', $links[0]);
|
||||
$this->assertEquals('relates to', $links[1]);
|
||||
|
||||
$links = $l->getList(1);
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(11, $links);
|
||||
$this->assertEquals('', $links[0]);
|
||||
$this->assertArrayNotHasKey(1, $links);
|
||||
$this->assertEquals('blocks', $links[2]);
|
||||
|
||||
$links = $l->getList(1, false);
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(10, $links);
|
||||
$this->assertArrayNotHasKey(0, $links);
|
||||
$this->assertArrayNotHasKey(1, $links);
|
||||
$this->assertEquals('blocks', $links[2]);
|
||||
|
||||
$links = $l->getList(0, false);
|
||||
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(11, $links);
|
||||
$this->assertArrayNotHasKey(0, $links);
|
||||
$this->assertEquals('relates to', $links[1]);
|
||||
}
|
||||
|
||||
public function testValidateCreation()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'a'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'relates to'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => ''));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
|
||||
public function testValidateModification()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => 0));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => '1'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => 'relates to', 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => '', 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('label' => '', 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('label' => 'test'));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
}
|
||||
336
tests/units/Model/NotificationTest.php
Normal file
336
tests/units/Model/NotificationTest.php
Normal file
@@ -0,0 +1,336 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\TaskFinder;
|
||||
use Model\TaskCreation;
|
||||
use Model\Subtask;
|
||||
use Model\Comment;
|
||||
use Model\User;
|
||||
use Model\File;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
use Model\Notification;
|
||||
use Subscriber\NotificationSubscriber;
|
||||
|
||||
class NotificationTest extends Base
|
||||
{
|
||||
public function testFilterNone()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_NONE)));
|
||||
$this->assertTrue($n->filterNone($u->getById(2), array()));
|
||||
|
||||
$this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH)));
|
||||
$this->assertFalse($n->filterNone($u->getById(3), array()));
|
||||
}
|
||||
|
||||
public function testFilterCreator()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_CREATOR)));
|
||||
$this->assertTrue($n->filterCreator($u->getById(2), array('task' => array('creator_id' => 2))));
|
||||
|
||||
$this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_CREATOR)));
|
||||
$this->assertFalse($n->filterCreator($u->getById(3), array('task' => array('creator_id' => 1))));
|
||||
|
||||
$this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => Notification::FILTER_NONE)));
|
||||
$this->assertFalse($n->filterCreator($u->getById(4), array('task' => array('creator_id' => 2))));
|
||||
}
|
||||
|
||||
public function testFilterAssignee()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_ASSIGNEE)));
|
||||
$this->assertTrue($n->filterAssignee($u->getById(2), array('task' => array('owner_id' => 2))));
|
||||
|
||||
$this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_ASSIGNEE)));
|
||||
$this->assertFalse($n->filterAssignee($u->getById(3), array('task' => array('owner_id' => 1))));
|
||||
|
||||
$this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => Notification::FILTER_NONE)));
|
||||
$this->assertFalse($n->filterAssignee($u->getById(4), array('task' => array('owner_id' => 2))));
|
||||
}
|
||||
|
||||
public function testFilterBoth()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_BOTH)));
|
||||
$this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 2, 'creator_id' => 1))));
|
||||
$this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 0, 'creator_id' => 2))));
|
||||
|
||||
$this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH)));
|
||||
$this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 1, 'creator_id' => 1))));
|
||||
$this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 2, 'creator_id' => 1))));
|
||||
|
||||
$this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => Notification::FILTER_NONE)));
|
||||
$this->assertFalse($n->filterBoth($u->getById(4), array('task' => array('owner_id' => 2, 'creator_id' => 1))));
|
||||
}
|
||||
|
||||
public function testFilterProject()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
||||
|
||||
// No project selected
|
||||
$this->assertTrue($n->filterProject($u->getById(1), array()));
|
||||
|
||||
// User that select only some projects
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_NONE)));
|
||||
$n->saveSettings(2, array('notifications_enabled' => 1, 'projects' => array(2 => true)));
|
||||
|
||||
$this->assertFalse($n->filterProject($u->getById(2), array('task' => array('project_id' => 1))));
|
||||
$this->assertTrue($n->filterProject($u->getById(2), array('task' => array('project_id' => 2))));
|
||||
}
|
||||
|
||||
public function testFilterUserWithNoFilter()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_NONE)));
|
||||
|
||||
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1))));
|
||||
}
|
||||
|
||||
public function testFilterUserWithAssigneeFilter()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_ASSIGNEE)));
|
||||
|
||||
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 2))));
|
||||
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 1))));
|
||||
}
|
||||
|
||||
public function testFilterUserWithCreatorFilter()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_CREATOR)));
|
||||
|
||||
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2))));
|
||||
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 1))));
|
||||
}
|
||||
|
||||
public function testFilterUserWithBothFilter()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH)));
|
||||
|
||||
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3))));
|
||||
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2))));
|
||||
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 4, 'owner_id' => 1))));
|
||||
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 5, 'owner_id' => 0))));
|
||||
}
|
||||
|
||||
public function testFilterUserWithBothFilterAndProjectSelected()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH)));
|
||||
|
||||
$n->saveSettings(2, array('notifications_enabled' => 1, 'projects' => array(2 => true)));
|
||||
|
||||
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3))));
|
||||
$this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2))));
|
||||
|
||||
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 2, 'owner_id' => 3))));
|
||||
$this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 0, 'owner_id' => 2))));
|
||||
}
|
||||
|
||||
public function testGetProjectMembersWithNotifications()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$p = new Project($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
|
||||
// Email + Notifications enabled
|
||||
$this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
|
||||
|
||||
// No email + Notifications enabled
|
||||
$this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
|
||||
|
||||
// Email + Notifications enabled
|
||||
$this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
|
||||
|
||||
// No email + notifications disabled
|
||||
$this->assertNotFalse($u->create(array('username' => 'user4')));
|
||||
|
||||
// Nobody is member of any projects
|
||||
$this->assertEmpty($pp->getMembers(1));
|
||||
$this->assertEmpty($n->getUsersWithNotificationEnabled(1));
|
||||
|
||||
// We allow all users to be member of our projects
|
||||
$this->assertTrue($pp->addMember(1, 1));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
$this->assertTrue($pp->addMember(1, 3));
|
||||
$this->assertTrue($pp->addMember(1, 4));
|
||||
|
||||
$this->assertNotEmpty($pp->getMembers(1));
|
||||
$users = $n->getUsersWithNotificationEnabled(1);
|
||||
|
||||
$this->assertNotEmpty($users);
|
||||
$this->assertEquals(2, count($users));
|
||||
$this->assertEquals('user1@here', $users[0]['email']);
|
||||
$this->assertEquals('user3@here', $users[1]['email']);
|
||||
}
|
||||
|
||||
public function testGetUsersWithNotificationsWhenEverybodyAllowed()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$p = new Project($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1)));
|
||||
$this->assertTrue($pp->isEverybodyAllowed(1));
|
||||
|
||||
// Email + Notifications enabled
|
||||
$this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
|
||||
|
||||
// No email + Notifications enabled
|
||||
$this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
|
||||
|
||||
// Email + Notifications enabled
|
||||
$this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
|
||||
|
||||
// No email + notifications disabled
|
||||
$this->assertNotFalse($u->create(array('username' => 'user4')));
|
||||
|
||||
$users = $n->getUsersWithNotificationEnabled(1);
|
||||
|
||||
$this->assertNotEmpty($users);
|
||||
$this->assertEquals(2, count($users));
|
||||
$this->assertEquals('user1@here', $users[0]['email']);
|
||||
$this->assertEquals('user3@here', $users[1]['email']);
|
||||
}
|
||||
|
||||
public function testGetMailContent()
|
||||
{
|
||||
$n = new Notification($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$c = new Comment($this->container);
|
||||
$f = new File($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
|
||||
$this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
|
||||
$this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
|
||||
|
||||
$task = $tf->getDetails(1);
|
||||
$subtask = $s->getById(1, true);
|
||||
$comment = $c->getById(1);
|
||||
$file = $c->getById(1);
|
||||
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertNotEmpty($comment);
|
||||
$this->assertNotEmpty($file);
|
||||
|
||||
foreach (Subscriber\NotificationSubscriber::getSubscribedEvents() as $event => $values) {
|
||||
$this->assertNotEmpty($n->getMailContent($event, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array())));
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetEmailSubject()
|
||||
{
|
||||
$n = new Notification($this->container);
|
||||
|
||||
$this->assertEquals(
|
||||
'[test][Task opened] blah (#2)',
|
||||
$n->getMailSubject('task.open', array('task' => array('id' => 2, 'title' => 'blah', 'project_name' => 'test')))
|
||||
);
|
||||
}
|
||||
|
||||
public function testSendNotificationsToCreator()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$p = new Project($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
$this->container['emailClient']->expects($this->once())
|
||||
->method('send')
|
||||
->with(
|
||||
$this->equalTo('user1@here'),
|
||||
$this->equalTo('user1'),
|
||||
$this->equalTo('[test][Task opened] blah (#2)'),
|
||||
$this->stringContains('blah')
|
||||
);
|
||||
|
||||
$n->sendNotifications('task.open', array('task' => array(
|
||||
'id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 0, 'creator_id' => 2
|
||||
)));
|
||||
}
|
||||
|
||||
public function testSendNotificationsToAnotherAssignee()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$p = new Project($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
$this->container['emailClient']->expects($this->never())->method('send');
|
||||
|
||||
$n->sendNotifications('task.open', array('task' => array(
|
||||
'id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 1, 'creator_id' => 1
|
||||
)));
|
||||
}
|
||||
|
||||
public function testSendNotificationsToNotMember()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$p = new Project($this->container);
|
||||
$n = new Notification($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
|
||||
|
||||
$this->container['emailClient']->expects($this->never())->method('send');
|
||||
|
||||
$n->sendNotifications('task.open', array('task' => array(
|
||||
'id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 0, 'creator_id' => 2
|
||||
)));
|
||||
}
|
||||
}
|
||||
114
tests/units/Model/ProjectActivityTest.php
Normal file
114
tests/units/Model/ProjectActivityTest.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskFinder;
|
||||
use Model\TaskCreation;
|
||||
use Model\ProjectActivity;
|
||||
use Model\Project;
|
||||
|
||||
class ProjectActivityTest extends Base
|
||||
{
|
||||
public function testDecode()
|
||||
{
|
||||
$e = new ProjectActivity($this->container);
|
||||
$input = array('test');
|
||||
$serialized = serialize($input);
|
||||
$json = json_encode($input);
|
||||
|
||||
$this->assertEquals($input, $e->decode($serialized));
|
||||
$this->assertEquals($input, $e->decode($json));
|
||||
}
|
||||
|
||||
public function testCreation()
|
||||
{
|
||||
$e = new ProjectActivity($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1)));
|
||||
|
||||
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
|
||||
$this->assertTrue($e->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $tf->getById(2))));
|
||||
$this->assertFalse($e->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $tf->getbyId(1))));
|
||||
|
||||
$events = $e->getProject(1);
|
||||
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertTrue(is_array($events));
|
||||
$this->assertEquals(2, count($events));
|
||||
$this->assertEquals(time(), $events[0]['date_creation'], '', 1);
|
||||
$this->assertEquals(Task::EVENT_UPDATE, $events[0]['event_name']);
|
||||
$this->assertEquals(Task::EVENT_CLOSE, $events[1]['event_name']);
|
||||
}
|
||||
|
||||
public function testFetchAllContent()
|
||||
{
|
||||
$e = new ProjectActivity($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
|
||||
|
||||
$nb_events = 80;
|
||||
|
||||
for ($i = 0; $i < $nb_events; $i++) {
|
||||
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_UPDATE, array('task' => $tf->getbyId(1))));
|
||||
}
|
||||
|
||||
$events = $e->getProject(1);
|
||||
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertTrue(is_array($events));
|
||||
$this->assertEquals(50, count($events));
|
||||
$this->assertEquals('admin', $events[0]['author']);
|
||||
$this->assertNotEmpty($events[0]['event_title']);
|
||||
$this->assertNotEmpty($events[0]['event_content']);
|
||||
}
|
||||
|
||||
public function testCleanup()
|
||||
{
|
||||
$e = new ProjectActivity($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
|
||||
|
||||
$max = 15;
|
||||
$nb_events = 100;
|
||||
|
||||
for ($i = 0; $i < $nb_events; $i++) {
|
||||
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
|
||||
}
|
||||
|
||||
$this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count());
|
||||
$e->cleanup($max);
|
||||
|
||||
$events = $e->getProject(1);
|
||||
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertTrue(is_array($events));
|
||||
$this->assertEquals($max, count($events));
|
||||
$this->assertEquals(100, $events[0]['id']);
|
||||
$this->assertEquals(99, $events[1]['id']);
|
||||
$this->assertEquals(86, $events[14]['id']);
|
||||
|
||||
// Cleanup during task creation
|
||||
|
||||
$nb_events = ProjectActivity::MAX_EVENTS + 10;
|
||||
|
||||
for ($i = 0; $i < $nb_events; $i++) {
|
||||
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
|
||||
}
|
||||
|
||||
$this->assertEquals(ProjectActivity::MAX_EVENTS, $this->container['db']->table('project_activities')->count());
|
||||
}
|
||||
}
|
||||
90
tests/units/Model/ProjectDailyColumnStatsTest.php
Normal file
90
tests/units/Model/ProjectDailyColumnStatsTest.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Project;
|
||||
use Model\ProjectDailyColumnStats;
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskStatus;
|
||||
|
||||
class ProjectDailyColumnStatsTest extends Base
|
||||
{
|
||||
public function testUpdateTotals()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pds = new ProjectDailyColumnStats($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$ts = new TaskStatus($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(0, $pds->countDays(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d')));
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 1)));
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4)));
|
||||
}
|
||||
|
||||
$pds->updateTotals(1, date('Y-m-d', strtotime('-2days')));
|
||||
|
||||
for ($i = 0; $i < 15; $i++) {
|
||||
$this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3)));
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 25; $i++) {
|
||||
$this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2)));
|
||||
}
|
||||
|
||||
$pds->updateTotals(1, date('Y-m-d', strtotime('-1 day')));
|
||||
|
||||
$this->assertNotFalse($ts->close(1));
|
||||
$this->assertNotFalse($ts->close(2));
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3)));
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2)));
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4)));
|
||||
}
|
||||
|
||||
$pds->updateTotals(1, date('Y-m-d'));
|
||||
|
||||
$this->assertEquals(3, $pds->countDays(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d')));
|
||||
$metrics = $pds->getAggregatedMetrics(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d'));
|
||||
|
||||
$this->assertNotEmpty($metrics);
|
||||
$this->assertEquals(4, count($metrics));
|
||||
$this->assertEquals(5, count($metrics[0]));
|
||||
$this->assertEquals('Date', $metrics[0][0]);
|
||||
$this->assertEquals('Backlog', $metrics[0][1]);
|
||||
$this->assertEquals('Ready', $metrics[0][2]);
|
||||
$this->assertEquals('Work in progress', $metrics[0][3]);
|
||||
$this->assertEquals('Done', $metrics[0][4]);
|
||||
|
||||
$this->assertEquals(date('Y-m-d', strtotime('-2days')), $metrics[1][0]);
|
||||
$this->assertEquals(10, $metrics[1][1]);
|
||||
$this->assertEquals(0, $metrics[1][2]);
|
||||
$this->assertEquals(0, $metrics[1][3]);
|
||||
$this->assertEquals(5, $metrics[1][4]);
|
||||
|
||||
$this->assertEquals(date('Y-m-d', strtotime('-1day')), $metrics[2][0]);
|
||||
$this->assertEquals(10, $metrics[2][1]);
|
||||
$this->assertEquals(25, $metrics[2][2]);
|
||||
$this->assertEquals(15, $metrics[2][3]);
|
||||
$this->assertEquals(5, $metrics[2][4]);
|
||||
|
||||
$this->assertEquals(date('Y-m-d'), $metrics[3][0]);
|
||||
$this->assertEquals(10, $metrics[3][1]);
|
||||
$this->assertEquals(30, $metrics[3][2]);
|
||||
$this->assertEquals(18, $metrics[3][3]);
|
||||
$this->assertEquals(9, $metrics[3][4]);
|
||||
}
|
||||
}
|
||||
359
tests/units/Model/ProjectDuplicationTest.php
Normal file
359
tests/units/Model/ProjectDuplicationTest.php
Normal file
@@ -0,0 +1,359 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Action;
|
||||
use Model\Project;
|
||||
use Model\Category;
|
||||
use Model\ProjectPermission;
|
||||
use Model\ProjectDuplication;
|
||||
use Model\User;
|
||||
use Model\Swimlane;
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
|
||||
class ProjectDuplicationTest extends Base
|
||||
{
|
||||
public function testProjectName()
|
||||
{
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
|
||||
$this->assertEquals('test (Clone)', $pd->getClonedProjectName('test'));
|
||||
|
||||
$this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 50))));
|
||||
$this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 50)));
|
||||
|
||||
$this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 60))));
|
||||
$this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 60)));
|
||||
}
|
||||
|
||||
public function testCopyProjectWithLongName()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => str_repeat('a', 50))));
|
||||
$this->assertEquals(2, $pd->duplicate(1));
|
||||
|
||||
$project = $p->getById(2);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals(str_repeat('a', 42).' (Clone)', $project['name']);
|
||||
}
|
||||
|
||||
public function testClonePublicProject()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Public')));
|
||||
$this->assertEquals(2, $pd->duplicate(1));
|
||||
|
||||
$project = $p->getById(2);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('Public (Clone)', $project['name']);
|
||||
$this->assertEquals(0, $project['is_private']);
|
||||
$this->assertEquals(0, $project['is_public']);
|
||||
$this->assertEmpty($project['token']);
|
||||
}
|
||||
|
||||
public function testClonePrivateProject()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true));
|
||||
$this->assertEquals(2, $pd->duplicate(1));
|
||||
|
||||
$project = $p->getById(2);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('Private (Clone)', $project['name']);
|
||||
$this->assertEquals(1, $project['is_private']);
|
||||
$this->assertEquals(0, $project['is_public']);
|
||||
$this->assertEmpty($project['token']);
|
||||
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$this->assertEquals(array(1 => 'admin'), $pp->getMembers(1));
|
||||
$this->assertEquals(array(1 => 'admin'), $pp->getMembers(2));
|
||||
}
|
||||
|
||||
public function testCloneProjectWithCategories()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
|
||||
$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(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(2, $pd->duplicate(1));
|
||||
|
||||
$project = $p->getById(2);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('P1 (Clone)', $project['name']);
|
||||
|
||||
$categories = $c->getAll(2);
|
||||
$this->assertNotempty($categories);
|
||||
$this->assertEquals(3, count($categories));
|
||||
|
||||
$this->assertEquals(4, $categories[0]['id']);
|
||||
$this->assertEquals('C1', $categories[0]['name']);
|
||||
|
||||
$this->assertEquals(5, $categories[1]['id']);
|
||||
$this->assertEquals('C2', $categories[1]['name']);
|
||||
|
||||
$this->assertEquals(6, $categories[2]['id']);
|
||||
$this->assertEquals('C3', $categories[2]['name']);
|
||||
}
|
||||
|
||||
public function testCloneProjectWithUsers()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$u = new User($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest1', 'password' => 'unittest')));
|
||||
$this->assertEquals(3, $u->create(array('username' => 'unittest2', 'password' => 'unittest')));
|
||||
$this->assertEquals(4, $u->create(array('username' => 'unittest3', 'password' => 'unittest')));
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
$this->assertTrue($pp->addMember(1, 4));
|
||||
$this->assertTrue($pp->addManager(1, 3));
|
||||
$this->assertTrue($pp->isMember(1, 2));
|
||||
$this->assertTrue($pp->isMember(1, 3));
|
||||
$this->assertTrue($pp->isMember(1, 4));
|
||||
$this->assertFalse($pp->isManager(1, 2));
|
||||
$this->assertTrue($pp->isManager(1, 3));
|
||||
$this->assertFalse($pp->isManager(1, 4));
|
||||
|
||||
$this->assertEquals(2, $pd->duplicate(1));
|
||||
|
||||
$project = $p->getById(2);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('P1 (Clone)', $project['name']);
|
||||
|
||||
$this->assertEquals(3, count($pp->getMembers(2)));
|
||||
$this->assertTrue($pp->isMember(2, 2));
|
||||
$this->assertTrue($pp->isMember(2, 3));
|
||||
$this->assertTrue($pp->isMember(2, 4));
|
||||
$this->assertFalse($pp->isManager(2, 2));
|
||||
$this->assertTrue($pp->isManager(2, 3));
|
||||
$this->assertFalse($pp->isManager(2, 4));
|
||||
}
|
||||
|
||||
public function testCloneProjectWithActionTaskAssignCurrentUser()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$a = new Action($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
|
||||
$this->assertEquals(1, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_MOVE_COLUMN,
|
||||
'action_name' => 'TaskAssignCurrentUser',
|
||||
'params' => array('column_id' => 2),
|
||||
)));
|
||||
|
||||
$this->assertEquals(2, $pd->duplicate(1));
|
||||
|
||||
$actions = $a->getAllByProject(2);
|
||||
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']);
|
||||
$this->assertNotEmpty($actions[0]['params']);
|
||||
$this->assertEquals(6, $actions[0]['params'][0]['value']);
|
||||
}
|
||||
|
||||
public function testCloneProjectWithActionTaskAssignColorCategory()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$a = new Action($this->container);
|
||||
$c = new Category($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
|
||||
$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(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(1, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE_UPDATE,
|
||||
'action_name' => 'TaskAssignColorCategory',
|
||||
'params' => array('color_id' => 'blue', 'category_id' => 2),
|
||||
)));
|
||||
|
||||
$this->assertEquals(2, $pd->duplicate(1));
|
||||
|
||||
$actions = $a->getAllByProject(2);
|
||||
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
|
||||
$this->assertNotEmpty($actions[0]['params']);
|
||||
$this->assertEquals('blue', $actions[0]['params'][0]['value']);
|
||||
$this->assertEquals(5, $actions[0]['params'][1]['value']);
|
||||
}
|
||||
|
||||
public function testCloneProjectWithSwimlanesAndTasks()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
|
||||
// create initial swimlanes
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
|
||||
$this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3')));
|
||||
|
||||
$default_swimlane1 = $s->getDefault(1);
|
||||
$default_swimlane1['default_swimlane'] = 'New Default';
|
||||
|
||||
$this->assertTrue($s->updateDefault($default_swimlane1));
|
||||
|
||||
//create initial tasks
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
|
||||
|
||||
$this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane', 'task')));
|
||||
$project = $p->getByName('P1 (Clone)');
|
||||
$this->assertNotFalse($project);
|
||||
$project_id = $project['id'];
|
||||
|
||||
// Check if Swimlanes have been duplicated
|
||||
$swimlanes = $s->getAll($project_id);
|
||||
|
||||
$this->assertCount(3, $swimlanes);
|
||||
$this->assertEquals(4, $swimlanes[0]['id']);
|
||||
$this->assertEquals('S1', $swimlanes[0]['name']);
|
||||
$this->assertEquals(5, $swimlanes[1]['id']);
|
||||
$this->assertEquals('S2', $swimlanes[1]['name']);
|
||||
$this->assertEquals(6, $swimlanes[2]['id']);
|
||||
$this->assertEquals('S3', $swimlanes[2]['name']);
|
||||
$new_default = $s->getDefault($project_id);
|
||||
$this->assertEquals('New Default', $new_default['default_swimlane']);
|
||||
|
||||
// Check if Tasks have been duplicated
|
||||
|
||||
$tasks = $tf->getAll($project_id);
|
||||
|
||||
$this->assertCount(3, $tasks);
|
||||
// $this->assertEquals(4, $tasks[0]['id']);
|
||||
$this->assertEquals('T1', $tasks[0]['title']);
|
||||
// $this->assertEquals(5, $tasks[1]['id']);
|
||||
$this->assertEquals('T2', $tasks[1]['title']);
|
||||
// $this->assertEquals(6, $tasks[2]['id']);
|
||||
$this->assertEquals('T3', $tasks[2]['title']);
|
||||
|
||||
$p->remove($project_id);
|
||||
|
||||
$this->assertFalse($p->exists($project_id));
|
||||
$this->assertCount(0, $s->getAll($project_id));
|
||||
$this->assertCount(0, $tf->getAll($project_id));
|
||||
}
|
||||
|
||||
public function testCloneProjectWithSwimlanes()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
|
||||
// create initial swimlanes
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
|
||||
$this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3')));
|
||||
|
||||
$default_swimlane1 = $s->getDefault(1);
|
||||
$default_swimlane1['default_swimlane'] = 'New Default';
|
||||
|
||||
$this->assertTrue($s->updateDefault($default_swimlane1));
|
||||
|
||||
//create initial tasks
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
|
||||
|
||||
$this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane')));
|
||||
$project = $p->getByName('P1 (Clone)');
|
||||
$this->assertNotFalse($project);
|
||||
$project_id = $project['id'];
|
||||
|
||||
$swimlanes = $s->getAll($project_id);
|
||||
|
||||
$this->assertCount(3, $swimlanes);
|
||||
$this->assertEquals(4, $swimlanes[0]['id']);
|
||||
$this->assertEquals('S1', $swimlanes[0]['name']);
|
||||
$this->assertEquals(5, $swimlanes[1]['id']);
|
||||
$this->assertEquals('S2', $swimlanes[1]['name']);
|
||||
$this->assertEquals(6, $swimlanes[2]['id']);
|
||||
$this->assertEquals('S3', $swimlanes[2]['name']);
|
||||
$new_default = $s->getDefault($project_id);
|
||||
$this->assertEquals('New Default', $new_default['default_swimlane']);
|
||||
|
||||
// Check if Tasks have NOT been duplicated
|
||||
$this->assertCount(0, $tf->getAll($project_id));
|
||||
}
|
||||
|
||||
public function testCloneProjectWithTasks()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pd = new ProjectDuplication($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
|
||||
// create initial swimlanes
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
|
||||
$this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3')));
|
||||
|
||||
$default_swimlane1 = $s->getDefault(1);
|
||||
$default_swimlane1['default_swimlane'] = 'New Default';
|
||||
|
||||
$this->assertTrue($s->updateDefault($default_swimlane1));
|
||||
|
||||
//create initial tasks
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
|
||||
|
||||
$this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'task')));
|
||||
$project = $p->getByName('P1 (Clone)');
|
||||
$this->assertNotFalse($project);
|
||||
$project_id = $project['id'];
|
||||
|
||||
// Check if Swimlanes have NOT been duplicated
|
||||
$this->assertCount(0, $s->getAll($project_id));
|
||||
|
||||
// Check if Tasks have been duplicated
|
||||
$tasks = $tf->getAll($project_id);
|
||||
|
||||
$this->assertCount(3, $tasks);
|
||||
//$this->assertEquals(4, $tasks[0]['id']);
|
||||
$this->assertEquals('T1', $tasks[0]['title']);
|
||||
//$this->assertEquals(5, $tasks[1]['id']);
|
||||
$this->assertEquals('T2', $tasks[1]['title']);
|
||||
//$this->assertEquals(6, $tasks[2]['id']);
|
||||
$this->assertEquals('T3', $tasks[2]['title']);
|
||||
}
|
||||
}
|
||||
287
tests/units/Model/ProjectPermissionTest.php
Normal file
287
tests/units/Model/ProjectPermissionTest.php
Normal file
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
use Model\User;
|
||||
|
||||
class ProjectPermissionTest extends Base
|
||||
{
|
||||
public function testAllowEverybody()
|
||||
{
|
||||
$user = new User($this->container);
|
||||
$this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
|
||||
$this->assertNotFalse($user->create(array('username' => 'unittest#2', 'password' => 'unittest')));
|
||||
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertFalse($pp->isEverybodyAllowed(1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertFalse($pp->isUserAllowed(1, 2));
|
||||
$this->assertFalse($pp->isUserAllowed(1, 3));
|
||||
$this->assertEquals(array(), $pp->getMembers(1));
|
||||
$this->assertEquals(array('Unassigned'), $pp->getMemberList(1));
|
||||
|
||||
$this->assertEmpty($pp->getMemberProjects(1));
|
||||
$this->assertEmpty($pp->getMemberProjects(2));
|
||||
$this->assertEmpty($pp->getMemberProjects(3));
|
||||
|
||||
$this->assertEmpty($pp->getMemberProjectIds(1));
|
||||
$this->assertEmpty($pp->getMemberProjectIds(2));
|
||||
$this->assertEmpty($pp->getMemberProjectIds(3));
|
||||
|
||||
$this->assertEmpty($pp->getActiveMemberProjectIds(1));
|
||||
$this->assertEmpty($pp->getActiveMemberProjectIds(2));
|
||||
$this->assertEmpty($pp->getActiveMemberProjectIds(3));
|
||||
|
||||
$this->assertEmpty($pp->getActiveMemberProjects(1));
|
||||
$this->assertEmpty($pp->getActiveMemberProjects(2));
|
||||
$this->assertEmpty($pp->getActiveMemberProjects(3));
|
||||
|
||||
$this->assertTrue($p->update(array('id' => 1, 'is_everybody_allowed' => 1)));
|
||||
$this->assertTrue($pp->isEverybodyAllowed(1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 2));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 3));
|
||||
$this->assertEquals(array('1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getMembers(1));
|
||||
$this->assertEquals(array('Unassigned', '1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getMemberList(1));
|
||||
|
||||
$this->assertNotEmpty($pp->getMemberProjects(1));
|
||||
$this->assertNotEmpty($pp->getMemberProjects(2));
|
||||
$this->assertNotEmpty($pp->getMemberProjects(3));
|
||||
|
||||
$this->assertNotEmpty($pp->getMemberProjectIds(1));
|
||||
$this->assertNotEmpty($pp->getMemberProjectIds(2));
|
||||
$this->assertNotEmpty($pp->getMemberProjectIds(3));
|
||||
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjectIds(1));
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjectIds(2));
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjectIds(3));
|
||||
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjects(1));
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjects(2));
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjects(3));
|
||||
|
||||
$this->assertTrue($p->disable(1));
|
||||
|
||||
$this->assertEmpty($pp->getActiveMemberProjectIds(1));
|
||||
$this->assertEmpty($pp->getActiveMemberProjectIds(2));
|
||||
$this->assertEmpty($pp->getActiveMemberProjectIds(3));
|
||||
|
||||
$this->assertEmpty($pp->getActiveMemberProjects(1));
|
||||
$this->assertEmpty($pp->getActiveMemberProjects(2));
|
||||
$this->assertEmpty($pp->getActiveMemberProjects(3));
|
||||
}
|
||||
|
||||
public function testDisallowEverybody()
|
||||
{
|
||||
// We create a regular user
|
||||
$user = new User($this->container);
|
||||
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
|
||||
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
|
||||
$this->assertEmpty($pp->getMembers(1)); // Nobody is specified for the given project
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1)); // Admin should be allowed
|
||||
$this->assertFalse($pp->isUserAllowed(1, 2)); // Regular user should be denied
|
||||
}
|
||||
|
||||
public function testAllowUser()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$user = new User($this->container);
|
||||
|
||||
$this->assertNotFalse($user->create(array('username' => 'unittest', 'password' => 'unittest')));
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
|
||||
$this->assertEmpty($pp->getMemberProjects(1));
|
||||
$this->assertEmpty($pp->getMemberProjects(2));
|
||||
|
||||
$this->assertEmpty($pp->getMemberProjectIds(1));
|
||||
$this->assertEmpty($pp->getMemberProjectIds(2));
|
||||
|
||||
$this->assertEmpty($pp->getActiveMemberProjectIds(1));
|
||||
$this->assertEmpty($pp->getActiveMemberProjectIds(2));
|
||||
|
||||
$this->assertEmpty($pp->getActiveMemberProjects(1));
|
||||
$this->assertEmpty($pp->getActiveMemberProjects(2));
|
||||
|
||||
// We allow the admin user
|
||||
$this->assertTrue($pp->addMember(1, 1));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
// Non-existant project
|
||||
$this->assertFalse($pp->addMember(50, 1));
|
||||
|
||||
// Non-existant user
|
||||
$this->assertFalse($pp->addMember(1, 50));
|
||||
|
||||
// Both users should be allowed
|
||||
$this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 2));
|
||||
|
||||
$this->assertNotEmpty($pp->getMemberProjects(1));
|
||||
$this->assertNotEmpty($pp->getMemberProjects(2));
|
||||
|
||||
$this->assertNotEmpty($pp->getMemberProjectIds(1));
|
||||
$this->assertNotEmpty($pp->getMemberProjectIds(2));
|
||||
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjectIds(1));
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjectIds(2));
|
||||
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjects(1));
|
||||
$this->assertNotEmpty($pp->getActiveMemberProjects(2));
|
||||
}
|
||||
|
||||
public function testRevokeUser()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$user = new User($this->container);
|
||||
|
||||
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
|
||||
// We revoke our admin user (not existing row)
|
||||
$this->assertFalse($pp->revokeMember(1, 1));
|
||||
|
||||
// We should have nobody in the users list
|
||||
$this->assertEmpty($pp->getMembers(1));
|
||||
|
||||
// Only admin is allowed
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertFalse($pp->isUserAllowed(1, 2));
|
||||
|
||||
// We allow only the regular user
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
// All users should be allowed (admin and regular)
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 2));
|
||||
|
||||
// However, we should have only our regular user in the list
|
||||
$this->assertEquals(array('2' => 'unittest'), $pp->getMembers(1));
|
||||
|
||||
// We allow our admin, we should have both in the list
|
||||
$this->assertTrue($pp->addMember(1, 1));
|
||||
$this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 2));
|
||||
|
||||
// We revoke the regular user
|
||||
$this->assertTrue($pp->revokeMember(1, 2));
|
||||
|
||||
// Only admin should be allowed
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertFalse($pp->isUserAllowed(1, 2));
|
||||
|
||||
// We should have only admin in the list
|
||||
$this->assertEquals(array('1' => 'admin'), $pp->getMembers(1));
|
||||
|
||||
// We revoke the admin user
|
||||
$this->assertTrue($pp->revokeMember(1, 1));
|
||||
$this->assertEmpty($pp->getMembers(1));
|
||||
|
||||
// Only admin should be allowed again
|
||||
$this->assertTrue($pp->isUserAllowed(1, 1));
|
||||
$this->assertFalse($pp->isUserAllowed(1, 2));
|
||||
}
|
||||
|
||||
public function testManager()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertFalse($pp->isMember(1, 2));
|
||||
$this->assertFalse($pp->isManager(1, 2));
|
||||
|
||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2'), 1, true));
|
||||
$this->assertFalse($pp->isMember(2, 2));
|
||||
$this->assertFalse($pp->isManager(2, 2));
|
||||
|
||||
$this->assertEquals(3, $p->create(array('name' => 'UnitTest3'), 2, true));
|
||||
$this->assertTrue($pp->isMember(3, 2));
|
||||
$this->assertTrue($pp->isManager(3, 2));
|
||||
|
||||
$this->assertEquals(4, $p->create(array('name' => 'UnitTest4')));
|
||||
|
||||
$this->assertTrue($pp->addManager(4, 2));
|
||||
$this->assertTrue($pp->isMember(4, 2));
|
||||
$this->assertTrue($pp->isManager(4, 2));
|
||||
|
||||
$this->assertEquals(5, $p->create(array('name' => 'UnitTest5')));
|
||||
$this->assertTrue($pp->addMember(5, 2));
|
||||
$this->assertTrue($pp->changeRole(5, 2, 1));
|
||||
$this->assertTrue($pp->isMember(5, 2));
|
||||
$this->assertTrue($pp->isManager(5, 2));
|
||||
$this->assertTrue($pp->changeRole(5, 2, 0));
|
||||
$this->assertTrue($pp->isMember(5, 2));
|
||||
$this->assertFalse($pp->isManager(5, 2));
|
||||
}
|
||||
|
||||
public function testUsersList()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
$user = new User($this->container);
|
||||
$this->assertNotFalse($user->create(array('username' => 'unittest', 'password' => 'unittest')));
|
||||
|
||||
// We create project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
|
||||
// No restriction, we should have no body
|
||||
$this->assertEquals(
|
||||
array('Unassigned'),
|
||||
$pp->getMemberList(1)
|
||||
);
|
||||
|
||||
// We allow only the regular user
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
$this->assertEquals(
|
||||
array(0 => 'Unassigned', 2 => 'unittest'),
|
||||
$pp->getMemberList(1)
|
||||
);
|
||||
|
||||
// We allow the admin user
|
||||
$this->assertTrue($pp->addMember(1, 1));
|
||||
|
||||
$this->assertEquals(
|
||||
array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'),
|
||||
$pp->getMemberList(1)
|
||||
);
|
||||
|
||||
// We revoke only the regular user
|
||||
$this->assertTrue($pp->revokeMember(1, 2));
|
||||
|
||||
$this->assertEquals(
|
||||
array(0 => 'Unassigned', 1 => 'admin'),
|
||||
$pp->getMemberList(1)
|
||||
);
|
||||
|
||||
// We revoke only the admin user, we should have everybody
|
||||
$this->assertTrue($pp->revokeMember(1, 1));
|
||||
|
||||
$this->assertEquals(
|
||||
array(0 => 'Unassigned'),
|
||||
$pp->getMemberList(1)
|
||||
);
|
||||
}
|
||||
}
|
||||
288
tests/units/Model/ProjectTest.php
Normal file
288
tests/units/Model/ProjectTest.php
Normal file
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Core\Translator;
|
||||
use Subscriber\ProjectModificationDateSubscriber;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
use Model\User;
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\Acl;
|
||||
use Model\Board;
|
||||
use Model\Config;
|
||||
use Model\Category;
|
||||
|
||||
class ProjectTest extends Base
|
||||
{
|
||||
public function testCreationForAllLanguages()
|
||||
{
|
||||
$c = new Config($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
foreach ($c->getLanguages() as $locale => $language) {
|
||||
Translator::load($locale);
|
||||
$this->assertNotFalse($p->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language);
|
||||
}
|
||||
|
||||
Translator::load('en_US');
|
||||
}
|
||||
|
||||
public function testCreation()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals(1, $project['is_active']);
|
||||
$this->assertEquals(0, $project['is_public']);
|
||||
$this->assertEquals(0, $project['is_private']);
|
||||
$this->assertEquals(time(), $project['last_modified'], '', 1);
|
||||
$this->assertEmpty($project['token']);
|
||||
}
|
||||
|
||||
public function testCreationWithStartAndDate()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31')));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('2015-01-01', $project['start_date']);
|
||||
$this->assertEquals('2015-12-31', $project['end_date']);
|
||||
}
|
||||
|
||||
public function testCreationWithDefaultCategories()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$c = new Config($this->container);
|
||||
$cat = new Category($this->container);
|
||||
|
||||
// Multiple categories correctly formatted
|
||||
|
||||
$this->assertTrue($c->save(array('project_categories' => 'Test1, Test2')));
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
|
||||
$categories = $cat->getAll(1);
|
||||
$this->assertNotEmpty($categories);
|
||||
$this->assertEquals(2, count($categories));
|
||||
$this->assertEquals('Test1', $categories[0]['name']);
|
||||
$this->assertEquals('Test2', $categories[1]['name']);
|
||||
|
||||
// Single category
|
||||
|
||||
$this->assertTrue($c->save(array('project_categories' => 'Test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
||||
|
||||
$project = $p->getById(2);
|
||||
$this->assertNotEmpty($project);
|
||||
|
||||
$categories = $cat->getAll(2);
|
||||
$this->assertNotEmpty($categories);
|
||||
$this->assertEquals(1, count($categories));
|
||||
$this->assertEquals('Test1', $categories[0]['name']);
|
||||
|
||||
// Multiple categories badly formatted
|
||||
|
||||
$this->assertTrue($c->save(array('project_categories' => 'ABC, , DEF 3, ')));
|
||||
$this->assertEquals(3, $p->create(array('name' => 'UnitTest3')));
|
||||
|
||||
$project = $p->getById(3);
|
||||
$this->assertNotEmpty($project);
|
||||
|
||||
$categories = $cat->getAll(3);
|
||||
$this->assertNotEmpty($categories);
|
||||
$this->assertEquals(2, count($categories));
|
||||
$this->assertEquals('ABC', $categories[0]['name']);
|
||||
$this->assertEquals('DEF 3', $categories[1]['name']);
|
||||
|
||||
// No default categories
|
||||
$this->assertTrue($c->save(array('project_categories' => ' ')));
|
||||
$this->assertEquals(4, $p->create(array('name' => 'UnitTest4')));
|
||||
|
||||
$project = $p->getById(4);
|
||||
$this->assertNotEmpty($project);
|
||||
|
||||
$categories = $cat->getAll(4);
|
||||
$this->assertEmpty($categories);
|
||||
}
|
||||
|
||||
public function testUpdateLastModifiedDate()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
|
||||
$now = time();
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1);
|
||||
|
||||
sleep(1);
|
||||
$this->assertTrue($p->updateModificationDate(1));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertGreaterThan($now, $project['last_modified']);
|
||||
}
|
||||
|
||||
public function testIsLastModified()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$now = time();
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals($now, $project['last_modified']);
|
||||
|
||||
sleep(1);
|
||||
|
||||
$listener = new ProjectModificationDateSubscriber($this->container);
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($listener, 'execute'));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.Subscriber\ProjectModificationDateSubscriber::execute', $called);
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertTrue($p->isModifiedSince(1, $now));
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertTrue($p->remove(1));
|
||||
$this->assertFalse($p->remove(1234));
|
||||
}
|
||||
|
||||
public function testEnable()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertTrue($p->disable(1));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals(0, $project['is_active']);
|
||||
|
||||
$this->assertFalse($p->disable(1111));
|
||||
}
|
||||
|
||||
public function testDisable()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertTrue($p->disable(1));
|
||||
$this->assertTrue($p->enable(1));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals(1, $project['is_active']);
|
||||
|
||||
$this->assertFalse($p->enable(1234567));
|
||||
}
|
||||
|
||||
public function testEnablePublicAccess()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertTrue($p->enablePublicAccess(1));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals(1, $project['is_public']);
|
||||
$this->assertNotEmpty($project['token']);
|
||||
|
||||
$this->assertFalse($p->enablePublicAccess(123));
|
||||
}
|
||||
|
||||
public function testDisablePublicAccess()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertTrue($p->enablePublicAccess(1));
|
||||
$this->assertTrue($p->disablePublicAccess(1));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals(0, $project['is_public']);
|
||||
$this->assertEmpty($project['token']);
|
||||
|
||||
$this->assertFalse($p->disablePublicAccess(123));
|
||||
}
|
||||
|
||||
public function testIdentifier()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
|
||||
// Creation
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
|
||||
|
||||
$project = $p->getById(1);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('TEST1', $project['identifier']);
|
||||
|
||||
$project = $p->getById(2);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('', $project['identifier']);
|
||||
|
||||
// Update
|
||||
$this->assertTrue($p->update(array('id' => '2', 'identifier' => 'test2')));
|
||||
|
||||
$project = $p->getById(2);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('TEST2', $project['identifier']);
|
||||
|
||||
$project = $p->getByIdentifier('test1');
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('TEST1', $project['identifier']);
|
||||
|
||||
$project = $p->getByIdentifier('');
|
||||
$this->assertFalse($project);
|
||||
|
||||
// Validation rules
|
||||
$r = $p->validateCreation(array('name' => 'test', 'identifier' => 'TEST1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => ''));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $p->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test 123'));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
}
|
||||
284
tests/units/Model/SubtaskTest.php
Normal file
284
tests/units/Model/SubtaskTest.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\Subtask;
|
||||
use Model\Project;
|
||||
use Model\Category;
|
||||
use Model\User;
|
||||
use Core\Session;
|
||||
use Model\UserSession;
|
||||
|
||||
class SubTaskTest extends Base
|
||||
{
|
||||
public function testToggleStatusWithoutSession()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(Subtask::STATUS_TODO, $subtask['status']);
|
||||
$this->assertEquals(0, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
|
||||
$this->assertTrue($s->toggleStatus(1));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']);
|
||||
$this->assertEquals(0, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
|
||||
$this->assertTrue($s->toggleStatus(1));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(Subtask::STATUS_DONE, $subtask['status']);
|
||||
$this->assertEquals(0, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
|
||||
$this->assertTrue($s->toggleStatus(1));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(Subtask::STATUS_TODO, $subtask['status']);
|
||||
$this->assertEquals(0, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
}
|
||||
|
||||
public function testToggleStatusWithSession()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
$ss = new Session;
|
||||
$us = new UserSession($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(Subtask::STATUS_TODO, $subtask['status']);
|
||||
$this->assertEquals(0, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
|
||||
// Set the current logged user
|
||||
$ss['user'] = array('id' => 1);
|
||||
|
||||
$this->assertTrue($s->toggleStatus(1));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']);
|
||||
$this->assertEquals(1, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
|
||||
$this->assertTrue($s->toggleStatus(1));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(Subtask::STATUS_DONE, $subtask['status']);
|
||||
$this->assertEquals(1, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
|
||||
$this->assertTrue($s->toggleStatus(1));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(Subtask::STATUS_TODO, $subtask['status']);
|
||||
$this->assertEquals(1, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
}
|
||||
|
||||
public function testCloseAll()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
|
||||
|
||||
$this->assertTrue($s->closeAll(1));
|
||||
|
||||
$subtasks = $s->getAll(1);
|
||||
$this->assertNotEmpty($subtasks);
|
||||
|
||||
foreach ($subtasks as $subtask) {
|
||||
$this->assertEquals(Subtask::STATUS_DONE, $subtask['status']);
|
||||
}
|
||||
}
|
||||
|
||||
public function testMoveUp()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
|
||||
$this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1)));
|
||||
|
||||
// Check positions
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(1, $subtask['position']);
|
||||
|
||||
$subtask = $s->getById(2);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(2, $subtask['position']);
|
||||
|
||||
$subtask = $s->getById(3);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(3, $subtask['position']);
|
||||
|
||||
// Move up
|
||||
$this->assertTrue($s->moveUp(1, 2));
|
||||
|
||||
// Check positions
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(2, $subtask['position']);
|
||||
|
||||
$subtask = $s->getById(2);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(1, $subtask['position']);
|
||||
|
||||
$subtask = $s->getById(3);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(3, $subtask['position']);
|
||||
|
||||
// We can't move up #2
|
||||
$this->assertFalse($s->moveUp(1, 2));
|
||||
|
||||
// Test remove
|
||||
$this->assertTrue($s->remove(1));
|
||||
$this->assertTrue($s->moveUp(1, 3));
|
||||
|
||||
// Check positions
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertEmpty($subtask);
|
||||
|
||||
$subtask = $s->getById(2);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(2, $subtask['position']);
|
||||
|
||||
$subtask = $s->getById(3);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(1, $subtask['position']);
|
||||
}
|
||||
|
||||
public function testMoveDown()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
|
||||
$this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1)));
|
||||
|
||||
// Move down #1
|
||||
$this->assertTrue($s->moveDown(1, 1));
|
||||
|
||||
// Check positions
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(2, $subtask['position']);
|
||||
|
||||
$subtask = $s->getById(2);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(1, $subtask['position']);
|
||||
|
||||
$subtask = $s->getById(3);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(3, $subtask['position']);
|
||||
|
||||
// We can't move down #3
|
||||
$this->assertFalse($s->moveDown(1, 3));
|
||||
|
||||
// Test remove
|
||||
$this->assertTrue($s->remove(1));
|
||||
$this->assertTrue($s->moveDown(1, 2));
|
||||
|
||||
// Check positions
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertEmpty($subtask);
|
||||
|
||||
$subtask = $s->getById(2);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(2, $subtask['position']);
|
||||
|
||||
$subtask = $s->getById(3);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(1, $subtask['position']);
|
||||
}
|
||||
|
||||
public function testDuplicate()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
|
||||
// We create 2 tasks
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
|
||||
|
||||
// We create many subtasks for the first task
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on')));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1)));
|
||||
|
||||
// We duplicate our subtasks
|
||||
$this->assertTrue($s->duplicate(1, 2));
|
||||
$subtasks = $s->getAll(2);
|
||||
|
||||
$this->assertNotFalse($subtasks);
|
||||
$this->assertNotEmpty($subtasks);
|
||||
$this->assertEquals(2, count($subtasks));
|
||||
|
||||
$this->assertEquals('subtask #1', $subtasks[0]['title']);
|
||||
$this->assertEquals('subtask #2', $subtasks[1]['title']);
|
||||
|
||||
$this->assertEquals(2, $subtasks[0]['task_id']);
|
||||
$this->assertEquals(2, $subtasks[1]['task_id']);
|
||||
|
||||
$this->assertEquals(5, $subtasks[0]['time_estimated']);
|
||||
$this->assertEquals(0, $subtasks[1]['time_estimated']);
|
||||
|
||||
$this->assertEquals(0, $subtasks[0]['time_spent']);
|
||||
$this->assertEquals(0, $subtasks[1]['time_spent']);
|
||||
|
||||
$this->assertEquals(0, $subtasks[0]['status']);
|
||||
$this->assertEquals(0, $subtasks[1]['status']);
|
||||
|
||||
$this->assertEquals(0, $subtasks[0]['user_id']);
|
||||
$this->assertEquals(0, $subtasks[1]['user_id']);
|
||||
|
||||
$this->assertEquals(1, $subtasks[0]['position']);
|
||||
$this->assertEquals(2, $subtasks[1]['position']);
|
||||
}
|
||||
}
|
||||
314
tests/units/Model/SubtaskTimeTrackingTest.php
Normal file
314
tests/units/Model/SubtaskTimeTrackingTest.php
Normal file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\TaskFinder;
|
||||
use Model\TaskCreation;
|
||||
use Model\Subtask;
|
||||
use Model\SubtaskTimeTracking;
|
||||
use Model\Project;
|
||||
use Model\Category;
|
||||
use Model\User;
|
||||
use Core\Session;
|
||||
|
||||
class SubtaskTimeTrackingTest extends Base
|
||||
{
|
||||
public function testHasTimer()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$st = new SubtaskTimeTracking($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
|
||||
|
||||
$this->assertFalse($st->hasTimer(1, 1));
|
||||
$this->assertTrue($st->logStartTime(1, 1));
|
||||
$this->assertTrue($st->hasTimer(1, 1));
|
||||
$this->assertFalse($st->logStartTime(1, 1));
|
||||
$this->assertTrue($st->logEndTime(1, 1));
|
||||
$this->assertFalse($st->hasTimer(1, 1));
|
||||
}
|
||||
|
||||
public function testGetTimerStatus()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$st = new SubtaskTimeTracking($this->container);
|
||||
$p = new Project($this->container);
|
||||
$ss = new Session;
|
||||
|
||||
$ss['user'] = array('id' => 1);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1)));
|
||||
|
||||
// Nothing started
|
||||
$subtasks = $s->getAll(1);
|
||||
$this->assertNotEmpty($subtasks);
|
||||
$this->assertEquals(0, $subtasks[0]['timer_start_date']);
|
||||
$this->assertFalse($subtasks[0]['is_timer_started']);
|
||||
|
||||
$subtask = $s->getbyId(1, true);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(0, $subtask['timer_start_date']);
|
||||
$this->assertFalse($subtask['is_timer_started']);
|
||||
|
||||
// Start the clock
|
||||
$this->assertTrue($st->logStartTime(1, 1));
|
||||
|
||||
$subtasks = $s->getAll(1);
|
||||
$this->assertNotEmpty($subtasks);
|
||||
$this->assertEquals(time(), $subtasks[0]['timer_start_date'], '', 3);
|
||||
$this->assertTrue($subtasks[0]['is_timer_started']);
|
||||
|
||||
$subtask = $s->getbyId(1, true);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(time(), $subtask['timer_start_date'], '', 3);
|
||||
$this->assertTrue($subtask['is_timer_started']);
|
||||
|
||||
// Stop the clock
|
||||
$this->assertTrue($st->logEndTime(1, 1));
|
||||
$subtasks = $s->getAll(1);
|
||||
$this->assertNotEmpty($subtasks);
|
||||
$this->assertEquals(0, $subtasks[0]['timer_start_date']);
|
||||
$this->assertFalse($subtasks[0]['is_timer_started']);
|
||||
|
||||
$subtask = $s->getbyId(1, true);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(0, $subtask['timer_start_date']);
|
||||
$this->assertFalse($subtask['is_timer_started']);
|
||||
}
|
||||
|
||||
public function testLogStartTime()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$st = new SubtaskTimeTracking($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
|
||||
|
||||
$this->assertTrue($st->logStartTime(1, 1));
|
||||
|
||||
$timesheet = $st->getUserTimesheet(1);
|
||||
$this->assertNotEmpty($timesheet);
|
||||
$this->assertCount(1, $timesheet);
|
||||
$this->assertNotEmpty($timesheet[0]['start']);
|
||||
$this->assertEmpty($timesheet[0]['end']);
|
||||
$this->assertEquals(1, $timesheet[0]['user_id']);
|
||||
$this->assertEquals(1, $timesheet[0]['subtask_id']);
|
||||
}
|
||||
|
||||
public function testLogStartEnd()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$st = new SubtaskTimeTracking($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
|
||||
|
||||
// No start time
|
||||
$this->assertTrue($st->logEndTime(1, 1));
|
||||
$timesheet = $st->getUserTimesheet(1);
|
||||
$this->assertEmpty($timesheet);
|
||||
|
||||
// Log start and end time
|
||||
$this->assertTrue($st->logStartTime(1, 1));
|
||||
sleep(1);
|
||||
$this->assertTrue($st->logEndTime(1, 1));
|
||||
|
||||
$timesheet = $st->getUserTimesheet(1);
|
||||
$this->assertNotEmpty($timesheet);
|
||||
$this->assertCount(1, $timesheet);
|
||||
$this->assertNotEmpty($timesheet[0]['start']);
|
||||
$this->assertNotEmpty($timesheet[0]['end']);
|
||||
$this->assertEquals(1, $timesheet[0]['user_id']);
|
||||
$this->assertEquals(1, $timesheet[0]['subtask_id']);
|
||||
$this->assertNotEquals($timesheet[0]['start'], $timesheet[0]['end']);
|
||||
}
|
||||
|
||||
public function testCalculateSubtaskTime()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$st = new SubtaskTimeTracking($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2, 'time_estimated' => 3.3)));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 1.1, 'time_estimated' => 4.4)));
|
||||
|
||||
$time = $st->calculateSubtaskTime(1);
|
||||
$this->assertNotempty($time);
|
||||
$this->assertCount(2, $time);
|
||||
$this->assertEquals(3.3, $time['total_spent'], 'Total spent', 0.01);
|
||||
$this->assertEquals(7.7, $time['total_estimated'], 'Total estimated', 0.01);
|
||||
}
|
||||
|
||||
public function testUpdateSubtaskTimeSpent()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$st = new SubtaskTimeTracking($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2)));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
|
||||
|
||||
$this->assertTrue($st->logStartTime(1, 1));
|
||||
$this->assertTrue($st->logStartTime(2, 1));
|
||||
|
||||
// Fake start time
|
||||
$this->container['db']->table(SubtaskTimeTracking::TABLE)->update(array('start' => time() - 3600));
|
||||
|
||||
$this->assertTrue($st->logEndTime(1, 1));
|
||||
$this->assertTrue($st->logEndTime(2, 1));
|
||||
|
||||
$timesheet = $st->getUserTimesheet(1);
|
||||
$this->assertNotEmpty($timesheet);
|
||||
$this->assertCount(2, $timesheet);
|
||||
$this->assertEquals(3600, $timesheet[0]['end'] - $timesheet[0]['start'], 'Wrong timestamps', 1);
|
||||
$this->assertEquals(3600, $timesheet[1]['end'] - $timesheet[1]['start'], 'Wrong timestamps', 1);
|
||||
|
||||
$time = $st->calculateSubtaskTime(1);
|
||||
$this->assertNotempty($time);
|
||||
$this->assertEquals(4.2, $time['total_spent'], 'Total spent', 0.01);
|
||||
$this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01);
|
||||
|
||||
$time = $st->calculateSubtaskTime(2);
|
||||
$this->assertNotempty($time);
|
||||
$this->assertEquals(0, $time['total_spent'], 'Total spent', 0.01);
|
||||
$this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01);
|
||||
}
|
||||
|
||||
public function testUpdateTaskTimeTracking()
|
||||
{
|
||||
$tf = new TaskFinder($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$st = new SubtaskTimeTracking($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
|
||||
|
||||
$this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 2, 'time_spent' => 3.4)));
|
||||
$this->assertEquals(4, $s->create(array('title' => 'subtask #4', 'task_id' => 2, 'time_estimated' => 1.25)));
|
||||
|
||||
$this->assertEquals(5, $s->create(array('title' => 'subtask #5', 'task_id' => 3, 'time_spent' => 8)));
|
||||
|
||||
$st->updateTaskTimeTracking(1);
|
||||
$st->updateTaskTimeTracking(2);
|
||||
$st->updateTaskTimeTracking(3);
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(2.2, $task['time_spent'], 'Total spent', 0.01);
|
||||
$this->assertEquals(1, $task['time_estimated'], 'Total estimated', 0.01);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(3.4, $task['time_spent'], 'Total spent', 0.01);
|
||||
$this->assertEquals(1.25, $task['time_estimated'], 'Total estimated', 0.01);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(4, $task['time_estimated']);
|
||||
$this->assertEquals(8, $task['time_spent']);
|
||||
}
|
||||
|
||||
public function testGetCalendarEvents()
|
||||
{
|
||||
$tf = new TaskFinder($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$st = new SubtaskTimeTracking($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'test 1', 'project_id' => 2)));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
|
||||
$this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1)));
|
||||
|
||||
$this->assertEquals(4, $s->create(array('title' => 'subtask #4', 'task_id' => 2)));
|
||||
$this->assertEquals(5, $s->create(array('title' => 'subtask #5', 'task_id' => 2)));
|
||||
$this->assertEquals(6, $s->create(array('title' => 'subtask #6', 'task_id' => 2)));
|
||||
$this->assertEquals(7, $s->create(array('title' => 'subtask #7', 'task_id' => 2)));
|
||||
$this->assertEquals(8, $s->create(array('title' => 'subtask #8', 'task_id' => 2)));
|
||||
|
||||
// Slot start before and finish inside the calendar time range
|
||||
$this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 1, 'start' => strtotime('-1 day'), 'end' => strtotime('+1 hour')));
|
||||
|
||||
// Slot start inside time range and finish after the time range
|
||||
$this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 2, 'start' => strtotime('+1 hour'), 'end' => strtotime('+2 days')));
|
||||
|
||||
// Start before time range and finish inside time range
|
||||
$this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 3, 'start' => strtotime('-1 day'), 'end' => strtotime('+1.5 days')));
|
||||
|
||||
// Start and finish inside time range
|
||||
$this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 4, 'start' => strtotime('+1 hour'), 'end' => strtotime('+2 hours')));
|
||||
|
||||
// Start and finish after the time range
|
||||
$this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 5, 'start' => strtotime('+2 days'), 'end' => strtotime('+3 days')));
|
||||
|
||||
// Start and finish before the time range
|
||||
$this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 6, 'start' => strtotime('-2 days'), 'end' => strtotime('-1 day')));
|
||||
|
||||
// Start before time range and not finished
|
||||
$this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 7, 'start' => strtotime('-1 day')));
|
||||
|
||||
// Start inside time range and not finish
|
||||
$this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 8, 'start' => strtotime('+3200 seconds')));
|
||||
|
||||
$timesheet = $st->getUserTimesheet(1);
|
||||
$this->assertNotEmpty($timesheet);
|
||||
$this->assertCount(8, $timesheet);
|
||||
|
||||
$events = $st->getUserCalendarEvents(1, date('Y-m-d'), date('Y-m-d', strtotime('+2 day')));
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertCount(6, $events);
|
||||
$this->assertEquals(1, $events[0]['subtask_id']);
|
||||
$this->assertEquals(2, $events[1]['subtask_id']);
|
||||
$this->assertEquals(3, $events[2]['subtask_id']);
|
||||
$this->assertEquals(4, $events[3]['subtask_id']);
|
||||
$this->assertEquals(7, $events[4]['subtask_id']);
|
||||
$this->assertEquals(8, $events[5]['subtask_id']);
|
||||
|
||||
$events = $st->getProjectCalendarEvents(1, date('Y-m-d'), date('Y-m-d', strtotime('+2 days')));
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertCount(3, $events);
|
||||
$this->assertEquals(1, $events[0]['subtask_id']);
|
||||
$this->assertEquals(2, $events[1]['subtask_id']);
|
||||
$this->assertEquals(3, $events[2]['subtask_id']);
|
||||
|
||||
$events = $st->getProjectCalendarEvents(2, date('Y-m-d'), date('Y-m-d', strtotime('+2 days')));
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertCount(3, $events);
|
||||
$this->assertEquals(4, $events[0]['subtask_id']);
|
||||
$this->assertEquals(7, $events[1]['subtask_id']);
|
||||
$this->assertEquals(8, $events[2]['subtask_id']);
|
||||
}
|
||||
}
|
||||
409
tests/units/Model/SwimlaneTest.php
Normal file
409
tests/units/Model/SwimlaneTest.php
Normal file
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Project;
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Swimlane;
|
||||
|
||||
class SwimlaneTest extends Base
|
||||
{
|
||||
public function testCreation()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
|
||||
$swimlanes = $s->getSwimlanes(1);
|
||||
$this->assertNotEmpty($swimlanes);
|
||||
$this->assertEquals(2, count($swimlanes));
|
||||
$this->assertEquals('Default swimlane', $swimlanes[0]['name']);
|
||||
$this->assertEquals('Swimlane #1', $swimlanes[1]['name']);
|
||||
|
||||
$this->assertEquals(1, $s->getIdByName(1, 'Swimlane #1'));
|
||||
$this->assertEquals(0, $s->getIdByName(2, 'Swimlane #2'));
|
||||
|
||||
$this->assertEquals('Swimlane #1', $s->getNameById(1));
|
||||
$this->assertEquals('', $s->getNameById(23));
|
||||
}
|
||||
|
||||
public function testGetList()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
|
||||
|
||||
$swimlanes = $s->getList(1);
|
||||
$expected = array('Default swimlane', 'Swimlane #1', 'Swimlane #2');
|
||||
|
||||
$this->assertEquals($expected, $swimlanes);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals('Swimlane #1', $swimlane['name']);
|
||||
|
||||
$this->assertTrue($s->update(array('id' => 1, 'name' => 'foobar')));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals('foobar', $swimlane['name']);
|
||||
}
|
||||
|
||||
public function testUpdateDefaultSwimlane()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertTrue($s->updateDefault(array('id' => 1, 'default_swimlane' => 'foo', 'show_default_swimlane' => 1)));
|
||||
|
||||
$default = $s->getDefault(1);
|
||||
$this->assertNotEmpty($default);
|
||||
$this->assertEquals('foo', $default['default_swimlane']);
|
||||
$this->assertEquals(1, $default['show_default_swimlane']);
|
||||
|
||||
$this->assertTrue($s->updateDefault(array('id' => 1, 'default_swimlane' => 'foo', 'show_default_swimlane' => 0)));
|
||||
|
||||
$default = $s->getDefault(1);
|
||||
$this->assertNotEmpty($default);
|
||||
$this->assertEquals('foo', $default['default_swimlane']);
|
||||
$this->assertEquals(0, $default['show_default_swimlane']);
|
||||
}
|
||||
|
||||
public function testDisable()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$this->assertEquals(2, $s->getLastPosition(1));
|
||||
$this->assertTrue($s->disable(1, 1));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(0, $swimlane['is_active']);
|
||||
$this->assertEquals(0, $swimlane['position']);
|
||||
|
||||
$this->assertEquals(1, $s->getLastPosition(1));
|
||||
|
||||
// Create a new swimlane
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
// Enable our disabled swimlane
|
||||
$this->assertTrue($s->enable(1, 1));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'swimlane_id' => 1)));
|
||||
|
||||
$task = $tf->getbyId(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['swimlane_id']);
|
||||
|
||||
$this->assertTrue($s->remove(1, 1));
|
||||
|
||||
$task = $tf->getbyId(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
$this->assertEmpty($s->getById(1));
|
||||
}
|
||||
|
||||
public function testUpdatePositions()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
|
||||
$this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'Swimlane #3')));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(3, $swimlane['position']);
|
||||
|
||||
// Disable the 2nd swimlane
|
||||
$this->assertTrue($s->disable(1, 2));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(0, $swimlane['is_active']);
|
||||
$this->assertEquals(0, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
|
||||
// Remove the first swimlane
|
||||
$this->assertTrue($s->remove(1, 1));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertEmpty($swimlane);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(0, $swimlane['is_active']);
|
||||
$this->assertEquals(0, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
}
|
||||
|
||||
public function testMoveUp()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
|
||||
$this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'Swimlane #3')));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(3, $swimlane['position']);
|
||||
|
||||
// Move the swimlane 3 up
|
||||
$this->assertTrue($s->moveUp(1, 3));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(3, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
|
||||
// First swimlane can be moved up
|
||||
$this->assertFalse($s->moveUp(1, 1));
|
||||
|
||||
// Move with a disabled swimlane
|
||||
$this->assertTrue($s->disable(1, 1));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(0, $swimlane['is_active']);
|
||||
$this->assertEquals(0, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
// Move the 2nd swimlane up
|
||||
$this->assertTrue($s->moveUp(1, 2));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(0, $swimlane['is_active']);
|
||||
$this->assertEquals(0, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
}
|
||||
|
||||
public function testMoveDown()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
|
||||
$this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'Swimlane #3')));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(3, $swimlane['position']);
|
||||
|
||||
// Move the swimlane 1 down
|
||||
$this->assertTrue($s->moveDown(1, 1));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(3, $swimlane['position']);
|
||||
|
||||
// Last swimlane can be moved down
|
||||
$this->assertFalse($s->moveDown(1, 3));
|
||||
|
||||
// Move with a disabled swimlane
|
||||
$this->assertTrue($s->disable(1, 3));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(0, $swimlane['is_active']);
|
||||
$this->assertEquals(0, $swimlane['position']);
|
||||
|
||||
// Move the 2st swimlane down
|
||||
$this->assertTrue($s->moveDown(1, 2));
|
||||
|
||||
$swimlane = $s->getById(1);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(1, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(2);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(1, $swimlane['is_active']);
|
||||
$this->assertEquals(2, $swimlane['position']);
|
||||
|
||||
$swimlane = $s->getById(3);
|
||||
$this->assertNotEmpty($swimlane);
|
||||
$this->assertEquals(0, $swimlane['is_active']);
|
||||
$this->assertEquals(0, $swimlane['position']);
|
||||
}
|
||||
|
||||
public function testDuplicateSwimlane()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'P2')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
|
||||
$this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3')));
|
||||
|
||||
$default_swimlane1 = $s->getDefault(1);
|
||||
$default_swimlane1['default_swimlane'] = 'New Default';
|
||||
|
||||
$this->assertTrue($s->updateDefault($default_swimlane1));
|
||||
|
||||
$this->assertTrue($s->duplicate(1, 2));
|
||||
|
||||
$swimlanes = $s->getAll(2);
|
||||
|
||||
$this->assertCount(3, $swimlanes);
|
||||
$this->assertEquals(4, $swimlanes[0]['id']);
|
||||
$this->assertEquals('S1', $swimlanes[0]['name']);
|
||||
$this->assertEquals(5, $swimlanes[1]['id']);
|
||||
$this->assertEquals('S2', $swimlanes[1]['name']);
|
||||
$this->assertEquals(6, $swimlanes[2]['id']);
|
||||
$this->assertEquals('S3', $swimlanes[2]['name']);
|
||||
$new_default = $s->getDefault(2);
|
||||
$this->assertEquals('New Default', $new_default['default_swimlane']);
|
||||
}
|
||||
}
|
||||
416
tests/units/Model/TaskCreationTest.php
Normal file
416
tests/units/Model/TaskCreationTest.php
Normal file
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Config;
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\TaskStatus;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
|
||||
class TaskCreationTest extends Base
|
||||
{
|
||||
public function onCreate($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
|
||||
$event_data = $event->getAll();
|
||||
$this->assertNotEmpty($event_data);
|
||||
$this->assertEquals(1, $event_data['task_id']);
|
||||
$this->assertEquals('test', $event_data['title']);
|
||||
}
|
||||
|
||||
public function testNoProjectId()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(0, $tc->create(array('title' => 'test', 'project_id' => 0)));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayNotHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
|
||||
$this->assertArrayNotHasKey(Task::EVENT_CREATE.'.closure', $called);
|
||||
}
|
||||
|
||||
public function testNoTitle()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1)));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called);
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals('Untitled', $task['title']);
|
||||
$this->assertEquals(1, $task['project_id']);
|
||||
}
|
||||
|
||||
public function testMinimum()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, array($this, 'onCreate'));
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE.'.TaskCreationTest::onCreate', $called);
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals('yellow', $task['color_id']);
|
||||
$this->assertEquals(1, $task['project_id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
$this->assertEquals(0, $task['creator_id']);
|
||||
|
||||
$this->assertEquals('test', $task['title']);
|
||||
$this->assertEquals('', $task['description']);
|
||||
$this->assertEquals('', $task['reference']);
|
||||
|
||||
$this->assertEquals(time(), $task['date_creation'], 'Wrong timestamp', 1);
|
||||
$this->assertEquals(time(), $task['date_modification'], 'Wrong timestamp', 1);
|
||||
$this->assertEquals(0, $task['date_due']);
|
||||
$this->assertEquals(0, $task['date_completed']);
|
||||
$this->assertEquals(0, $task['date_started']);
|
||||
|
||||
$this->assertEquals(0, $task['time_estimated']);
|
||||
$this->assertEquals(0, $task['time_spent']);
|
||||
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(1, $task['is_active']);
|
||||
$this->assertEquals(0, $task['score']);
|
||||
}
|
||||
|
||||
public function testColorId()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'color_id' => 'blue')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals('blue', $task['color_id']);
|
||||
}
|
||||
|
||||
public function testOwnerId()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['owner_id']);
|
||||
}
|
||||
|
||||
public function testCategoryId()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['category_id']);
|
||||
}
|
||||
|
||||
public function testCreatorId()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['creator_id']);
|
||||
}
|
||||
|
||||
public function testThatCreatorIsDefined()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$_SESSION = array();
|
||||
$_SESSION['user']['id'] = 1;
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['creator_id']);
|
||||
|
||||
$_SESSION = array();
|
||||
}
|
||||
|
||||
public function testColumnId()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
}
|
||||
|
||||
public function testPosition()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
}
|
||||
|
||||
public function testDescription()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'description' => 'test')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals('test', $task['description']);
|
||||
}
|
||||
|
||||
public function testReference()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'reference' => 'test')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals('test', $task['reference']);
|
||||
}
|
||||
|
||||
public function testDateDue()
|
||||
{
|
||||
$date = '2014-11-23';
|
||||
$timestamp = strtotime('+2days');
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $date)));
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $timestamp)));
|
||||
$this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => '')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals($date, date('Y-m-d', $task['date_due']));
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals($timestamp, $task['date_due']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(0, $task['date_due']);
|
||||
}
|
||||
|
||||
public function testDateStarted()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
|
||||
// Set only a date
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
|
||||
|
||||
// Set a datetime
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24 16:25')));
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
|
||||
|
||||
// Set a datetime
|
||||
$this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24 6:25pm')));
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
|
||||
|
||||
// Set a timestamp
|
||||
$this->assertEquals(4, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => time())));
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(time(), $task['date_started'], '', 1);
|
||||
|
||||
// Set empty string
|
||||
$this->assertEquals(5, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '')));
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(0, $task['date_started']);
|
||||
}
|
||||
|
||||
public function testTime()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.5, 'time_spent' => 2.3)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1.5, $task['time_estimated']);
|
||||
$this->assertEquals(2.3, $task['time_spent']);
|
||||
}
|
||||
|
||||
public function testStripColumn()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'another_task' => '1')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
}
|
||||
|
||||
public function testScore()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'score' => '3')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotFalse($task);
|
||||
$this->assertEquals(3, $task['score']);
|
||||
}
|
||||
|
||||
public function testDefaultColor()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$c = new Config($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test1')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals('yellow', $task['color_id']);
|
||||
|
||||
$this->assertTrue($c->save(array('default_color' => 'orange')));
|
||||
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test2')));
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals('orange', $task['color_id']);
|
||||
}
|
||||
}
|
||||
707
tests/units/Model/TaskDuplicationTest.php
Normal file
707
tests/units/Model/TaskDuplicationTest.php
Normal file
@@ -0,0 +1,707 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskDuplication;
|
||||
use Model\TaskFinder;
|
||||
use Model\TaskStatus;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
use Model\Category;
|
||||
use Model\User;
|
||||
use Model\Swimlane;
|
||||
|
||||
class TaskDuplicationTest extends Base
|
||||
{
|
||||
public function testThatDuplicateDefineCreator()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(1, $task['project_id']);
|
||||
$this->assertEquals(0, $task['creator_id']);
|
||||
|
||||
$_SESSION = array();
|
||||
$_SESSION['user']['id'] = 1;
|
||||
|
||||
// We duplicate our task
|
||||
$this->assertEquals(2, $td->duplicate(1));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['creator_id']);
|
||||
|
||||
$_SESSION = array();
|
||||
}
|
||||
|
||||
public function testDuplicateSameProject()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
// We create a task and a project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
|
||||
// Some categories
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
|
||||
$this->assertTrue($c->exists(1, 1));
|
||||
$this->assertTrue($c->exists(2, 1));
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2, 'time_spent' => 4.4)
|
||||
));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(1, $task['project_id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(2, $task['category_id']);
|
||||
$this->assertEquals(4.4, $task['time_spent']);
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
|
||||
|
||||
// We duplicate our task
|
||||
$this->assertEquals(2, $td->duplicate(1));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called);
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
|
||||
$this->assertEquals(1, $task['project_id']);
|
||||
$this->assertEquals(1, $task['owner_id']);
|
||||
$this->assertEquals(2, $task['category_id']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
$this->assertEquals(0, $task['time_spent']);
|
||||
}
|
||||
|
||||
public function testDuplicateAnotherProject()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
|
||||
$this->assertTrue($c->exists(1, 1));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertEquals(2, $td->duplicateToProject(1, 2));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called);
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['owner_id']);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
}
|
||||
|
||||
public function testDuplicateAnotherProjectWithCategory()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
|
||||
$this->assertTrue($c->exists(1, 1));
|
||||
$this->assertTrue($c->exists(2, 2));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertEquals(2, $td->duplicateToProject(1, 2));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(2, $task['category_id']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
}
|
||||
|
||||
public function testDuplicateAnotherProjectWithPredefinedCategory()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 2)));
|
||||
$this->assertTrue($c->exists(1, 1));
|
||||
$this->assertTrue($c->exists(2, 2));
|
||||
$this->assertTrue($c->exists(3, 2));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
|
||||
|
||||
// We duplicate our task to the 2nd project with no category
|
||||
$this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, 0));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
|
||||
// We duplicate our task to the 2nd project with a different category
|
||||
$this->assertEquals(3, $td->duplicateToProject(1, 2, null, null, 3));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(3);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(3, $task['category_id']);
|
||||
}
|
||||
|
||||
public function testDuplicateAnotherProjectWithSwimlane()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertEquals(2, $td->duplicateToProject(1, 2));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
$this->assertEquals(2, $task['swimlane_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
}
|
||||
|
||||
public function testDuplicateAnotherProjectWithoutSwimlane()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertEquals(2, $td->duplicateToProject(1, 2));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
}
|
||||
|
||||
public function testDuplicateAnotherProjectWithPredefinedSwimlane()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
|
||||
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertEquals(2, $td->duplicateToProject(1, 2, 3));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(3, $task['swimlane_id']);
|
||||
}
|
||||
|
||||
public function testDuplicateAnotherProjectWithPredefinedColumn()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2)));
|
||||
|
||||
// We duplicate our task to the 2nd project with a different column
|
||||
$this->assertEquals(2, $td->duplicateToProject(1, 2, null, 7));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(7, $task['column_id']);
|
||||
}
|
||||
|
||||
public function testDuplicateAnotherProjectWithUser()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertEquals(2, $td->duplicateToProject(1, 2));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
|
||||
// We create a new user for our project
|
||||
$user = new User($this->container);
|
||||
$this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
$this->assertTrue($pp->addMember(2, 2));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 2));
|
||||
$this->assertTrue($pp->isUserAllowed(2, 2));
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertEquals(3, $td->duplicateToProject(1, 2));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(3);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
$this->assertEquals(2, $task['owner_id']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
|
||||
// We duplicate a task with a not allowed user
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3)));
|
||||
$this->assertEquals(5, $td->duplicateToProject(4, 2));
|
||||
|
||||
$task = $tf->getById(5);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
}
|
||||
|
||||
public function testDuplicateAnotherProjectWithPredefinedUser()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, null, 1));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['owner_id']);
|
||||
}
|
||||
|
||||
public function onMoveProject($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
|
||||
$event_data = $event->getAll();
|
||||
$this->assertNotEmpty($event_data);
|
||||
$this->assertEquals(1, $event_data['task_id']);
|
||||
$this->assertEquals('test', $event_data['title']);
|
||||
}
|
||||
|
||||
public function testMoveAnotherProject()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$user = new User($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333)));
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_MOVE_PROJECT, array($this, 'onMoveProject'));
|
||||
|
||||
// We duplicate our task to the 2nd project
|
||||
$this->assertTrue($td->moveToProject(1, 2));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called);
|
||||
|
||||
// Check the values of the moved task
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['owner_id']);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
}
|
||||
|
||||
public function testMoveAnotherProjectWithCategory()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
|
||||
$this->assertTrue($c->exists(1, 1));
|
||||
$this->assertTrue($c->exists(2, 2));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
|
||||
|
||||
// We move our task to the 2nd project
|
||||
$this->assertTrue($td->moveToProject(1, 2));
|
||||
|
||||
// Check the values of the duplicated task
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(2, $task['category_id']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
}
|
||||
|
||||
public function testMoveAnotherProjectWithUser()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$user = new User($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
// We create a new user for our project
|
||||
$this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
$this->assertTrue($pp->addMember(2, 2));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 2));
|
||||
$this->assertTrue($pp->isUserAllowed(2, 2));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
|
||||
|
||||
// We move our task to the 2nd project
|
||||
$this->assertTrue($td->moveToProject(1, 2));
|
||||
|
||||
// Check the values of the moved task
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(2, $task['owner_id']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
}
|
||||
|
||||
public function testMoveAnotherProjectWithForbiddenUser()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectPermission($this->container);
|
||||
$user = new User($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
// We create a new user for our project
|
||||
$this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
$this->assertTrue($pp->addMember(2, 2));
|
||||
$this->assertTrue($pp->isUserAllowed(1, 2));
|
||||
$this->assertTrue($pp->isUserAllowed(2, 2));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3)));
|
||||
|
||||
// We move our task to the 2nd project
|
||||
$this->assertTrue($td->moveToProject(1, 2));
|
||||
|
||||
// Check the values of the moved task
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
}
|
||||
|
||||
public function testMoveAnotherProjectWithSwimlane()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
|
||||
|
||||
// We move our task to the 2nd project
|
||||
$this->assertTrue($td->moveToProject(1, 2));
|
||||
|
||||
// Check the values of the moved task
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
$this->assertEquals(2, $task['swimlane_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
}
|
||||
|
||||
public function testMoveAnotherProjectWithoutSwimlane()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
// We create 2 projects
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
|
||||
$this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
|
||||
|
||||
// We move our task to the 2nd project
|
||||
$this->assertTrue($td->moveToProject(1, 2));
|
||||
|
||||
// Check the values of the moved task
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
$this->assertEquals(5, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(2, $task['project_id']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
}
|
||||
|
||||
public function testCalculateRecurringTaskDueDate()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
|
||||
$values = array('date_due' => 0);
|
||||
$td->calculateRecurringTaskDueDate($values);
|
||||
$this->assertEquals(0, $values['date_due']);
|
||||
|
||||
$values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
|
||||
$td->calculateRecurringTaskDueDate($values);
|
||||
$this->assertEquals(0, $values['date_due']);
|
||||
|
||||
$values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
|
||||
$td->calculateRecurringTaskDueDate($values);
|
||||
$this->assertEquals(time() + 86400, $values['date_due'], '', 1);
|
||||
|
||||
$values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
|
||||
$td->calculateRecurringTaskDueDate($values);
|
||||
$this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1);
|
||||
|
||||
$values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
|
||||
$td->calculateRecurringTaskDueDate($values);
|
||||
$this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1);
|
||||
|
||||
$values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
|
||||
$td->calculateRecurringTaskDueDate($values);
|
||||
$this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1);
|
||||
|
||||
$values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_MONTHS);
|
||||
$td->calculateRecurringTaskDueDate($values);
|
||||
$this->assertEquals(1436561776, $values['date_due'], '', 1);
|
||||
|
||||
$values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_YEARS);
|
||||
$td->calculateRecurringTaskDueDate($values);
|
||||
$this->assertEquals(1494449776, $values['date_due'], '', 1);
|
||||
}
|
||||
|
||||
public function testDuplicateRecurringTask()
|
||||
{
|
||||
$td = new TaskDuplication($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array(
|
||||
'title' => 'test',
|
||||
'project_id' => 1,
|
||||
'date_due' => 1436561776,
|
||||
'recurrence_status' => Task::RECURRING_STATUS_PENDING,
|
||||
'recurrence_trigger' => Task::RECURRING_TRIGGER_CLOSE,
|
||||
'recurrence_factor' => 2,
|
||||
'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS,
|
||||
'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE,
|
||||
)));
|
||||
|
||||
$this->assertEquals(2, $td->duplicateRecurringTask(1));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(Task::RECURRING_STATUS_PROCESSED, $task['recurrence_status']);
|
||||
$this->assertEquals(2, $task['recurrence_child']);
|
||||
$this->assertEquals(1436561776, $task['date_due'], '', 2);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(Task::RECURRING_STATUS_PENDING, $task['recurrence_status']);
|
||||
$this->assertEquals(Task::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']);
|
||||
$this->assertEquals(Task::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
|
||||
$this->assertEquals(Task::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']);
|
||||
$this->assertEquals(1, $task['recurrence_parent']);
|
||||
$this->assertEquals(2, $task['recurrence_factor']);
|
||||
$this->assertEquals(strtotime('+2 days'), $task['date_due'], '', 2);
|
||||
}
|
||||
}
|
||||
58
tests/units/Model/TaskExportTest.php
Normal file
58
tests/units/Model/TaskExportTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskExport;
|
||||
use Model\Project;
|
||||
use Model\Category;
|
||||
use Model\User;
|
||||
use Model\Swimlane;
|
||||
|
||||
class TaskExportTest extends Base
|
||||
{
|
||||
public function testExport()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
$e = new TaskExport($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Export Project')));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
|
||||
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
|
||||
$this->assertNotFalse($c->create(array('name' => 'Category #3', 'project_id' => 1)));
|
||||
|
||||
for ($i = 1; $i <= 100; $i++) {
|
||||
|
||||
$task = array(
|
||||
'title' => 'Task #'.$i,
|
||||
'project_id' => 1,
|
||||
'column_id' => rand(1, 3),
|
||||
'creator_id' => rand(0, 1),
|
||||
'owner_id' => rand(0, 1),
|
||||
'color_id' => rand(0, 1) === 0 ? 'green' : 'purple',
|
||||
'category_id' => rand(0, 3),
|
||||
'date_due' => array_rand(array(0, date('Y-m-d'), date('Y-m-d', strtotime('+'.$i.'day')))),
|
||||
'score' => rand(0, 21),
|
||||
'swimlane_id' => rand(0, 2),
|
||||
);
|
||||
|
||||
$this->assertEquals($i, $tc->create($task));
|
||||
}
|
||||
|
||||
$rows = $e->export(1, strtotime('-1 day'), strtotime('+1 day'));
|
||||
|
||||
$this->assertEquals($i, count($rows));
|
||||
$this->assertEquals('Task Id', $rows[0][0]);
|
||||
$this->assertEquals(1, $rows[1][0]);
|
||||
$this->assertEquals('Task #'.($i - 1), $rows[$i - 1][12]);
|
||||
$this->assertTrue(in_array($rows[$i - 1][4], array('Default swimlane', 'S1', 'S2')));
|
||||
}
|
||||
}
|
||||
629
tests/units/Model/TaskFilterTest.php
Normal file
629
tests/units/Model/TaskFilterTest.php
Normal file
@@ -0,0 +1,629 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Project;
|
||||
use Model\User;
|
||||
use Model\TaskFilter;
|
||||
use Model\TaskCreation;
|
||||
use Model\DateParser;
|
||||
use Model\Category;
|
||||
use Model\Subtask;
|
||||
use Model\Config;
|
||||
use Model\Swimlane;
|
||||
|
||||
class TaskFilterTest extends Base
|
||||
{
|
||||
public function testGetGanttbar()
|
||||
{
|
||||
$dp = new DateParser($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
|
||||
|
||||
$this->assertNotEmpty($tf->search('status:open')->toGanttBars());
|
||||
$this->assertNotEmpty($p->getGanttBars(array(1)));
|
||||
}
|
||||
|
||||
public function testIcalEventsWithCreatorAndDueDate()
|
||||
{
|
||||
$dp = new DateParser($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1', 'creator_id' => 1, 'date_due' => $dp->getTimestampFromIsoFormat('-2 days'))));
|
||||
|
||||
$events = $tf->create()->filterByDueDateRange(strtotime('-1 month'), strtotime('+1 month'))->addAllDayIcalEvents();
|
||||
$ics = $events->render();
|
||||
|
||||
$this->assertContains('UID:task-#1-date_due', $ics);
|
||||
$this->assertContains('DTSTART;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('-2 days')), $ics);
|
||||
$this->assertContains('DTEND;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('-2 days')), $ics);
|
||||
$this->assertContains('URL:http://localhost/?controller=task&action=show&task_id=1&project_id=1', $ics);
|
||||
$this->assertContains('SUMMARY:#1 task1', $ics);
|
||||
$this->assertContains('ATTENDEE:MAILTO:admin@kanboard.local', $ics);
|
||||
$this->assertContains('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE', $ics);
|
||||
}
|
||||
|
||||
public function testIcalEventsWithAssigneeAndDueDate()
|
||||
{
|
||||
$dp = new DateParser($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
$u = new User($this->container);
|
||||
$c = new Config($this->container);
|
||||
|
||||
$this->assertNotFalse($c->save(array('application_url' => 'http://kb/')));
|
||||
$this->assertEquals('http://kb/', $c->get('application_url'));
|
||||
|
||||
$this->assertNotFalse($u->update(array('id' => 1, 'email' => 'bob@localhost')));
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1', 'owner_id' => 1, 'date_due' => $dp->getTimestampFromIsoFormat('+5 days'))));
|
||||
|
||||
$events = $tf->create()->filterByDueDateRange(strtotime('-1 month'), strtotime('+1 month'))->addAllDayIcalEvents();
|
||||
$ics = $events->render();
|
||||
|
||||
$this->assertContains('UID:task-#1-date_due', $ics);
|
||||
$this->assertContains('DTSTART;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('+5 days')), $ics);
|
||||
$this->assertContains('DTEND;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('+5 days')), $ics);
|
||||
$this->assertContains('URL:http://kb/?controller=task&action=show&task_id=1&project_id=1', $ics);
|
||||
$this->assertContains('SUMMARY:#1 task1', $ics);
|
||||
$this->assertContains('ORGANIZER;CN=admin:MAILTO:bob@localhost', $ics);
|
||||
$this->assertContains('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE', $ics);
|
||||
}
|
||||
|
||||
public function testSearchWithEmptyResult()
|
||||
{
|
||||
$dp = new DateParser($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'date_due' => $dp->getTimestampFromIsoFormat('-2 days'))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'date_due' => $dp->getTimestampFromIsoFormat('+1 day'))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'date_due' => $dp->getTimestampFromIsoFormat('-1 day'))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'youpi', 'date_due' => $dp->getTimestampFromIsoFormat(time()))));
|
||||
|
||||
$this->assertEmpty($tf->search('search something')->findAll());
|
||||
}
|
||||
|
||||
public function testSearchWithEmptyInput()
|
||||
{
|
||||
$dp = new DateParser($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'date_due' => $dp->getTimestampFromIsoFormat('-2 days'))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'date_due' => $dp->getTimestampFromIsoFormat('+1 day'))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'date_due' => $dp->getTimestampFromIsoFormat('-1 day'))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'youpi', 'date_due' => $dp->getTimestampFromIsoFormat(time()))));
|
||||
|
||||
$result = $tf->search('')->findAll();
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertCount(4, $result);
|
||||
}
|
||||
|
||||
public function testSearchById()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task 43')));
|
||||
|
||||
$tf->search('#2');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task2', $tasks[0]['title']);
|
||||
|
||||
$tf->search('1');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
|
||||
$tf->search('something');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
|
||||
$tf->search('#');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
|
||||
$tf->search('#abcd');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
|
||||
$tf->search('task1');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
|
||||
$tf->search('43');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task 43', $tasks[0]['title']);
|
||||
}
|
||||
|
||||
public function testSearchWithReference()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'reference' => 123)));
|
||||
|
||||
$tf->search('ref:123');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task2', $tasks[0]['title']);
|
||||
|
||||
$tf->search('reference:123');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task2', $tasks[0]['title']);
|
||||
|
||||
$tf->search('ref:plop');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
|
||||
$tf->search('ref:');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
}
|
||||
|
||||
public function testSearchWithStatus()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'is_active' => 0)));
|
||||
|
||||
$tf->search('status:open');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
|
||||
$tf->search('status:plop');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(3, $tasks);
|
||||
|
||||
$tf->search('status:closed');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
}
|
||||
|
||||
public function testSearchWithDescription()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'description' => '**something to do**')));
|
||||
|
||||
$tf->search('description:"something"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task2', $tasks[0]['title']);
|
||||
|
||||
$tf->search('description:"rainy day"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
}
|
||||
|
||||
public function testSearchWithCategory()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $c->create(array('name' => 'Feature request', 'project_id' => 1)));
|
||||
$this->assertEquals(2, $c->create(array('name' => 'hé hé', 'project_id' => 1)));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'category_id' => 1)));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task3', 'category_id' => 2)));
|
||||
|
||||
$tf->search('category:"Feature request"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task2', $tasks[0]['title']);
|
||||
$this->assertEquals('Feature request', $tasks[0]['category_name']);
|
||||
|
||||
$tf->search('category:"hé hé"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task3', $tasks[0]['title']);
|
||||
$this->assertEquals('hé hé', $tasks[0]['category_name']);
|
||||
|
||||
$tf->search('category:"Feature request" category:"hé hé"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('task2', $tasks[0]['title']);
|
||||
$this->assertEquals('Feature request', $tasks[0]['category_name']);
|
||||
$this->assertEquals('task3', $tasks[1]['title']);
|
||||
$this->assertEquals('hé hé', $tasks[1]['category_name']);
|
||||
|
||||
$tf->search('category:none');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
$this->assertEquals('', $tasks[0]['category_name']);
|
||||
|
||||
$tf->search('category:"not found"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
}
|
||||
|
||||
public function testSearchWithProject()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'My project A')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'My project B')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 2, 'title' => 'task2')));
|
||||
|
||||
$tf->search('project:"My project A"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
$this->assertEquals('My project A', $tasks[0]['project_name']);
|
||||
|
||||
$tf->search('project:2');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task2', $tasks[0]['title']);
|
||||
$this->assertEquals('My project B', $tasks[0]['project_name']);
|
||||
|
||||
$tf->search('project:"My project A" project:"my project b"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
$this->assertEquals('My project A', $tasks[0]['project_name']);
|
||||
$this->assertEquals('task2', $tasks[1]['title']);
|
||||
$this->assertEquals('My project B', $tasks[1]['project_name']);
|
||||
|
||||
$tf->search('project:"not found"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
}
|
||||
|
||||
public function testSearchWithSwimlane()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'My project A')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Version 1.1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Version 1.2')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1', 'swimlane_id' => 1)));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'swimlane_id' => 2)));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task3', 'swimlane_id' => 0)));
|
||||
|
||||
$tf->search('swimlane:"Version 1.1"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
$this->assertEquals('Version 1.1', $tasks[0]['swimlane_name']);
|
||||
|
||||
$tf->search('swimlane:"versioN 1.2"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task2', $tasks[0]['title']);
|
||||
$this->assertEquals('Version 1.2', $tasks[0]['swimlane_name']);
|
||||
|
||||
$tf->search('swimlane:"Default swimlane"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task3', $tasks[0]['title']);
|
||||
$this->assertEquals('Default swimlane', $tasks[0]['default_swimlane']);
|
||||
$this->assertEquals('', $tasks[0]['swimlane_name']);
|
||||
|
||||
$tf->search('swimlane:default');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task3', $tasks[0]['title']);
|
||||
$this->assertEquals('Default swimlane', $tasks[0]['default_swimlane']);
|
||||
$this->assertEquals('', $tasks[0]['swimlane_name']);
|
||||
|
||||
$tf->search('swimlane:"Version 1.1" swimlane:"Version 1.2"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
$this->assertEquals('Version 1.1', $tasks[0]['swimlane_name']);
|
||||
$this->assertEquals('task2', $tasks[1]['title']);
|
||||
$this->assertEquals('Version 1.2', $tasks[1]['swimlane_name']);
|
||||
|
||||
$tf->search('swimlane:"not found"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
}
|
||||
|
||||
public function testSearchWithColumn()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'My project A')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'column_id' => 3)));
|
||||
|
||||
$tf->search('column:Backlog');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
$this->assertEquals('Backlog', $tasks[0]['column_name']);
|
||||
|
||||
$tf->search('column:backlog column:"Work in progress"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
$this->assertEquals('Backlog', $tasks[0]['column_name']);
|
||||
$this->assertEquals('task2', $tasks[1]['title']);
|
||||
$this->assertEquals('Work in progress', $tasks[1]['column_name']);
|
||||
|
||||
$tf->search('column:"not found"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
}
|
||||
|
||||
public function testSearchWithDueDate()
|
||||
{
|
||||
$dp = new DateParser($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'date_due' => $dp->getTimestampFromIsoFormat('-2 days'))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'date_due' => $dp->getTimestampFromIsoFormat('+1 day'))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'date_due' => $dp->getTimestampFromIsoFormat('-1 day'))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'youpi', 'date_due' => $dp->getTimestampFromIsoFormat(time()))));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'no due date')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'due date at 0', 'date_due' => 0)));
|
||||
|
||||
$tf->search('due:>'.date('Y-m-d'));
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
|
||||
|
||||
$tf->search('due:>='.date('Y-m-d'));
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
|
||||
$this->assertEquals('youpi', $tasks[1]['title']);
|
||||
|
||||
$tf->search('due:<'.date('Y-m-d'));
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('my task title is awesome', $tasks[0]['title']);
|
||||
$this->assertEquals('Bob at work', $tasks[1]['title']);
|
||||
|
||||
$tf->search('due:<='.date('Y-m-d'));
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(3, $tasks);
|
||||
$this->assertEquals('my task title is awesome', $tasks[0]['title']);
|
||||
$this->assertEquals('Bob at work', $tasks[1]['title']);
|
||||
$this->assertEquals('youpi', $tasks[2]['title']);
|
||||
|
||||
$tf->search('due:tomorrow');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
|
||||
|
||||
$tf->search('due:yesterday');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('Bob at work', $tasks[0]['title']);
|
||||
|
||||
$tf->search('due:today');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('youpi', $tasks[0]['title']);
|
||||
}
|
||||
|
||||
public function testSearchWithColor()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$u = new User($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'color_id' => 'light_green')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'color_id' => 'blue')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work')));
|
||||
|
||||
$tf->search('color:"Light Green"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('my task title is awesome', $tasks[0]['title']);
|
||||
|
||||
$tf->search('color:"Light Green" amazing');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
|
||||
$tf->search('color:"plop');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
|
||||
$tf->search('color:unknown');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(3, $tasks);
|
||||
|
||||
$tf->search('color:blue amazing');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
|
||||
|
||||
$tf->search('color:blue color:Yellow');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
|
||||
$this->assertEquals('Bob at work', $tasks[1]['title']);
|
||||
}
|
||||
|
||||
public function testSearchWithAssignee()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$u = new User($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan')));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'owner_id' => 1)));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'owner_id' => 0)));
|
||||
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'owner_id' => 2)));
|
||||
|
||||
$tf->search('assignee:john');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertEmpty($tasks);
|
||||
|
||||
$tf->search('assignee:admin my task title');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('my task title is awesome', $tasks[0]['title']);
|
||||
|
||||
$tf->search('my task title');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('my task title is awesome', $tasks[0]['title']);
|
||||
$this->assertEquals('my task title is amazing', $tasks[1]['title']);
|
||||
|
||||
$tf->search('my task title assignee:nobody');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
|
||||
|
||||
$tf->search('assignee:"Bob ryan" assignee:nobody');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
|
||||
$this->assertEquals('Bob at work', $tasks[1]['title']);
|
||||
}
|
||||
|
||||
public function testSearchWithAssigneeIncludingSubtasks()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$u = new User($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$tf = new TaskFilter($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Paul Ryan')));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'task1', 'owner_id' => 2)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'status' => 1, 'user_id' => 0)));
|
||||
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'task2', 'owner_id' => 0)));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 2, 'status' => 1, 'user_id' => 2)));
|
||||
|
||||
$this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'task3', 'owner_id' => 0)));
|
||||
$this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 3, 'user_id' => 1)));
|
||||
|
||||
$tf->search('assignee:bob');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
$this->assertEquals('task2', $tasks[1]['title']);
|
||||
|
||||
$tf->search('assignee:"Paul Ryan"');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('task1', $tasks[0]['title']);
|
||||
$this->assertEquals('task2', $tasks[1]['title']);
|
||||
|
||||
$tf->search('assignee:nobody');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('task2', $tasks[0]['title']);
|
||||
$this->assertEquals('task3', $tasks[1]['title']);
|
||||
|
||||
$tf->search('assignee:admin');
|
||||
$tasks = $tf->findAll();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('task3', $tasks[0]['title']);
|
||||
}
|
||||
|
||||
public function testCopy()
|
||||
{
|
||||
$tf = new TaskFilter($this->container);
|
||||
$filter1 = $tf->create();
|
||||
$filter2 = $tf->copy();
|
||||
|
||||
$this->assertTrue($filter1 !== $filter2);
|
||||
$this->assertTrue($filter1->query !== $filter2->query);
|
||||
$this->assertTrue($filter1->query->condition !== $filter2->query->condition);
|
||||
}
|
||||
}
|
||||
33
tests/units/Model/TaskFinderTest.php
Normal file
33
tests/units/Model/TaskFinderTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
use Model\Category;
|
||||
use Model\User;
|
||||
|
||||
class TaskFinderTest extends Base
|
||||
{
|
||||
public function testGetOverdueTasks()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #3', 'project_id' => 1)));
|
||||
|
||||
$tasks = $tf->getOverdueTasks();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertTrue(is_array($tasks));
|
||||
$this->assertEquals(1, count($tasks));
|
||||
$this->assertEquals('Task #1', $tasks[0]['title']);
|
||||
}
|
||||
}
|
||||
185
tests/units/Model/TaskLinkTest.php
Normal file
185
tests/units/Model/TaskLinkTest.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Link;
|
||||
use Model\TaskLink;
|
||||
use Model\TaskCreation;
|
||||
use Model\Project;
|
||||
|
||||
class TaskLinkTest extends Base
|
||||
{
|
||||
public function testCreateTaskLinkWithNoOpposite()
|
||||
{
|
||||
$tl = new TaskLink($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
|
||||
$this->assertEquals(1, $tl->create(1, 2, 1));
|
||||
|
||||
$links = $tl->getAll(1);
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(1, $links);
|
||||
$this->assertEquals('relates to', $links[0]['label']);
|
||||
$this->assertEquals('B', $links[0]['title']);
|
||||
$this->assertEquals(2, $links[0]['task_id']);
|
||||
$this->assertEquals(1, $links[0]['is_active']);
|
||||
|
||||
$links = $tl->getAll(2);
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(1, $links);
|
||||
$this->assertEquals('relates to', $links[0]['label']);
|
||||
$this->assertEquals('A', $links[0]['title']);
|
||||
$this->assertEquals(1, $links[0]['task_id']);
|
||||
$this->assertEquals(1, $links[0]['is_active']);
|
||||
|
||||
$task_link = $tl->getById(1);
|
||||
$this->assertNotEmpty($task_link);
|
||||
$this->assertEquals(1, $task_link['id']);
|
||||
$this->assertEquals(1, $task_link['task_id']);
|
||||
$this->assertEquals(2, $task_link['opposite_task_id']);
|
||||
$this->assertEquals(1, $task_link['link_id']);
|
||||
|
||||
$opposite_task_link = $tl->getOppositeTaskLink($task_link);
|
||||
$this->assertNotEmpty($opposite_task_link);
|
||||
$this->assertEquals(2, $opposite_task_link['id']);
|
||||
$this->assertEquals(2, $opposite_task_link['task_id']);
|
||||
$this->assertEquals(1, $opposite_task_link['opposite_task_id']);
|
||||
$this->assertEquals(1, $opposite_task_link['link_id']);
|
||||
}
|
||||
|
||||
public function testCreateTaskLinkWithOpposite()
|
||||
{
|
||||
$tl = new TaskLink($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
|
||||
$this->assertEquals(1, $tl->create(1, 2, 2));
|
||||
|
||||
$links = $tl->getAll(1);
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(1, $links);
|
||||
$this->assertEquals('blocks', $links[0]['label']);
|
||||
$this->assertEquals('B', $links[0]['title']);
|
||||
$this->assertEquals(2, $links[0]['task_id']);
|
||||
$this->assertEquals(1, $links[0]['is_active']);
|
||||
|
||||
$links = $tl->getAll(2);
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(1, $links);
|
||||
$this->assertEquals('is blocked by', $links[0]['label']);
|
||||
$this->assertEquals('A', $links[0]['title']);
|
||||
$this->assertEquals(1, $links[0]['task_id']);
|
||||
$this->assertEquals(1, $links[0]['is_active']);
|
||||
|
||||
$task_link = $tl->getById(1);
|
||||
$this->assertNotEmpty($task_link);
|
||||
$this->assertEquals(1, $task_link['id']);
|
||||
$this->assertEquals(1, $task_link['task_id']);
|
||||
$this->assertEquals(2, $task_link['opposite_task_id']);
|
||||
$this->assertEquals(2, $task_link['link_id']);
|
||||
|
||||
$opposite_task_link = $tl->getOppositeTaskLink($task_link);
|
||||
$this->assertNotEmpty($opposite_task_link);
|
||||
$this->assertEquals(2, $opposite_task_link['id']);
|
||||
$this->assertEquals(2, $opposite_task_link['task_id']);
|
||||
$this->assertEquals(1, $opposite_task_link['opposite_task_id']);
|
||||
$this->assertEquals(3, $opposite_task_link['link_id']);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$tl = new TaskLink($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'test2')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 2, 'title' => 'B')));
|
||||
$this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
|
||||
|
||||
$this->assertEquals(1, $tl->create(1, 2, 5));
|
||||
$this->assertTrue($tl->update(1, 1, 3, 11));
|
||||
|
||||
$links = $tl->getAll(1);
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(1, $links);
|
||||
$this->assertEquals('is fixed by', $links[0]['label']);
|
||||
$this->assertEquals('C', $links[0]['title']);
|
||||
$this->assertEquals(3, $links[0]['task_id']);
|
||||
|
||||
$links = $tl->getAll(2);
|
||||
$this->assertEmpty($links);
|
||||
|
||||
$links = $tl->getAll(3);
|
||||
$this->assertNotEmpty($links);
|
||||
$this->assertCount(1, $links);
|
||||
$this->assertEquals('fixes', $links[0]['label']);
|
||||
$this->assertEquals('A', $links[0]['title']);
|
||||
$this->assertEquals(1, $links[0]['task_id']);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$tl = new TaskLink($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
|
||||
$this->assertEquals(1, $tl->create(1, 2, 2));
|
||||
|
||||
$links = $tl->getAll(1);
|
||||
$this->assertNotEmpty($links);
|
||||
$links = $tl->getAll(2);
|
||||
$this->assertNotEmpty($links);
|
||||
|
||||
$this->assertTrue($tl->remove($links[0]['id']));
|
||||
|
||||
$links = $tl->getAll(1);
|
||||
$this->assertEmpty($links);
|
||||
$links = $tl->getAll(2);
|
||||
$this->assertEmpty($links);
|
||||
}
|
||||
|
||||
public function testValidation()
|
||||
{
|
||||
$tl = new TaskLink($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
|
||||
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
|
||||
|
||||
$links = $tl->getAll(1);
|
||||
$this->assertEmpty($links);
|
||||
|
||||
$links = $tl->getAll(2);
|
||||
$this->assertEmpty($links);
|
||||
|
||||
// Check validation
|
||||
$r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
}
|
||||
267
tests/units/Model/TaskModificationTest.php
Normal file
267
tests/units/Model/TaskModificationTest.php
Normal file
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskModification;
|
||||
use Model\TaskFinder;
|
||||
use Model\TaskStatus;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
|
||||
class TaskModificationTest extends Base
|
||||
{
|
||||
public function onCreateUpdate($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
|
||||
$event_data = $event->getAll();
|
||||
$this->assertNotEmpty($event_data);
|
||||
$this->assertEquals(1, $event_data['task_id']);
|
||||
$this->assertEquals('Task #1', $event_data['title']);
|
||||
}
|
||||
|
||||
public function onUpdate($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
|
||||
$event_data = $event->getAll();
|
||||
$this->assertNotEmpty($event_data);
|
||||
$this->assertEquals(1, $event_data['task_id']);
|
||||
$this->assertEquals('Task #1', $event_data['title']);
|
||||
}
|
||||
|
||||
public function onAssigneeChange($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
|
||||
$event_data = $event->getAll();
|
||||
$this->assertNotEmpty($event_data);
|
||||
$this->assertEquals(1, $event_data['task_id']);
|
||||
$this->assertEquals(1, $event_data['owner_id']);
|
||||
}
|
||||
|
||||
public function testChangeTitle()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate'));
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'title' => 'Task #1')));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.TaskModificationTest::onCreateUpdate', $called);
|
||||
$this->assertArrayHasKey(Task::EVENT_UPDATE.'.TaskModificationTest::onUpdate', $called);
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('Task #1', $task['title']);
|
||||
}
|
||||
|
||||
public function testChangeAssignee()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange'));
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'owner_id' => 1)));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_ASSIGNEE_CHANGE.'.TaskModificationTest::onAssigneeChange', $called);
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['owner_id']);
|
||||
}
|
||||
|
||||
public function testChangeDescription()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('', $task['description']);
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'description' => 'test')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('test', $task['description']);
|
||||
}
|
||||
|
||||
public function testChangeCategory()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'category_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['category_id']);
|
||||
}
|
||||
|
||||
public function testChangeColor()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('yellow', $task['color_id']);
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'color_id' => 'blue')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('blue', $task['color_id']);
|
||||
}
|
||||
|
||||
public function testChangeScore()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(0, $task['score']);
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'score' => 13)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(13, $task['score']);
|
||||
}
|
||||
|
||||
public function testChangeDueDate()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(0, $task['date_due']);
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'date_due' => '2014-11-24')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('2014-11-24', date('Y-m-d', $task['date_due']));
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'date_due' => time())));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(date('Y-m-d'), date('Y-m-d', $task['date_due']));
|
||||
}
|
||||
|
||||
public function testChangeStartedDate()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(0, $task['date_started']);
|
||||
|
||||
// Set only a date
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
|
||||
|
||||
// Set a datetime
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24 16:25')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
|
||||
|
||||
// Set a datetime
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24 6:25pm')));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
|
||||
|
||||
// Set a timestamp
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'date_started' => time())));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(time(), $task['date_started'], '', 1);
|
||||
}
|
||||
|
||||
public function testChangeTimeEstimated()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(0, $task['time_estimated']);
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'time_estimated' => 13.3)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(13.3, $task['time_estimated']);
|
||||
}
|
||||
|
||||
public function testChangeTimeSpent()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(0, $task['time_spent']);
|
||||
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'time_spent' => 13.3)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(13.3, $task['time_spent']);
|
||||
}
|
||||
}
|
||||
77
tests/units/Model/TaskMovedDateSubscriberTest.php
Normal file
77
tests/units/Model/TaskMovedDateSubscriberTest.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\TaskPosition;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Project;
|
||||
use Model\Swimlane;
|
||||
use Subscriber\TaskMovedDateSubscriber;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
|
||||
class TaskMovedDateSubscriberTest extends Base
|
||||
{
|
||||
public function testMoveTaskAnotherColumn()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
|
||||
$this->container['dispatcher'] = new EventDispatcher;
|
||||
$this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container));
|
||||
|
||||
$now = time();
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals($now, $task['date_moved'], '', 1);
|
||||
|
||||
sleep(1);
|
||||
|
||||
$this->assertTrue($tp->movePosition(1, 1, 2, 1));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotEquals($now, $task['date_moved']);
|
||||
}
|
||||
|
||||
public function testMoveTaskAnotherSwimlane()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->container['dispatcher'] = new EventDispatcher;
|
||||
$this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container));
|
||||
|
||||
$now = time();
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
|
||||
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals($now, $task['date_moved'], '', 1);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
sleep(1);
|
||||
|
||||
$this->assertTrue($tp->movePosition(1, 1, 2, 1, 2));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertNotEquals($now, $task['date_moved']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['swimlane_id']);
|
||||
}
|
||||
}
|
||||
105
tests/units/Model/TaskPermissionTest.php
Normal file
105
tests/units/Model/TaskPermissionTest.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\TaskPermission;
|
||||
use Model\Project;
|
||||
use Model\Category;
|
||||
use Model\User;
|
||||
use Model\UserSession;
|
||||
|
||||
class TaskPermissionTest extends Base
|
||||
{
|
||||
public function testPrepareCreation()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$tp = new TaskPermission($this->container);
|
||||
$p = new Project($this->container);
|
||||
$u = new User($this->container);
|
||||
$us = new UserSession($this->container);
|
||||
|
||||
$this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456')));
|
||||
$this->assertNotFalse($u->create(array('username' => 'toto2', 'password' => '123456')));
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1)));
|
||||
|
||||
// User #1 can remove everything
|
||||
$user = $u->getbyId(1);
|
||||
$this->assertNotEmpty($user);
|
||||
$us->refresh($user);
|
||||
|
||||
$task = $tf->getbyId(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertTrue($tp->canRemoveTask($task));
|
||||
|
||||
// User #2 can't remove the task #1
|
||||
$user = $u->getbyId(2);
|
||||
$this->assertNotEmpty($user);
|
||||
$us->refresh($user);
|
||||
|
||||
$task = $tf->getbyId(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertFalse($tp->canRemoveTask($task));
|
||||
|
||||
// User #1 can remove everything
|
||||
$user = $u->getbyId(1);
|
||||
$this->assertNotEmpty($user);
|
||||
$us->refresh($user);
|
||||
|
||||
$task = $tf->getbyId(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertTrue($tp->canRemoveTask($task));
|
||||
|
||||
// User #2 can remove his own task
|
||||
$user = $u->getbyId(2);
|
||||
$this->assertNotEmpty($user);
|
||||
$us->refresh($user);
|
||||
|
||||
$task = $tf->getbyId(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertTrue($tp->canRemoveTask($task));
|
||||
|
||||
// User #1 can remove everything
|
||||
$user = $u->getbyId(1);
|
||||
$this->assertNotEmpty($user);
|
||||
$us->refresh($user);
|
||||
|
||||
$task = $tf->getbyId(3);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertTrue($tp->canRemoveTask($task));
|
||||
|
||||
// User #2 can't remove the task #3
|
||||
$user = $u->getbyId(2);
|
||||
$this->assertNotEmpty($user);
|
||||
$us->refresh($user);
|
||||
|
||||
$task = $tf->getbyId(3);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertFalse($tp->canRemoveTask($task));
|
||||
|
||||
// User #1 can remove everything
|
||||
$user = $u->getbyId(1);
|
||||
$this->assertNotEmpty($user);
|
||||
$us->refresh($user);
|
||||
|
||||
$task = $tf->getbyId(4);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertTrue($tp->canRemoveTask($task));
|
||||
|
||||
// User #2 can't remove the task #4
|
||||
$user = $u->getbyId(2);
|
||||
$this->assertNotEmpty($user);
|
||||
$us->refresh($user);
|
||||
|
||||
$task = $tf->getbyId(4);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertFalse($tp->canRemoveTask($task));
|
||||
}
|
||||
}
|
||||
634
tests/units/Model/TaskPositionTest.php
Normal file
634
tests/units/Model/TaskPositionTest.php
Normal file
@@ -0,0 +1,634 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\Board;
|
||||
use Model\TaskStatus;
|
||||
use Model\TaskPosition;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Project;
|
||||
use Model\Swimlane;
|
||||
|
||||
class TaskPositionTest extends Base
|
||||
{
|
||||
public function testGetTaskProgression()
|
||||
{
|
||||
$t = new Task($this->container);
|
||||
$ts = new TaskStatus($this->container);
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$b = new Board($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(0, $t->getProgress($tf->getById(1), $b->getColumnsList(1)));
|
||||
|
||||
$this->assertTrue($tp->movePosition(1, 1, 2, 1));
|
||||
$this->assertEquals(25, $t->getProgress($tf->getById(1), $b->getColumnsList(1)));
|
||||
|
||||
$this->assertTrue($tp->movePosition(1, 1, 3, 1));
|
||||
$this->assertEquals(50, $t->getProgress($tf->getById(1), $b->getColumnsList(1)));
|
||||
|
||||
$this->assertTrue($tp->movePosition(1, 1, 4, 1));
|
||||
$this->assertEquals(75, $t->getProgress($tf->getById(1), $b->getColumnsList(1)));
|
||||
|
||||
$this->assertTrue($ts->close(1));
|
||||
$this->assertEquals(100, $t->getProgress($tf->getById(1), $b->getColumnsList(1)));
|
||||
}
|
||||
|
||||
public function testMoveTaskToWrongPosition()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// We move the task 2 to the position 0
|
||||
$this->assertFalse($tp->movePosition(1, 1, 3, 0));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskToGreaterPosition()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// We move the task 2 to the position 42
|
||||
$this->assertTrue($tp->movePosition(1, 1, 1, 42));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskToEmptyColumn()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// We move the task 2 to the column 3
|
||||
$this->assertTrue($tp->movePosition(1, 1, 3, 1));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskToAnotherColumn()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
|
||||
$this->assertEquals(7, $tc->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
|
||||
$this->assertEquals(8, $tc->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// We move the task 3 to the column 3
|
||||
$this->assertTrue($tp->movePosition(1, 3, 3, 2));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(6);
|
||||
$this->assertEquals(6, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$task = $tf->getById(7);
|
||||
$this->assertEquals(7, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(8);
|
||||
$this->assertEquals(8, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskTop()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// Move the last task to the top
|
||||
$this->assertTrue($tp->movePosition(1, 4, 1, 1));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
}
|
||||
|
||||
public function testMoveTaskBottom()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// Move the last task to the bottom
|
||||
$this->assertTrue($tp->movePosition(1, 1, 1, 4));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
}
|
||||
|
||||
public function testMovePosition()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$counter = 1;
|
||||
$task_per_column = 5;
|
||||
|
||||
foreach (array(1, 2, 3, 4) as $column_id) {
|
||||
|
||||
for ($i = 1; $i <= $task_per_column; $i++, $counter++) {
|
||||
|
||||
$task = array(
|
||||
'title' => 'Task #'.$i.'-'.$column_id,
|
||||
'project_id' => 1,
|
||||
'column_id' => $column_id,
|
||||
'owner_id' => 0,
|
||||
);
|
||||
|
||||
$this->assertEquals($counter, $tc->create($task));
|
||||
|
||||
$task = $tf->getById($counter);
|
||||
$this->assertNotFalse($task);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals($i, $task['position']);
|
||||
}
|
||||
}
|
||||
|
||||
// We move task id #4, column 1, position 4 to the column 2, position 3
|
||||
$this->assertTrue($tp->movePosition(1, 4, 2, 3));
|
||||
|
||||
// We check the new position of the task
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
// The tasks before have the correct position
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$task = $tf->getById(7);
|
||||
$this->assertEquals(7, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
// The tasks after have the correct position
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
$task = $tf->getById(8);
|
||||
$this->assertEquals(8, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(4, $task['position']);
|
||||
|
||||
// The number of tasks per column
|
||||
$this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 4));
|
||||
|
||||
// We move task id #1, column 1, position 1 to the column 4, position 6 (last position)
|
||||
$this->assertTrue($tp->movePosition(1, 1, 4, $task_per_column + 1));
|
||||
|
||||
// We check the new position of the task
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(4, $task['column_id']);
|
||||
$this->assertEquals($task_per_column + 1, $task['position']);
|
||||
|
||||
// The tasks before have the correct position
|
||||
$task = $tf->getById(20);
|
||||
$this->assertEquals(20, $task['id']);
|
||||
$this->assertEquals(4, $task['column_id']);
|
||||
$this->assertEquals($task_per_column, $task['position']);
|
||||
|
||||
// The tasks after have the correct position
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
// The number of tasks per column
|
||||
$this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
|
||||
|
||||
// Our previous moved task should stay at the same place
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
// Test wrong position number
|
||||
$this->assertFalse($tp->movePosition(1, 2, 3, 0));
|
||||
$this->assertFalse($tp->movePosition(1, 2, 3, -2));
|
||||
|
||||
// Wrong column
|
||||
$this->assertFalse($tp->movePosition(1, 2, 22, 2));
|
||||
|
||||
// Test position greater than the last position
|
||||
$this->assertTrue($tp->movePosition(1, 11, 1, 22));
|
||||
|
||||
$task = $tf->getById(11);
|
||||
$this->assertEquals(11, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals($tf->countByColumnId(1, 1), $task['position']);
|
||||
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
$this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
|
||||
|
||||
// Our previous moved task should stay at the same place
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
|
||||
// Test moving task to position 1
|
||||
$this->assertTrue($tp->movePosition(1, 14, 1, 1));
|
||||
|
||||
$task = $tf->getById(14);
|
||||
$this->assertEquals(14, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$this->assertEquals($task_per_column, $tf->countByColumnId(1, 1));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
|
||||
$this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 3));
|
||||
$this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
|
||||
}
|
||||
|
||||
public function testMoveTaskSwimlane()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// Move the task to the swimlane
|
||||
$this->assertTrue($tp->movePosition(1, 1, 2, 1, 1));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(1, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(3, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
// Move the task to the swimlane
|
||||
$this->assertTrue($tp->movePosition(1, 2, 2, 1, 1));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
$this->assertEquals(1, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(1, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
// Move the task 5 to the last column
|
||||
$this->assertTrue($tp->movePosition(1, 5, 4, 1, 0));
|
||||
|
||||
// Check tasks position
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
$this->assertEquals(1, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(1, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(3);
|
||||
$this->assertEquals(3, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(4);
|
||||
$this->assertEquals(4, $task['id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(5);
|
||||
$this->assertEquals(5, $task['id']);
|
||||
$this->assertEquals(4, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
}
|
||||
|
||||
public function testEvents()
|
||||
{
|
||||
$tp = new TaskPosition($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$s = new Swimlane($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1')));
|
||||
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2)));
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn'));
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_MOVE_POSITION, array($this, 'onMovePosition'));
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane'));
|
||||
|
||||
// We move the task 1 to the column 2
|
||||
$this->assertTrue($tp->movePosition(1, 1, 2, 1));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called);
|
||||
$this->assertEquals(1, count($called));
|
||||
|
||||
// We move the task 1 to the position 2
|
||||
$this->assertTrue($tp->movePosition(1, 1, 2, 2));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(2, $task['position']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called);
|
||||
$this->assertEquals(2, count($called));
|
||||
|
||||
// Move to another swimlane
|
||||
$this->assertTrue($tp->movePosition(1, 1, 3, 1, 1));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(1, $task['swimlane_id']);
|
||||
|
||||
$task = $tf->getById(2);
|
||||
$this->assertEquals(2, $task['id']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
$this->assertEquals(0, $task['swimlane_id']);
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(Task::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called);
|
||||
$this->assertEquals(3, count($called));
|
||||
}
|
||||
|
||||
public function onMoveColumn($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
|
||||
$event_data = $event->getAll();
|
||||
$this->assertNotEmpty($event_data);
|
||||
$this->assertEquals(1, $event_data['task_id']);
|
||||
$this->assertEquals(1, $event_data['position']);
|
||||
$this->assertEquals(2, $event_data['column_id']);
|
||||
$this->assertEquals(1, $event_data['project_id']);
|
||||
}
|
||||
|
||||
public function onMovePosition($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
|
||||
$event_data = $event->getAll();
|
||||
$this->assertNotEmpty($event_data);
|
||||
$this->assertEquals(1, $event_data['task_id']);
|
||||
$this->assertEquals(2, $event_data['position']);
|
||||
$this->assertEquals(2, $event_data['column_id']);
|
||||
$this->assertEquals(1, $event_data['project_id']);
|
||||
}
|
||||
|
||||
public function onMoveSwimlane($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
|
||||
$event_data = $event->getAll();
|
||||
$this->assertNotEmpty($event_data);
|
||||
$this->assertEquals(1, $event_data['task_id']);
|
||||
$this->assertEquals(1, $event_data['position']);
|
||||
$this->assertEquals(3, $event_data['column_id']);
|
||||
$this->assertEquals(1, $event_data['project_id']);
|
||||
$this->assertEquals(1, $event_data['swimlane_id']);
|
||||
}
|
||||
}
|
||||
101
tests/units/Model/TaskStatusTest.php
Normal file
101
tests/units/Model/TaskStatusTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Subtask;
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\TaskStatus;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
|
||||
class TaskStatusTest extends Base
|
||||
{
|
||||
public function testStatus()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$ts = new TaskStatus($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
|
||||
|
||||
// The task must be open
|
||||
|
||||
$this->assertTrue($ts->isOpen(1));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
|
||||
$this->assertEquals(0, $task['date_completed']);
|
||||
$this->assertEquals(time(), $task['date_modification'], '', 1);
|
||||
|
||||
// We close the task
|
||||
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_CLOSE, array($this, 'onTaskClose'));
|
||||
$this->container['dispatcher']->addListener(Task::EVENT_OPEN, array($this, 'onTaskOpen'));
|
||||
|
||||
$this->assertTrue($ts->close(1));
|
||||
$this->assertTrue($ts->isClosed(1));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(Task::STATUS_CLOSED, $task['is_active']);
|
||||
$this->assertEquals(time(), $task['date_completed'], 'Bad completion timestamp', 1);
|
||||
$this->assertEquals(time(), $task['date_modification'], 'Bad modification timestamp', 1);
|
||||
|
||||
// We open the task again
|
||||
|
||||
$this->assertTrue($ts->open(1));
|
||||
$this->assertTrue($ts->isOpen(1));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
|
||||
$this->assertEquals(0, $task['date_completed']);
|
||||
$this->assertEquals(time(), $task['date_modification'], '', 1);
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey('task.close.TaskStatusTest::onTaskClose', $called);
|
||||
$this->assertArrayHasKey('task.open.TaskStatusTest::onTaskOpen', $called);
|
||||
}
|
||||
|
||||
public function onTaskOpen($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
$this->assertArrayHasKey('task_id', $event);
|
||||
$this->assertNotEmpty($event['task_id']);
|
||||
}
|
||||
|
||||
public function onTaskClose($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\TaskEvent', $event);
|
||||
$this->assertArrayHasKey('task_id', $event);
|
||||
$this->assertNotEmpty($event['task_id']);
|
||||
}
|
||||
|
||||
public function testThatAllSubtasksAreClosed()
|
||||
{
|
||||
$ts = new TaskStatus($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
|
||||
|
||||
$this->assertTrue($ts->close(1));
|
||||
|
||||
$subtasks = $s->getAll(1);
|
||||
$this->assertNotEmpty($subtasks);
|
||||
|
||||
foreach ($subtasks as $subtask) {
|
||||
$this->assertEquals(Subtask::STATUS_DONE, $subtask['status']);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
tests/units/Model/TaskTest.php
Normal file
29
tests/units/Model/TaskTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\TaskStatus;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
use Model\Category;
|
||||
use Model\User;
|
||||
|
||||
class TaskTest extends Base
|
||||
{
|
||||
public function testRemove()
|
||||
{
|
||||
$t = new Task($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
|
||||
|
||||
$this->assertTrue($t->remove(1));
|
||||
$this->assertFalse($t->remove(1234));
|
||||
}
|
||||
}
|
||||
256
tests/units/Model/TimetableTest.php
Normal file
256
tests/units/Model/TimetableTest.php
Normal file
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\User;
|
||||
use Model\Timetable;
|
||||
use Model\TimetableDay;
|
||||
use Model\TimetableWeek;
|
||||
use Model\TimetableOff;
|
||||
use Model\TimetableExtra;
|
||||
|
||||
class TimetableTest extends Base
|
||||
{
|
||||
public function testCalculateWorkDays()
|
||||
{
|
||||
$w = new TimetableWeek($this->container);
|
||||
$t = new Timetable($this->container);
|
||||
|
||||
$this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
|
||||
|
||||
$monday = new DateTime('next Monday');
|
||||
|
||||
$timetable = $t->calculate(1, $monday, new DateTime('next Monday + 6 days'));
|
||||
$this->assertNotEmpty($timetable);
|
||||
$this->assertCount(4, $timetable);
|
||||
|
||||
$this->assertEquals($monday->format('Y-m-d').' 09:30', $timetable[0][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 12:00', $timetable[0][1]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 13:00', $timetable[1][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 17:00', $timetable[1][1]->format('Y-m-d H:i'));
|
||||
|
||||
$this->assertEquals($monday->add(new DateInterval('P1D'))->format('Y-m-d').' 09:30', $timetable[2][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 12:00', $timetable[2][1]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 13:00', $timetable[3][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 17:00', $timetable[3][1]->format('Y-m-d H:i'));
|
||||
}
|
||||
|
||||
public function testCalculateOverTime()
|
||||
{
|
||||
$d = new TimetableDay($this->container);
|
||||
$w = new TimetableWeek($this->container);
|
||||
$e = new TimetableExtra($this->container);
|
||||
$t = new Timetable($this->container);
|
||||
|
||||
$monday = new DateTime('next Monday');
|
||||
$tuesday = new DateTime('next Monday + 1 day');
|
||||
$friday = new DateTime('next Monday + 4 days');
|
||||
|
||||
$this->assertNotFalse($d->create(1, '08:00', '12:00'));
|
||||
$this->assertNotFalse($d->create(1, '14:00', '18:00'));
|
||||
|
||||
$this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
|
||||
|
||||
$this->assertNotFalse($e->create(1, $tuesday->format('Y-m-d'), 0, '17:00', '22:00'));
|
||||
$this->assertNotFalse($e->create(1, $friday->format('Y-m-d'), 1));
|
||||
|
||||
$timetable = $t->calculate(1, $monday, new DateTime('next Monday + 6 days'));
|
||||
$this->assertNotEmpty($timetable);
|
||||
$this->assertCount(7, $timetable);
|
||||
|
||||
$this->assertEquals($monday->format('Y-m-d').' 09:30', $timetable[0][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 12:00', $timetable[0][1]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 13:00', $timetable[1][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 17:00', $timetable[1][1]->format('Y-m-d H:i'));
|
||||
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 09:30', $timetable[2][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 12:00', $timetable[2][1]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 13:00', $timetable[3][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 17:00', $timetable[3][1]->format('Y-m-d H:i'));
|
||||
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 17:00', $timetable[4][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 22:00', $timetable[4][1]->format('Y-m-d H:i'));
|
||||
|
||||
$this->assertEquals($friday->format('Y-m-d').' 08:00', $timetable[5][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($friday->format('Y-m-d').' 12:00', $timetable[5][1]->format('Y-m-d H:i'));
|
||||
|
||||
$this->assertEquals($friday->format('Y-m-d').' 14:00', $timetable[6][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($friday->format('Y-m-d').' 18:00', $timetable[6][1]->format('Y-m-d H:i'));
|
||||
}
|
||||
|
||||
public function testCalculateTimeOff()
|
||||
{
|
||||
$d = new TimetableDay($this->container);
|
||||
$w = new TimetableWeek($this->container);
|
||||
$o = new TimetableOff($this->container);
|
||||
$t = new Timetable($this->container);
|
||||
|
||||
$monday = new DateTime('next Monday');
|
||||
$tuesday = new DateTime('next Monday + 1 day');
|
||||
$friday = new DateTime('next Monday + 4 days');
|
||||
|
||||
$this->assertNotFalse($d->create(1, '08:00', '12:00'));
|
||||
$this->assertNotFalse($d->create(1, '14:00', '18:00'));
|
||||
|
||||
$this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
|
||||
$this->assertNotFalse($w->create(1, 5, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 5, '13:00', '17:00'));
|
||||
|
||||
$this->assertNotFalse($o->create(1, $tuesday->format('Y-m-d'), 0, '14:00', '15:00'));
|
||||
$this->assertNotFalse($o->create(1, $monday->format('Y-m-d'), 1));
|
||||
|
||||
$timetable = $t->calculate(1, $monday, new DateTime('next Monday + 6 days'));
|
||||
$this->assertNotEmpty($timetable);
|
||||
$this->assertCount(5, $timetable);
|
||||
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 09:30', $timetable[0][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 12:00', $timetable[0][1]->format('Y-m-d H:i'));
|
||||
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 13:00', $timetable[1][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 14:00', $timetable[1][1]->format('Y-m-d H:i'));
|
||||
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 15:00', $timetable[2][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 17:00', $timetable[2][1]->format('Y-m-d H:i'));
|
||||
|
||||
$this->assertEquals($friday->format('Y-m-d').' 09:30', $timetable[3][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($friday->format('Y-m-d').' 12:00', $timetable[3][1]->format('Y-m-d H:i'));
|
||||
|
||||
$this->assertEquals($friday->format('Y-m-d').' 13:00', $timetable[4][0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($friday->format('Y-m-d').' 17:00', $timetable[4][1]->format('Y-m-d H:i'));
|
||||
}
|
||||
|
||||
public function testClosestTimeSlot()
|
||||
{
|
||||
$w = new TimetableWeek($this->container);
|
||||
$t = new Timetable($this->container);
|
||||
|
||||
$this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
|
||||
|
||||
$monday = new DateTime('next Monday');
|
||||
$tuesday = new DateTime('next Monday + 1 day');
|
||||
|
||||
$timetable = $t->calculate(1, new DateTime('next Monday'), new DateTime('next Monday + 6 days'));
|
||||
$this->assertNotEmpty($timetable);
|
||||
$this->assertCount(4, $timetable);
|
||||
|
||||
// Start to work before timetable
|
||||
$date = clone($monday);
|
||||
$date->setTime(5, 02);
|
||||
|
||||
$slot = $t->findClosestTimeSlot($date, $timetable);
|
||||
$this->assertNotEmpty($slot);
|
||||
$this->assertEquals($monday->format('Y-m-d').' 09:30', $slot[0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 12:00', $slot[1]->format('Y-m-d H:i'));
|
||||
|
||||
// Start to work at the end of the timeslot
|
||||
$date = clone($monday);
|
||||
$date->setTime(12, 02);
|
||||
|
||||
$slot = $t->findClosestTimeSlot($date, $timetable);
|
||||
$this->assertNotEmpty($slot);
|
||||
$this->assertEquals($monday->format('Y-m-d').' 09:30', $slot[0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 12:00', $slot[1]->format('Y-m-d H:i'));
|
||||
|
||||
// Start to work at lunch time
|
||||
$date = clone($monday);
|
||||
$date->setTime(12, 32);
|
||||
|
||||
$slot = $t->findClosestTimeSlot($date, $timetable);
|
||||
$this->assertNotEmpty($slot);
|
||||
$this->assertEquals($monday->format('Y-m-d').' 13:00', $slot[0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($monday->format('Y-m-d').' 17:00', $slot[1]->format('Y-m-d H:i'));
|
||||
|
||||
// Start to work early in the morning
|
||||
$date = clone($tuesday);
|
||||
$date->setTime(8, 02);
|
||||
|
||||
$slot = $t->findClosestTimeSlot($date, $timetable);
|
||||
$this->assertNotEmpty($slot);
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 09:30', $slot[0]->format('Y-m-d H:i'));
|
||||
$this->assertEquals($tuesday->format('Y-m-d').' 12:00', $slot[1]->format('Y-m-d H:i'));
|
||||
}
|
||||
|
||||
public function testCalculateDuration()
|
||||
{
|
||||
$w = new TimetableWeek($this->container);
|
||||
$t = new Timetable($this->container);
|
||||
|
||||
$this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
|
||||
$this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
|
||||
|
||||
$monday = new DateTime('next Monday');
|
||||
$tuesday = new DateTime('next Monday + 1 day');
|
||||
|
||||
// Different day
|
||||
$start = clone($monday);
|
||||
$start->setTime(16, 02);
|
||||
|
||||
$end = clone($tuesday);
|
||||
$end->setTime(10, 03);
|
||||
|
||||
$this->assertEquals(1.5, $t->calculateEffectiveDuration(1, $start, $end));
|
||||
|
||||
// Same time slot
|
||||
$start = clone($monday);
|
||||
$start->setTime(16, 02);
|
||||
|
||||
$end = clone($monday);
|
||||
$end->setTime(17, 03);
|
||||
|
||||
$this->assertEquals(1, $t->calculateEffectiveDuration(1, $start, $end));
|
||||
|
||||
// Intermediate time slot
|
||||
$start = clone($monday);
|
||||
$start->setTime(10, 02);
|
||||
|
||||
$end = clone($tuesday);
|
||||
$end->setTime(16, 03);
|
||||
|
||||
$this->assertEquals(11.5, $t->calculateEffectiveDuration(1, $start, $end));
|
||||
|
||||
// Different day
|
||||
$start = clone($monday);
|
||||
$start->setTime(9, 02);
|
||||
|
||||
$end = clone($tuesday);
|
||||
$end->setTime(10, 03);
|
||||
|
||||
$this->assertEquals(7, $t->calculateEffectiveDuration(1, $start, $end));
|
||||
|
||||
// Start before first time slot
|
||||
$start = clone($monday);
|
||||
$start->setTime(5, 32);
|
||||
|
||||
$end = clone($tuesday);
|
||||
$end->setTime(11, 17);
|
||||
|
||||
$this->assertEquals(8.25, $t->calculateEffectiveDuration(1, $start, $end));
|
||||
}
|
||||
|
||||
public function testCalculateDurationWithEmptyTimetable()
|
||||
{
|
||||
$t = new Timetable($this->container);
|
||||
|
||||
$start = new DateTime('next Monday');
|
||||
$start->setTime(16, 02);
|
||||
|
||||
$end = new DateTime('next Monday');
|
||||
$end->setTime(17, 03);
|
||||
|
||||
$this->assertEquals(1, $t->calculateEffectiveDuration(1, $start, $end));
|
||||
}
|
||||
}
|
||||
32
tests/units/Model/UserSessionTest.php
Normal file
32
tests/units/Model/UserSessionTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Core\Session;
|
||||
use Model\UserSession;
|
||||
|
||||
class UserSessionTest extends Base
|
||||
{
|
||||
public function testIsAdmin()
|
||||
{
|
||||
$s = new Session;
|
||||
$us = new UserSession($this->container);
|
||||
|
||||
$this->assertFalse($us->isAdmin());
|
||||
|
||||
$s['user'] = array();
|
||||
$this->assertFalse($us->isAdmin());
|
||||
|
||||
$s['user'] = array('is_admin' => '1');
|
||||
$this->assertFalse($us->isAdmin());
|
||||
|
||||
$s['user'] = array('is_admin' => false);
|
||||
$this->assertFalse($us->isAdmin());
|
||||
|
||||
$s['user'] = array('is_admin' => '2');
|
||||
$this->assertFalse($us->isAdmin());
|
||||
|
||||
$s['user'] = array('is_admin' => true);
|
||||
$this->assertTrue($us->isAdmin());
|
||||
}
|
||||
}
|
||||
273
tests/units/Model/UserTest.php
Normal file
273
tests/units/Model/UserTest.php
Normal file
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\User;
|
||||
use Model\Subtask;
|
||||
use Model\Comment;
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Project;
|
||||
|
||||
class UserTest extends Base
|
||||
{
|
||||
public function testFailedLogin()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(0, $u->getFailedLogin('admin'));
|
||||
$this->assertEquals(0, $u->getFailedLogin('not_found'));
|
||||
|
||||
$this->assertTrue($u->incrementFailedLogin('admin'));
|
||||
$this->assertTrue($u->incrementFailedLogin('admin'));
|
||||
|
||||
$this->assertEquals(2, $u->getFailedLogin('admin'));
|
||||
$this->assertTrue($u->resetFailedLogin('admin'));
|
||||
$this->assertEquals(0, $u->getFailedLogin('admin'));
|
||||
}
|
||||
|
||||
public function testLocking()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertFalse($u->isLocked('admin'));
|
||||
$this->assertFalse($u->isLocked('not_found'));
|
||||
$this->assertTrue($u->lock('admin', 1));
|
||||
$this->assertTrue($u->isLocked('admin'));
|
||||
}
|
||||
|
||||
public function testGetByEmail()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost')));
|
||||
$this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'email' => '')));
|
||||
|
||||
$this->assertNotEmpty($u->getByEmail('user1@localhost'));
|
||||
$this->assertEmpty($u->getByEmail(''));
|
||||
}
|
||||
|
||||
public function testGetByGitlabId()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234')));
|
||||
|
||||
$this->assertNotEmpty($u->getByGitlabId('1234'));
|
||||
$this->assertEmpty($u->getByGitlabId(''));
|
||||
}
|
||||
|
||||
public function testGetByGithubId()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'github_id' => 'plop')));
|
||||
$this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'github_id' => '')));
|
||||
|
||||
$this->assertNotEmpty($u->getByGithubId('plop'));
|
||||
$this->assertEmpty($u->getByGithubId(''));
|
||||
}
|
||||
|
||||
public function testGetByGoogleId()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'google_id' => '1234')));
|
||||
$this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'google_id' => '')));
|
||||
|
||||
$this->assertNotEmpty($u->getByGoogleId('1234'));
|
||||
$this->assertEmpty($u->getByGoogleId(''));
|
||||
}
|
||||
|
||||
public function testPassword()
|
||||
{
|
||||
$password = 'test123';
|
||||
$hash = password_hash($password, PASSWORD_BCRYPT);
|
||||
|
||||
$this->assertNotEmpty($hash);
|
||||
$this->assertTrue(password_verify($password, $hash));
|
||||
}
|
||||
|
||||
public function testPrepare()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
|
||||
$input = array(
|
||||
'username' => 'user1',
|
||||
'password' => '1234',
|
||||
'confirmation' => '1234',
|
||||
'name' => 'me',
|
||||
'is_admin' => '',
|
||||
);
|
||||
|
||||
$u->prepare($input);
|
||||
$this->assertArrayNotHasKey('confirmation', $input);
|
||||
|
||||
$this->assertArrayHasKey('password', $input);
|
||||
$this->assertNotEquals('1234', $input['password']);
|
||||
$this->assertNotEmpty($input['password']);
|
||||
|
||||
$this->assertArrayHasKey('is_admin', $input);
|
||||
$this->assertInternalType('integer', $input['is_admin']);
|
||||
|
||||
$input = array(
|
||||
'username' => 'user1',
|
||||
'password' => '1234',
|
||||
'current_password' => 'bla',
|
||||
'confirmation' => '1234',
|
||||
'name' => 'me',
|
||||
'is_ldap_user' => '1',
|
||||
);
|
||||
|
||||
$u->prepare($input);
|
||||
$this->assertArrayNotHasKey('confirmation', $input);
|
||||
$this->assertArrayNotHasKey('current_password', $input);
|
||||
|
||||
$this->assertArrayHasKey('password', $input);
|
||||
$this->assertNotEquals('1234', $input['password']);
|
||||
$this->assertNotEmpty($input['password']);
|
||||
|
||||
$this->assertArrayHasKey('is_ldap_user', $input);
|
||||
$this->assertEquals(1, $input['is_ldap_user']);
|
||||
|
||||
$input = array(
|
||||
'id' => 2,
|
||||
'name' => 'me',
|
||||
);
|
||||
|
||||
$u->prepare($input);
|
||||
$this->assertEquals(array('id' => 2, 'name' => 'me'), $input);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
|
||||
$this->assertNotFalse($u->create(array('username' => 'titi', 'is_ldap_user' => 1)));
|
||||
$this->assertNotFalse($u->create(array('username' => 'papa', 'is_project_admin' => 1)));
|
||||
$this->assertFalse($u->create(array('username' => 'toto')));
|
||||
|
||||
$user = $u->getById(1);
|
||||
$this->assertNotFalse($user);
|
||||
$this->assertTrue(is_array($user));
|
||||
$this->assertEquals('admin', $user['username']);
|
||||
$this->assertEquals('', $user['name']);
|
||||
$this->assertEquals(1, $user['is_admin']);
|
||||
$this->assertEquals(0, $user['is_ldap_user']);
|
||||
|
||||
$user = $u->getById(2);
|
||||
$this->assertNotFalse($user);
|
||||
$this->assertTrue(is_array($user));
|
||||
$this->assertEquals('toto', $user['username']);
|
||||
$this->assertEquals('Toto', $user['name']);
|
||||
$this->assertEquals(0, $user['is_admin']);
|
||||
$this->assertEquals(0, $user['is_ldap_user']);
|
||||
|
||||
$user = $u->getById(3);
|
||||
$this->assertNotFalse($user);
|
||||
$this->assertTrue(is_array($user));
|
||||
$this->assertEquals('titi', $user['username']);
|
||||
$this->assertEquals('', $user['name']);
|
||||
$this->assertEquals(0, $user['is_admin']);
|
||||
$this->assertEquals(1, $user['is_ldap_user']);
|
||||
|
||||
$user = $u->getById(4);
|
||||
$this->assertNotFalse($user);
|
||||
$this->assertTrue(is_array($user));
|
||||
$this->assertEquals('papa', $user['username']);
|
||||
$this->assertEquals(0, $user['is_admin']);
|
||||
$this->assertEquals(1, $user['is_project_admin']);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
|
||||
$this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute')));
|
||||
|
||||
$user = $u->getById(2);
|
||||
$this->assertNotFalse($user);
|
||||
$this->assertTrue(is_array($user));
|
||||
$this->assertEquals('biloute', $user['username']);
|
||||
$this->assertEquals('Toto', $user['name']);
|
||||
$this->assertEquals(0, $user['is_admin']);
|
||||
$this->assertEquals(0, $user['is_ldap_user']);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$c = new Comment($this->container);
|
||||
|
||||
$this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
|
||||
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
|
||||
$this->assertEquals(1, $c->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(2, $task['owner_id']);
|
||||
|
||||
$this->assertTrue($u->remove(1));
|
||||
$this->assertTrue($u->remove(2));
|
||||
$this->assertFalse($u->remove(2));
|
||||
$this->assertFalse($u->remove(55));
|
||||
|
||||
// Make sure that assigned tasks are unassigned after removing the user
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(0, $task['owner_id']);
|
||||
|
||||
// Make sure that assigned subtasks are unassigned after removing the user
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertEquals(1, $subtask['id']);
|
||||
$this->assertEquals(0, $subtask['user_id']);
|
||||
|
||||
// Make sure that comments are not related to the user anymore
|
||||
$comment = $c->getById(1);
|
||||
$this->assertEquals(1, $comment['id']);
|
||||
$this->assertEquals(0, $comment['user_id']);
|
||||
|
||||
// Make sure that private projects are also removed
|
||||
$user_id1 = $u->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto'));
|
||||
$user_id2 = $u->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto'));
|
||||
$this->assertNotFalse($user_id1);
|
||||
$this->assertNotFalse($user_id2);
|
||||
$this->assertEquals(2, $p->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true));
|
||||
$this->assertEquals(3, $p->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true));
|
||||
|
||||
$this->assertTrue($u->remove($user_id1));
|
||||
|
||||
$this->assertNotEmpty($p->getById(1));
|
||||
$this->assertNotEmpty($p->getById(3));
|
||||
|
||||
$this->assertEmpty($p->getById(2));
|
||||
}
|
||||
|
||||
public function testEnableDisablePublicAccess()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
$this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456')));
|
||||
|
||||
$user = $u->getById(2);
|
||||
$this->assertNotEmpty($user);
|
||||
$this->assertEquals('toto', $user['username']);
|
||||
$this->assertEmpty($user['token']);
|
||||
|
||||
$this->assertTrue($u->enablePublicAccess(2));
|
||||
|
||||
$user = $u->getById(2);
|
||||
$this->assertNotEmpty($user);
|
||||
$this->assertEquals('toto', $user['username']);
|
||||
$this->assertNotEmpty($user['token']);
|
||||
|
||||
$this->assertTrue($u->disablePublicAccess(2));
|
||||
|
||||
$user = $u->getById(2);
|
||||
$this->assertNotEmpty($user);
|
||||
$this->assertEquals('toto', $user['username']);
|
||||
$this->assertEmpty($user['token']);
|
||||
}
|
||||
}
|
||||
112
tests/units/Model/WebhookTest.php
Normal file
112
tests/units/Model/WebhookTest.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Model\Config;
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskModification;
|
||||
use Model\Project;
|
||||
use Model\Comment;
|
||||
use Subscriber\WebhookSubscriber;
|
||||
|
||||
class WebhookTest extends Base
|
||||
{
|
||||
public function testTaskCreation()
|
||||
{
|
||||
$c = new Config($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
|
||||
|
||||
$c->save(array('webhook_url' => 'http://localhost/?task-creation'));
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
$this->assertStringStartsWith('http://localhost/?task-creation&token=', $this->container['httpClient']->getUrl());
|
||||
|
||||
$event = $this->container['httpClient']->getData();
|
||||
$this->assertNotEmpty($event);
|
||||
$this->assertArrayHasKey('event_name', $event);
|
||||
$this->assertArrayHasKey('event_data', $event);
|
||||
$this->assertEquals('task.create', $event['event_name']);
|
||||
$this->assertNotEmpty($event['event_data']);
|
||||
|
||||
$this->assertArrayHasKey('project_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('task_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('title', $event['event_data']);
|
||||
$this->assertArrayHasKey('column_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('color_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('swimlane_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('date_creation', $event['event_data']);
|
||||
$this->assertArrayHasKey('date_modification', $event['event_data']);
|
||||
$this->assertArrayHasKey('date_moved', $event['event_data']);
|
||||
$this->assertArrayHasKey('position', $event['event_data']);
|
||||
}
|
||||
|
||||
public function testTaskModification()
|
||||
{
|
||||
$c = new Config($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tm = new TaskModification($this->container);
|
||||
$this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
|
||||
|
||||
$c->save(array('webhook_url' => 'http://localhost/modif/'));
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
$this->assertTrue($tm->update(array('id' => 1, 'title' => 'test update')));
|
||||
|
||||
$this->assertStringStartsWith('http://localhost/modif/?token=', $this->container['httpClient']->getUrl());
|
||||
|
||||
$event = $this->container['httpClient']->getData();
|
||||
$this->assertNotEmpty($event);
|
||||
$this->assertArrayHasKey('event_name', $event);
|
||||
$this->assertArrayHasKey('event_data', $event);
|
||||
$this->assertEquals('task.update', $event['event_name']);
|
||||
$this->assertNotEmpty($event['event_data']);
|
||||
|
||||
$this->assertArrayHasKey('project_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('task_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('title', $event['event_data']);
|
||||
$this->assertArrayHasKey('column_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('color_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('swimlane_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('date_creation', $event['event_data']);
|
||||
$this->assertArrayHasKey('date_modification', $event['event_data']);
|
||||
$this->assertArrayHasKey('date_moved', $event['event_data']);
|
||||
$this->assertArrayHasKey('position', $event['event_data']);
|
||||
}
|
||||
|
||||
public function testCommentCreation()
|
||||
{
|
||||
$c = new Config($this->container);
|
||||
$p = new Project($this->container);
|
||||
$tc = new TaskCreation($this->container);
|
||||
$cm = new Comment($this->container);
|
||||
$this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
|
||||
|
||||
$c->save(array('webhook_url' => 'http://localhost/comment'));
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
|
||||
$this->assertEquals(1, $cm->create(array('task_id' => 1, 'comment' => 'test comment', 'user_id' => 1)));
|
||||
|
||||
$this->assertStringStartsWith('http://localhost/comment?token=', $this->container['httpClient']->getUrl());
|
||||
|
||||
$event = $this->container['httpClient']->getData();
|
||||
$this->assertNotEmpty($event);
|
||||
$this->assertArrayHasKey('event_name', $event);
|
||||
$this->assertArrayHasKey('event_data', $event);
|
||||
$this->assertEquals('comment.create', $event['event_name']);
|
||||
$this->assertNotEmpty($event['event_data']);
|
||||
|
||||
$this->assertArrayHasKey('task_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('user_id', $event['event_data']);
|
||||
$this->assertArrayHasKey('comment', $event['event_data']);
|
||||
$this->assertArrayHasKey('id', $event['event_data']);
|
||||
$this->assertEquals('test comment', $event['event_data']['comment']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user