diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-10-17 12:30:05 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-10-17 12:30:05 -0400 |
commit | 472f94efee77d8f47ece4ead7d36ee02e5df3e56 (patch) | |
tree | 3456ca052db268b1477aa8b9a741d14bb9927515 /tests/units/Model | |
parent | 3543f45c2d4d6e96e5b88c3168075c0d583fc261 (diff) |
Move webhook to project notification type
Diffstat (limited to 'tests/units/Model')
-rw-r--r-- | tests/units/Model/ProjectNotificationTypeTest.php | 41 | ||||
-rw-r--r-- | tests/units/Model/UserNotificationTypeTest.php | 2 | ||||
-rw-r--r-- | tests/units/Model/WebhookTest.php | 112 |
3 files changed, 42 insertions, 113 deletions
diff --git a/tests/units/Model/ProjectNotificationTypeTest.php b/tests/units/Model/ProjectNotificationTypeTest.php new file mode 100644 index 00000000..d03bffe0 --- /dev/null +++ b/tests/units/Model/ProjectNotificationTypeTest.php @@ -0,0 +1,41 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Project; +use Kanboard\Model\ProjectNotificationType; + +class ProjectNotificationTypeTest extends Base +{ + public function testGetTypes() + { + $nt = new ProjectNotificationType($this->container); + $this->assertEmpty($nt->getTypes()); + + $nt->setType('foo', 'Foo', 'Something1'); + $nt->setType('bar', 'Bar', 'Something2'); + $nt->setType('baz', 'Baz', 'Something3', true); + + $this->assertEquals(array('bar' => 'Bar', 'foo' => 'Foo'), $nt->getTypes()); + $this->assertEquals(array('baz'), $nt->getHiddenTypes()); + } + + public function testGetSelectedTypes() + { + $nt = new ProjectNotificationType($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + + // No type defined + $this->assertEmpty($nt->getSelectedTypes(1)); + + // Hidden type + $nt->setType('baz', 'Baz', 'Something3', true); + $this->assertEquals(array('baz'), $nt->getSelectedTypes(1)); + + // User defined types + $this->assertTrue($nt->saveSelectedTypes(1, array('foo', 'bar'))); + $this->assertEquals(array('baz', 'bar', 'foo'), $nt->getSelectedTypes(1)); + } +} diff --git a/tests/units/Model/UserNotificationTypeTest.php b/tests/units/Model/UserNotificationTypeTest.php index a0a1491d..6982e890 100644 --- a/tests/units/Model/UserNotificationTypeTest.php +++ b/tests/units/Model/UserNotificationTypeTest.php @@ -16,7 +16,7 @@ class UserNotificationTypeTest extends Base $this->assertEquals(array('email' => 'Email', 'web' => 'Web'), $nt->getTypes()); } - public function testGetUserNotificationTypes() + public function testGetSelectedTypes() { $nt = new UserNotificationType($this->container); $types = $nt->getSelectedTypes(1); diff --git a/tests/units/Model/WebhookTest.php b/tests/units/Model/WebhookTest.php deleted file mode 100644 index 39819ba7..00000000 --- a/tests/units/Model/WebhookTest.php +++ /dev/null @@ -1,112 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Model\Config; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskModification; -use Kanboard\Model\Project; -use Kanboard\Model\Comment; -use Kanboard\Subscriber\WebhookSubscriber; - -class WebhookTest extends Base -{ - public function testTaskCreation() - { - $c = new Config($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container)); - - $c->save(array('webhook_url' => 'http://localhost/?task-creation')); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - - $this->assertStringStartsWith('http://localhost/?task-creation&token=', $this->container['httpClient']->getUrl()); - - $event = $this->container['httpClient']->getData(); - $this->assertNotEmpty($event); - $this->assertArrayHasKey('event_name', $event); - $this->assertArrayHasKey('event_data', $event); - $this->assertEquals('task.create', $event['event_name']); - $this->assertNotEmpty($event['event_data']); - - $this->assertArrayHasKey('project_id', $event['event_data']); - $this->assertArrayHasKey('task_id', $event['event_data']); - $this->assertArrayHasKey('title', $event['event_data']); - $this->assertArrayHasKey('column_id', $event['event_data']); - $this->assertArrayHasKey('color_id', $event['event_data']); - $this->assertArrayHasKey('swimlane_id', $event['event_data']); - $this->assertArrayHasKey('date_creation', $event['event_data']); - $this->assertArrayHasKey('date_modification', $event['event_data']); - $this->assertArrayHasKey('date_moved', $event['event_data']); - $this->assertArrayHasKey('position', $event['event_data']); - } - - public function testTaskModification() - { - $c = new Config($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container)); - - $c->save(array('webhook_url' => 'http://localhost/modif/')); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertTrue($tm->update(array('id' => 1, 'title' => 'test update'))); - - $this->assertStringStartsWith('http://localhost/modif/?token=', $this->container['httpClient']->getUrl()); - - $event = $this->container['httpClient']->getData(); - $this->assertNotEmpty($event); - $this->assertArrayHasKey('event_name', $event); - $this->assertArrayHasKey('event_data', $event); - $this->assertEquals('task.update', $event['event_name']); - $this->assertNotEmpty($event['event_data']); - - $this->assertArrayHasKey('project_id', $event['event_data']); - $this->assertArrayHasKey('task_id', $event['event_data']); - $this->assertArrayHasKey('title', $event['event_data']); - $this->assertArrayHasKey('column_id', $event['event_data']); - $this->assertArrayHasKey('color_id', $event['event_data']); - $this->assertArrayHasKey('swimlane_id', $event['event_data']); - $this->assertArrayHasKey('date_creation', $event['event_data']); - $this->assertArrayHasKey('date_modification', $event['event_data']); - $this->assertArrayHasKey('date_moved', $event['event_data']); - $this->assertArrayHasKey('position', $event['event_data']); - } - - public function testCommentCreation() - { - $c = new Config($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $cm = new Comment($this->container); - $this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container)); - - $c->save(array('webhook_url' => 'http://localhost/comment')); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $cm->create(array('task_id' => 1, 'comment' => 'test comment', 'user_id' => 1))); - - $this->assertStringStartsWith('http://localhost/comment?token=', $this->container['httpClient']->getUrl()); - - $event = $this->container['httpClient']->getData(); - $this->assertNotEmpty($event); - $this->assertArrayHasKey('event_name', $event); - $this->assertArrayHasKey('event_data', $event); - $this->assertEquals('comment.create', $event['event_name']); - $this->assertNotEmpty($event['event_data']); - - $this->assertArrayHasKey('task_id', $event['event_data']); - $this->assertArrayHasKey('user_id', $event['event_data']); - $this->assertArrayHasKey('comment', $event['event_data']); - $this->assertArrayHasKey('id', $event['event_data']); - $this->assertEquals('test comment', $event['event_data']['comment']); - } -} |