diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-06-20 14:34:47 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-06-20 14:34:47 -0400 |
commit | aa6fdd3544b64eeab3d577c58425e128c809a135 (patch) | |
tree | 388de73e11567e8927bc12694cc65a3c629f6a59 /tests | |
parent | d3f789764dcf90923a0d0f639dd2ee56b1177f84 (diff) |
Improve automatic action duplication with unit tests and improve database schema
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/ActionTaskAssignColorCategoryTest.php | 4 | ||||
-rw-r--r-- | tests/units/ActionTest.php | 242 | ||||
-rw-r--r-- | tests/units/MailgunTest.php | 2 | ||||
-rw-r--r-- | tests/units/PostmarkTest.php | 4 | ||||
-rw-r--r-- | tests/units/ProjectPermissionTest.php | 2 | ||||
-rw-r--r-- | tests/units/SendgridTest.php | 2 |
6 files changed, 247 insertions, 9 deletions
diff --git a/tests/units/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php index c9665268..3669ce46 100644 --- a/tests/units/ActionTaskAssignColorCategoryTest.php +++ b/tests/units/ActionTaskAssignColorCategoryTest.php @@ -38,8 +38,8 @@ class ActionTaskAssignColorCategory extends Base $c = new Category($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $c->create(array('name' => 'c1'))); - $this->assertEquals(2, $c->create(array('name' => 'c2'))); + $this->assertEquals(1, $c->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(2, $c->create(array('name' => 'c2', 'project_id' => 1))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green', 'category_id' => 2))); // We create an event but we don't do anything diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php index 67957a26..7e0287a2 100644 --- a/tests/units/ActionTest.php +++ b/tests/units/ActionTest.php @@ -10,10 +10,250 @@ use Model\TaskPosition; use Model\TaskCreation; use Model\TaskFinder; use Model\Category; +use Model\User; +use Model\ProjectPermission; use Integration\GithubWebhook; +use Integration\BitbucketWebhook; class ActionTest extends Base { + public function testGetActions() + { + $a = new Action($this->container); + + $actions = $a->getAvailableActions(); + $this->assertNotEmpty($actions); + $this->assertEquals('Add a comment log when moving the task between columns', current($actions)); + $this->assertEquals('TaskLogMoveAnotherColumn', key($actions)); + } + + public function testGetEvents() + { + $a = new Action($this->container); + + $events = $a->getAvailableEvents(); + $this->assertNotEmpty($events); + $this->assertEquals('Bitbucket commit received', current($events)); + $this->assertEquals(BitbucketWebhook::EVENT_COMMIT, key($events)); + } + + public function testGetCompatibleEvents() + { + $a = new Action($this->container); + $events = $a->getCompatibleEvents('TaskAssignSpecificUser'); + + $this->assertNotEmpty($events); + $this->assertCount(2, $events); + $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE, $events); + $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events); + } + + public function testResolveDuplicatedParameters() + { + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $a = new Action($this->container); + $c = new Category($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(2, $p->create(array('name' => 'P2'))); + + $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1))); + + $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2))); + $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2))); + + $this->assertEquals(2, $u->create(array('username' => 'unittest1'))); + $this->assertEquals(3, $u->create(array('username' => 'unittest2'))); + + $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->addMember(1, 3)); + $this->assertTrue($pp->addMember(2, 3)); + + // anything + $this->assertEquals('blah', $a->resolveParameters(array('name' => 'foobar', 'value' => 'blah'), 2)); + + // project_id + $this->assertEquals(2, $a->resolveParameters(array('name' => 'project_id', 'value' => 'blah'), 2)); + + // category_id + $this->assertEquals(3, $a->resolveParameters(array('name' => 'category_id', 'value' => 1), 2)); + $this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 0), 2)); + $this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 5), 2)); + + // column_id + $this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 10), 2)); + $this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 0), 2)); + $this->assertEquals(5, $a->resolveParameters(array('name' => 'column_id', 'value' => 1), 2)); + $this->assertEquals(6, $a->resolveParameters(array('name' => 'dest_column_id', 'value' => 2), 2)); + $this->assertEquals(7, $a->resolveParameters(array('name' => 'dst_column_id', 'value' => 3), 2)); + $this->assertEquals(8, $a->resolveParameters(array('name' => 'src_column_id', 'value' => 4), 2)); + + // user_id + $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 10), 2)); + $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 0), 2)); + $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 2), 2)); + $this->assertFalse($a->resolveParameters(array('name' => 'owner_id', 'value' => 2), 2)); + $this->assertEquals(3, $a->resolveParameters(array('name' => 'user_id', 'value' => 3), 2)); + $this->assertEquals(3, $a->resolveParameters(array('name' => 'owner_id', 'value' => 3), 2)); + } + + public function testDuplicateSuccess() + { + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $a = new Action($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(2, $p->create(array('name' => 'P2'))); + + $this->assertEquals(2, $u->create(array('username' => 'unittest1'))); + $this->assertEquals(3, $u->create(array('username' => 'unittest2'))); + + $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->addMember(1, 3)); + $this->assertTrue($pp->addMember(2, 3)); + + $this->assertEquals(1, $a->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE_UPDATE, + 'action_name' => 'TaskAssignSpecificUser', + 'params' => array( + 'column_id' => 1, + 'user_id' => 3, + ) + ))); + + $action = $a->getById(1); + $this->assertNotEmpty($action); + $this->assertNotEmpty($action['params']); + $this->assertEquals(1, $action['project_id']); + + $this->assertTrue($a->duplicate(1, 2)); + + $action = $a->getById(2); + $this->assertNotEmpty($action); + $this->assertNotEmpty($action['params']); + $this->assertEquals(2, $action['project_id']); + $this->assertEquals(Task::EVENT_CREATE_UPDATE, $action['event_name']); + $this->assertEquals('TaskAssignSpecificUser', $action['action_name']); + $this->assertEquals('column_id', $action['params'][0]['name']); + $this->assertEquals(5, $action['params'][0]['value']); + $this->assertEquals('user_id', $action['params'][1]['name']); + $this->assertEquals(3, $action['params'][1]['value']); + } + + public function testDuplicateUnableToResolveParams() + { + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $a = new Action($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(2, $p->create(array('name' => 'P2'))); + + $this->assertEquals(2, $u->create(array('username' => 'unittest1'))); + + $this->assertTrue($pp->addMember(1, 2)); + + $this->assertEquals(1, $a->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE_UPDATE, + 'action_name' => 'TaskAssignSpecificUser', + 'params' => array( + 'column_id' => 1, + 'user_id' => 2, + ) + ))); + + $action = $a->getById(1); + $this->assertNotEmpty($action); + $this->assertNotEmpty($action['params']); + $this->assertEquals(1, $action['project_id']); + $this->assertEquals('user_id', $action['params'][1]['name']); + $this->assertEquals(2, $action['params'][1]['value']); + + $this->assertTrue($a->duplicate(1, 2)); + + $action = $a->getById(2); + $this->assertEmpty($action); + } + + public function testDuplicateMixedResults() + { + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $a = new Action($this->container); + $u = new User($this->container); + $c = new Category($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(2, $p->create(array('name' => 'P2'))); + + $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1))); + $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2))); + $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2))); + + $this->assertEquals(2, $u->create(array('username' => 'unittest1'))); + + $this->assertTrue($pp->addMember(1, 2)); + + $this->assertEquals(1, $a->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE_UPDATE, + 'action_name' => 'TaskAssignSpecificUser', + 'params' => array( + 'column_id' => 1, + 'user_id' => 2, + ) + ))); + + $action = $a->getById(1); + $this->assertNotEmpty($action); + $this->assertNotEmpty($action['params']); + + $this->assertEquals(2, $a->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE_UPDATE, + 'action_name' => 'TaskAssignCategoryColor', + 'params' => array( + 'color_id' => 'blue', + 'category_id' => 1, + ) + ))); + + $action = $a->getById(2); + $this->assertNotEmpty($action); + $this->assertNotEmpty($action['params']); + $this->assertEquals('category_id', $action['params'][1]['name']); + $this->assertEquals(1, $action['params'][1]['value']); + + $actions = $a->getAllByProject(1); + $this->assertNotEmpty($actions); + $this->assertCount(2, $actions); + + $this->assertTrue($a->duplicate(1, 2)); + + $actions = $a->getAllByProject(2); + $this->assertNotEmpty($actions); + $this->assertCount(1, $actions); + + $actions = $a->getAll(); + $this->assertNotEmpty($actions); + $this->assertCount(3, $actions); + + $action = $a->getById($actions[2]['id']); + $this->assertNotEmpty($action); + $this->assertNotEmpty($action['params']); + $this->assertEquals('color_id', $action['params'][0]['name']); + $this->assertEquals('blue', $action['params'][0]['value']); + $this->assertEquals('category_id', $action['params'][1]['name']); + $this->assertEquals(3, $action['params'][1]['value']); + } + public function testSingleAction() { $tp = new TaskPosition($this->container); @@ -70,12 +310,10 @@ class ActionTest extends Base $b = new Board($this->container); $p = new Project($this->container); $a = new Action($this->container); - $c = new Category($this->container); $g = new GithubWebhook($this->container); // We create a project $this->assertEquals(1, $p->create(array('name' => 'unit_test'))); - $this->assertEquals(1, $c->create(array('name' => 'unit_test'))); // We create a new action $this->assertEquals(1, $a->create(array( diff --git a/tests/units/MailgunTest.php b/tests/units/MailgunTest.php index b33a66fe..ce53228e 100644 --- a/tests/units/MailgunTest.php +++ b/tests/units/MailgunTest.php @@ -40,7 +40,7 @@ class MailgunTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); - $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost'))); + $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost'))); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); diff --git a/tests/units/PostmarkTest.php b/tests/units/PostmarkTest.php index b708217d..f3d2e55b 100644 --- a/tests/units/PostmarkTest.php +++ b/tests/units/PostmarkTest.php @@ -43,7 +43,7 @@ class PostmarkTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); - $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost'))); + $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost'))); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); @@ -81,7 +81,7 @@ class PostmarkTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); - $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost'))); + $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost'))); $this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); $this->assertTrue($pp->addMember(1, 2)); diff --git a/tests/units/ProjectPermissionTest.php b/tests/units/ProjectPermissionTest.php index 66406392..9f6d6a52 100644 --- a/tests/units/ProjectPermissionTest.php +++ b/tests/units/ProjectPermissionTest.php @@ -241,7 +241,7 @@ class ProjectPermissionTest extends Base $pp = new ProjectPermission($this->container); $user = new User($this->container); - $user->create(array('username' => 'unittest', 'password' => 'unittest')); + $this->assertNotFalse($user->create(array('username' => 'unittest', 'password' => 'unittest'))); // We create project $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); diff --git a/tests/units/SendgridTest.php b/tests/units/SendgridTest.php index 1814c761..1fc5d0d5 100644 --- a/tests/units/SendgridTest.php +++ b/tests/units/SendgridTest.php @@ -48,7 +48,7 @@ class SendgridTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); - $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost'))); + $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost'))); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); |