From 710f2c7bb046b43ec9878ae795a181101f6d7515 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 5 Sep 2015 23:30:56 -0400 Subject: Improve unit tests --- app/Auth/Ldap.php | 45 +- app/Controller/Board.php | 2 +- app/Controller/Doc.php | 2 +- tests/units/AclTest.php | 293 --------- tests/units/Action/CommentCreationTest.php | 124 ++++ tests/units/Action/TaskAssignColorCategoryTest.php | 80 +++ tests/units/Action/TaskAssignColorColumnTest.php | 41 ++ tests/units/Action/TaskAssignColorLinkTest.php | 47 ++ tests/units/Action/TaskAssignColorUserTest.php | 72 +++ tests/units/Action/TaskAssignCurrentUserTest.php | 77 +++ tests/units/Action/TaskAssignSpecificUserTest.php | 70 ++ tests/units/Action/TaskCloseTest.php | 108 ++++ .../Action/TaskDuplicateAnotherProjectTest.php | 94 +++ tests/units/Action/TaskEmailTest.php | 149 +++++ tests/units/Action/TaskMoveAnotherProjectTest.php | 88 +++ .../Action/TaskMoveColumnCategoryChangeTest.php | 61 ++ tests/units/Action/TaskUpdateStartDateTest.php | 45 ++ tests/units/ActionCommentCreationTest.php | 124 ---- tests/units/ActionTaskAssignColorCategoryTest.php | 80 --- tests/units/ActionTaskAssignColorColumnTest.php | 41 -- tests/units/ActionTaskAssignColorLinkTest.php | 47 -- tests/units/ActionTaskAssignColorUserTest.php | 72 --- tests/units/ActionTaskAssignCurrentUserTest.php | 77 --- tests/units/ActionTaskAssignSpecificUserTest.php | 70 -- tests/units/ActionTaskCloseTest.php | 108 ---- .../ActionTaskDuplicateAnotherProjectTest.php | 94 --- tests/units/ActionTaskEmailTest.php | 149 ----- tests/units/ActionTaskMoveAnotherProjectTest.php | 88 --- .../ActionTaskMoveColumnCategoryChangeTest.php | 61 -- tests/units/ActionTaskUpdateStartDateTest.php | 45 -- tests/units/ActionTest.php | 379 ----------- tests/units/AppHelperTest.php | 38 -- tests/units/AssetHelperTest.php | 21 - tests/units/Auth/LdapTest.php | 122 ++++ tests/units/AuthenticationTest.php | 39 -- tests/units/Base.php | 3 + tests/units/BitbucketWebhookTest.php | 398 ------------ tests/units/BoardTest.php | 372 ----------- tests/units/CategoryTest.php | 67 -- tests/units/CommentTest.php | 142 ----- tests/units/ConfigTest.php | 66 -- tests/units/Core/LexerTest.php | 443 +++++++++++++ tests/units/Core/OAuth2Test.php | 43 ++ tests/units/Core/RouterTest.php | 79 +++ tests/units/Core/ToolTest.php | 15 + tests/units/DateParserTest.php | 84 --- tests/units/DatetimeHelperTest.php | 56 -- tests/units/FileHelperText.php | 15 - tests/units/FileTest.php | 190 ------ tests/units/GithubWebhookTest.php | 459 ------------- tests/units/GitlabWebhookTest.php | 221 ------- tests/units/Helper/AppHelperTest.php | 38 ++ tests/units/Helper/AssetHelperTest.php | 21 + tests/units/Helper/DatetimeHelperTest.php | 56 ++ tests/units/Helper/FileHelperText.php | 15 + tests/units/Helper/TextHelperTest.php | 56 ++ tests/units/Helper/UrlHelperTest.php | 86 +++ tests/units/Helper/UserHelperTest.php | 16 + tests/units/HourlyRate.php | 43 -- tests/units/Integration/BitbucketWebhookTest.php | 398 ++++++++++++ tests/units/Integration/GithubWebhookTest.php | 459 +++++++++++++ tests/units/Integration/GitlabWebhookTest.php | 221 +++++++ tests/units/Integration/MailgunTest.php | 71 +++ tests/units/Integration/PostmarkTest.php | 106 +++ tests/units/Integration/SendgridTest.php | 135 ++++ tests/units/LexerTest.php | 443 ------------- tests/units/LinkTest.php | 173 ----- tests/units/Locale/LocaleTest.php | 33 + tests/units/LocaleTest.php | 33 - tests/units/MailgunTest.php | 71 --- tests/units/Model/AclTest.php | 293 +++++++++ tests/units/Model/ActionTest.php | 379 +++++++++++ tests/units/Model/AuthenticationTest.php | 39 ++ tests/units/Model/BoardTest.php | 372 +++++++++++ tests/units/Model/CategoryTest.php | 67 ++ tests/units/Model/CommentTest.php | 142 +++++ tests/units/Model/ConfigTest.php | 66 ++ tests/units/Model/DateParserTest.php | 84 +++ tests/units/Model/FileTest.php | 190 ++++++ tests/units/Model/HourlyRateTest.php | 43 ++ tests/units/Model/LinkTest.php | 173 +++++ tests/units/Model/NotificationTest.php | 336 ++++++++++ tests/units/Model/ProjectActivityTest.php | 114 ++++ tests/units/Model/ProjectDailyColumnStatsTest.php | 90 +++ tests/units/Model/ProjectDuplicationTest.php | 359 +++++++++++ tests/units/Model/ProjectPermissionTest.php | 287 +++++++++ tests/units/Model/ProjectTest.php | 288 +++++++++ tests/units/Model/SubtaskTest.php | 284 +++++++++ tests/units/Model/SubtaskTimeTrackingTest.php | 314 +++++++++ tests/units/Model/SwimlaneTest.php | 409 ++++++++++++ tests/units/Model/TaskCreationTest.php | 416 ++++++++++++ tests/units/Model/TaskDuplicationTest.php | 707 +++++++++++++++++++++ tests/units/Model/TaskExportTest.php | 58 ++ tests/units/Model/TaskFilterTest.php | 629 ++++++++++++++++++ tests/units/Model/TaskFinderTest.php | 33 + tests/units/Model/TaskLinkTest.php | 185 ++++++ tests/units/Model/TaskModificationTest.php | 267 ++++++++ tests/units/Model/TaskMovedDateSubscriberTest.php | 77 +++ tests/units/Model/TaskPermissionTest.php | 105 +++ tests/units/Model/TaskPositionTest.php | 634 ++++++++++++++++++ tests/units/Model/TaskStatusTest.php | 101 +++ tests/units/Model/TaskTest.php | 29 + tests/units/Model/TimetableTest.php | 256 ++++++++ tests/units/Model/UserSessionTest.php | 32 + tests/units/Model/UserTest.php | 273 ++++++++ tests/units/Model/WebhookTest.php | 112 ++++ tests/units/NotificationTest.php | 336 ---------- tests/units/OAuth2Test.php | 43 -- tests/units/PostmarkTest.php | 106 --- tests/units/ProjectActivityTest.php | 114 ---- tests/units/ProjectDailyColumnStatsTest.php | 90 --- tests/units/ProjectDuplicationTest.php | 359 ----------- tests/units/ProjectPermissionTest.php | 287 --------- tests/units/ProjectTest.php | 288 --------- tests/units/RouterTest.php | 79 --- tests/units/SendgridTest.php | 135 ---- tests/units/SubtaskTest.php | 284 --------- tests/units/SubtaskTimeTrackingTest.php | 314 --------- tests/units/SwimlaneTest.php | 409 ------------ tests/units/TaskCreationTest.php | 416 ------------ tests/units/TaskDuplicationTest.php | 707 --------------------- tests/units/TaskExportTest.php | 58 -- tests/units/TaskFilterTest.php | 629 ------------------ tests/units/TaskFinderTest.php | 33 - tests/units/TaskLinkTest.php | 185 ------ tests/units/TaskModificationTest.php | 267 -------- tests/units/TaskMovedDateSubscriberTest.php | 77 --- tests/units/TaskPermissionTest.php | 105 --- tests/units/TaskPositionTest.php | 634 ------------------ tests/units/TaskStatusTest.php | 101 --- tests/units/TaskTest.php | 29 - tests/units/TextHelperTest.php | 56 -- tests/units/TimetableTest.php | 256 -------- tests/units/ToolTest.php | 15 - tests/units/UrlHelperTest.php | 86 --- tests/units/UserHelperTest.php | 16 - tests/units/UserSessionTest.php | 32 - tests/units/UserTest.php | 273 -------- tests/units/WebhookTest.php | 112 ---- 139 files changed, 11742 insertions(+), 11612 deletions(-) delete mode 100644 tests/units/AclTest.php create mode 100644 tests/units/Action/CommentCreationTest.php create mode 100644 tests/units/Action/TaskAssignColorCategoryTest.php create mode 100644 tests/units/Action/TaskAssignColorColumnTest.php create mode 100644 tests/units/Action/TaskAssignColorLinkTest.php create mode 100644 tests/units/Action/TaskAssignColorUserTest.php create mode 100644 tests/units/Action/TaskAssignCurrentUserTest.php create mode 100644 tests/units/Action/TaskAssignSpecificUserTest.php create mode 100644 tests/units/Action/TaskCloseTest.php create mode 100644 tests/units/Action/TaskDuplicateAnotherProjectTest.php create mode 100644 tests/units/Action/TaskEmailTest.php create mode 100644 tests/units/Action/TaskMoveAnotherProjectTest.php create mode 100644 tests/units/Action/TaskMoveColumnCategoryChangeTest.php create mode 100644 tests/units/Action/TaskUpdateStartDateTest.php delete mode 100644 tests/units/ActionCommentCreationTest.php delete mode 100644 tests/units/ActionTaskAssignColorCategoryTest.php delete mode 100644 tests/units/ActionTaskAssignColorColumnTest.php delete mode 100644 tests/units/ActionTaskAssignColorLinkTest.php delete mode 100644 tests/units/ActionTaskAssignColorUserTest.php delete mode 100644 tests/units/ActionTaskAssignCurrentUserTest.php delete mode 100644 tests/units/ActionTaskAssignSpecificUserTest.php delete mode 100644 tests/units/ActionTaskCloseTest.php delete mode 100644 tests/units/ActionTaskDuplicateAnotherProjectTest.php delete mode 100644 tests/units/ActionTaskEmailTest.php delete mode 100644 tests/units/ActionTaskMoveAnotherProjectTest.php delete mode 100644 tests/units/ActionTaskMoveColumnCategoryChangeTest.php delete mode 100644 tests/units/ActionTaskUpdateStartDateTest.php delete mode 100644 tests/units/ActionTest.php delete mode 100644 tests/units/AppHelperTest.php delete mode 100644 tests/units/AssetHelperTest.php create mode 100644 tests/units/Auth/LdapTest.php delete mode 100644 tests/units/AuthenticationTest.php delete mode 100644 tests/units/BitbucketWebhookTest.php delete mode 100644 tests/units/BoardTest.php delete mode 100644 tests/units/CategoryTest.php delete mode 100644 tests/units/CommentTest.php delete mode 100644 tests/units/ConfigTest.php create mode 100644 tests/units/Core/LexerTest.php create mode 100644 tests/units/Core/OAuth2Test.php create mode 100644 tests/units/Core/RouterTest.php create mode 100644 tests/units/Core/ToolTest.php delete mode 100644 tests/units/DateParserTest.php delete mode 100644 tests/units/DatetimeHelperTest.php delete mode 100644 tests/units/FileHelperText.php delete mode 100644 tests/units/FileTest.php delete mode 100644 tests/units/GithubWebhookTest.php delete mode 100644 tests/units/GitlabWebhookTest.php create mode 100644 tests/units/Helper/AppHelperTest.php create mode 100644 tests/units/Helper/AssetHelperTest.php create mode 100644 tests/units/Helper/DatetimeHelperTest.php create mode 100644 tests/units/Helper/FileHelperText.php create mode 100644 tests/units/Helper/TextHelperTest.php create mode 100644 tests/units/Helper/UrlHelperTest.php create mode 100644 tests/units/Helper/UserHelperTest.php delete mode 100644 tests/units/HourlyRate.php create mode 100644 tests/units/Integration/BitbucketWebhookTest.php create mode 100644 tests/units/Integration/GithubWebhookTest.php create mode 100644 tests/units/Integration/GitlabWebhookTest.php create mode 100644 tests/units/Integration/MailgunTest.php create mode 100644 tests/units/Integration/PostmarkTest.php create mode 100644 tests/units/Integration/SendgridTest.php delete mode 100644 tests/units/LexerTest.php delete mode 100644 tests/units/LinkTest.php create mode 100644 tests/units/Locale/LocaleTest.php delete mode 100644 tests/units/LocaleTest.php delete mode 100644 tests/units/MailgunTest.php create mode 100644 tests/units/Model/AclTest.php create mode 100644 tests/units/Model/ActionTest.php create mode 100644 tests/units/Model/AuthenticationTest.php create mode 100644 tests/units/Model/BoardTest.php create mode 100644 tests/units/Model/CategoryTest.php create mode 100644 tests/units/Model/CommentTest.php create mode 100644 tests/units/Model/ConfigTest.php create mode 100644 tests/units/Model/DateParserTest.php create mode 100644 tests/units/Model/FileTest.php create mode 100644 tests/units/Model/HourlyRateTest.php create mode 100644 tests/units/Model/LinkTest.php create mode 100644 tests/units/Model/NotificationTest.php create mode 100644 tests/units/Model/ProjectActivityTest.php create mode 100644 tests/units/Model/ProjectDailyColumnStatsTest.php create mode 100644 tests/units/Model/ProjectDuplicationTest.php create mode 100644 tests/units/Model/ProjectPermissionTest.php create mode 100644 tests/units/Model/ProjectTest.php create mode 100644 tests/units/Model/SubtaskTest.php create mode 100644 tests/units/Model/SubtaskTimeTrackingTest.php create mode 100644 tests/units/Model/SwimlaneTest.php create mode 100644 tests/units/Model/TaskCreationTest.php create mode 100644 tests/units/Model/TaskDuplicationTest.php create mode 100644 tests/units/Model/TaskExportTest.php create mode 100644 tests/units/Model/TaskFilterTest.php create mode 100644 tests/units/Model/TaskFinderTest.php create mode 100644 tests/units/Model/TaskLinkTest.php create mode 100644 tests/units/Model/TaskModificationTest.php create mode 100644 tests/units/Model/TaskMovedDateSubscriberTest.php create mode 100644 tests/units/Model/TaskPermissionTest.php create mode 100644 tests/units/Model/TaskPositionTest.php create mode 100644 tests/units/Model/TaskStatusTest.php create mode 100644 tests/units/Model/TaskTest.php create mode 100644 tests/units/Model/TimetableTest.php create mode 100644 tests/units/Model/UserSessionTest.php create mode 100644 tests/units/Model/UserTest.php create mode 100644 tests/units/Model/WebhookTest.php delete mode 100644 tests/units/NotificationTest.php delete mode 100644 tests/units/OAuth2Test.php delete mode 100644 tests/units/PostmarkTest.php delete mode 100644 tests/units/ProjectActivityTest.php delete mode 100644 tests/units/ProjectDailyColumnStatsTest.php delete mode 100644 tests/units/ProjectDuplicationTest.php delete mode 100644 tests/units/ProjectPermissionTest.php delete mode 100644 tests/units/ProjectTest.php delete mode 100644 tests/units/RouterTest.php delete mode 100644 tests/units/SendgridTest.php delete mode 100644 tests/units/SubtaskTest.php delete mode 100644 tests/units/SubtaskTimeTrackingTest.php delete mode 100644 tests/units/SwimlaneTest.php delete mode 100644 tests/units/TaskCreationTest.php delete mode 100644 tests/units/TaskDuplicationTest.php delete mode 100644 tests/units/TaskExportTest.php delete mode 100644 tests/units/TaskFilterTest.php delete mode 100644 tests/units/TaskFinderTest.php delete mode 100644 tests/units/TaskLinkTest.php delete mode 100644 tests/units/TaskModificationTest.php delete mode 100644 tests/units/TaskMovedDateSubscriberTest.php delete mode 100644 tests/units/TaskPermissionTest.php delete mode 100644 tests/units/TaskPositionTest.php delete mode 100644 tests/units/TaskStatusTest.php delete mode 100644 tests/units/TaskTest.php delete mode 100644 tests/units/TextHelperTest.php delete mode 100644 tests/units/TimetableTest.php delete mode 100644 tests/units/ToolTest.php delete mode 100644 tests/units/UrlHelperTest.php delete mode 100644 tests/units/UserHelperTest.php delete mode 100644 tests/units/UserSessionTest.php delete mode 100644 tests/units/UserTest.php delete mode 100644 tests/units/WebhookTest.php diff --git a/app/Auth/Ldap.php b/app/Auth/Ldap.php index c1459b4e..e46d9b81 100644 --- a/app/Auth/Ldap.php +++ b/app/Auth/Ldap.php @@ -98,7 +98,7 @@ class Ldap extends Base { $ldap = $this->connect(); - if (is_resource($ldap) && $this->bind($ldap, $username, $password)) { + if ($ldap !== false && $this->bind($ldap, $username, $password)) { return $this->search($ldap, $username, $password); } @@ -108,13 +108,14 @@ class Ldap extends Base /** * LDAP connection * - * @access private - * @return resource $ldap LDAP connection + * @access public + * @return resource|boolean */ - private function connect() + public function connect() { if (! function_exists('ldap_connect')) { - die('The PHP LDAP extension is required'); + $this->logger->error('The PHP LDAP extension is required'); + return false; } // Skip SSL certificate verification @@ -124,8 +125,9 @@ class Ldap extends Base $ldap = ldap_connect(LDAP_SERVER, LDAP_PORT); - if (! is_resource($ldap)) { - die('Unable to connect to the LDAP server: "'.LDAP_SERVER.'"'); + if ($ldap === false) { + $this->logger->error('Unable to connect to the LDAP server: "'.LDAP_SERVER.'"'); + return false; } ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); @@ -134,7 +136,8 @@ class Ldap extends Base ldap_set_option($ldap, LDAP_OPT_TIMELIMIT, 1); if (LDAP_START_TLS && ! @ldap_start_tls($ldap)) { - die('Unable to use ldap_start_tls()'); + $this->logger->error('Unable to use ldap_start_tls()'); + return false; } return $ldap; @@ -143,21 +146,24 @@ class Ldap extends Base /** * LDAP bind * - * @access private - * @param resource $ldap LDAP connection - * @param string $username Username - * @param string $password Password + * @access public + * @param resource $ldap + * @param string $username + * @param string $password + * @param string $ldap_type + * @param string $ldap_username + * @param string $ldap_password * @return boolean */ - private function bind($ldap, $username, $password) + public function bind($ldap, $username, $password, $ldap_type = LDAP_BIND_TYPE, $ldap_username = LDAP_USERNAME, $ldap_password = LDAP_PASSWORD) { - if (LDAP_BIND_TYPE === 'user') { - $ldap_username = sprintf(LDAP_USERNAME, $username); + if ($ldap_type === 'user') { + $ldap_username = sprintf($ldap_username, $username); $ldap_password = $password; } - else if (LDAP_BIND_TYPE === 'proxy') { - $ldap_username = LDAP_USERNAME; - $ldap_password = LDAP_PASSWORD; + else if ($ldap_type === 'proxy') { + $ldap_username = $ldap_username; + $ldap_password = $ldap_password; } else { $ldap_username = null; @@ -191,13 +197,12 @@ class Ldap extends Base $info = ldap_get_entries($ldap, $sr); // User not found - if (count($info) == 0 || $info['count'] == 0) { + if (count($info) === 0 || $info['count'] == 0) { return false; } // We got our user if (@ldap_bind($ldap, $info[0]['dn'], $password)) { - return array( 'username' => $username, 'name' => $this->getFromInfo($info, LDAP_ACCOUNT_FULLNAME), diff --git a/app/Controller/Board.php b/app/Controller/Board.php index 360a705f..a552b9cf 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -327,7 +327,7 @@ class Board extends Base */ public function swimlane() { - $project = $this->getProject(); + $this->getProject(); $swimlane = $this->swimlane->getById($this->request->getIntegerParam('swimlane_id')); $this->response->html($this->template->render('board/tooltip_description', array('task' => $swimlane))); } diff --git a/app/Controller/Doc.php b/app/Controller/Doc.php index 19644b84..d9f7b5e7 100644 --- a/app/Controller/Doc.php +++ b/app/Controller/Doc.php @@ -16,7 +16,7 @@ class Doc extends Base { $url = $this->helper->url; $data = file_get_contents($filename); - list($title,, $content) = explode("\n", $data, 3); + list($title,) = explode("\n", $data, 2); $replaceUrl = function (array $matches) use ($url) { return '('.$url->to('doc', 'show', array('file' => str_replace('.markdown', '', $matches[1]))).')'; diff --git a/tests/units/AclTest.php b/tests/units/AclTest.php deleted file mode 100644 index 4d735dfb..00000000 --- a/tests/units/AclTest.php +++ /dev/null @@ -1,293 +0,0 @@ - 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)); - } -} diff --git a/tests/units/Action/CommentCreationTest.php b/tests/units/Action/CommentCreationTest.php new file mode 100644 index 00000000..6b5fe1ea --- /dev/null +++ b/tests/units/Action/CommentCreationTest.php @@ -0,0 +1,124 @@ +container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $c = new Comment($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'user_id' => 1, + ); + + // Our event should be executed + $this->assertFalse($action->execute(new GenericEvent($event))); + + $comment = $c->getById(1); + $this->assertEmpty($comment); + } + + public function testWithCommitMessage() + { + $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $c = new Comment($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'commit_comment' => 'plop', + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + $comment = $c->getById(1); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(0, $comment['user_id']); + $this->assertEquals('plop', $comment['comment']); + } + + public function testWithUser() + { + $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $c = new Comment($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'user_id' => 1, + 'comment' => 'youpi', + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + $comment = $c->getById(1); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(1, $comment['user_id']); + $this->assertEquals('youpi', $comment['comment']); + } + + public function testWithNoUser() + { + $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $c = new Comment($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'user_id' => 0, + 'comment' => 'youpi', + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + $comment = $c->getById(1); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(0, $comment['user_id']); + $this->assertEquals('youpi', $comment['comment']); + } +} diff --git a/tests/units/Action/TaskAssignColorCategoryTest.php b/tests/units/Action/TaskAssignColorCategoryTest.php new file mode 100644 index 00000000..44d23943 --- /dev/null +++ b/tests/units/Action/TaskAssignColorCategoryTest.php @@ -0,0 +1,80 @@ +container, 3, Task::EVENT_CREATE_UPDATE); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE); + $action->setParam('category_id', 1); + $action->setParam('color_id', 'blue'); + + // We create a task in the first column + $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' => 'test'))); + $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 + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 1, + 'category_id' => 2, + 'position' => 2, + ); + + // Our event should NOT be executed + $this->assertFalse($action->execute(new GenericEvent($event))); + + // Our task should be assigned to the ategory_id=1 and have the green color + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['category_id']); + $this->assertEquals('green', $task['color_id']); + + // We create an event to move the task + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 1, + 'position' => 5, + 'category_id' => 1, + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should have the blue color + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('blue', $task['color_id']); + } +} diff --git a/tests/units/Action/TaskAssignColorColumnTest.php b/tests/units/Action/TaskAssignColorColumnTest.php new file mode 100644 index 00000000..55767327 --- /dev/null +++ b/tests/units/Action/TaskAssignColorColumnTest.php @@ -0,0 +1,41 @@ +container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('color_id', 'green'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($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, 'column_id' => 1, 'color_id' => 'yellow'))); + + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + 'color_id' => 'green', + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should have color green + $task = $tf->getById(1); + $this->assertEquals('green', $task['color_id']); + } +} diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php new file mode 100644 index 00000000..c78af5bb --- /dev/null +++ b/tests/units/Action/TaskAssignColorLinkTest.php @@ -0,0 +1,47 @@ +container, 1, TaskLink::EVENT_CREATE_UPDATE); + $action->setParam('link_id', 2); + $action->setParam('color_id', 'green'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $tl = new TaskLink($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 color should be yellow + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('yellow', $task['color_id']); + + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'link_id' => 2, + ); + + // Our event should be executed + $this->assertTrue($action->execute(new TaskLinkEvent($event))); + + // The color should be green + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('green', $task['color_id']); + } +} diff --git a/tests/units/Action/TaskAssignColorUserTest.php b/tests/units/Action/TaskAssignColorUserTest.php new file mode 100644 index 00000000..896b48fc --- /dev/null +++ b/tests/units/Action/TaskAssignColorUserTest.php @@ -0,0 +1,72 @@ +container, 3, Task::EVENT_CREATE); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE); + $action->setParam('user_id', 1); + $action->setParam('color_id', 'blue'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($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, 'column_id' => 1, 'color_id' => 'green'))); + + // We change the assignee + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'owner_id' => 5, + ); + + // Our event should NOT be executed + $this->assertFalse($action->execute(new GenericEvent($event))); + + // Our task should be assigned to nobody and have the green color + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals('green', $task['color_id']); + + // We change the assignee + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'owner_id' => 1, + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be assigned to nobody and have the blue color + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals('blue', $task['color_id']); + } +} diff --git a/tests/units/Action/TaskAssignCurrentUserTest.php b/tests/units/Action/TaskAssignCurrentUserTest.php new file mode 100644 index 00000000..9ea816d4 --- /dev/null +++ b/tests/units/Action/TaskAssignCurrentUserTest.php @@ -0,0 +1,77 @@ +container, 3, Task::EVENT_CREATE); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $_SESSION = array( + 'user' => array('id' => 5) + ); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $us = new UserSession($this->container); + + $this->assertEquals(5, $us->getId()); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be assigned to the user 5 (from the session) + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['id']); + $this->assertEquals(5, $task['owner_id']); + } +} diff --git a/tests/units/Action/TaskAssignSpecificUserTest.php b/tests/units/Action/TaskAssignSpecificUserTest.php new file mode 100644 index 00000000..ae8de177 --- /dev/null +++ b/tests/units/Action/TaskAssignSpecificUserTest.php @@ -0,0 +1,70 @@ +container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($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, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be assigned to the user 1 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['owner_id']); + } +} diff --git a/tests/units/Action/TaskCloseTest.php b/tests/units/Action/TaskCloseTest.php new file mode 100644 index 00000000..8cee6f13 --- /dev/null +++ b/tests/units/Action/TaskCloseTest.php @@ -0,0 +1,108 @@ +container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertTrue($action->isExecutable($event)); + + $action = new Action\TaskClose($this->container, 3, GithubWebhook::EVENT_COMMIT); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + ); + + $this->assertTrue($action->isExecutable($event)); + } + + public function testBadEvent() + { + $action = new Action\TaskClose($this->container, 3, Task::EVENT_UPDATE); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testBadProject() + { + $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskClose($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($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, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be closed + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['is_active']); + } +} diff --git a/tests/units/Action/TaskDuplicateAnotherProjectTest.php b/tests/units/Action/TaskDuplicateAnotherProjectTest.php new file mode 100644 index 00000000..37eb4052 --- /dev/null +++ b/tests/units/Action/TaskDuplicateAnotherProjectTest.php @@ -0,0 +1,94 @@ +container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskDuplicateAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); + + // We create a task in the first column + $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(2, $p->create(array('name' => 'project 2'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Our event should NOT be executed because we define the same project + $action->setParam('column_id', 2); + $action->setParam('project_id', 1); + $this->assertFalse($action->execute(new GenericEvent($event))); + + // Our task should be assigned to the project 1 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['project_id']); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Our event should be executed because we define a different project + $action->setParam('column_id', 2); + $action->setParam('project_id', 2); + $this->assertTrue($action->hasRequiredCondition($event)); + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be assigned to the project 1 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['project_id']); + + // We should have another task assigned to the project 2 + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + } +} diff --git a/tests/units/Action/TaskEmailTest.php b/tests/units/Action/TaskEmailTest.php new file mode 100644 index 00000000..d74e1af2 --- /dev/null +++ b/tests/units/Action/TaskEmailTest.php @@ -0,0 +1,149 @@ +container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + $action->setParam('subject', 'My email subject'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Email should be not be sent + $this->container['emailClient']->expects($this->never())->method('send'); + + // Our event should be executed + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testWrongColumn() + { + $action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + $action->setParam('subject', 'My email subject'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 3, + ); + + // Email should be not be sent + $this->container['emailClient']->expects($this->never())->method('send'); + + // Our event should be executed + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testMoveColumn() + { + $action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + $action->setParam('subject', 'My email subject'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost'))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Email should be sent + $this->container['emailClient']->expects($this->once()) + ->method('send') + ->with( + $this->equalTo('admin@localhost'), + $this->equalTo('admin'), + $this->equalTo('My email subject'), + $this->stringContains('test') + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + } + + public function testTaskClose() + { + $action = new Action\TaskEmail($this->container, 1, Task::EVENT_CLOSE); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + $action->setParam('subject', 'My email subject'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost'))); + + // We create an event + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Email should be sent + $this->container['emailClient']->expects($this->once()) + ->method('send') + ->with( + $this->equalTo('admin@localhost'), + $this->equalTo('admin'), + $this->equalTo('My email subject'), + $this->stringContains('test') + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + } +} \ No newline at end of file diff --git a/tests/units/Action/TaskMoveAnotherProjectTest.php b/tests/units/Action/TaskMoveAnotherProjectTest.php new file mode 100644 index 00000000..78bc6570 --- /dev/null +++ b/tests/units/Action/TaskMoveAnotherProjectTest.php @@ -0,0 +1,88 @@ +container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); + + // We create a task in the first column + $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(2, $p->create(array('name' => 'project 2'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Our event should NOT be executed because we define the same project + $action->setParam('column_id', 2); + $action->setParam('project_id', 1); + $this->assertFalse($action->execute(new GenericEvent($event))); + + // Our task should be assigned to the project 1 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['project_id']); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Our event should be executed because we define a different project + $action->setParam('column_id', 2); + $action->setParam('project_id', 2); + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be assigned to the project 2 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + } +} diff --git a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php new file mode 100644 index 00000000..4b7dec68 --- /dev/null +++ b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php @@ -0,0 +1,61 @@ +container, 1, Task::EVENT_UPDATE); + $action->setParam('dest_column_id', 3); + $action->setParam('category_id', 1); + + $this->assertEquals(3, $action->getParam('dest_column_id')); + $this->assertEquals(1, $action->getParam('category_id')); + + // We create a task in the first column + $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' => 'test'))); + $this->assertEquals(1, $c->create(array('name' => 'bug', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // No category should be assigned + column_id=1 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEmpty($task['category_id']); + $this->assertEquals(1, $task['column_id']); + + // We create an event to move the task to the 2nd column + $event = array( + 'task_id' => 1, + 'column_id' => 1, + 'project_id' => 1, + 'category_id' => 1, + ); + + // Our event should be executed + $this->assertTrue($action->hasCompatibleEvent()); + $this->assertTrue($action->hasRequiredProject($event)); + $this->assertTrue($action->hasRequiredParameters($event)); + $this->assertTrue($action->hasRequiredCondition($event)); + $this->assertTrue($action->isExecutable($event)); + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be moved to the other column + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(3, $task['column_id']); + } +} diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php new file mode 100644 index 00000000..14f3b5b7 --- /dev/null +++ b/tests/units/Action/TaskUpdateStartDateTest.php @@ -0,0 +1,45 @@ +container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($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, 'column_id' => 1))); + + // The start date must be empty + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEmpty($task['date_started']); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be updated + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(time(), $task['date_started'], '', 2); + } +} diff --git a/tests/units/ActionCommentCreationTest.php b/tests/units/ActionCommentCreationTest.php deleted file mode 100644 index cf9e1e0a..00000000 --- a/tests/units/ActionCommentCreationTest.php +++ /dev/null @@ -1,124 +0,0 @@ -container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Comment($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'user_id' => 1, - ); - - // Our event should be executed - $this->assertFalse($action->execute(new GenericEvent($event))); - - $comment = $c->getById(1); - $this->assertEmpty($comment); - } - - public function testWithCommitMessage() - { - $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Comment($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'commit_comment' => 'plop', - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - $comment = $c->getById(1); - $this->assertNotEmpty($comment); - $this->assertEquals(1, $comment['task_id']); - $this->assertEquals(0, $comment['user_id']); - $this->assertEquals('plop', $comment['comment']); - } - - public function testWithUser() - { - $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Comment($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'user_id' => 1, - 'comment' => 'youpi', - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - $comment = $c->getById(1); - $this->assertNotEmpty($comment); - $this->assertEquals(1, $comment['task_id']); - $this->assertEquals(1, $comment['user_id']); - $this->assertEquals('youpi', $comment['comment']); - } - - public function testWithNoUser() - { - $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Comment($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'user_id' => 0, - 'comment' => 'youpi', - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - $comment = $c->getById(1); - $this->assertNotEmpty($comment); - $this->assertEquals(1, $comment['task_id']); - $this->assertEquals(0, $comment['user_id']); - $this->assertEquals('youpi', $comment['comment']); - } -} diff --git a/tests/units/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php deleted file mode 100644 index 3669ce46..00000000 --- a/tests/units/ActionTaskAssignColorCategoryTest.php +++ /dev/null @@ -1,80 +0,0 @@ -container, 3, Task::EVENT_CREATE_UPDATE); - - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testExecute() - { - $action = new Action\TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE); - $action->setParam('category_id', 1); - $action->setParam('color_id', 'blue'); - - // We create a task in the first column - $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' => 'test'))); - $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 - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 1, - 'category_id' => 2, - 'position' => 2, - ); - - // Our event should NOT be executed - $this->assertFalse($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the ategory_id=1 and have the green color - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['category_id']); - $this->assertEquals('green', $task['color_id']); - - // We create an event to move the task - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 1, - 'position' => 5, - 'category_id' => 1, - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should have the blue color - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals('blue', $task['color_id']); - } -} diff --git a/tests/units/ActionTaskAssignColorColumnTest.php b/tests/units/ActionTaskAssignColorColumnTest.php deleted file mode 100644 index 363bb05c..00000000 --- a/tests/units/ActionTaskAssignColorColumnTest.php +++ /dev/null @@ -1,41 +0,0 @@ -container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $action->setParam('color_id', 'green'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($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, 'column_id' => 1, 'color_id' => 'yellow'))); - - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - 'color_id' => 'green', - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should have color green - $task = $tf->getById(1); - $this->assertEquals('green', $task['color_id']); - } -} diff --git a/tests/units/ActionTaskAssignColorLinkTest.php b/tests/units/ActionTaskAssignColorLinkTest.php deleted file mode 100644 index b0cd269e..00000000 --- a/tests/units/ActionTaskAssignColorLinkTest.php +++ /dev/null @@ -1,47 +0,0 @@ -container, 1, TaskLink::EVENT_CREATE_UPDATE); - $action->setParam('link_id', 2); - $action->setParam('color_id', 'green'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $tl = new TaskLink($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 color should be yellow - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals('yellow', $task['color_id']); - - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'link_id' => 2, - ); - - // Our event should be executed - $this->assertTrue($action->execute(new TaskLinkEvent($event))); - - // The color should be green - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals('green', $task['color_id']); - } -} diff --git a/tests/units/ActionTaskAssignColorUserTest.php b/tests/units/ActionTaskAssignColorUserTest.php deleted file mode 100644 index c1bf3a34..00000000 --- a/tests/units/ActionTaskAssignColorUserTest.php +++ /dev/null @@ -1,72 +0,0 @@ -container, 3, Task::EVENT_CREATE); - - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testExecute() - { - $action = new Action\TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE); - $action->setParam('user_id', 1); - $action->setParam('color_id', 'blue'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($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, 'column_id' => 1, 'color_id' => 'green'))); - - // We change the assignee - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'owner_id' => 5, - ); - - // Our event should NOT be executed - $this->assertFalse($action->execute(new GenericEvent($event))); - - // Our task should be assigned to nobody and have the green color - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals('green', $task['color_id']); - - // We change the assignee - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'owner_id' => 1, - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be assigned to nobody and have the blue color - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals('blue', $task['color_id']); - } -} diff --git a/tests/units/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php deleted file mode 100644 index f32fc77c..00000000 --- a/tests/units/ActionTaskAssignCurrentUserTest.php +++ /dev/null @@ -1,77 +0,0 @@ -container, 3, Task::EVENT_CREATE); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testBadColumn() - { - $action = new Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); - - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testExecute() - { - $action = new Action\TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $_SESSION = array( - 'user' => array('id' => 5) - ); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $us = new UserSession($this->container); - - $this->assertEquals(5, $us->getId()); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the user 5 (from the session) - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['id']); - $this->assertEquals(5, $task['owner_id']); - } -} diff --git a/tests/units/ActionTaskAssignSpecificUserTest.php b/tests/units/ActionTaskAssignSpecificUserTest.php deleted file mode 100644 index ac054ba6..00000000 --- a/tests/units/ActionTaskAssignSpecificUserTest.php +++ /dev/null @@ -1,70 +0,0 @@ -container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testBadColumn() - { - $action = new Action\TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); - - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testExecute() - { - $action = new Action\TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($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, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the user 1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['owner_id']); - } -} diff --git a/tests/units/ActionTaskCloseTest.php b/tests/units/ActionTaskCloseTest.php deleted file mode 100644 index 7f2c42de..00000000 --- a/tests/units/ActionTaskCloseTest.php +++ /dev/null @@ -1,108 +0,0 @@ -container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertTrue($action->isExecutable($event)); - - $action = new Action\TaskClose($this->container, 3, GithubWebhook::EVENT_COMMIT); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - ); - - $this->assertTrue($action->isExecutable($event)); - } - - public function testBadEvent() - { - $action = new Action\TaskClose($this->container, 3, Task::EVENT_UPDATE); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testBadProject() - { - $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testBadColumn() - { - $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); - - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testExecute() - { - $action = new Action\TaskClose($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($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, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be closed - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['is_active']); - } -} diff --git a/tests/units/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php deleted file mode 100644 index 10c7c36a..00000000 --- a/tests/units/ActionTaskDuplicateAnotherProjectTest.php +++ /dev/null @@ -1,94 +0,0 @@ -container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testBadColumn() - { - $action = new Action\TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); - - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testExecute() - { - $action = new Action\TaskDuplicateAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); - - // We create a task in the first column - $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(2, $p->create(array('name' => 'project 2'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should NOT be executed because we define the same project - $action->setParam('column_id', 2); - $action->setParam('project_id', 1); - $this->assertFalse($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the project 1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['project_id']); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should be executed because we define a different project - $action->setParam('column_id', 2); - $action->setParam('project_id', 2); - $this->assertTrue($action->hasRequiredCondition($event)); - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the project 1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['project_id']); - - // We should have another task assigned to the project 2 - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); - } -} diff --git a/tests/units/ActionTaskEmailTest.php b/tests/units/ActionTaskEmailTest.php deleted file mode 100644 index adc74512..00000000 --- a/tests/units/ActionTaskEmailTest.php +++ /dev/null @@ -1,149 +0,0 @@ -container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); - $action->setParam('subject', 'My email subject'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $u = new User($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Email should be not be sent - $this->container['emailClient']->expects($this->never())->method('send'); - - // Our event should be executed - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testWrongColumn() - { - $action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); - $action->setParam('subject', 'My email subject'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $u = new User($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 3, - ); - - // Email should be not be sent - $this->container['emailClient']->expects($this->never())->method('send'); - - // Our event should be executed - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testMoveColumn() - { - $action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); - $action->setParam('subject', 'My email subject'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $u = new User($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost'))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Email should be sent - $this->container['emailClient']->expects($this->once()) - ->method('send') - ->with( - $this->equalTo('admin@localhost'), - $this->equalTo('admin'), - $this->equalTo('My email subject'), - $this->stringContains('test') - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - } - - public function testTaskClose() - { - $action = new Action\TaskEmail($this->container, 1, Task::EVENT_CLOSE); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); - $action->setParam('subject', 'My email subject'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $u = new User($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost'))); - - // We create an event - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Email should be sent - $this->container['emailClient']->expects($this->once()) - ->method('send') - ->with( - $this->equalTo('admin@localhost'), - $this->equalTo('admin'), - $this->equalTo('My email subject'), - $this->stringContains('test') - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - } -} \ No newline at end of file diff --git a/tests/units/ActionTaskMoveAnotherProjectTest.php b/tests/units/ActionTaskMoveAnotherProjectTest.php deleted file mode 100644 index 3f0c3de6..00000000 --- a/tests/units/ActionTaskMoveAnotherProjectTest.php +++ /dev/null @@ -1,88 +0,0 @@ -container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testBadColumn() - { - $action = new Action\TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); - - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testExecute() - { - $action = new Action\TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); - - // We create a task in the first column - $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(2, $p->create(array('name' => 'project 2'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should NOT be executed because we define the same project - $action->setParam('column_id', 2); - $action->setParam('project_id', 1); - $this->assertFalse($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the project 1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['project_id']); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should be executed because we define a different project - $action->setParam('column_id', 2); - $action->setParam('project_id', 2); - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the project 2 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); - } -} diff --git a/tests/units/ActionTaskMoveColumnCategoryChangeTest.php b/tests/units/ActionTaskMoveColumnCategoryChangeTest.php deleted file mode 100644 index 0ddee786..00000000 --- a/tests/units/ActionTaskMoveColumnCategoryChangeTest.php +++ /dev/null @@ -1,61 +0,0 @@ -container, 1, Task::EVENT_UPDATE); - $action->setParam('dest_column_id', 3); - $action->setParam('category_id', 1); - - $this->assertEquals(3, $action->getParam('dest_column_id')); - $this->assertEquals(1, $action->getParam('category_id')); - - // We create a task in the first column - $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' => 'test'))); - $this->assertEquals(1, $c->create(array('name' => 'bug', 'project_id' => 1))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // No category should be assigned + column_id=1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEmpty($task['category_id']); - $this->assertEquals(1, $task['column_id']); - - // We create an event to move the task to the 2nd column - $event = array( - 'task_id' => 1, - 'column_id' => 1, - 'project_id' => 1, - 'category_id' => 1, - ); - - // Our event should be executed - $this->assertTrue($action->hasCompatibleEvent()); - $this->assertTrue($action->hasRequiredProject($event)); - $this->assertTrue($action->hasRequiredParameters($event)); - $this->assertTrue($action->hasRequiredCondition($event)); - $this->assertTrue($action->isExecutable($event)); - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be moved to the other column - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(3, $task['column_id']); - } -} diff --git a/tests/units/ActionTaskUpdateStartDateTest.php b/tests/units/ActionTaskUpdateStartDateTest.php deleted file mode 100644 index a7df820f..00000000 --- a/tests/units/ActionTaskUpdateStartDateTest.php +++ /dev/null @@ -1,45 +0,0 @@ -container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($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, 'column_id' => 1))); - - // The start date must be empty - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEmpty($task['date_started']); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be updated - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(time(), $task['date_started'], '', 2); - } -} diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php deleted file mode 100644 index 7e0287a2..00000000 --- a/tests/units/ActionTest.php +++ /dev/null @@ -1,379 +0,0 @@ -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']); - } -} diff --git a/tests/units/AppHelperTest.php b/tests/units/AppHelperTest.php deleted file mode 100644 index ad4bc151..00000000 --- a/tests/units/AppHelperTest.php +++ /dev/null @@ -1,38 +0,0 @@ -container); - $this->assertEquals('en', $h->jsLang()); - } - - public function testTimezone() - { - $h = new App($this->container); - $this->assertEquals('UTC', $h->getTimezone()); - } - - public function testFlashMessage() - { - $h = new App($this->container); - $s = new Session; - - $this->assertEmpty($h->flashMessage()); - $s->flash('test & test'); - $this->assertEquals('
test & test
', $h->flashMessage()); - $this->assertEmpty($h->flashMessage()); - - $this->assertEmpty($h->flashMessage()); - $s->flashError('test & test'); - $this->assertEquals('
test & test
', $h->flashMessage()); - $this->assertEmpty($h->flashMessage()); - } -} diff --git a/tests/units/AssetHelperTest.php b/tests/units/AssetHelperTest.php deleted file mode 100644 index 1143ce1f..00000000 --- a/tests/units/AssetHelperTest.php +++ /dev/null @@ -1,21 +0,0 @@ -container); - $c = new Config($this->container); - - $this->assertEmpty($h->customCss()); - - $this->assertTrue($c->save(array('application_stylesheet' => 'p { color: red }'))); - - $this->assertEquals('', $h->customCss()); - } -} diff --git a/tests/units/Auth/LdapTest.php b/tests/units/Auth/LdapTest.php new file mode 100644 index 00000000..e861be98 --- /dev/null +++ b/tests/units/Auth/LdapTest.php @@ -0,0 +1,122 @@ +ldap_connect($hostname, $port); +} + +function ldap_set_option() +{ +} + +function ldap_bind($ldap, $ldap_username, $ldap_password) +{ + return LdapTest::$functions->ldap_bind($ldap, $ldap_username, $ldap_password); +} + +class LdapTest extends \Base +{ + public static $functions; + + public function setUp() + { + parent::setup(); + + self::$functions = $this + ->getMockBuilder('stdClass') + ->setMethods(array( + 'ldap_connect', + 'ldap_set_option', + 'ldap_bind', + )) + ->getMock(); + } + + public function tearDown() + { + parent::tearDown(); + self::$functions = null; + } + + public function testConnectSuccess() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->willReturn(true); + + $ldap = new Ldap($this->container); + $this->assertNotFalse($ldap->connect()); + } + + public function testConnectFailure() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->willReturn(false); + + $ldap = new Ldap($this->container); + $this->assertFalse($ldap->connect()); + } + + public function testBindAnonymous() + { + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->with( + $this->equalTo('my_ldap_connection'), + $this->equalTo(null), + $this->equalTo(null) + ) + ->willReturn(true); + + $ldap = new Ldap($this->container); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'anonymous')); + } + + public function testBindUser() + { + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->with( + $this->equalTo('my_ldap_connection'), + $this->equalTo('uid=my_user'), + $this->equalTo('my_password') + ) + ->willReturn(true); + + $ldap = new Ldap($this->container); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'user', 'uid=%s', 'something')); + } + + public function testBindProxy() + { + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->with( + $this->equalTo('my_ldap_connection'), + $this->equalTo('someone'), + $this->equalTo('something') + ) + ->willReturn(true); + + $ldap = new Ldap($this->container); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'proxy', 'someone', 'something')); + } +} diff --git a/tests/units/AuthenticationTest.php b/tests/units/AuthenticationTest.php deleted file mode 100644 index 75b55ece..00000000 --- a/tests/units/AuthenticationTest.php +++ /dev/null @@ -1,39 +0,0 @@ -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')); - } -} diff --git a/tests/units/Base.php b/tests/units/Base.php index 0a045a09..a48ae5ec 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -1,6 +1,9 @@ container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, array($this, 'onCommit')); - - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $bw = new BitbucketWebhook($this->container); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_push.json'), true); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $bw->setProjectId(1); - - // No task - $this->assertFalse($bw->handlePush($payload)); - - // Create task with the wrong id - $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1))); - $this->assertFalse($bw->handlePush($payload)); - - // Create task with the right id - $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1))); - $this->assertTrue($bw->handlePush($payload)); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.BitbucketWebhookTest::onCommit', $called); - } - - public function testIssueOpened() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_OPENED, array($this, 'onIssueOpened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $bw = new BitbucketWebhook($this->container); - $bw->setProjectId(1); - - $this->assertNotFalse($bw->parsePayload( - 'issue:created', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_opened.json'), true) - )); - } - - public function testCommentCreatedWithNoUser() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:comment_created', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithNotMember() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:comment_created', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithUser() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:comment_created', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_comment_created.json'), true) - )); - } - - public function testIssueClosed() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_closed.json'), true) - )); - } - - public function testIssueClosedWithNoTask() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 42, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_closed.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueReopened() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_reopened.json'), true) - )); - } - - public function testIssueReopenedWithNoTask() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 42, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_reopened.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueUnassigned() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueUnassigned')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_unassigned.json'), true) - )); - } - - public function testIssueAssigned() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueAssigned')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true) - )); - - $this->assertNotEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueAssignedWithNoPermission() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function() {}); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueAssignedWithNoUser() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function() {}); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueAssignedWithNoTask() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function() {}); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 43, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function onCommit($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(2, $data['task_id']); - $this->assertEquals('test2', $data['title']); - $this->assertEquals("Test another commit #2\n\n\n[Commit made by @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6)", $data['commit_comment']); - $this->assertEquals("Test another commit #2\n", $data['commit_message']); - $this->assertEquals('https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6', $data['commit_url']); - } - - public function onIssueOpened($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['reference']); - $this->assertEquals('My new issue', $data['title']); - $this->assertEquals("**test**\n\n[Bitbucket Issue](https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue)", $data['description']); - } - - public function onCommentCreatedWithNoUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(19176252, $data['reference']); - $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']); - } - - public function onCommentCreatedWithNotMember($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(19176252, $data['reference']); - $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']); - } - - public function onCommentCreatedWithUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(2, $data['user_id']); - $this->assertEquals(19176252, $data['reference']); - $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']); - } - - public function onIssueClosed($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(1, $data['reference']); - } - - public function onIssueReopened($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(1, $data['reference']); - } - - public function onIssueAssigned($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(1, $data['reference']); - $this->assertEquals(2, $data['owner_id']); - } - - public function onIssueUnassigned($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(1, $data['reference']); - $this->assertEquals(0, $data['owner_id']); - } -} diff --git a/tests/units/BoardTest.php b/tests/units/BoardTest.php deleted file mode 100644 index 3542f783..00000000 --- a/tests/units/BoardTest.php +++ /dev/null @@ -1,372 +0,0 @@ -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']); - } -} diff --git a/tests/units/CategoryTest.php b/tests/units/CategoryTest.php deleted file mode 100644 index 638f3fe4..00000000 --- a/tests/units/CategoryTest.php +++ /dev/null @@ -1,67 +0,0 @@ -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']); - } -} diff --git a/tests/units/CommentTest.php b/tests/units/CommentTest.php deleted file mode 100644 index 295ac60e..00000000 --- a/tests/units/CommentTest.php +++ /dev/null @@ -1,142 +0,0 @@ -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]); - } -} diff --git a/tests/units/ConfigTest.php b/tests/units/ConfigTest.php deleted file mode 100644 index f93619d6..00000000 --- a/tests/units/ConfigTest.php +++ /dev/null @@ -1,66 +0,0 @@ -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')); - } -} diff --git a/tests/units/Core/LexerTest.php b/tests/units/Core/LexerTest.php new file mode 100644 index 00000000..044655fc --- /dev/null +++ b/tests/units/Core/LexerTest.php @@ -0,0 +1,443 @@ +assertEquals( + array(array('match' => 'swimlane:', 'token' => 'T_SWIMLANE'), array('match' => 'Version 42', 'token' => 'T_STRING')), + $lexer->tokenize('swimlane:"Version 42"') + ); + + $this->assertEquals( + array(array('match' => 'swimlane:', 'token' => 'T_SWIMLANE'), array('match' => 'v3', 'token' => 'T_STRING')), + $lexer->tokenize('swimlane:v3') + ); + + $this->assertEquals( + array('T_SWIMLANE' => array('v3')), + $lexer->map($lexer->tokenize('swimlane:v3')) + ); + + $this->assertEquals( + array('T_SWIMLANE' => array('Version 42', 'v3')), + $lexer->map($lexer->tokenize('swimlane:"Version 42" swimlane:v3')) + ); + } + + public function testAssigneeQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'me', 'token' => 'T_STRING')), + $lexer->tokenize('assignee:me') + ); + + $this->assertEquals( + array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'everybody', 'token' => 'T_STRING')), + $lexer->tokenize('assignee:everybody') + ); + + $this->assertEquals( + array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'nobody', 'token' => 'T_STRING')), + $lexer->tokenize('assignee:nobody') + ); + + $this->assertEquals( + array('T_ASSIGNEE' => array('nobody')), + $lexer->map($lexer->tokenize('assignee:nobody')) + ); + + $this->assertEquals( + array('T_ASSIGNEE' => array('John Doe', 'me')), + $lexer->map($lexer->tokenize('assignee:"John Doe" assignee:me')) + ); + } + + public function testColorQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'color:', 'token' => 'T_COLOR'), array('match' => 'Blue', 'token' => 'T_STRING')), + $lexer->tokenize('color:Blue') + ); + + $this->assertEquals( + array(array('match' => 'color:', 'token' => 'T_COLOR'), array('match' => 'Dark Grey', 'token' => 'T_STRING')), + $lexer->tokenize('color:"Dark Grey"') + ); + + $this->assertEquals( + array('T_COLOR' => array('Blue')), + $lexer->map($lexer->tokenize('color:Blue')) + ); + + $this->assertEquals( + array('T_COLOR' => array('Dark Grey')), + $lexer->map($lexer->tokenize('color:"Dark Grey"')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('color: ')) + ); + } + + public function testCategoryQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'category:', 'token' => 'T_CATEGORY'), array('match' => 'Feature Request', 'token' => 'T_STRING')), + $lexer->tokenize('category:"Feature Request"') + ); + + $this->assertEquals( + array('T_CATEGORY' => array('Feature Request')), + $lexer->map($lexer->tokenize('category:"Feature Request"')) + ); + + $this->assertEquals( + array('T_CATEGORY' => array('Feature Request', 'Bug')), + $lexer->map($lexer->tokenize('category:"Feature Request" category:Bug')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('category: ')) + ); + } + + public function testColumnQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'column:', 'token' => 'T_COLUMN'), array('match' => 'Feature Request', 'token' => 'T_STRING')), + $lexer->tokenize('column:"Feature Request"') + ); + + $this->assertEquals( + array('T_COLUMN' => array('Feature Request')), + $lexer->map($lexer->tokenize('column:"Feature Request"')) + ); + + $this->assertEquals( + array('T_COLUMN' => array('Feature Request', 'Bug')), + $lexer->map($lexer->tokenize('column:"Feature Request" column:Bug')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('column: ')) + ); + } + + public function testProjectQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'project:', 'token' => 'T_PROJECT'), array('match' => 'My project', 'token' => 'T_STRING')), + $lexer->tokenize('project:"My project"') + ); + + $this->assertEquals( + array('T_PROJECT' => array('My project')), + $lexer->map($lexer->tokenize('project:"My project"')) + ); + + $this->assertEquals( + array('T_PROJECT' => array('My project', 'plop')), + $lexer->map($lexer->tokenize('project:"My project" project:plop')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('project: ')) + ); + } + + public function testStatusQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'status:', 'token' => 'T_STATUS'), array('match' => 'open', 'token' => 'T_STRING')), + $lexer->tokenize('status:open') + ); + + $this->assertEquals( + array(array('match' => 'status:', 'token' => 'T_STATUS'), array('match' => 'closed', 'token' => 'T_STRING')), + $lexer->tokenize('status:closed') + ); + + $this->assertEquals( + array('T_STATUS' => 'open'), + $lexer->map($lexer->tokenize('status:open')) + ); + + $this->assertEquals( + array('T_STATUS' => 'closed'), + $lexer->map($lexer->tokenize('status:closed')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('status: ')) + ); + } + + public function testReferenceQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'ref:', 'token' => 'T_REFERENCE'), array('match' => '123', 'token' => 'T_STRING')), + $lexer->tokenize('ref:123') + ); + + $this->assertEquals( + array(array('match' => 'reference:', 'token' => 'T_REFERENCE'), array('match' => '456', 'token' => 'T_STRING')), + $lexer->tokenize('reference:456') + ); + + $this->assertEquals( + array('T_REFERENCE' => '123'), + $lexer->map($lexer->tokenize('reference:123')) + ); + + $this->assertEquals( + array('T_REFERENCE' => '456'), + $lexer->map($lexer->tokenize('ref:456')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('ref: ')) + ); + } + + public function testDescriptionQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'description:', 'token' => 'T_DESCRIPTION'), array('match' => 'my text search', 'token' => 'T_STRING')), + $lexer->tokenize('description:"my text search"') + ); + + $this->assertEquals( + array('T_DESCRIPTION' => 'my text search'), + $lexer->map($lexer->tokenize('description:"my text search"')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('description: ')) + ); + } + + public function testDueDateQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('due:2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '<2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('due:<2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '>2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('due:>2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '<=2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('due:<=2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '>=2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('due:>=2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => 'yesterday', 'token' => 'T_DATE')), + $lexer->tokenize('due:yesterday') + ); + + $this->assertEquals( + array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => 'tomorrow', 'token' => 'T_DATE')), + $lexer->tokenize('due:tomorrow') + ); + + $this->assertEquals( + array(), + $lexer->tokenize('due:#2015-05-01') + ); + + $this->assertEquals( + array(), + $lexer->tokenize('due:01-05-1024') + ); + + $this->assertEquals( + array('T_DUE' => '2015-05-01'), + $lexer->map($lexer->tokenize('due:2015-05-01')) + ); + + $this->assertEquals( + array('T_DUE' => '<2015-05-01'), + $lexer->map($lexer->tokenize('due:<2015-05-01')) + ); + + $this->assertEquals( + array('T_DUE' => 'today'), + $lexer->map($lexer->tokenize('due:today')) + ); + } + + public function testModifiedQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'modified:', 'token' => 'T_UPDATED'), array('match' => '2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('modified:2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'modified:', 'token' => 'T_UPDATED'), array('match' => '<2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('modified:<2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'modified:', 'token' => 'T_UPDATED'), array('match' => '>2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('modified:>2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => '<=2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('updated:<=2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => '>=2015-05-01', 'token' => 'T_DATE')), + $lexer->tokenize('updated:>=2015-05-01') + ); + + $this->assertEquals( + array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => 'yesterday', 'token' => 'T_DATE')), + $lexer->tokenize('updated:yesterday') + ); + + $this->assertEquals( + array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => 'tomorrow', 'token' => 'T_DATE')), + $lexer->tokenize('updated:tomorrow') + ); + + $this->assertEquals( + array(), + $lexer->tokenize('updated:#2015-05-01') + ); + + $this->assertEquals( + array(), + $lexer->tokenize('modified:01-05-1024') + ); + + $this->assertEquals( + array('T_UPDATED' => '2015-05-01'), + $lexer->map($lexer->tokenize('modified:2015-05-01')) + ); + + $this->assertEquals( + array('T_UPDATED' => '<2015-05-01'), + $lexer->map($lexer->tokenize('modified:<2015-05-01')) + ); + + $this->assertEquals( + array('T_UPDATED' => 'today'), + $lexer->map($lexer->tokenize('modified:today')) + ); + } + + public function testMultipleCriterias() + { + $lexer = new Lexer; + + $this->assertEquals( + array('T_COLOR' => array('Dark Grey'), 'T_ASSIGNEE' => array('Fred G'), 'T_TITLE' => 'my task title'), + $lexer->map($lexer->tokenize('color:"Dark Grey" assignee:"Fred G" my task title')) + ); + + $this->assertEquals( + array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow')), + $lexer->map($lexer->tokenize('my title color:yellow')) + ); + + $this->assertEquals( + array('T_TITLE' => 'my title', 'T_DUE' => '2015-04-01'), + $lexer->map($lexer->tokenize('my title due:2015-04-01')) + ); + + $this->assertEquals( + array('T_TITLE' => 'awesome', 'T_DUE' => '<=2015-04-01'), + $lexer->map($lexer->tokenize('due:<=2015-04-01 awesome')) + ); + + $this->assertEquals( + array('T_TITLE' => 'awesome', 'T_DUE' => 'today'), + $lexer->map($lexer->tokenize('due:today awesome')) + ); + + $this->assertEquals( + array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow'), 'T_DUE' => '2015-04-01'), + $lexer->map($lexer->tokenize('my title color:yellow due:2015-04-01')) + ); + + $this->assertEquals( + array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow'), 'T_DUE' => '2015-04-01', 'T_ASSIGNEE' => array('John Doe')), + $lexer->map($lexer->tokenize('my title color:yellow due:2015-04-01 assignee:"John Doe"')) + ); + + $this->assertEquals( + array('T_TITLE' => 'my title'), + $lexer->map($lexer->tokenize('my title color:')) + ); + + $this->assertEquals( + array('T_TITLE' => 'my title'), + $lexer->map($lexer->tokenize('my title color:assignee:')) + ); + + $this->assertEquals( + array('T_TITLE' => 'my title'), + $lexer->map($lexer->tokenize('my title ')) + ); + + $this->assertEquals( + array('T_TITLE' => '#123'), + $lexer->map($lexer->tokenize('#123')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('color:assignee:')) + ); + } +} diff --git a/tests/units/Core/OAuth2Test.php b/tests/units/Core/OAuth2Test.php new file mode 100644 index 00000000..a0e4b43f --- /dev/null +++ b/tests/units/Core/OAuth2Test.php @@ -0,0 +1,43 @@ +container); + $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); + $this->assertEquals('D?response_type=code&client_id=A&redirect_uri=C&scope=f+g', $oauth->getAuthorizationUrl()); + } + + public function testAuthHeader() + { + $oauth = new OAuth2($this->container); + $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); + + $oauth->setAccessToken('foobar', 'BeaRer'); + $this->assertEquals('Authorization: Bearer foobar', $oauth->getAuthorizationHeader()); + + $oauth->setAccessToken('foobar', 'unknown'); + $this->assertEquals('', $oauth->getAuthorizationHeader()); + } + + public function testAccessToken() + { + $oauth = new OAuth2($this->container); + $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); + $oauth->getAccessToken('something'); + + $data = $this->container['httpClient']->getData(); + $this->assertEquals('something', $data['code']); + $this->assertEquals('A', $data['client_id']); + $this->assertEquals('B', $data['client_secret']); + $this->assertEquals('C', $data['redirect_uri']); + $this->assertEquals('authorization_code', $data['grant_type']); + + $this->assertEquals('E', $this->container['httpClient']->getUrl()); + } +} diff --git a/tests/units/Core/RouterTest.php b/tests/units/Core/RouterTest.php new file mode 100644 index 00000000..99c49ba8 --- /dev/null +++ b/tests/units/Core/RouterTest.php @@ -0,0 +1,79 @@ +container); + + $this->assertEquals('plop', $r->sanitize('PloP', 'default')); + $this->assertEquals('default', $r->sanitize('', 'default')); + $this->assertEquals('default', $r->sanitize('123-AB', 'default')); + $this->assertEquals('default', $r->sanitize('R&D', 'default')); + $this->assertEquals('default', $r->sanitize('Test123', 'default')); + } + + public function testPath() + { + $r = new Router($this->container); + + $this->assertEquals('a/b/c', $r->getPath('/a/b/c')); + $this->assertEquals('a/b/something', $r->getPath('/a/b/something?test=a', 'test=a')); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['PHP_SELF'] = '/a/index.php'; + + $this->assertEquals('b/c', $r->getPath('/a/b/c')); + $this->assertEquals('b/c', $r->getPath('/a/b/c?e=f', 'e=f')); + } + + public function testFindRouteWithEmptyTable() + { + $r = new Router($this->container); + $this->assertEquals(array('app', 'index'), $r->findRoute('')); + $this->assertEquals(array('app', 'index'), $r->findRoute('/')); + } + + public function testFindRouteWithoutPlaceholders() + { + $r = new Router($this->container); + $r->addRoute('a/b', 'controller', 'action'); + $this->assertEquals(array('app', 'index'), $r->findRoute('a/b/c')); + $this->assertEquals(array('controller', 'action'), $r->findRoute('a/b')); + } + + public function testFindRouteWithPlaceholders() + { + $r = new Router($this->container); + $r->addRoute('a/:myvar1/b/:myvar2', 'controller', 'action'); + $this->assertEquals(array('app', 'index'), $r->findRoute('a/123/b')); + $this->assertEquals(array('controller', 'action'), $r->findRoute('a/456/b/789')); + $this->assertEquals(array('myvar1' => 456, 'myvar2' => 789), $_GET); + } + + public function testFindMultipleRoutes() + { + $r = new Router($this->container); + $r->addRoute('a/b', 'controller1', 'action1'); + $r->addRoute('a/b', 'duplicate', 'duplicate'); + $r->addRoute('a', 'controller2', 'action2'); + $this->assertEquals(array('controller1', 'action1'), $r->findRoute('a/b')); + $this->assertEquals(array('controller2', 'action2'), $r->findRoute('a')); + } + + public function testFindUrl() + { + $r = new Router($this->container); + $r->addRoute('a/b', 'controller1', 'action1'); + $r->addRoute('a/:myvar1/b/:myvar2', 'controller2', 'action2', array('myvar1', 'myvar2')); + + $this->assertEquals('a/1/b/2', $r->findUrl('controller2', 'action2', array('myvar1' => 1, 'myvar2' => 2))); + $this->assertEquals('', $r->findUrl('controller2', 'action2', array('myvar1' => 1))); + $this->assertEquals('a/b', $r->findUrl('controller1', 'action1')); + $this->assertEquals('', $r->findUrl('controller1', 'action2')); + } +} diff --git a/tests/units/Core/ToolTest.php b/tests/units/Core/ToolTest.php new file mode 100644 index 00000000..e714f506 --- /dev/null +++ b/tests/units/Core/ToolTest.php @@ -0,0 +1,15 @@ +assertEquals('test1', Tool::getMailboxHash('a+test1@localhost')); + $this->assertEquals('', Tool::getMailboxHash('test1@localhost')); + $this->assertEquals('', Tool::getMailboxHash('test1')); + } +} diff --git a/tests/units/DateParserTest.php b/tests/units/DateParserTest.php deleted file mode 100644 index 4b3e93c8..00000000 --- a/tests/units/DateParserTest.php +++ /dev/null @@ -1,84 +0,0 @@ -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'])); - } -} diff --git a/tests/units/DatetimeHelperTest.php b/tests/units/DatetimeHelperTest.php deleted file mode 100644 index 21d452dd..00000000 --- a/tests/units/DatetimeHelperTest.php +++ /dev/null @@ -1,56 +0,0 @@ -container); - - $this->assertEquals('<15m', $h->age(0, 30)); - $this->assertEquals('<30m', $h->age(0, 1000)); - $this->assertEquals('<1h', $h->age(0, 3000)); - $this->assertEquals('~2h', $h->age(0, 2*3600)); - $this->assertEquals('1d', $h->age(0, 30*3600)); - $this->assertEquals('2d', $h->age(0, 65*3600)); - } - - public function testGetDayHours() - { - $h = new Dt($this->container); - - $slots = $h->getDayHours(); - - $this->assertNotEmpty($slots); - $this->assertCount(48, $slots); - $this->assertArrayHasKey('00:00', $slots); - $this->assertArrayHasKey('00:30', $slots); - $this->assertArrayHasKey('01:00', $slots); - $this->assertArrayHasKey('01:30', $slots); - $this->assertArrayHasKey('23:30', $slots); - $this->assertArrayNotHasKey('24:00', $slots); - } - - public function testGetWeekDays() - { - $h = new Dt($this->container); - - $slots = $h->getWeekDays(); - - $this->assertNotEmpty($slots); - $this->assertCount(7, $slots); - $this->assertContains('Monday', $slots); - $this->assertContains('Sunday', $slots); - } - - public function testGetWeekDay() - { - $h = new Dt($this->container); - - $this->assertEquals('Monday', $h->getWeekDay(1)); - $this->assertEquals('Sunday', $h->getWeekDay(7)); - } -} diff --git a/tests/units/FileHelperText.php b/tests/units/FileHelperText.php deleted file mode 100644 index ce04fdbd..00000000 --- a/tests/units/FileHelperText.php +++ /dev/null @@ -1,15 +0,0 @@ -container); - $this->assertEquals('fa-file-image-o', $h->icon('test.png')); - $this->assertEquals('fa-file-o', $h->icon('test')); - } -} diff --git a/tests/units/FileTest.php b/tests/units/FileTest.php deleted file mode 100644 index 4ea7f386..00000000 --- a/tests/units/FileTest.php +++ /dev/null @@ -1,190 +0,0 @@ -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); - } -} diff --git a/tests/units/GithubWebhookTest.php b/tests/units/GithubWebhookTest.php deleted file mode 100644 index e143cc1d..00000000 --- a/tests/units/GithubWebhookTest.php +++ /dev/null @@ -1,459 +0,0 @@ -container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_OPENED, array($this, 'onIssueOpened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_opened.json'), true) - )); - } - - public function testIssueAssigned() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueAssigned')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true) - )); - } - - public function testIssueAssignedWithNoExistingTask() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true); - - $this->assertFalse($g->handleIssueAssigned($payload['issue'])); - } - - public function testIssueAssignedWithNoExistingUser() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true); - - $this->assertFalse($g->handleIssueAssigned($payload['issue'])); - } - - public function testIssueAssignedWithNoMember() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true); - - $this->assertFalse($g->handleIssueAssigned($payload['issue'])); - } - - public function testIssueAssignedWithMember() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true); - - $this->assertTrue($g->handleIssueAssigned($payload['issue'])); - } - - public function testIssueUnassigned() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueUnassigned')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_unassigned.json'), true) - )); - } - - public function testIssueClosed() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_closed.json'), true) - )); - } - - public function testIssueClosedWithTaskNotFound() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_closed.json'), true); - - $this->assertFalse($g->handleIssueClosed($payload['issue'])); - } - - public function testIssueReopened() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_reopened.json'), true) - )); - } - - public function testIssueReopenedWithTaskNotFound() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_reopened.json'), true); - - $this->assertFalse($g->handleIssueReopened($payload['issue'])); - } - - public function testIssueLabeled() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_LABEL_CHANGE, array($this, 'onIssueLabeled')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_labeled.json'), true) - )); - } - - public function testIssueLabeledWithTaskNotFound() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_labeled.json'), true); - - $this->assertFalse($g->handleIssueLabeled($payload['issue'], $payload['label'])); - } - - public function testIssueUnLabeled() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_LABEL_CHANGE, array($this, 'onIssueUnlabeled')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_unlabeled.json'), true) - )); - } - - public function testIssueUnLabeledWithTaskNotFound() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_unlabeled.json'), true); - - $this->assertFalse($g->handleIssueUnlabeled($payload['issue'], $payload['label'])); - } - - public function testCommentCreatedWithNoUser() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue_comment', - json_decode(file_get_contents(__DIR__.'/fixtures/github_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithNotMember() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue_comment', - json_decode(file_get_contents(__DIR__.'/fixtures/github_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithUser() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue_comment', - json_decode(file_get_contents(__DIR__.'/fixtures/github_comment_created.json'), true) - )); - } - - public function testPush() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_COMMIT, array($this, 'onPush')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'push', - json_decode(file_get_contents(__DIR__.'/fixtures/github_push.json'), true) - )); - } - - public function onIssueOpened($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals('Test Webhook', $data['title']); - $this->assertEquals("plop\n\n[Github Issue](https://github.com/kanboardapp/webhook/issues/3)", $data['description']); - } - - public function onIssueAssigned($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals(2, $data['owner_id']); - } - - public function onIssueUnassigned($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals(0, $data['owner_id']); - } - - public function onIssueClosed($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - } - - public function onIssueReopened($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - } - - public function onIssueLabeled($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals('bug', $data['label']); - } - - public function onIssueUnlabeled($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals('bug', $data['label']); - $this->assertEquals(0, $data['category_id']); - } - - public function onCommentCreatedWithNoUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(113834672, $data['reference']); - $this->assertEquals("test\n\n[By @fguillot on Github](https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672)", $data['comment']); - } - - public function onCommentCreatedWithNotMember($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(113834672, $data['reference']); - $this->assertEquals("test\n\n[By @fguillot on Github](https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672)", $data['comment']); - } - - public function onCommentCreatedWithUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(2, $data['user_id']); - $this->assertEquals(113834672, $data['reference']); - $this->assertEquals("test\n\n[By @fguillot on Github](https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672)", $data['comment']); - } - - public function onPush($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals('boo', $data['title']); - $this->assertEquals("Update README to fix #1\n\n[Commit made by @fguillot on Github](https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6)", $data['commit_comment']); - $this->assertEquals('Update README to fix #1', $data['commit_message']); - $this->assertEquals('https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6', $data['commit_url']); - } -} diff --git a/tests/units/GitlabWebhookTest.php b/tests/units/GitlabWebhookTest.php deleted file mode 100644 index a2dc0d3a..00000000 --- a/tests/units/GitlabWebhookTest.php +++ /dev/null @@ -1,221 +0,0 @@ -container); - - $this->assertEquals(GitlabWebhook::TYPE_PUSH, $g->getType(json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_push.json'), true))); - $this->assertEquals(GitlabWebhook::TYPE_ISSUE, $g->getType(json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_issue_opened.json'), true))); - $this->assertEquals(GitlabWebhook::TYPE_COMMENT, $g->getType(json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_comment_created.json'), true))); - $this->assertEquals('', $g->getType(array())); - } - - public function testHandleCommit() - { - $g = new GitlabWebhook($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $g->setProjectId(1); - - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_COMMIT, array($this, 'onCommit')); - - $event = json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_push.json'), true); - - // No task - $this->assertFalse($g->handleCommit($event['commits'][0])); - - // Create task with the wrong id - $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1))); - $this->assertFalse($g->handleCommit($event['commits'][0])); - - // Create task with the right id - $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1))); - $this->assertTrue($g->handleCommit($event['commits'][0])); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(GitlabWebhook::EVENT_COMMIT.'.GitlabWebhookTest::onCommit', $called); - } - - public function testHandleIssueOpened() - { - $g = new GitlabWebhook($this->container); - $g->setProjectId(1); - - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_OPENED, array($this, 'onOpen')); - - $event = json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_issue_opened.json'), true); - $this->assertTrue($g->handleIssueOpened($event['object_attributes'])); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_OPENED.'.GitlabWebhookTest::onOpen', $called); - } - - public function testHandleIssueClosed() - { - $g = new GitlabWebhook($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $g->setProjectId(1); - - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_CLOSED, array($this, 'onClose')); - - $event = json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_issue_closed.json'), true); - - // Issue not there - $this->assertFalse($g->handleIssueClosed($event['object_attributes'])); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertEmpty($called); - - // Create a task with the issue reference - $this->assertEquals(1, $tc->create(array('title' => 'A', 'project_id' => 1, 'reference' => 355691))); - $task = $tf->getByReference(1, 355691); - $this->assertNotEmpty($task); - - $task = $tf->getByReference(2, 355691); - $this->assertEmpty($task); - - $this->assertTrue($g->handleIssueClosed($event['object_attributes'])); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_CLOSED.'.GitlabWebhookTest::onClose', $called); - } - - public function testCommentCreatedWithNoUser() - { - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1))); - - $g = new GitlabWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithNotMember() - { - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $g = new GitlabWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithUser() - { - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new GitlabWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_comment_created.json'), true) - )); - } - - public function onOpen($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(355691, $data['reference']); - $this->assertEquals('Bug', $data['title']); - $this->assertEquals("There is a bug somewhere.\r\n\r\nBye\n\n[Gitlab Issue](https://gitlab.com/minicoders/test-webhook/issues/1)", $data['description']); - } - - public function onClose($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(355691, $data['reference']); - } - - public function onCommit($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(2, $data['task_id']); - $this->assertEquals('test2', $data['title']); - $this->assertEquals("Fix bug #2\n\n[Commit made by @Fred on Gitlab](https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78)", $data['commit_comment']); - $this->assertEquals("Fix bug #2", $data['commit_message']); - $this->assertEquals('https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78', $data['commit_url']); - } - - public function onCommentCreatedWithNoUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(1642761, $data['reference']); - $this->assertEquals("Super comment!\n\n[By @minicoders on Gitlab](https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761)", $data['comment']); - } - - public function onCommentCreatedWithNotMember($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(1642761, $data['reference']); - $this->assertEquals("Super comment!\n\n[By @minicoders on Gitlab](https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761)", $data['comment']); - } - - public function onCommentCreatedWithUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(2, $data['user_id']); - $this->assertEquals(1642761, $data['reference']); - $this->assertEquals("Super comment!\n\n[By @minicoders on Gitlab](https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761)", $data['comment']); - } -} diff --git a/tests/units/Helper/AppHelperTest.php b/tests/units/Helper/AppHelperTest.php new file mode 100644 index 00000000..54ccd697 --- /dev/null +++ b/tests/units/Helper/AppHelperTest.php @@ -0,0 +1,38 @@ +container); + $this->assertEquals('en', $h->jsLang()); + } + + public function testTimezone() + { + $h = new App($this->container); + $this->assertEquals('UTC', $h->getTimezone()); + } + + public function testFlashMessage() + { + $h = new App($this->container); + $s = new Session; + + $this->assertEmpty($h->flashMessage()); + $s->flash('test & test'); + $this->assertEquals('
test & test
', $h->flashMessage()); + $this->assertEmpty($h->flashMessage()); + + $this->assertEmpty($h->flashMessage()); + $s->flashError('test & test'); + $this->assertEquals('
test & test
', $h->flashMessage()); + $this->assertEmpty($h->flashMessage()); + } +} diff --git a/tests/units/Helper/AssetHelperTest.php b/tests/units/Helper/AssetHelperTest.php new file mode 100644 index 00000000..ece81d04 --- /dev/null +++ b/tests/units/Helper/AssetHelperTest.php @@ -0,0 +1,21 @@ +container); + $c = new Config($this->container); + + $this->assertEmpty($h->customCss()); + + $this->assertTrue($c->save(array('application_stylesheet' => 'p { color: red }'))); + + $this->assertEquals('', $h->customCss()); + } +} diff --git a/tests/units/Helper/DatetimeHelperTest.php b/tests/units/Helper/DatetimeHelperTest.php new file mode 100644 index 00000000..d4fc3c3d --- /dev/null +++ b/tests/units/Helper/DatetimeHelperTest.php @@ -0,0 +1,56 @@ +container); + + $this->assertEquals('<15m', $h->age(0, 30)); + $this->assertEquals('<30m', $h->age(0, 1000)); + $this->assertEquals('<1h', $h->age(0, 3000)); + $this->assertEquals('~2h', $h->age(0, 2*3600)); + $this->assertEquals('1d', $h->age(0, 30*3600)); + $this->assertEquals('2d', $h->age(0, 65*3600)); + } + + public function testGetDayHours() + { + $h = new Dt($this->container); + + $slots = $h->getDayHours(); + + $this->assertNotEmpty($slots); + $this->assertCount(48, $slots); + $this->assertArrayHasKey('00:00', $slots); + $this->assertArrayHasKey('00:30', $slots); + $this->assertArrayHasKey('01:00', $slots); + $this->assertArrayHasKey('01:30', $slots); + $this->assertArrayHasKey('23:30', $slots); + $this->assertArrayNotHasKey('24:00', $slots); + } + + public function testGetWeekDays() + { + $h = new Dt($this->container); + + $slots = $h->getWeekDays(); + + $this->assertNotEmpty($slots); + $this->assertCount(7, $slots); + $this->assertContains('Monday', $slots); + $this->assertContains('Sunday', $slots); + } + + public function testGetWeekDay() + { + $h = new Dt($this->container); + + $this->assertEquals('Monday', $h->getWeekDay(1)); + $this->assertEquals('Sunday', $h->getWeekDay(7)); + } +} diff --git a/tests/units/Helper/FileHelperText.php b/tests/units/Helper/FileHelperText.php new file mode 100644 index 00000000..cd5ebffd --- /dev/null +++ b/tests/units/Helper/FileHelperText.php @@ -0,0 +1,15 @@ +container); + $this->assertEquals('fa-file-image-o', $h->icon('test.png')); + $this->assertEquals('fa-file-o', $h->icon('test')); + } +} diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php new file mode 100644 index 00000000..5495cd1c --- /dev/null +++ b/tests/units/Helper/TextHelperTest.php @@ -0,0 +1,56 @@ +container); + + $this->assertEquals('

Test

', $h->markdown('Test')); + + $this->assertEquals( + '

Task #123

', + $h->markdown('Task #123') + ); + + $this->assertEquals( + '

Task #123

', + $h->markdown('Task #123', array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd'))) + ); + + $this->assertEquals( + '

Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

', + $h->markdown( + 'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454', + array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd')) + ) + ); + } + + public function testFormatBytes() + { + $h = new Text($this->container); + + $this->assertEquals('1k', $h->bytes(1024)); + $this->assertEquals('33.71k', $h->bytes(34520)); + } + + public function testContains() + { + $h = new Text($this->container); + + $this->assertTrue($h->contains('abc', 'b')); + $this->assertFalse($h->contains('abc', 'd')); + } + + public function testInList() + { + $h = new Text($this->container); + $this->assertEquals('?', $h->in('a', array('b' => 'c'))); + $this->assertEquals('c', $h->in('b', array('b' => 'c'))); + } +} diff --git a/tests/units/Helper/UrlHelperTest.php b/tests/units/Helper/UrlHelperTest.php new file mode 100644 index 00000000..5c2477b5 --- /dev/null +++ b/tests/units/Helper/UrlHelperTest.php @@ -0,0 +1,86 @@ +container); + $this->assertEquals( + 'label', + $h->link('label', 'a', 'b', array('d' => 'e'), false, 'f', 'g', true) + ); + } + + public function testHref() + { + $h = new Url($this->container); + $this->assertEquals( + '?controller=a&action=b&d=e', + $h->href('a', 'b', array('d' => 'e')) + ); + } + + public function testTo() + { + $h = new Url($this->container); + $this->assertEquals( + '?controller=a&action=b&d=e', + $h->to('a', 'b', array('d' => 'e')) + ); + } + + public function testDir() + { + $h = new Url($this->container); + $this->assertEquals('', $h->dir()); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['PHP_SELF'] = '/plop/index.php'; + $h = new Url($this->container); + $this->assertEquals('/plop/', $h->dir()); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['PHP_SELF'] = ''; + $h = new Url($this->container); + $this->assertEquals('/', $h->dir()); + } + + public function testServer() + { + $h = new Url($this->container); + + $this->assertEquals('http://localhost/', $h->server()); + + $_SERVER['PHP_SELF'] = '/'; + $_SERVER['SERVER_NAME'] = 'kb'; + $_SERVER['SERVER_PORT'] = 1234; + + $this->assertEquals('http://kb:1234/', $h->server()); + } + + public function testBase() + { + $h = new Url($this->container); + + $this->assertEquals('http://localhost/', $h->base()); + + $_SERVER['PHP_SELF'] = '/'; + $_SERVER['SERVER_NAME'] = 'kb'; + $_SERVER['SERVER_PORT'] = 1234; + + $h = new Url($this->container); + $this->assertEquals('http://kb:1234/', $h->base()); + + $c = new Config($this->container); + $c->save(array('application_url' => 'https://mykanboard/')); + + $h = new Url($this->container); + $this->assertEquals('https://mykanboard/', $c->get('application_url')); + $this->assertEquals('https://mykanboard/', $h->base()); + } +} diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php new file mode 100644 index 00000000..947f606a --- /dev/null +++ b/tests/units/Helper/UserHelperTest.php @@ -0,0 +1,16 @@ +container); + + $this->assertEquals('CN', $h->getInitials('chuck norris')); + $this->assertEquals('A', $h->getInitials('admin')); + } +} diff --git a/tests/units/HourlyRate.php b/tests/units/HourlyRate.php deleted file mode 100644 index 5daf0446..00000000 --- a/tests/units/HourlyRate.php +++ /dev/null @@ -1,43 +0,0 @@ -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); - } -} diff --git a/tests/units/Integration/BitbucketWebhookTest.php b/tests/units/Integration/BitbucketWebhookTest.php new file mode 100644 index 00000000..1902f738 --- /dev/null +++ b/tests/units/Integration/BitbucketWebhookTest.php @@ -0,0 +1,398 @@ +container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, array($this, 'onCommit')); + + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $bw = new BitbucketWebhook($this->container); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_push.json'), true); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $bw->setProjectId(1); + + // No task + $this->assertFalse($bw->handlePush($payload)); + + // Create task with the wrong id + $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1))); + $this->assertFalse($bw->handlePush($payload)); + + // Create task with the right id + $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1))); + $this->assertTrue($bw->handlePush($payload)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.BitbucketWebhookTest::onCommit', $called); + } + + public function testIssueOpened() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_OPENED, array($this, 'onIssueOpened')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $bw = new BitbucketWebhook($this->container); + $bw->setProjectId(1); + + $this->assertNotFalse($bw->parsePayload( + 'issue:created', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_opened.json'), true) + )); + } + + public function testCommentCreatedWithNoUser() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue:comment_created', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_comment_created.json'), true) + )); + } + + public function testCommentCreatedWithNotMember() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue:comment_created', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_comment_created.json'), true) + )); + } + + public function testCommentCreatedWithUser() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); + + $pp = new ProjectPermission($this->container); + $this->assertTrue($pp->addMember(1, 2)); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue:comment_created', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_comment_created.json'), true) + )); + } + + public function testIssueClosed() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue:updated', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_closed.json'), true) + )); + } + + public function testIssueClosedWithNoTask() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 42, 'project_id' => 1))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertFalse($g->parsePayload( + 'issue:updated', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_closed.json'), true) + )); + + $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); + } + + public function testIssueReopened() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue:updated', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_reopened.json'), true) + )); + } + + public function testIssueReopenedWithNoTask() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 42, 'project_id' => 1))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertFalse($g->parsePayload( + 'issue:updated', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_reopened.json'), true) + )); + + $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); + } + + public function testIssueUnassigned() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueUnassigned')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue:updated', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_unassigned.json'), true) + )); + } + + public function testIssueAssigned() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueAssigned')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); + + $pp = new ProjectPermission($this->container); + $this->assertTrue($pp->addMember(1, 2)); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue:updated', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) + )); + + $this->assertNotEmpty($this->container['dispatcher']->getCalledListeners()); + } + + public function testIssueAssignedWithNoPermission() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function() {}); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertFalse($g->parsePayload( + 'issue:updated', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) + )); + + $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); + } + + public function testIssueAssignedWithNoUser() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function() {}); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertFalse($g->parsePayload( + 'issue:updated', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) + )); + + $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); + } + + public function testIssueAssignedWithNoTask() + { + $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function() {}); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 43, 'project_id' => 1))); + + $g = new BitbucketWebhook($this->container); + $g->setProjectId(1); + + $this->assertFalse($g->parsePayload( + 'issue:updated', + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) + )); + + $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); + } + + public function onCommit($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(2, $data['task_id']); + $this->assertEquals('test2', $data['title']); + $this->assertEquals("Test another commit #2\n\n\n[Commit made by @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6)", $data['commit_comment']); + $this->assertEquals("Test another commit #2\n", $data['commit_message']); + $this->assertEquals('https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6', $data['commit_url']); + } + + public function onIssueOpened($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['reference']); + $this->assertEquals('My new issue', $data['title']); + $this->assertEquals("**test**\n\n[Bitbucket Issue](https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue)", $data['description']); + } + + public function onCommentCreatedWithNoUser($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(0, $data['user_id']); + $this->assertEquals(19176252, $data['reference']); + $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']); + } + + public function onCommentCreatedWithNotMember($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(0, $data['user_id']); + $this->assertEquals(19176252, $data['reference']); + $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']); + } + + public function onCommentCreatedWithUser($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(2, $data['user_id']); + $this->assertEquals(19176252, $data['reference']); + $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']); + } + + public function onIssueClosed($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(1, $data['reference']); + } + + public function onIssueReopened($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(1, $data['reference']); + } + + public function onIssueAssigned($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(1, $data['reference']); + $this->assertEquals(2, $data['owner_id']); + } + + public function onIssueUnassigned($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(1, $data['reference']); + $this->assertEquals(0, $data['owner_id']); + } +} diff --git a/tests/units/Integration/GithubWebhookTest.php b/tests/units/Integration/GithubWebhookTest.php new file mode 100644 index 00000000..3b67ad1c --- /dev/null +++ b/tests/units/Integration/GithubWebhookTest.php @@ -0,0 +1,459 @@ +container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_OPENED, array($this, 'onIssueOpened')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issues', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_opened.json'), true) + )); + } + + public function testIssueAssigned() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueAssigned')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); + + $pp = new ProjectPermission($this->container); + $this->assertTrue($pp->addMember(1, 2)); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issues', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true) + )); + } + + public function testIssueAssignedWithNoExistingTask() + { + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); + + $this->assertFalse($g->handleIssueAssigned($payload['issue'])); + } + + public function testIssueAssignedWithNoExistingUser() + { + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); + + $this->assertFalse($g->handleIssueAssigned($payload['issue'])); + } + + public function testIssueAssignedWithNoMember() + { + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); + + $this->assertFalse($g->handleIssueAssigned($payload['issue'])); + } + + public function testIssueAssignedWithMember() + { + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); + + $pp = new ProjectPermission($this->container); + $this->assertTrue($pp->addMember(1, 2)); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); + + $this->assertTrue($g->handleIssueAssigned($payload['issue'])); + } + + public function testIssueUnassigned() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueUnassigned')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issues', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_unassigned.json'), true) + )); + } + + public function testIssueClosed() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issues', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_closed.json'), true) + )); + } + + public function testIssueClosedWithTaskNotFound() + { + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_closed.json'), true); + + $this->assertFalse($g->handleIssueClosed($payload['issue'])); + } + + public function testIssueReopened() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issues', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_reopened.json'), true) + )); + } + + public function testIssueReopenedWithTaskNotFound() + { + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_reopened.json'), true); + + $this->assertFalse($g->handleIssueReopened($payload['issue'])); + } + + public function testIssueLabeled() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_LABEL_CHANGE, array($this, 'onIssueLabeled')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issues', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_labeled.json'), true) + )); + } + + public function testIssueLabeledWithTaskNotFound() + { + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_labeled.json'), true); + + $this->assertFalse($g->handleIssueLabeled($payload['issue'], $payload['label'])); + } + + public function testIssueUnLabeled() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_LABEL_CHANGE, array($this, 'onIssueUnlabeled')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issues', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_unlabeled.json'), true) + )); + } + + public function testIssueUnLabeledWithTaskNotFound() + { + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_unlabeled.json'), true); + + $this->assertFalse($g->handleIssueUnlabeled($payload['issue'], $payload['label'])); + } + + public function testCommentCreatedWithNoUser() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue_comment', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_comment_created.json'), true) + )); + } + + public function testCommentCreatedWithNotMember() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue_comment', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_comment_created.json'), true) + )); + } + + public function testCommentCreatedWithUser() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); + + $pp = new ProjectPermission($this->container); + $this->assertTrue($pp->addMember(1, 2)); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'issue_comment', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_comment_created.json'), true) + )); + } + + public function testPush() + { + $this->container['dispatcher']->addListener(GithubWebhook::EVENT_COMMIT, array($this, 'onPush')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'project_id' => 1))); + + $g = new GithubWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + 'push', + json_decode(file_get_contents(__DIR__.'/../fixtures/github_push.json'), true) + )); + } + + public function onIssueOpened($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(3, $data['reference']); + $this->assertEquals('Test Webhook', $data['title']); + $this->assertEquals("plop\n\n[Github Issue](https://github.com/kanboardapp/webhook/issues/3)", $data['description']); + } + + public function onIssueAssigned($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(3, $data['reference']); + $this->assertEquals(2, $data['owner_id']); + } + + public function onIssueUnassigned($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(3, $data['reference']); + $this->assertEquals(0, $data['owner_id']); + } + + public function onIssueClosed($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(3, $data['reference']); + } + + public function onIssueReopened($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(3, $data['reference']); + } + + public function onIssueLabeled($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(3, $data['reference']); + $this->assertEquals('bug', $data['label']); + } + + public function onIssueUnlabeled($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(3, $data['reference']); + $this->assertEquals('bug', $data['label']); + $this->assertEquals(0, $data['category_id']); + } + + public function onCommentCreatedWithNoUser($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(0, $data['user_id']); + $this->assertEquals(113834672, $data['reference']); + $this->assertEquals("test\n\n[By @fguillot on Github](https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672)", $data['comment']); + } + + public function onCommentCreatedWithNotMember($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(0, $data['user_id']); + $this->assertEquals(113834672, $data['reference']); + $this->assertEquals("test\n\n[By @fguillot on Github](https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672)", $data['comment']); + } + + public function onCommentCreatedWithUser($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(2, $data['user_id']); + $this->assertEquals(113834672, $data['reference']); + $this->assertEquals("test\n\n[By @fguillot on Github](https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672)", $data['comment']); + } + + public function onPush($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals('boo', $data['title']); + $this->assertEquals("Update README to fix #1\n\n[Commit made by @fguillot on Github](https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6)", $data['commit_comment']); + $this->assertEquals('Update README to fix #1', $data['commit_message']); + $this->assertEquals('https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6', $data['commit_url']); + } +} diff --git a/tests/units/Integration/GitlabWebhookTest.php b/tests/units/Integration/GitlabWebhookTest.php new file mode 100644 index 00000000..ec073fee --- /dev/null +++ b/tests/units/Integration/GitlabWebhookTest.php @@ -0,0 +1,221 @@ +container); + + $this->assertEquals(GitlabWebhook::TYPE_PUSH, $g->getType(json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_push.json'), true))); + $this->assertEquals(GitlabWebhook::TYPE_ISSUE, $g->getType(json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_issue_opened.json'), true))); + $this->assertEquals(GitlabWebhook::TYPE_COMMENT, $g->getType(json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true))); + $this->assertEquals('', $g->getType(array())); + } + + public function testHandleCommit() + { + $g = new GitlabWebhook($this->container); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $g->setProjectId(1); + + $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_COMMIT, array($this, 'onCommit')); + + $event = json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_push.json'), true); + + // No task + $this->assertFalse($g->handleCommit($event['commits'][0])); + + // Create task with the wrong id + $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1))); + $this->assertFalse($g->handleCommit($event['commits'][0])); + + // Create task with the right id + $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1))); + $this->assertTrue($g->handleCommit($event['commits'][0])); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(GitlabWebhook::EVENT_COMMIT.'.GitlabWebhookTest::onCommit', $called); + } + + public function testHandleIssueOpened() + { + $g = new GitlabWebhook($this->container); + $g->setProjectId(1); + + $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_OPENED, array($this, 'onOpen')); + + $event = json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_issue_opened.json'), true); + $this->assertTrue($g->handleIssueOpened($event['object_attributes'])); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_OPENED.'.GitlabWebhookTest::onOpen', $called); + } + + public function testHandleIssueClosed() + { + $g = new GitlabWebhook($this->container); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $g->setProjectId(1); + + $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_CLOSED, array($this, 'onClose')); + + $event = json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_issue_closed.json'), true); + + // Issue not there + $this->assertFalse($g->handleIssueClosed($event['object_attributes'])); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertEmpty($called); + + // Create a task with the issue reference + $this->assertEquals(1, $tc->create(array('title' => 'A', 'project_id' => 1, 'reference' => 355691))); + $task = $tf->getByReference(1, 355691); + $this->assertNotEmpty($task); + + $task = $tf->getByReference(2, 355691); + $this->assertEmpty($task); + + $this->assertTrue($g->handleIssueClosed($event['object_attributes'])); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_CLOSED.'.GitlabWebhookTest::onClose', $called); + } + + public function testCommentCreatedWithNoUser() + { + $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1))); + + $g = new GitlabWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true) + )); + } + + public function testCommentCreatedWithNotMember() + { + $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); + + $g = new GitlabWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true) + )); + } + + public function testCommentCreatedWithUser() + { + $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + + $tc = new TaskCreation($this->container); + $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1))); + + $u = new User($this->container); + $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); + + $pp = new ProjectPermission($this->container); + $this->assertTrue($pp->addMember(1, 2)); + + $g = new GitlabWebhook($this->container); + $g->setProjectId(1); + + $this->assertNotFalse($g->parsePayload( + json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true) + )); + } + + public function onOpen($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(355691, $data['reference']); + $this->assertEquals('Bug', $data['title']); + $this->assertEquals("There is a bug somewhere.\r\n\r\nBye\n\n[Gitlab Issue](https://gitlab.com/minicoders/test-webhook/issues/1)", $data['description']); + } + + public function onClose($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(355691, $data['reference']); + } + + public function onCommit($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(2, $data['task_id']); + $this->assertEquals('test2', $data['title']); + $this->assertEquals("Fix bug #2\n\n[Commit made by @Fred on Gitlab](https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78)", $data['commit_comment']); + $this->assertEquals("Fix bug #2", $data['commit_message']); + $this->assertEquals('https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78', $data['commit_url']); + } + + public function onCommentCreatedWithNoUser($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(0, $data['user_id']); + $this->assertEquals(1642761, $data['reference']); + $this->assertEquals("Super comment!\n\n[By @minicoders on Gitlab](https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761)", $data['comment']); + } + + public function onCommentCreatedWithNotMember($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(0, $data['user_id']); + $this->assertEquals(1642761, $data['reference']); + $this->assertEquals("Super comment!\n\n[By @minicoders on Gitlab](https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761)", $data['comment']); + } + + public function onCommentCreatedWithUser($event) + { + $data = $event->getAll(); + $this->assertEquals(1, $data['project_id']); + $this->assertEquals(1, $data['task_id']); + $this->assertEquals(2, $data['user_id']); + $this->assertEquals(1642761, $data['reference']); + $this->assertEquals("Super comment!\n\n[By @minicoders on Gitlab](https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761)", $data['comment']); + } +} diff --git a/tests/units/Integration/MailgunTest.php b/tests/units/Integration/MailgunTest.php new file mode 100644 index 00000000..67914b0a --- /dev/null +++ b/tests/units/Integration/MailgunTest.php @@ -0,0 +1,71 @@ +container); + $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); + + $this->assertStringStartsWith('https://api.mailgun.net/v3/', $this->container['httpClient']->getUrl()); + + $data = $this->container['httpClient']->getData(); + + $this->assertArrayHasKey('from', $data); + $this->assertArrayHasKey('to', $data); + $this->assertArrayHasKey('subject', $data); + $this->assertArrayHasKey('html', $data); + + $this->assertEquals('Me ', $data['to']); + $this->assertEquals('Bob ', $data['from']); + $this->assertEquals('Test', $data['subject']); + $this->assertEquals('Content', $data['html']); + } + + public function testHandlePayload() + { + $w = new Mailgun($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $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'))); + + // Empty payload + $this->assertFalse($w->receiveEmail(array())); + + // Unknown user + $this->assertFalse($w->receiveEmail(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo'))); + + // Project not found + $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo'))); + + // User is not member + $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); + $this->assertTrue($pp->addMember(2, 2)); + + // The task must be created + $this->assertTrue($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('boo', $task['description']); + $this->assertEquals(2, $task['creator_id']); + } +} diff --git a/tests/units/Integration/PostmarkTest.php b/tests/units/Integration/PostmarkTest.php new file mode 100644 index 00000000..9115e24a --- /dev/null +++ b/tests/units/Integration/PostmarkTest.php @@ -0,0 +1,106 @@ +container); + $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); + + $this->assertEquals('https://api.postmarkapp.com/email', $this->container['httpClient']->getUrl()); + + $data = $this->container['httpClient']->getData(); + + $this->assertArrayHasKey('From', $data); + $this->assertArrayHasKey('To', $data); + $this->assertArrayHasKey('Subject', $data); + $this->assertArrayHasKey('HtmlBody', $data); + + $this->assertEquals('Me ', $data['To']); + $this->assertEquals('Bob ', $data['From']); + $this->assertEquals('Test', $data['Subject']); + $this->assertEquals('Content', $data['HtmlBody']); + + $this->assertContains('Accept: application/json', $this->container['httpClient']->getHeaders()); + $this->assertContains('X-Postmark-Server-Token: ', $this->container['httpClient']->getHeaders()); + } + + public function testHandlePayload() + { + $w = new Postmark($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $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'))); + + // Empty payload + $this->assertFalse($w->receiveEmail(array())); + + // Unknown user + $this->assertFalse($w->receiveEmail(array('From' => 'a@b.c', 'Subject' => 'Email task', 'MailboxHash' => 'foobar', 'TextBody' => 'boo'))); + + // Project not found + $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test', 'TextBody' => 'boo'))); + + // User is not member + $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); + $this->assertTrue($pp->addMember(2, 2)); + + // The task must be created + $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('boo', $task['description']); + $this->assertEquals(2, $task['creator_id']); + } + + public function testHtml2Markdown() + { + $w = new Postmark($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $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)); + + $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '

boo

'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('**boo**', $task['description']); + $this->assertEquals(2, $task['creator_id']); + + $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => ''))); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('**boo**', $task['description']); + $this->assertEquals(2, $task['creator_id']); + } +} diff --git a/tests/units/Integration/SendgridTest.php b/tests/units/Integration/SendgridTest.php new file mode 100644 index 00000000..b2352076 --- /dev/null +++ b/tests/units/Integration/SendgridTest.php @@ -0,0 +1,135 @@ +container); + $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); + + $this->assertEquals('https://api.sendgrid.com/api/mail.send.json', $this->container['httpClient']->getUrl()); + + $data = $this->container['httpClient']->getData(); + + $this->assertArrayHasKey('api_user', $data); + $this->assertArrayHasKey('api_key', $data); + $this->assertArrayHasKey('from', $data); + $this->assertArrayHasKey('fromname', $data); + $this->assertArrayHasKey('to', $data); + $this->assertArrayHasKey('toname', $data); + $this->assertArrayHasKey('subject', $data); + $this->assertArrayHasKey('html', $data); + + $this->assertEquals('test@localhost', $data['to']); + $this->assertEquals('Me', $data['toname']); + $this->assertEquals('notifications@kanboard.local', $data['from']); + $this->assertEquals('Bob', $data['fromname']); + $this->assertEquals('Test', $data['subject']); + $this->assertEquals('Content', $data['html']); + $this->assertEquals('', $data['api_key']); + $this->assertEquals('', $data['api_user']); + } + + public function testHandlePayload() + { + $w = new Sendgrid($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $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'))); + + // Empty payload + $this->assertFalse($w->receiveEmail(array())); + + // Unknown user + $this->assertFalse($w->receiveEmail(array( + 'envelope' => '{"to":["a@b.c"],"from":"a.b.c"}', + 'subject' => 'Email task' + ))); + + // Project not found + $this->assertFalse($w->receiveEmail(array( + 'envelope' => '{"to":["a@b.c"],"from":"me@localhost"}', + 'subject' => 'Email task' + ))); + + // User is not member + $this->assertFalse($w->receiveEmail(array( + 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', + 'subject' => 'Email task' + ))); + + $this->assertTrue($pp->addMember(2, 2)); + + // The task must be created + $this->assertTrue($w->receiveEmail(array( + 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', + 'subject' => 'Email task' + ))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('', $task['description']); + $this->assertEquals(2, $task['creator_id']); + + // Html content + $this->assertTrue($w->receiveEmail(array( + 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', + 'subject' => 'Email task', + 'html' => 'bold text', + ))); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('**bold** text', $task['description']); + $this->assertEquals(2, $task['creator_id']); + + // Text content + $this->assertTrue($w->receiveEmail(array( + 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', + 'subject' => 'Email task', + 'text' => '**bold** text', + ))); + + $task = $tf->getById(3); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('**bold** text', $task['description']); + $this->assertEquals(2, $task['creator_id']); + + // Text + html content + $this->assertTrue($w->receiveEmail(array( + 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', + 'subject' => 'Email task', + 'html' => 'bold html', + 'text' => '**bold** text', + ))); + + $task = $tf->getById(4); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('**bold** html', $task['description']); + $this->assertEquals(2, $task['creator_id']); + } +} diff --git a/tests/units/LexerTest.php b/tests/units/LexerTest.php deleted file mode 100644 index 3b15810e..00000000 --- a/tests/units/LexerTest.php +++ /dev/null @@ -1,443 +0,0 @@ -assertEquals( - array(array('match' => 'swimlane:', 'token' => 'T_SWIMLANE'), array('match' => 'Version 42', 'token' => 'T_STRING')), - $lexer->tokenize('swimlane:"Version 42"') - ); - - $this->assertEquals( - array(array('match' => 'swimlane:', 'token' => 'T_SWIMLANE'), array('match' => 'v3', 'token' => 'T_STRING')), - $lexer->tokenize('swimlane:v3') - ); - - $this->assertEquals( - array('T_SWIMLANE' => array('v3')), - $lexer->map($lexer->tokenize('swimlane:v3')) - ); - - $this->assertEquals( - array('T_SWIMLANE' => array('Version 42', 'v3')), - $lexer->map($lexer->tokenize('swimlane:"Version 42" swimlane:v3')) - ); - } - - public function testAssigneeQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'me', 'token' => 'T_STRING')), - $lexer->tokenize('assignee:me') - ); - - $this->assertEquals( - array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'everybody', 'token' => 'T_STRING')), - $lexer->tokenize('assignee:everybody') - ); - - $this->assertEquals( - array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'nobody', 'token' => 'T_STRING')), - $lexer->tokenize('assignee:nobody') - ); - - $this->assertEquals( - array('T_ASSIGNEE' => array('nobody')), - $lexer->map($lexer->tokenize('assignee:nobody')) - ); - - $this->assertEquals( - array('T_ASSIGNEE' => array('John Doe', 'me')), - $lexer->map($lexer->tokenize('assignee:"John Doe" assignee:me')) - ); - } - - public function testColorQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'color:', 'token' => 'T_COLOR'), array('match' => 'Blue', 'token' => 'T_STRING')), - $lexer->tokenize('color:Blue') - ); - - $this->assertEquals( - array(array('match' => 'color:', 'token' => 'T_COLOR'), array('match' => 'Dark Grey', 'token' => 'T_STRING')), - $lexer->tokenize('color:"Dark Grey"') - ); - - $this->assertEquals( - array('T_COLOR' => array('Blue')), - $lexer->map($lexer->tokenize('color:Blue')) - ); - - $this->assertEquals( - array('T_COLOR' => array('Dark Grey')), - $lexer->map($lexer->tokenize('color:"Dark Grey"')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('color: ')) - ); - } - - public function testCategoryQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'category:', 'token' => 'T_CATEGORY'), array('match' => 'Feature Request', 'token' => 'T_STRING')), - $lexer->tokenize('category:"Feature Request"') - ); - - $this->assertEquals( - array('T_CATEGORY' => array('Feature Request')), - $lexer->map($lexer->tokenize('category:"Feature Request"')) - ); - - $this->assertEquals( - array('T_CATEGORY' => array('Feature Request', 'Bug')), - $lexer->map($lexer->tokenize('category:"Feature Request" category:Bug')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('category: ')) - ); - } - - public function testColumnQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'column:', 'token' => 'T_COLUMN'), array('match' => 'Feature Request', 'token' => 'T_STRING')), - $lexer->tokenize('column:"Feature Request"') - ); - - $this->assertEquals( - array('T_COLUMN' => array('Feature Request')), - $lexer->map($lexer->tokenize('column:"Feature Request"')) - ); - - $this->assertEquals( - array('T_COLUMN' => array('Feature Request', 'Bug')), - $lexer->map($lexer->tokenize('column:"Feature Request" column:Bug')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('column: ')) - ); - } - - public function testProjectQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'project:', 'token' => 'T_PROJECT'), array('match' => 'My project', 'token' => 'T_STRING')), - $lexer->tokenize('project:"My project"') - ); - - $this->assertEquals( - array('T_PROJECT' => array('My project')), - $lexer->map($lexer->tokenize('project:"My project"')) - ); - - $this->assertEquals( - array('T_PROJECT' => array('My project', 'plop')), - $lexer->map($lexer->tokenize('project:"My project" project:plop')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('project: ')) - ); - } - - public function testStatusQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'status:', 'token' => 'T_STATUS'), array('match' => 'open', 'token' => 'T_STRING')), - $lexer->tokenize('status:open') - ); - - $this->assertEquals( - array(array('match' => 'status:', 'token' => 'T_STATUS'), array('match' => 'closed', 'token' => 'T_STRING')), - $lexer->tokenize('status:closed') - ); - - $this->assertEquals( - array('T_STATUS' => 'open'), - $lexer->map($lexer->tokenize('status:open')) - ); - - $this->assertEquals( - array('T_STATUS' => 'closed'), - $lexer->map($lexer->tokenize('status:closed')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('status: ')) - ); - } - - public function testReferenceQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'ref:', 'token' => 'T_REFERENCE'), array('match' => '123', 'token' => 'T_STRING')), - $lexer->tokenize('ref:123') - ); - - $this->assertEquals( - array(array('match' => 'reference:', 'token' => 'T_REFERENCE'), array('match' => '456', 'token' => 'T_STRING')), - $lexer->tokenize('reference:456') - ); - - $this->assertEquals( - array('T_REFERENCE' => '123'), - $lexer->map($lexer->tokenize('reference:123')) - ); - - $this->assertEquals( - array('T_REFERENCE' => '456'), - $lexer->map($lexer->tokenize('ref:456')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('ref: ')) - ); - } - - public function testDescriptionQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'description:', 'token' => 'T_DESCRIPTION'), array('match' => 'my text search', 'token' => 'T_STRING')), - $lexer->tokenize('description:"my text search"') - ); - - $this->assertEquals( - array('T_DESCRIPTION' => 'my text search'), - $lexer->map($lexer->tokenize('description:"my text search"')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('description: ')) - ); - } - - public function testDueDateQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '<2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:<2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '>2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:>2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '<=2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:<=2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '>=2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:>=2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => 'yesterday', 'token' => 'T_DATE')), - $lexer->tokenize('due:yesterday') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => 'tomorrow', 'token' => 'T_DATE')), - $lexer->tokenize('due:tomorrow') - ); - - $this->assertEquals( - array(), - $lexer->tokenize('due:#2015-05-01') - ); - - $this->assertEquals( - array(), - $lexer->tokenize('due:01-05-1024') - ); - - $this->assertEquals( - array('T_DUE' => '2015-05-01'), - $lexer->map($lexer->tokenize('due:2015-05-01')) - ); - - $this->assertEquals( - array('T_DUE' => '<2015-05-01'), - $lexer->map($lexer->tokenize('due:<2015-05-01')) - ); - - $this->assertEquals( - array('T_DUE' => 'today'), - $lexer->map($lexer->tokenize('due:today')) - ); - } - - public function testModifiedQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'modified:', 'token' => 'T_UPDATED'), array('match' => '2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('modified:2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'modified:', 'token' => 'T_UPDATED'), array('match' => '<2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('modified:<2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'modified:', 'token' => 'T_UPDATED'), array('match' => '>2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('modified:>2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => '<=2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('updated:<=2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => '>=2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('updated:>=2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => 'yesterday', 'token' => 'T_DATE')), - $lexer->tokenize('updated:yesterday') - ); - - $this->assertEquals( - array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => 'tomorrow', 'token' => 'T_DATE')), - $lexer->tokenize('updated:tomorrow') - ); - - $this->assertEquals( - array(), - $lexer->tokenize('updated:#2015-05-01') - ); - - $this->assertEquals( - array(), - $lexer->tokenize('modified:01-05-1024') - ); - - $this->assertEquals( - array('T_UPDATED' => '2015-05-01'), - $lexer->map($lexer->tokenize('modified:2015-05-01')) - ); - - $this->assertEquals( - array('T_UPDATED' => '<2015-05-01'), - $lexer->map($lexer->tokenize('modified:<2015-05-01')) - ); - - $this->assertEquals( - array('T_UPDATED' => 'today'), - $lexer->map($lexer->tokenize('modified:today')) - ); - } - - public function testMultipleCriterias() - { - $lexer = new Lexer; - - $this->assertEquals( - array('T_COLOR' => array('Dark Grey'), 'T_ASSIGNEE' => array('Fred G'), 'T_TITLE' => 'my task title'), - $lexer->map($lexer->tokenize('color:"Dark Grey" assignee:"Fred G" my task title')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow')), - $lexer->map($lexer->tokenize('my title color:yellow')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title', 'T_DUE' => '2015-04-01'), - $lexer->map($lexer->tokenize('my title due:2015-04-01')) - ); - - $this->assertEquals( - array('T_TITLE' => 'awesome', 'T_DUE' => '<=2015-04-01'), - $lexer->map($lexer->tokenize('due:<=2015-04-01 awesome')) - ); - - $this->assertEquals( - array('T_TITLE' => 'awesome', 'T_DUE' => 'today'), - $lexer->map($lexer->tokenize('due:today awesome')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow'), 'T_DUE' => '2015-04-01'), - $lexer->map($lexer->tokenize('my title color:yellow due:2015-04-01')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow'), 'T_DUE' => '2015-04-01', 'T_ASSIGNEE' => array('John Doe')), - $lexer->map($lexer->tokenize('my title color:yellow due:2015-04-01 assignee:"John Doe"')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title'), - $lexer->map($lexer->tokenize('my title color:')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title'), - $lexer->map($lexer->tokenize('my title color:assignee:')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title'), - $lexer->map($lexer->tokenize('my title ')) - ); - - $this->assertEquals( - array('T_TITLE' => '#123'), - $lexer->map($lexer->tokenize('#123')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('color:assignee:')) - ); - } -} diff --git a/tests/units/LinkTest.php b/tests/units/LinkTest.php deleted file mode 100644 index 45e9796c..00000000 --- a/tests/units/LinkTest.php +++ /dev/null @@ -1,173 +0,0 @@ -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]); - } -} diff --git a/tests/units/Locale/LocaleTest.php b/tests/units/Locale/LocaleTest.php new file mode 100644 index 00000000..6cace0d5 --- /dev/null +++ b/tests/units/Locale/LocaleTest.php @@ -0,0 +1,33 @@ + $v) { + + if (strpos($k,'%B %e, %Y') !== false) { + continue; + } + + if (strpos($k,'%b %e, %Y') !== false) { + continue; + } + + foreach(array('%s', '%d') as $placeholder) { + $this->assertEquals( + substr_count($k, $placeholder), + substr_count($v, $placeholder), + 'Incorrect number of ' . $placeholder . ' in ' . basename($file) .' translation of: ' . $k + ); + } + } + } + } +} diff --git a/tests/units/LocaleTest.php b/tests/units/LocaleTest.php deleted file mode 100644 index e00b8c83..00000000 --- a/tests/units/LocaleTest.php +++ /dev/null @@ -1,33 +0,0 @@ - $v) { - - if (strpos($k,'%B %e, %Y') !== false) { - continue; - } - - if (strpos($k,'%b %e, %Y') !== false) { - continue; - } - - foreach(array('%s', '%d') as $placeholder) { - $this->assertEquals( - substr_count($k, $placeholder), - substr_count($v, $placeholder), - 'Incorrect number of ' . $placeholder . ' in ' . basename($file) .' translation of: ' . $k - ); - } - } - } - } -} diff --git a/tests/units/MailgunTest.php b/tests/units/MailgunTest.php deleted file mode 100644 index ce53228e..00000000 --- a/tests/units/MailgunTest.php +++ /dev/null @@ -1,71 +0,0 @@ -container); - $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); - - $this->assertStringStartsWith('https://api.mailgun.net/v3/', $this->container['httpClient']->getUrl()); - - $data = $this->container['httpClient']->getData(); - - $this->assertArrayHasKey('from', $data); - $this->assertArrayHasKey('to', $data); - $this->assertArrayHasKey('subject', $data); - $this->assertArrayHasKey('html', $data); - - $this->assertEquals('Me ', $data['to']); - $this->assertEquals('Bob ', $data['from']); - $this->assertEquals('Test', $data['subject']); - $this->assertEquals('Content', $data['html']); - } - - public function testHandlePayload() - { - $w = new Mailgun($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - - $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'))); - - // Empty payload - $this->assertFalse($w->receiveEmail(array())); - - // Unknown user - $this->assertFalse($w->receiveEmail(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo'))); - - // Project not found - $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo'))); - - // User is not member - $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); - $this->assertTrue($pp->addMember(2, 2)); - - // The task must be created - $this->assertTrue($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('Email task', $task['title']); - $this->assertEquals('boo', $task['description']); - $this->assertEquals(2, $task['creator_id']); - } -} diff --git a/tests/units/Model/AclTest.php b/tests/units/Model/AclTest.php new file mode 100644 index 00000000..fef03990 --- /dev/null +++ b/tests/units/Model/AclTest.php @@ -0,0 +1,293 @@ + 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)); + } +} diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionTest.php new file mode 100644 index 00000000..9034679b --- /dev/null +++ b/tests/units/Model/ActionTest.php @@ -0,0 +1,379 @@ +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']); + } +} diff --git a/tests/units/Model/AuthenticationTest.php b/tests/units/Model/AuthenticationTest.php new file mode 100644 index 00000000..7ce81d8b --- /dev/null +++ b/tests/units/Model/AuthenticationTest.php @@ -0,0 +1,39 @@ +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')); + } +} diff --git a/tests/units/Model/BoardTest.php b/tests/units/Model/BoardTest.php new file mode 100644 index 00000000..b527e983 --- /dev/null +++ b/tests/units/Model/BoardTest.php @@ -0,0 +1,372 @@ +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']); + } +} diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryTest.php new file mode 100644 index 00000000..0467dda4 --- /dev/null +++ b/tests/units/Model/CategoryTest.php @@ -0,0 +1,67 @@ +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']); + } +} diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentTest.php new file mode 100644 index 00000000..5e532b8a --- /dev/null +++ b/tests/units/Model/CommentTest.php @@ -0,0 +1,142 @@ +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]); + } +} diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php new file mode 100644 index 00000000..c0ed0313 --- /dev/null +++ b/tests/units/Model/ConfigTest.php @@ -0,0 +1,66 @@ +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')); + } +} diff --git a/tests/units/Model/DateParserTest.php b/tests/units/Model/DateParserTest.php new file mode 100644 index 00000000..23c31f14 --- /dev/null +++ b/tests/units/Model/DateParserTest.php @@ -0,0 +1,84 @@ +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'])); + } +} diff --git a/tests/units/Model/FileTest.php b/tests/units/Model/FileTest.php new file mode 100644 index 00000000..da00917d --- /dev/null +++ b/tests/units/Model/FileTest.php @@ -0,0 +1,190 @@ +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); + } +} diff --git a/tests/units/Model/HourlyRateTest.php b/tests/units/Model/HourlyRateTest.php new file mode 100644 index 00000000..ffc0d87e --- /dev/null +++ b/tests/units/Model/HourlyRateTest.php @@ -0,0 +1,43 @@ +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); + } +} diff --git a/tests/units/Model/LinkTest.php b/tests/units/Model/LinkTest.php new file mode 100644 index 00000000..0399f13e --- /dev/null +++ b/tests/units/Model/LinkTest.php @@ -0,0 +1,173 @@ +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]); + } +} diff --git a/tests/units/Model/NotificationTest.php b/tests/units/Model/NotificationTest.php new file mode 100644 index 00000000..b0eafc83 --- /dev/null +++ b/tests/units/Model/NotificationTest.php @@ -0,0 +1,336 @@ +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 + ))); + } +} diff --git a/tests/units/Model/ProjectActivityTest.php b/tests/units/Model/ProjectActivityTest.php new file mode 100644 index 00000000..fa45d740 --- /dev/null +++ b/tests/units/Model/ProjectActivityTest.php @@ -0,0 +1,114 @@ +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()); + } +} diff --git a/tests/units/Model/ProjectDailyColumnStatsTest.php b/tests/units/Model/ProjectDailyColumnStatsTest.php new file mode 100644 index 00000000..e01bdcc4 --- /dev/null +++ b/tests/units/Model/ProjectDailyColumnStatsTest.php @@ -0,0 +1,90 @@ +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]); + } +} diff --git a/tests/units/Model/ProjectDuplicationTest.php b/tests/units/Model/ProjectDuplicationTest.php new file mode 100644 index 00000000..0388d4a2 --- /dev/null +++ b/tests/units/Model/ProjectDuplicationTest.php @@ -0,0 +1,359 @@ +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']); + } +} diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php new file mode 100644 index 00000000..475dd013 --- /dev/null +++ b/tests/units/Model/ProjectPermissionTest.php @@ -0,0 +1,287 @@ +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) + ); + } +} diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectTest.php new file mode 100644 index 00000000..97357796 --- /dev/null +++ b/tests/units/Model/ProjectTest.php @@ -0,0 +1,288 @@ +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]); + } +} diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php new file mode 100644 index 00000000..1ef04c32 --- /dev/null +++ b/tests/units/Model/SubtaskTest.php @@ -0,0 +1,284 @@ +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']); + } +} diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php new file mode 100644 index 00000000..ed286287 --- /dev/null +++ b/tests/units/Model/SubtaskTimeTrackingTest.php @@ -0,0 +1,314 @@ +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']); + } +} diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php new file mode 100644 index 00000000..7e1adb8e --- /dev/null +++ b/tests/units/Model/SwimlaneTest.php @@ -0,0 +1,409 @@ +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']); + } +} diff --git a/tests/units/Model/TaskCreationTest.php b/tests/units/Model/TaskCreationTest.php new file mode 100644 index 00000000..f292c7f1 --- /dev/null +++ b/tests/units/Model/TaskCreationTest.php @@ -0,0 +1,416 @@ +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']); + } +} diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php new file mode 100644 index 00000000..56718841 --- /dev/null +++ b/tests/units/Model/TaskDuplicationTest.php @@ -0,0 +1,707 @@ +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); + } +} diff --git a/tests/units/Model/TaskExportTest.php b/tests/units/Model/TaskExportTest.php new file mode 100644 index 00000000..52996369 --- /dev/null +++ b/tests/units/Model/TaskExportTest.php @@ -0,0 +1,58 @@ +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'))); + } +} diff --git a/tests/units/Model/TaskFilterTest.php b/tests/units/Model/TaskFilterTest.php new file mode 100644 index 00000000..1987265d --- /dev/null +++ b/tests/units/Model/TaskFilterTest.php @@ -0,0 +1,629 @@ +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); + } +} diff --git a/tests/units/Model/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php new file mode 100644 index 00000000..da0db7a7 --- /dev/null +++ b/tests/units/Model/TaskFinderTest.php @@ -0,0 +1,33 @@ +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']); + } +} diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php new file mode 100644 index 00000000..1e79ea74 --- /dev/null +++ b/tests/units/Model/TaskLinkTest.php @@ -0,0 +1,185 @@ +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]); + } +} diff --git a/tests/units/Model/TaskModificationTest.php b/tests/units/Model/TaskModificationTest.php new file mode 100644 index 00000000..f85f1c10 --- /dev/null +++ b/tests/units/Model/TaskModificationTest.php @@ -0,0 +1,267 @@ +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']); + } +} diff --git a/tests/units/Model/TaskMovedDateSubscriberTest.php b/tests/units/Model/TaskMovedDateSubscriberTest.php new file mode 100644 index 00000000..6e3fb3bd --- /dev/null +++ b/tests/units/Model/TaskMovedDateSubscriberTest.php @@ -0,0 +1,77 @@ +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']); + } +} diff --git a/tests/units/Model/TaskPermissionTest.php b/tests/units/Model/TaskPermissionTest.php new file mode 100644 index 00000000..af413a76 --- /dev/null +++ b/tests/units/Model/TaskPermissionTest.php @@ -0,0 +1,105 @@ +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)); + } +} diff --git a/tests/units/Model/TaskPositionTest.php b/tests/units/Model/TaskPositionTest.php new file mode 100644 index 00000000..86814c03 --- /dev/null +++ b/tests/units/Model/TaskPositionTest.php @@ -0,0 +1,634 @@ +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']); + } +} diff --git a/tests/units/Model/TaskStatusTest.php b/tests/units/Model/TaskStatusTest.php new file mode 100644 index 00000000..e5172c4d --- /dev/null +++ b/tests/units/Model/TaskStatusTest.php @@ -0,0 +1,101 @@ +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']); + } + } +} diff --git a/tests/units/Model/TaskTest.php b/tests/units/Model/TaskTest.php new file mode 100644 index 00000000..ebafa612 --- /dev/null +++ b/tests/units/Model/TaskTest.php @@ -0,0 +1,29 @@ +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)); + } +} diff --git a/tests/units/Model/TimetableTest.php b/tests/units/Model/TimetableTest.php new file mode 100644 index 00000000..887e1787 --- /dev/null +++ b/tests/units/Model/TimetableTest.php @@ -0,0 +1,256 @@ +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)); + } +} diff --git a/tests/units/Model/UserSessionTest.php b/tests/units/Model/UserSessionTest.php new file mode 100644 index 00000000..31072e6a --- /dev/null +++ b/tests/units/Model/UserSessionTest.php @@ -0,0 +1,32 @@ +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()); + } +} diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php new file mode 100644 index 00000000..5b7edfb9 --- /dev/null +++ b/tests/units/Model/UserTest.php @@ -0,0 +1,273 @@ +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']); + } +} diff --git a/tests/units/Model/WebhookTest.php b/tests/units/Model/WebhookTest.php new file mode 100644 index 00000000..8ed630e4 --- /dev/null +++ b/tests/units/Model/WebhookTest.php @@ -0,0 +1,112 @@ +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']); + } +} diff --git a/tests/units/NotificationTest.php b/tests/units/NotificationTest.php deleted file mode 100644 index 4ae46ee3..00000000 --- a/tests/units/NotificationTest.php +++ /dev/null @@ -1,336 +0,0 @@ -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 - ))); - } -} diff --git a/tests/units/OAuth2Test.php b/tests/units/OAuth2Test.php deleted file mode 100644 index 0275f426..00000000 --- a/tests/units/OAuth2Test.php +++ /dev/null @@ -1,43 +0,0 @@ -container); - $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); - $this->assertEquals('D?response_type=code&client_id=A&redirect_uri=C&scope=f+g', $oauth->getAuthorizationUrl()); - } - - public function testAuthHeader() - { - $oauth = new OAuth2($this->container); - $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); - - $oauth->setAccessToken('foobar', 'BeaRer'); - $this->assertEquals('Authorization: Bearer foobar', $oauth->getAuthorizationHeader()); - - $oauth->setAccessToken('foobar', 'unknown'); - $this->assertEquals('', $oauth->getAuthorizationHeader()); - } - - public function testAccessToken() - { - $oauth = new OAuth2($this->container); - $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); - $oauth->getAccessToken('something'); - - $data = $this->container['httpClient']->getData(); - $this->assertEquals('something', $data['code']); - $this->assertEquals('A', $data['client_id']); - $this->assertEquals('B', $data['client_secret']); - $this->assertEquals('C', $data['redirect_uri']); - $this->assertEquals('authorization_code', $data['grant_type']); - - $this->assertEquals('E', $this->container['httpClient']->getUrl()); - } -} diff --git a/tests/units/PostmarkTest.php b/tests/units/PostmarkTest.php deleted file mode 100644 index f3d2e55b..00000000 --- a/tests/units/PostmarkTest.php +++ /dev/null @@ -1,106 +0,0 @@ -container); - $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); - - $this->assertEquals('https://api.postmarkapp.com/email', $this->container['httpClient']->getUrl()); - - $data = $this->container['httpClient']->getData(); - - $this->assertArrayHasKey('From', $data); - $this->assertArrayHasKey('To', $data); - $this->assertArrayHasKey('Subject', $data); - $this->assertArrayHasKey('HtmlBody', $data); - - $this->assertEquals('Me ', $data['To']); - $this->assertEquals('Bob ', $data['From']); - $this->assertEquals('Test', $data['Subject']); - $this->assertEquals('Content', $data['HtmlBody']); - - $this->assertContains('Accept: application/json', $this->container['httpClient']->getHeaders()); - $this->assertContains('X-Postmark-Server-Token: ', $this->container['httpClient']->getHeaders()); - } - - public function testHandlePayload() - { - $w = new Postmark($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - - $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'))); - - // Empty payload - $this->assertFalse($w->receiveEmail(array())); - - // Unknown user - $this->assertFalse($w->receiveEmail(array('From' => 'a@b.c', 'Subject' => 'Email task', 'MailboxHash' => 'foobar', 'TextBody' => 'boo'))); - - // Project not found - $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test', 'TextBody' => 'boo'))); - - // User is not member - $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); - $this->assertTrue($pp->addMember(2, 2)); - - // The task must be created - $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('Email task', $task['title']); - $this->assertEquals('boo', $task['description']); - $this->assertEquals(2, $task['creator_id']); - } - - public function testHtml2Markdown() - { - $w = new Postmark($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - - $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)); - - $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '

boo

'))); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['project_id']); - $this->assertEquals('Email task', $task['title']); - $this->assertEquals('**boo**', $task['description']); - $this->assertEquals(2, $task['creator_id']); - - $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => ''))); - - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['project_id']); - $this->assertEquals('Email task', $task['title']); - $this->assertEquals('**boo**', $task['description']); - $this->assertEquals(2, $task['creator_id']); - } -} diff --git a/tests/units/ProjectActivityTest.php b/tests/units/ProjectActivityTest.php deleted file mode 100644 index f0b27649..00000000 --- a/tests/units/ProjectActivityTest.php +++ /dev/null @@ -1,114 +0,0 @@ -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()); - } -} diff --git a/tests/units/ProjectDailyColumnStatsTest.php b/tests/units/ProjectDailyColumnStatsTest.php deleted file mode 100644 index d314ac93..00000000 --- a/tests/units/ProjectDailyColumnStatsTest.php +++ /dev/null @@ -1,90 +0,0 @@ -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]); - } -} diff --git a/tests/units/ProjectDuplicationTest.php b/tests/units/ProjectDuplicationTest.php deleted file mode 100644 index 0a0bc3eb..00000000 --- a/tests/units/ProjectDuplicationTest.php +++ /dev/null @@ -1,359 +0,0 @@ -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']); - } -} diff --git a/tests/units/ProjectPermissionTest.php b/tests/units/ProjectPermissionTest.php deleted file mode 100644 index 9f6d6a52..00000000 --- a/tests/units/ProjectPermissionTest.php +++ /dev/null @@ -1,287 +0,0 @@ -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) - ); - } -} diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php deleted file mode 100644 index b7f168d7..00000000 --- a/tests/units/ProjectTest.php +++ /dev/null @@ -1,288 +0,0 @@ -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]); - } -} diff --git a/tests/units/RouterTest.php b/tests/units/RouterTest.php deleted file mode 100644 index e4582121..00000000 --- a/tests/units/RouterTest.php +++ /dev/null @@ -1,79 +0,0 @@ -container); - - $this->assertEquals('plop', $r->sanitize('PloP', 'default')); - $this->assertEquals('default', $r->sanitize('', 'default')); - $this->assertEquals('default', $r->sanitize('123-AB', 'default')); - $this->assertEquals('default', $r->sanitize('R&D', 'default')); - $this->assertEquals('default', $r->sanitize('Test123', 'default')); - } - - public function testPath() - { - $r = new Router($this->container); - - $this->assertEquals('a/b/c', $r->getPath('/a/b/c')); - $this->assertEquals('a/b/something', $r->getPath('/a/b/something?test=a', 'test=a')); - - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['PHP_SELF'] = '/a/index.php'; - - $this->assertEquals('b/c', $r->getPath('/a/b/c')); - $this->assertEquals('b/c', $r->getPath('/a/b/c?e=f', 'e=f')); - } - - public function testFindRouteWithEmptyTable() - { - $r = new Router($this->container); - $this->assertEquals(array('app', 'index'), $r->findRoute('')); - $this->assertEquals(array('app', 'index'), $r->findRoute('/')); - } - - public function testFindRouteWithoutPlaceholders() - { - $r = new Router($this->container); - $r->addRoute('a/b', 'controller', 'action'); - $this->assertEquals(array('app', 'index'), $r->findRoute('a/b/c')); - $this->assertEquals(array('controller', 'action'), $r->findRoute('a/b')); - } - - public function testFindRouteWithPlaceholders() - { - $r = new Router($this->container); - $r->addRoute('a/:myvar1/b/:myvar2', 'controller', 'action'); - $this->assertEquals(array('app', 'index'), $r->findRoute('a/123/b')); - $this->assertEquals(array('controller', 'action'), $r->findRoute('a/456/b/789')); - $this->assertEquals(array('myvar1' => 456, 'myvar2' => 789), $_GET); - } - - public function testFindMultipleRoutes() - { - $r = new Router($this->container); - $r->addRoute('a/b', 'controller1', 'action1'); - $r->addRoute('a/b', 'duplicate', 'duplicate'); - $r->addRoute('a', 'controller2', 'action2'); - $this->assertEquals(array('controller1', 'action1'), $r->findRoute('a/b')); - $this->assertEquals(array('controller2', 'action2'), $r->findRoute('a')); - } - - public function testFindUrl() - { - $r = new Router($this->container); - $r->addRoute('a/b', 'controller1', 'action1'); - $r->addRoute('a/:myvar1/b/:myvar2', 'controller2', 'action2', array('myvar1', 'myvar2')); - - $this->assertEquals('a/1/b/2', $r->findUrl('controller2', 'action2', array('myvar1' => 1, 'myvar2' => 2))); - $this->assertEquals('', $r->findUrl('controller2', 'action2', array('myvar1' => 1))); - $this->assertEquals('a/b', $r->findUrl('controller1', 'action1')); - $this->assertEquals('', $r->findUrl('controller1', 'action2')); - } -} diff --git a/tests/units/SendgridTest.php b/tests/units/SendgridTest.php deleted file mode 100644 index 1fc5d0d5..00000000 --- a/tests/units/SendgridTest.php +++ /dev/null @@ -1,135 +0,0 @@ -container); - $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); - - $this->assertEquals('https://api.sendgrid.com/api/mail.send.json', $this->container['httpClient']->getUrl()); - - $data = $this->container['httpClient']->getData(); - - $this->assertArrayHasKey('api_user', $data); - $this->assertArrayHasKey('api_key', $data); - $this->assertArrayHasKey('from', $data); - $this->assertArrayHasKey('fromname', $data); - $this->assertArrayHasKey('to', $data); - $this->assertArrayHasKey('toname', $data); - $this->assertArrayHasKey('subject', $data); - $this->assertArrayHasKey('html', $data); - - $this->assertEquals('test@localhost', $data['to']); - $this->assertEquals('Me', $data['toname']); - $this->assertEquals('notifications@kanboard.local', $data['from']); - $this->assertEquals('Bob', $data['fromname']); - $this->assertEquals('Test', $data['subject']); - $this->assertEquals('Content', $data['html']); - $this->assertEquals('', $data['api_key']); - $this->assertEquals('', $data['api_user']); - } - - public function testHandlePayload() - { - $w = new Sendgrid($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - - $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'))); - - // Empty payload - $this->assertFalse($w->receiveEmail(array())); - - // Unknown user - $this->assertFalse($w->receiveEmail(array( - 'envelope' => '{"to":["a@b.c"],"from":"a.b.c"}', - 'subject' => 'Email task' - ))); - - // Project not found - $this->assertFalse($w->receiveEmail(array( - 'envelope' => '{"to":["a@b.c"],"from":"me@localhost"}', - 'subject' => 'Email task' - ))); - - // User is not member - $this->assertFalse($w->receiveEmail(array( - 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', - 'subject' => 'Email task' - ))); - - $this->assertTrue($pp->addMember(2, 2)); - - // The task must be created - $this->assertTrue($w->receiveEmail(array( - 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', - 'subject' => 'Email task' - ))); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('Email task', $task['title']); - $this->assertEquals('', $task['description']); - $this->assertEquals(2, $task['creator_id']); - - // Html content - $this->assertTrue($w->receiveEmail(array( - 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', - 'subject' => 'Email task', - 'html' => 'bold text', - ))); - - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('Email task', $task['title']); - $this->assertEquals('**bold** text', $task['description']); - $this->assertEquals(2, $task['creator_id']); - - // Text content - $this->assertTrue($w->receiveEmail(array( - 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', - 'subject' => 'Email task', - 'text' => '**bold** text', - ))); - - $task = $tf->getById(3); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('Email task', $task['title']); - $this->assertEquals('**bold** text', $task['description']); - $this->assertEquals(2, $task['creator_id']); - - // Text + html content - $this->assertTrue($w->receiveEmail(array( - 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', - 'subject' => 'Email task', - 'html' => 'bold html', - 'text' => '**bold** text', - ))); - - $task = $tf->getById(4); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('Email task', $task['title']); - $this->assertEquals('**bold** html', $task['description']); - $this->assertEquals(2, $task['creator_id']); - } -} diff --git a/tests/units/SubtaskTest.php b/tests/units/SubtaskTest.php deleted file mode 100644 index 3c8cab49..00000000 --- a/tests/units/SubtaskTest.php +++ /dev/null @@ -1,284 +0,0 @@ -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']); - } -} diff --git a/tests/units/SubtaskTimeTrackingTest.php b/tests/units/SubtaskTimeTrackingTest.php deleted file mode 100644 index 94f2ce54..00000000 --- a/tests/units/SubtaskTimeTrackingTest.php +++ /dev/null @@ -1,314 +0,0 @@ -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']); - } -} diff --git a/tests/units/SwimlaneTest.php b/tests/units/SwimlaneTest.php deleted file mode 100644 index af187f41..00000000 --- a/tests/units/SwimlaneTest.php +++ /dev/null @@ -1,409 +0,0 @@ -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']); - } -} diff --git a/tests/units/TaskCreationTest.php b/tests/units/TaskCreationTest.php deleted file mode 100644 index a77778d6..00000000 --- a/tests/units/TaskCreationTest.php +++ /dev/null @@ -1,416 +0,0 @@ -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']); - } -} diff --git a/tests/units/TaskDuplicationTest.php b/tests/units/TaskDuplicationTest.php deleted file mode 100644 index 25b9e9fe..00000000 --- a/tests/units/TaskDuplicationTest.php +++ /dev/null @@ -1,707 +0,0 @@ -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); - } -} diff --git a/tests/units/TaskExportTest.php b/tests/units/TaskExportTest.php deleted file mode 100644 index 964418d3..00000000 --- a/tests/units/TaskExportTest.php +++ /dev/null @@ -1,58 +0,0 @@ -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'))); - } -} diff --git a/tests/units/TaskFilterTest.php b/tests/units/TaskFilterTest.php deleted file mode 100644 index 07a34691..00000000 --- a/tests/units/TaskFilterTest.php +++ /dev/null @@ -1,629 +0,0 @@ -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); - } -} diff --git a/tests/units/TaskFinderTest.php b/tests/units/TaskFinderTest.php deleted file mode 100644 index 96a3809b..00000000 --- a/tests/units/TaskFinderTest.php +++ /dev/null @@ -1,33 +0,0 @@ -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']); - } -} diff --git a/tests/units/TaskLinkTest.php b/tests/units/TaskLinkTest.php deleted file mode 100644 index e213e25a..00000000 --- a/tests/units/TaskLinkTest.php +++ /dev/null @@ -1,185 +0,0 @@ -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]); - } -} diff --git a/tests/units/TaskModificationTest.php b/tests/units/TaskModificationTest.php deleted file mode 100644 index 4dd89c5e..00000000 --- a/tests/units/TaskModificationTest.php +++ /dev/null @@ -1,267 +0,0 @@ -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']); - } -} diff --git a/tests/units/TaskMovedDateSubscriberTest.php b/tests/units/TaskMovedDateSubscriberTest.php deleted file mode 100644 index 3b7e494b..00000000 --- a/tests/units/TaskMovedDateSubscriberTest.php +++ /dev/null @@ -1,77 +0,0 @@ -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']); - } -} diff --git a/tests/units/TaskPermissionTest.php b/tests/units/TaskPermissionTest.php deleted file mode 100644 index 0bf68ce3..00000000 --- a/tests/units/TaskPermissionTest.php +++ /dev/null @@ -1,105 +0,0 @@ -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)); - } -} diff --git a/tests/units/TaskPositionTest.php b/tests/units/TaskPositionTest.php deleted file mode 100644 index ec0f7927..00000000 --- a/tests/units/TaskPositionTest.php +++ /dev/null @@ -1,634 +0,0 @@ -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']); - } -} diff --git a/tests/units/TaskStatusTest.php b/tests/units/TaskStatusTest.php deleted file mode 100644 index c1f79142..00000000 --- a/tests/units/TaskStatusTest.php +++ /dev/null @@ -1,101 +0,0 @@ -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']); - } - } -} diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php deleted file mode 100644 index d9c0fa4f..00000000 --- a/tests/units/TaskTest.php +++ /dev/null @@ -1,29 +0,0 @@ -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)); - } -} diff --git a/tests/units/TextHelperTest.php b/tests/units/TextHelperTest.php deleted file mode 100644 index 95c83e57..00000000 --- a/tests/units/TextHelperTest.php +++ /dev/null @@ -1,56 +0,0 @@ -container); - - $this->assertEquals('

Test

', $h->markdown('Test')); - - $this->assertEquals( - '

Task #123

', - $h->markdown('Task #123') - ); - - $this->assertEquals( - '

Task #123

', - $h->markdown('Task #123', array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd'))) - ); - - $this->assertEquals( - '

Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

', - $h->markdown( - 'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454', - array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd')) - ) - ); - } - - public function testFormatBytes() - { - $h = new Text($this->container); - - $this->assertEquals('1k', $h->bytes(1024)); - $this->assertEquals('33.71k', $h->bytes(34520)); - } - - public function testContains() - { - $h = new Text($this->container); - - $this->assertTrue($h->contains('abc', 'b')); - $this->assertFalse($h->contains('abc', 'd')); - } - - public function testInList() - { - $h = new Text($this->container); - $this->assertEquals('?', $h->in('a', array('b' => 'c'))); - $this->assertEquals('c', $h->in('b', array('b' => 'c'))); - } -} diff --git a/tests/units/TimetableTest.php b/tests/units/TimetableTest.php deleted file mode 100644 index 9c40dce1..00000000 --- a/tests/units/TimetableTest.php +++ /dev/null @@ -1,256 +0,0 @@ -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)); - } -} diff --git a/tests/units/ToolTest.php b/tests/units/ToolTest.php deleted file mode 100644 index 4a62fe3b..00000000 --- a/tests/units/ToolTest.php +++ /dev/null @@ -1,15 +0,0 @@ -assertEquals('test1', Tool::getMailboxHash('a+test1@localhost')); - $this->assertEquals('', Tool::getMailboxHash('test1@localhost')); - $this->assertEquals('', Tool::getMailboxHash('test1')); - } -} diff --git a/tests/units/UrlHelperTest.php b/tests/units/UrlHelperTest.php deleted file mode 100644 index ebfe9c99..00000000 --- a/tests/units/UrlHelperTest.php +++ /dev/null @@ -1,86 +0,0 @@ -container); - $this->assertEquals( - 'label', - $h->link('label', 'a', 'b', array('d' => 'e'), false, 'f', 'g', true) - ); - } - - public function testHref() - { - $h = new Url($this->container); - $this->assertEquals( - '?controller=a&action=b&d=e', - $h->href('a', 'b', array('d' => 'e')) - ); - } - - public function testTo() - { - $h = new Url($this->container); - $this->assertEquals( - '?controller=a&action=b&d=e', - $h->to('a', 'b', array('d' => 'e')) - ); - } - - public function testDir() - { - $h = new Url($this->container); - $this->assertEquals('', $h->dir()); - - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['PHP_SELF'] = '/plop/index.php'; - $h = new Url($this->container); - $this->assertEquals('/plop/', $h->dir()); - - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['PHP_SELF'] = ''; - $h = new Url($this->container); - $this->assertEquals('/', $h->dir()); - } - - public function testServer() - { - $h = new Url($this->container); - - $this->assertEquals('http://localhost/', $h->server()); - - $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'kb'; - $_SERVER['SERVER_PORT'] = 1234; - - $this->assertEquals('http://kb:1234/', $h->server()); - } - - public function testBase() - { - $h = new Url($this->container); - - $this->assertEquals('http://localhost/', $h->base()); - - $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'kb'; - $_SERVER['SERVER_PORT'] = 1234; - - $h = new Url($this->container); - $this->assertEquals('http://kb:1234/', $h->base()); - - $c = new Config($this->container); - $c->save(array('application_url' => 'https://mykanboard/')); - - $h = new Url($this->container); - $this->assertEquals('https://mykanboard/', $c->get('application_url')); - $this->assertEquals('https://mykanboard/', $h->base()); - } -} diff --git a/tests/units/UserHelperTest.php b/tests/units/UserHelperTest.php deleted file mode 100644 index 9129edd9..00000000 --- a/tests/units/UserHelperTest.php +++ /dev/null @@ -1,16 +0,0 @@ -container); - - $this->assertEquals('CN', $h->getInitials('chuck norris')); - $this->assertEquals('A', $h->getInitials('admin')); - } -} diff --git a/tests/units/UserSessionTest.php b/tests/units/UserSessionTest.php deleted file mode 100644 index 6a831183..00000000 --- a/tests/units/UserSessionTest.php +++ /dev/null @@ -1,32 +0,0 @@ -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()); - } -} diff --git a/tests/units/UserTest.php b/tests/units/UserTest.php deleted file mode 100644 index f63ed3de..00000000 --- a/tests/units/UserTest.php +++ /dev/null @@ -1,273 +0,0 @@ -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']); - } -} diff --git a/tests/units/WebhookTest.php b/tests/units/WebhookTest.php deleted file mode 100644 index 946d744c..00000000 --- a/tests/units/WebhookTest.php +++ /dev/null @@ -1,112 +0,0 @@ -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']); - } -} -- cgit v1.2.3