summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-06-20 20:55:50 -0400
committerFrederic Guillot <fred@kanboard.net>2015-06-20 20:55:50 -0400
commit98fd34bfe340fae6d0fd3b7333b6f9a6647cbae2 (patch)
treed22b7bff634a05e73f89d423938776df43554f52 /tests
parent7b947ebdbd3b6bcd9de10ea4255bfa11fc88695c (diff)
Improve automatic action to create comments based on commit messages
Diffstat (limited to 'tests')
-rw-r--r--tests/units/BitbucketWebhookTest.php19
-rw-r--r--tests/units/GithubWebhookTest.php3
-rw-r--r--tests/units/GitlabWebhookTest.php19
3 files changed, 33 insertions, 8 deletions
diff --git a/tests/units/BitbucketWebhookTest.php b/tests/units/BitbucketWebhookTest.php
index cb33b595..f1735d3d 100644
--- a/tests/units/BitbucketWebhookTest.php
+++ b/tests/units/BitbucketWebhookTest.php
@@ -21,7 +21,7 @@ class BitbucketWebhookTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test')));
$g->setProjectId(1);
- $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, function() {});
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, array($this, 'onCommit'));
$event = json_decode($this->post_payload, true);
@@ -29,15 +29,15 @@ class BitbucketWebhookTest extends Base
$this->assertFalse($g->handleCommit($event['commits'][0]));
// Create task with the wrong id
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1)));
$this->assertFalse($g->handleCommit($event['commits'][1]));
// Create task with the right id
- $this->assertEquals(2, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1)));
$this->assertTrue($g->handleCommit($event['commits'][1]));
$called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.closure', $called);
+ $this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.BitbucketWebhookTest::onCommit', $called);
}
public function testParsePayload()
@@ -62,4 +62,15 @@ class BitbucketWebhookTest extends Base
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.closure', $called);
}
+
+ 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 #2\n\n\nCommit made by @Frederic Guillot on Bitbucket", $data['commit_comment']);
+ $this->assertEquals("Fix #2\n", $data['commit_message']);
+ $this->assertEquals('', $data['commit_url']);
+ }
}
diff --git a/tests/units/GithubWebhookTest.php b/tests/units/GithubWebhookTest.php
index 65aa045f..8d9d7144 100644
--- a/tests/units/GithubWebhookTest.php
+++ b/tests/units/GithubWebhookTest.php
@@ -451,5 +451,8 @@ class GithubWebhookTest extends Base
$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
index cea4e839..b69f7431 100644
--- a/tests/units/GitlabWebhookTest.php
+++ b/tests/units/GitlabWebhookTest.php
@@ -33,7 +33,7 @@ class GitlabWebhookTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test')));
$g->setProjectId(1);
- $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_COMMIT, function() {});
+ $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_COMMIT, array($this, 'onCommit'));
$event = json_decode($this->push_payload, true);
@@ -41,15 +41,15 @@ class GitlabWebhookTest extends Base
$this->assertFalse($g->handleCommit($event['commits'][0]));
// Create task with the wrong id
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $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' => 'test', 'project_id' => 1)));
+ $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.'.closure', $called);
+ $this->assertArrayHasKey(GitlabWebhook::EVENT_COMMIT.'.GitlabWebhookTest::onCommit', $called);
}
public function testHandleIssueOpened()
@@ -116,4 +116,15 @@ class GitlabWebhookTest extends Base
$this->assertEquals(1, $data['task_id']);
$this->assertEquals(103361, $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\n[Commit made by @Frédéric Guillot on Gitlab](https://gitlab.com/minicoders/kanboard/commit/b3caaee62ad27dc31497946065ac18299784aee4)", $data['commit_comment']);
+ $this->assertEquals("Fix bug #2\n", $data['commit_message']);
+ $this->assertEquals('https://gitlab.com/minicoders/kanboard/commit/b3caaee62ad27dc31497946065ac18299784aee4', $data['commit_url']);
+ }
}