From 710f2c7bb046b43ec9878ae795a181101f6d7515 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 5 Sep 2015 23:30:56 -0400 Subject: [PATCH] Improve unit tests --- app/Auth/Ldap.php | 45 ++++--- app/Controller/Board.php | 2 +- app/Controller/Doc.php | 2 +- .../CommentCreationTest.php} | 4 +- .../TaskAssignColorCategoryTest.php} | 4 +- .../TaskAssignColorColumnTest.php} | 4 +- .../TaskAssignColorLinkTest.php} | 4 +- .../TaskAssignColorUserTest.php} | 4 +- .../TaskAssignCurrentUserTest.php} | 4 +- .../TaskAssignSpecificUserTest.php} | 4 +- .../TaskCloseTest.php} | 4 +- .../TaskDuplicateAnotherProjectTest.php} | 4 +- .../TaskEmailTest.php} | 4 +- .../TaskMoveAnotherProjectTest.php} | 4 +- .../TaskMoveColumnCategoryChangeTest.php} | 4 +- .../TaskUpdateStartDateTest.php} | 4 +- tests/units/Auth/LdapTest.php | 122 ++++++++++++++++++ tests/units/Base.php | 3 + tests/units/{ => Core}/LexerTest.php | 2 +- tests/units/{ => Core}/OAuth2Test.php | 2 +- tests/units/{ => Core}/RouterTest.php | 2 +- tests/units/{ => Core}/ToolTest.php | 2 +- tests/units/{ => Helper}/AppHelperTest.php | 2 +- tests/units/{ => Helper}/AssetHelperTest.php | 2 +- .../units/{ => Helper}/DatetimeHelperTest.php | 2 +- tests/units/{ => Helper}/FileHelperText.php | 2 +- tests/units/{ => Helper}/TextHelperTest.php | 2 +- tests/units/{ => Helper}/UrlHelperTest.php | 2 +- tests/units/{ => Helper}/UserHelperTest.php | 2 +- .../BitbucketWebhookTest.php | 30 ++--- .../{ => Integration}/GithubWebhookTest.php | 40 +++--- .../{ => Integration}/GitlabWebhookTest.php | 20 +-- tests/units/{ => Integration}/MailgunTest.php | 2 +- .../units/{ => Integration}/PostmarkTest.php | 2 +- .../units/{ => Integration}/SendgridTest.php | 2 +- tests/units/{ => Locale}/LocaleTest.php | 2 +- tests/units/{ => Model}/AclTest.php | 2 +- tests/units/{ => Model}/ActionTest.php | 2 +- .../units/{ => Model}/AuthenticationTest.php | 2 +- tests/units/{ => Model}/BoardTest.php | 2 +- tests/units/{ => Model}/CategoryTest.php | 2 +- tests/units/{ => Model}/CommentTest.php | 2 +- tests/units/{ => Model}/ConfigTest.php | 2 +- tests/units/{ => Model}/DateParserTest.php | 2 +- tests/units/{ => Model}/FileTest.php | 2 +- .../HourlyRateTest.php} | 2 +- tests/units/{ => Model}/LinkTest.php | 2 +- tests/units/{ => Model}/NotificationTest.php | 2 +- .../units/{ => Model}/ProjectActivityTest.php | 2 +- .../ProjectDailyColumnStatsTest.php | 2 +- .../{ => Model}/ProjectDuplicationTest.php | 8 +- .../{ => Model}/ProjectPermissionTest.php | 2 +- tests/units/{ => Model}/ProjectTest.php | 2 +- tests/units/{ => Model}/SubtaskTest.php | 2 +- .../{ => Model}/SubtaskTimeTrackingTest.php | 2 +- tests/units/{ => Model}/SwimlaneTest.php | 8 +- tests/units/{ => Model}/TaskCreationTest.php | 2 +- .../units/{ => Model}/TaskDuplicationTest.php | 4 +- tests/units/{ => Model}/TaskExportTest.php | 2 +- tests/units/{ => Model}/TaskFilterTest.php | 2 +- tests/units/{ => Model}/TaskFinderTest.php | 2 +- tests/units/{ => Model}/TaskLinkTest.php | 2 +- .../{ => Model}/TaskModificationTest.php | 2 +- .../TaskMovedDateSubscriberTest.php | 2 +- .../units/{ => Model}/TaskPermissionTest.php | 2 +- tests/units/{ => Model}/TaskPositionTest.php | 2 +- tests/units/{ => Model}/TaskStatusTest.php | 2 +- tests/units/{ => Model}/TaskTest.php | 2 +- tests/units/{ => Model}/TimetableTest.php | 2 +- tests/units/{ => Model}/UserSessionTest.php | 2 +- tests/units/{ => Model}/UserTest.php | 2 +- tests/units/{ => Model}/WebhookTest.php | 2 +- 72 files changed, 281 insertions(+), 151 deletions(-) rename tests/units/{ActionCommentCreationTest.php => Action/CommentCreationTest.php} (98%) rename tests/units/{ActionTaskAssignColorCategoryTest.php => Action/TaskAssignColorCategoryTest.php} (96%) rename tests/units/{ActionTaskAssignColorColumnTest.php => Action/TaskAssignColorColumnTest.php} (93%) rename tests/units/{ActionTaskAssignColorLinkTest.php => Action/TaskAssignColorLinkTest.php} (94%) rename tests/units/{ActionTaskAssignColorUserTest.php => Action/TaskAssignColorUserTest.php} (96%) rename tests/units/{ActionTaskAssignCurrentUserTest.php => Action/TaskAssignCurrentUserTest.php} (96%) rename tests/units/{ActionTaskAssignSpecificUserTest.php => Action/TaskAssignSpecificUserTest.php} (96%) rename tests/units/{ActionTaskCloseTest.php => Action/TaskCloseTest.php} (97%) rename tests/units/{ActionTaskDuplicateAnotherProjectTest.php => Action/TaskDuplicateAnotherProjectTest.php} (97%) rename tests/units/{ActionTaskEmailTest.php => Action/TaskEmailTest.php} (98%) rename tests/units/{ActionTaskMoveAnotherProjectTest.php => Action/TaskMoveAnotherProjectTest.php} (97%) rename tests/units/{ActionTaskMoveColumnCategoryChangeTest.php => Action/TaskMoveColumnCategoryChangeTest.php} (95%) rename tests/units/{ActionTaskUpdateStartDateTest.php => Action/TaskUpdateStartDateTest.php} (94%) create mode 100644 tests/units/Auth/LdapTest.php rename tests/units/{ => Core}/LexerTest.php (99%) rename tests/units/{ => Core}/OAuth2Test.php (97%) rename tests/units/{ => Core}/RouterTest.php (98%) rename tests/units/{ => Core}/ToolTest.php (89%) rename tests/units/{ => Helper}/AppHelperTest.php (96%) rename tests/units/{ => Helper}/AssetHelperTest.php (92%) rename tests/units/{ => Helper}/DatetimeHelperTest.php (97%) rename tests/units/{ => Helper}/FileHelperText.php (88%) rename tests/units/{ => Helper}/TextHelperTest.php (97%) rename tests/units/{ => Helper}/UrlHelperTest.php (98%) rename tests/units/{ => Helper}/UserHelperTest.php (88%) rename tests/units/{ => Integration}/BitbucketWebhookTest.php (90%) rename tests/units/{ => Integration}/GithubWebhookTest.php (88%) rename tests/units/{ => Integration}/GitlabWebhookTest.php (90%) rename tests/units/{ => Integration}/MailgunTest.php (98%) rename tests/units/{ => Integration}/PostmarkTest.php (99%) rename tests/units/{ => Integration}/SendgridTest.php (99%) rename tests/units/{ => Locale}/LocaleTest.php (95%) rename tests/units/{ => Model}/AclTest.php (99%) rename tests/units/{ => Model}/ActionTest.php (99%) rename tests/units/{ => Model}/AuthenticationTest.php (96%) rename tests/units/{ => Model}/BoardTest.php (99%) rename tests/units/{ => Model}/CategoryTest.php (98%) rename tests/units/{ => Model}/CommentTest.php (99%) rename tests/units/{ => Model}/ConfigTest.php (98%) rename tests/units/{ => Model}/DateParserTest.php (99%) rename tests/units/{ => Model}/FileTest.php (99%) rename tests/units/{HourlyRate.php => Model/HourlyRateTest.php} (97%) rename tests/units/{ => Model}/LinkTest.php (99%) rename tests/units/{ => Model}/NotificationTest.php (99%) rename tests/units/{ => Model}/ProjectActivityTest.php (99%) rename tests/units/{ => Model}/ProjectDailyColumnStatsTest.php (98%) rename tests/units/{ => Model}/ProjectDuplicationTest.php (99%) rename tests/units/{ => Model}/ProjectPermissionTest.php (99%) rename tests/units/{ => Model}/ProjectTest.php (99%) rename tests/units/{ => Model}/SubtaskTest.php (99%) rename tests/units/{ => Model}/SubtaskTimeTrackingTest.php (99%) rename tests/units/{ => Model}/SwimlaneTest.php (99%) rename tests/units/{ => Model}/TaskCreationTest.php (99%) rename tests/units/{ => Model}/TaskDuplicationTest.php (99%) rename tests/units/{ => Model}/TaskExportTest.php (98%) rename tests/units/{ => Model}/TaskFilterTest.php (99%) rename tests/units/{ => Model}/TaskFinderTest.php (96%) rename tests/units/{ => Model}/TaskLinkTest.php (99%) rename tests/units/{ => Model}/TaskModificationTest.php (99%) rename tests/units/{ => Model}/TaskMovedDateSubscriberTest.php (98%) rename tests/units/{ => Model}/TaskPermissionTest.php (98%) rename tests/units/{ => Model}/TaskPositionTest.php (99%) rename tests/units/{ => Model}/TaskStatusTest.php (98%) rename tests/units/{ => Model}/TaskTest.php (94%) rename tests/units/{ => Model}/TimetableTest.php (99%) rename tests/units/{ => Model}/UserSessionTest.php (94%) rename tests/units/{ => Model}/UserTest.php (99%) rename tests/units/{ => Model}/WebhookTest.php (99%) diff --git a/app/Auth/Ldap.php b/app/Auth/Ldap.php index c1459b4eb..e46d9b810 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 360a705f1..a552b9cfd 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 19644b842..d9f7b5e70 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/ActionCommentCreationTest.php b/tests/units/Action/CommentCreationTest.php similarity index 98% rename from tests/units/ActionCommentCreationTest.php rename to tests/units/Action/CommentCreationTest.php index cf9e1e0a2..6b5fe1ea3 100644 --- a/tests/units/ActionCommentCreationTest.php +++ b/tests/units/Action/CommentCreationTest.php @@ -1,6 +1,6 @@ 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/Base.php b/tests/units/Base.php index 0a045a097..a48ae5eca 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -1,6 +1,9 @@ container); $p = new Project($this->container); $bw = new BitbucketWebhook($this->container); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_push.json'), true); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_push.json'), true); $this->assertEquals(1, $p->create(array('name' => 'test'))); $bw->setProjectId(1); @@ -50,7 +50,7 @@ class BitbucketWebhookTest extends Base $this->assertNotFalse($bw->parsePayload( 'issue:created', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_opened.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_opened.json'), true) )); } @@ -69,7 +69,7 @@ class BitbucketWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue:comment_created', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_comment_created.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_comment_created.json'), true) )); } @@ -91,7 +91,7 @@ class BitbucketWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue:comment_created', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_comment_created.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_comment_created.json'), true) )); } @@ -116,7 +116,7 @@ class BitbucketWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue:comment_created', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_comment_created.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_comment_created.json'), true) )); } @@ -135,7 +135,7 @@ class BitbucketWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_closed.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_closed.json'), true) )); } @@ -154,7 +154,7 @@ class BitbucketWebhookTest extends Base $this->assertFalse($g->parsePayload( 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_closed.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_closed.json'), true) )); $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); @@ -175,7 +175,7 @@ class BitbucketWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_reopened.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_reopened.json'), true) )); } @@ -194,7 +194,7 @@ class BitbucketWebhookTest extends Base $this->assertFalse($g->parsePayload( 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_reopened.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_reopened.json'), true) )); $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); @@ -215,7 +215,7 @@ class BitbucketWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_unassigned.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_unassigned.json'), true) )); } @@ -240,7 +240,7 @@ class BitbucketWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) )); $this->assertNotEmpty($this->container['dispatcher']->getCalledListeners()); @@ -264,7 +264,7 @@ class BitbucketWebhookTest extends Base $this->assertFalse($g->parsePayload( 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) )); $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); @@ -285,7 +285,7 @@ class BitbucketWebhookTest extends Base $this->assertFalse($g->parsePayload( 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) )); $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); @@ -306,7 +306,7 @@ class BitbucketWebhookTest extends Base $this->assertFalse($g->parsePayload( 'issue:updated', - json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) )); $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); diff --git a/tests/units/GithubWebhookTest.php b/tests/units/Integration/GithubWebhookTest.php similarity index 88% rename from tests/units/GithubWebhookTest.php rename to tests/units/Integration/GithubWebhookTest.php index e143cc1d8..3b67ad1c9 100644 --- a/tests/units/GithubWebhookTest.php +++ b/tests/units/Integration/GithubWebhookTest.php @@ -1,6 +1,6 @@ assertNotFalse($g->parsePayload( 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_opened.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_opened.json'), true) )); } @@ -48,7 +48,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true) )); } @@ -60,7 +60,7 @@ class GithubWebhookTest extends Base $g = new GithubWebhook($this->container); $g->setProjectId(1); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); $this->assertFalse($g->handleIssueAssigned($payload['issue'])); } @@ -76,7 +76,7 @@ class GithubWebhookTest extends Base $g = new GithubWebhook($this->container); $g->setProjectId(1); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); $this->assertFalse($g->handleIssueAssigned($payload['issue'])); } @@ -95,7 +95,7 @@ class GithubWebhookTest extends Base $g = new GithubWebhook($this->container); $g->setProjectId(1); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); $this->assertFalse($g->handleIssueAssigned($payload['issue'])); } @@ -117,7 +117,7 @@ class GithubWebhookTest extends Base $g = new GithubWebhook($this->container); $g->setProjectId(1); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_assigned.json'), true); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); $this->assertTrue($g->handleIssueAssigned($payload['issue'])); } @@ -137,7 +137,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_unassigned.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_unassigned.json'), true) )); } @@ -156,7 +156,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_closed.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_closed.json'), true) )); } @@ -168,7 +168,7 @@ class GithubWebhookTest extends Base $g = new GithubWebhook($this->container); $g->setProjectId(1); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_closed.json'), true); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_closed.json'), true); $this->assertFalse($g->handleIssueClosed($payload['issue'])); } @@ -188,7 +188,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_reopened.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_reopened.json'), true) )); } @@ -200,7 +200,7 @@ class GithubWebhookTest extends Base $g = new GithubWebhook($this->container); $g->setProjectId(1); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_reopened.json'), true); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_reopened.json'), true); $this->assertFalse($g->handleIssueReopened($payload['issue'])); } @@ -220,7 +220,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_labeled.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_labeled.json'), true) )); } @@ -232,7 +232,7 @@ class GithubWebhookTest extends Base $g = new GithubWebhook($this->container); $g->setProjectId(1); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_labeled.json'), true); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_labeled.json'), true); $this->assertFalse($g->handleIssueLabeled($payload['issue'], $payload['label'])); } @@ -252,7 +252,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issues', - json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_unlabeled.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_unlabeled.json'), true) )); } @@ -264,7 +264,7 @@ class GithubWebhookTest extends Base $g = new GithubWebhook($this->container); $g->setProjectId(1); - $payload = json_decode(file_get_contents(__DIR__.'/fixtures/github_issue_unlabeled.json'), true); + $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_unlabeled.json'), true); $this->assertFalse($g->handleIssueUnlabeled($payload['issue'], $payload['label'])); } @@ -284,7 +284,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue_comment', - json_decode(file_get_contents(__DIR__.'/fixtures/github_comment_created.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_comment_created.json'), true) )); } @@ -306,7 +306,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue_comment', - json_decode(file_get_contents(__DIR__.'/fixtures/github_comment_created.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_comment_created.json'), true) )); } @@ -331,7 +331,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'issue_comment', - json_decode(file_get_contents(__DIR__.'/fixtures/github_comment_created.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_comment_created.json'), true) )); } @@ -350,7 +350,7 @@ class GithubWebhookTest extends Base $this->assertNotFalse($g->parsePayload( 'push', - json_decode(file_get_contents(__DIR__.'/fixtures/github_push.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/github_push.json'), true) )); } diff --git a/tests/units/GitlabWebhookTest.php b/tests/units/Integration/GitlabWebhookTest.php similarity index 90% rename from tests/units/GitlabWebhookTest.php rename to tests/units/Integration/GitlabWebhookTest.php index a2dc0d3ac..ec073fee9 100644 --- a/tests/units/GitlabWebhookTest.php +++ b/tests/units/Integration/GitlabWebhookTest.php @@ -1,6 +1,6 @@ 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(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())); } @@ -33,7 +33,7 @@ class GitlabWebhookTest extends Base $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_COMMIT, array($this, 'onCommit')); - $event = json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_push.json'), true); + $event = json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_push.json'), true); // No task $this->assertFalse($g->handleCommit($event['commits'][0])); @@ -57,7 +57,7 @@ class GitlabWebhookTest extends Base $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_OPENED, array($this, 'onOpen')); - $event = json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_issue_opened.json'), true); + $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(); @@ -76,7 +76,7 @@ class GitlabWebhookTest extends Base $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_CLOSED, array($this, 'onClose')); - $event = json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_issue_closed.json'), true); + $event = json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_issue_closed.json'), true); // Issue not there $this->assertFalse($g->handleIssueClosed($event['object_attributes'])); @@ -112,7 +112,7 @@ class GitlabWebhookTest extends Base $g->setProjectId(1); $this->assertNotFalse($g->parsePayload( - json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_comment_created.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true) )); } @@ -133,7 +133,7 @@ class GitlabWebhookTest extends Base $g->setProjectId(1); $this->assertNotFalse($g->parsePayload( - json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_comment_created.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true) )); } @@ -157,7 +157,7 @@ class GitlabWebhookTest extends Base $g->setProjectId(1); $this->assertNotFalse($g->parsePayload( - json_decode(file_get_contents(__DIR__.'/fixtures/gitlab_comment_created.json'), true) + json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true) )); } diff --git a/tests/units/MailgunTest.php b/tests/units/Integration/MailgunTest.php similarity index 98% rename from tests/units/MailgunTest.php rename to tests/units/Integration/MailgunTest.php index ce53228e1..67914b0a2 100644 --- a/tests/units/MailgunTest.php +++ b/tests/units/Integration/MailgunTest.php @@ -1,6 +1,6 @@ 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))); @@ -155,7 +155,7 @@ class ProjectDuplicationTest extends Base $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, @@ -185,7 +185,7 @@ class ProjectDuplicationTest extends Base $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, diff --git a/tests/units/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php similarity index 99% rename from tests/units/ProjectPermissionTest.php rename to tests/units/Model/ProjectPermissionTest.php index 9f6d6a526..475dd0130 100644 --- a/tests/units/ProjectPermissionTest.php +++ b/tests/units/Model/ProjectPermissionTest.php @@ -1,6 +1,6 @@ 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']); @@ -302,7 +302,7 @@ class SwimlaneTest extends Base $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']); @@ -386,7 +386,7 @@ class SwimlaneTest extends Base $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'; diff --git a/tests/units/TaskCreationTest.php b/tests/units/Model/TaskCreationTest.php similarity index 99% rename from tests/units/TaskCreationTest.php rename to tests/units/Model/TaskCreationTest.php index a77778d6d..f292c7f1a 100644 --- a/tests/units/TaskCreationTest.php +++ b/tests/units/Model/TaskCreationTest.php @@ -1,6 +1,6 @@ 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))); diff --git a/tests/units/TaskExportTest.php b/tests/units/Model/TaskExportTest.php similarity index 98% rename from tests/units/TaskExportTest.php rename to tests/units/Model/TaskExportTest.php index 964418d3e..529963691 100644 --- a/tests/units/TaskExportTest.php +++ b/tests/units/Model/TaskExportTest.php @@ -1,6 +1,6 @@