summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-17 22:19:49 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-17 22:19:49 -0400
commit09da289c2fb18475f372bee24e885617da484e0b (patch)
tree95d1869ba3236ccdd9234d7909fc16c495c84d44 /tests
parent9283fb88d80cb355ff98364a9a57b657fc511d98 (diff)
Move slack, hipchat and jabber integrations to plugins
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Base.php2
-rw-r--r--tests/units/Integration/SlackWebhookTest.php377
-rw-r--r--tests/units/Model/NotificationTest.php69
-rw-r--r--tests/units/Model/ProjectActivityTest.php40
-rw-r--r--tests/units/Model/ProjectNotificationTypeTest.php11
-rw-r--r--tests/units/Model/UserNotificationTest.php23
-rw-r--r--tests/units/Model/UserNotificationTypeTest.php21
-rw-r--r--tests/units/Model/UserUnreadNotificationTest.php43
8 files changed, 115 insertions, 471 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php
index 4a5b303f..89d0e2bf 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -91,7 +91,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
$this->container['userNotificationType'] = $this
->getMockBuilder('\Kanboard\Model\UserNotificationType')
->setConstructorArgs(array($this->container))
- ->setMethods(array('getType'))
+ ->setMethods(array('getType', 'getSelectedTypes'))
->getMock();
}
diff --git a/tests/units/Integration/SlackWebhookTest.php b/tests/units/Integration/SlackWebhookTest.php
deleted file mode 100644
index cf8c8645..00000000
--- a/tests/units/Integration/SlackWebhookTest.php
+++ /dev/null
@@ -1,377 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Integration\SlackWebhook;
-use Kanboard\Model\Project;
-use Kanboard\Model\Task;
-
-class SlackWebhookTest extends Base
-{
- public function testIsActivatedFromGlobalConfig()
- {
- $slack = new SlackWebhook($this->container);
-
- $this->container['config'] = $this
- ->getMockBuilder('\Kanboard\Model\Config')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'get',
- ))
- ->getMock();
-
- $this->container['config']
- ->expects($this->once())
- ->method('get')
- ->with($this->equalTo('integration_slack_webhook'))
- ->will($this->returnValue(1));
-
- $this->assertTrue($slack->isActivated(1));
- }
-
- public function testIsActivatedFromProjectConfig()
- {
- $slack = new SlackWebhook($this->container);
-
- $this->container['config'] = $this
- ->getMockBuilder('\Kanboard\Model\Config')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'get',
- ))
- ->getMock();
-
- $this->container['projectIntegration'] = $this
- ->getMockBuilder('\Kanboard\Model\ProjectIntegration')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'hasValue',
- ))
- ->getMock();
-
- $this->container['config']
- ->expects($this->once())
- ->method('get')
- ->with($this->equalTo('integration_slack_webhook'))
- ->will($this->returnValue(0));
-
- $this->container['projectIntegration']
- ->expects($this->once())
- ->method('hasValue')
- ->with(
- $this->equalTo(1),
- $this->equalTo('slack'),
- $this->equalTo(1)
- )
- ->will($this->returnValue(true));
-
- $this->assertTrue($slack->isActivated(1));
- }
-
- public function testIsNotActivated()
- {
- $slack = new SlackWebhook($this->container);
-
- $this->container['config'] = $this
- ->getMockBuilder('\Kanboard\Model\Config')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'get',
- ))
- ->getMock();
-
- $this->container['projectIntegration'] = $this
- ->getMockBuilder('\Kanboard\Model\ProjectIntegration')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'hasValue',
- ))
- ->getMock();
-
- $this->container['config']
- ->expects($this->once())
- ->method('get')
- ->with($this->equalTo('integration_slack_webhook'))
- ->will($this->returnValue(0));
-
- $this->container['projectIntegration']
- ->expects($this->once())
- ->method('hasValue')
- ->with(
- $this->equalTo(1),
- $this->equalTo('slack'),
- $this->equalTo(1)
- )
- ->will($this->returnValue(false));
-
- $this->assertFalse($slack->isActivated(1));
- }
-
- public function testGetChannelFromGlobalConfig()
- {
- $slack = new SlackWebhook($this->container);
-
- $this->container['config'] = $this
- ->getMockBuilder('\Kanboard\Model\Config')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'get',
- ))
- ->getMock();
-
- $this->container['config']
- ->expects($this->once())
- ->method('get')
- ->with($this->equalTo('integration_slack_webhook_channel'))
- ->will($this->returnValue('mychannel'));
-
- $this->assertEquals('mychannel', $slack->getChannel(1));
- }
-
- public function testGetChannelFromProjectConfig()
- {
- $slack = new SlackWebhook($this->container);
-
- $this->container['config'] = $this
- ->getMockBuilder('\Kanboard\Model\Config')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'get',
- ))
- ->getMock();
-
- $this->container['projectIntegration'] = $this
- ->getMockBuilder('\Kanboard\Model\ProjectIntegration')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'getParameters',
- ))
- ->getMock();
-
- $this->container['config']
- ->expects($this->once())
- ->method('get')
- ->with($this->equalTo('integration_slack_webhook_channel'))
- ->will($this->returnValue(''));
-
- $this->container['projectIntegration']
- ->expects($this->once())
- ->method('getParameters')
- ->with($this->equalTo(1))
- ->will($this->returnValue(array('slack_webhook_channel' => 'my_project_channel')));
-
- $this->assertEquals('my_project_channel', $slack->getChannel(1));
- }
-
- public function testGetWebhoookUrlFromGlobalConfig()
- {
- $slack = new SlackWebhook($this->container);
-
- $this->container['config'] = $this
- ->getMockBuilder('\Kanboard\Model\Config')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'get',
- ))
- ->getMock();
-
- $this->container['config']
- ->expects($this->at(0))
- ->method('get')
- ->with($this->equalTo('integration_slack_webhook'))
- ->will($this->returnValue(1));
-
- $this->container['config']
- ->expects($this->at(1))
- ->method('get')
- ->with($this->equalTo('integration_slack_webhook_url'))
- ->will($this->returnValue('url'));
-
- $this->assertEquals('url', $slack->getWebhookUrl(1));
- }
-
- public function testGetWebhookUrlFromProjectConfig()
- {
- $slack = new SlackWebhook($this->container);
-
- $this->container['config'] = $this
- ->getMockBuilder('\Kanboard\Model\Config')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'get',
- ))
- ->getMock();
-
- $this->container['projectIntegration'] = $this
- ->getMockBuilder('\Kanboard\Model\ProjectIntegration')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'getParameters',
- ))
- ->getMock();
-
- $this->container['config']
- ->expects($this->once())
- ->method('get')
- ->with($this->equalTo('integration_slack_webhook'))
- ->will($this->returnValue(0));
-
- $this->container['projectIntegration']
- ->expects($this->once())
- ->method('getParameters')
- ->with($this->equalTo(1))
- ->will($this->returnValue(array('slack_webhook_url' => 'my_project_url')));
-
- $this->assertEquals('my_project_url', $slack->getWebhookUrl(1));
- }
-
- public function testSendPayloadWithChannel()
- {
- $this->container['httpClient'] = $this
- ->getMockBuilder('\Kanboard\Core\HttpClient')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'postJson',
- ))
- ->getMock();
-
- $slack = $this
- ->getMockBuilder('\Kanboard\Integration\SlackWebhook')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'getChannel',
- 'getWebhookUrl',
- ))
- ->getMock();
-
- $slack
- ->expects($this->at(0))
- ->method('getChannel')
- ->with(
- $this->equalTo(1)
- )
- ->will($this->returnValue('mychannel'));
-
- $slack
- ->expects($this->at(1))
- ->method('getWebhookUrl')
- ->with(
- $this->equalTo(1)
- )
- ->will($this->returnValue('url'));
-
- $this->container['httpClient']
- ->expects($this->once())
- ->method('postJson')
- ->with(
- $this->equalTo('url'),
- $this->equalTo(array('text' => 'test', 'channel' => 'mychannel'))
- );
-
- $slack->sendPayload(1, array('text' => 'test'));
- }
-
- public function testSendPayloadWithoutChannel()
- {
- $this->container['httpClient'] = $this
- ->getMockBuilder('\Kanboard\Core\HttpClient')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'postJson',
- ))
- ->getMock();
-
- $slack = $this
- ->getMockBuilder('\Kanboard\Integration\SlackWebhook')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'getChannel',
- 'getWebhookUrl',
- ))
- ->getMock();
-
- $slack
- ->expects($this->at(0))
- ->method('getChannel')
- ->with(
- $this->equalTo(1)
- )
- ->will($this->returnValue(''));
-
- $slack
- ->expects($this->at(1))
- ->method('getWebhookUrl')
- ->with(
- $this->equalTo(1)
- )
- ->will($this->returnValue('url'));
-
- $this->container['httpClient']
- ->expects($this->once())
- ->method('postJson')
- ->with(
- $this->equalTo('url'),
- $this->equalTo(array('text' => 'test'))
- );
-
- $slack->sendPayload(1, array('text' => 'test'));
- }
-
- public function testSendMessage()
- {
- $message = 'test';
-
- $payload = array(
- 'text' => $message,
- 'username' => 'Kanboard',
- 'icon_url' => 'http://kanboard.net/assets/img/favicon.png',
- );
-
- $slack = $this
- ->getMockBuilder('\Kanboard\Integration\SlackWebhook')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'sendPayload',
- ))
- ->getMock();
-
- $slack
- ->expects($this->once())
- ->method('sendPayload')
- ->with(
- $this->equalTo(1),
- $this->equalTo($payload)
- );
-
- $slack->sendMessage(1, $message);
- }
-
- public function testNotify()
- {
- $message = '*[foobar]* FooBar created the task #1 (task #1)';
-
- $this->container['session']['user'] = array('username' => 'foobar', 'name' => 'FooBar');
-
- $p = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'foobar')));
- $this->assertTrue($this->container['config']->save(array('integration_slack_webhook' => 1)));
-
- $slack = $this
- ->getMockBuilder('\Kanboard\Integration\SlackWebhook')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array(
- 'sendMessage',
- ))
- ->getMock();
-
- $slack
- ->expects($this->once())
- ->method('sendMessage')
- ->with(
- $this->equalTo(1),
- $this->equalTo($message)
- );
-
- $slack->notify(1, 1, Task::EVENT_CREATE, array('task' => array('id' => 1, 'title' => 'task #1')));
- }
-}
diff --git a/tests/units/Model/NotificationTest.php b/tests/units/Model/NotificationTest.php
new file mode 100644
index 00000000..7f9977ce
--- /dev/null
+++ b/tests/units/Model/NotificationTest.php
@@ -0,0 +1,69 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\Subtask;
+use Kanboard\Model\Comment;
+use Kanboard\Model\User;
+use Kanboard\Model\File;
+use Kanboard\Model\Task;
+use Kanboard\Model\Project;
+use Kanboard\Model\Notification;
+use Kanboard\Subscriber\NotificationSubscriber;
+
+class NotificationTest extends Base
+{
+ public function testGetTitle()
+ {
+ $wn = 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 (NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
+ $title = $wn->getTitleWithoutAuthor($event_name, array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'changes' => array()
+ ));
+
+ $this->assertNotEmpty($title);
+
+ $title = $wn->getTitleWithAuthor('foobar', $event_name, array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'changes' => array()
+ ));
+
+ $this->assertNotEmpty($title);
+ }
+
+ $this->assertNotEmpty($wn->getTitleWithoutAuthor(Task::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
+ $this->assertNotEmpty($wn->getTitleWithoutAuthor('unkown', array()));
+ }
+}
diff --git a/tests/units/Model/ProjectActivityTest.php b/tests/units/Model/ProjectActivityTest.php
index ead74e08..5a242cb2 100644
--- a/tests/units/Model/ProjectActivityTest.php
+++ b/tests/units/Model/ProjectActivityTest.php
@@ -10,49 +10,9 @@ use Kanboard\Model\Project;
use Kanboard\Model\Subtask;
use Kanboard\Model\Comment;
use Kanboard\Model\File;
-use Kanboard\Subscriber\NotificationSubscriber;
class ProjectActivityTest extends Base
{
- public function testGetTitle()
- {
- $pa = new ProjectActivity($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 (NotificationSubscriber::getSubscribedEvents() as $event_name => $listeners) {
- $this->assertNotEmpty($pa->getTitle(array(
- 'event_name' => $event_name,
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'author' => 'bob',
- 'changes' => array())
- ));
- }
- }
-
public function testDecode()
{
$e = new ProjectActivity($this->container);
diff --git a/tests/units/Model/ProjectNotificationTypeTest.php b/tests/units/Model/ProjectNotificationTypeTest.php
index d03bffe0..71e2b964 100644
--- a/tests/units/Model/ProjectNotificationTypeTest.php
+++ b/tests/units/Model/ProjectNotificationTypeTest.php
@@ -32,10 +32,15 @@ class ProjectNotificationTypeTest extends Base
// Hidden type
$nt->setType('baz', 'Baz', 'Something3', true);
- $this->assertEquals(array('baz'), $nt->getSelectedTypes(1));
+ $this->assertEmpty($nt->getSelectedTypes(1));
- // User defined types
+ // User defined types but not registered
$this->assertTrue($nt->saveSelectedTypes(1, array('foo', 'bar')));
- $this->assertEquals(array('baz', 'bar', 'foo'), $nt->getSelectedTypes(1));
+ $this->assertEmpty($nt->getSelectedTypes(1));
+
+ // User defined types and registered
+ $nt->setType('bar', 'Bar', 'Something4');
+ $nt->setType('foo', 'Foo', 'Something3');
+ $this->assertEquals(array('bar', 'foo'), $nt->getSelectedTypes(1));
}
}
diff --git a/tests/units/Model/UserNotificationTest.php b/tests/units/Model/UserNotificationTest.php
index 8d7dec60..729667de 100644
--- a/tests/units/Model/UserNotificationTest.php
+++ b/tests/units/Model/UserNotificationTest.php
@@ -50,6 +50,22 @@ class UserNotificationTest extends Base
'notification_projects' => array(),
));
+ $this->container['userNotificationType']
+ ->expects($this->at(0))
+ ->method('getSelectedTypes')
+ ->will($this->returnValue(array('email')));
+
+ $this->container['userNotificationType']
+ ->expects($this->at(1))
+ ->method('getSelectedTypes')
+ ->will($this->returnValue(array('email')));
+
+ $this->container['userNotificationType']
+ ->expects($this->at(2))
+ ->method('getSelectedTypes')
+ ->with($this->equalTo(1))
+ ->will($this->returnValue(array('email', 'web')));
+
$settings = $n->readSettings(1);
$this->assertNotEmpty($settings);
$this->assertEquals(1, $settings['notifications_enabled']);
@@ -183,12 +199,17 @@ class UserNotificationTest extends Base
$this->container['userNotificationType']
->expects($this->at(0))
+ ->method('getSelectedTypes')
+ ->will($this->returnValue(array('email', 'web')));
+
+ $this->container['userNotificationType']
+ ->expects($this->at(1))
->method('getType')
->with($this->equalTo('email'))
->will($this->returnValue($notifier));
$this->container['userNotificationType']
- ->expects($this->at(1))
+ ->expects($this->at(2))
->method('getType')
->with($this->equalTo('web'))
->will($this->returnValue($notifier));
diff --git a/tests/units/Model/UserNotificationTypeTest.php b/tests/units/Model/UserNotificationTypeTest.php
index 6982e890..da22afef 100644
--- a/tests/units/Model/UserNotificationTypeTest.php
+++ b/tests/units/Model/UserNotificationTypeTest.php
@@ -19,12 +19,21 @@ class UserNotificationTypeTest extends Base
public function testGetSelectedTypes()
{
$nt = new UserNotificationType($this->container);
- $types = $nt->getSelectedTypes(1);
- $this->assertEmpty($types);
- $this->assertTrue($nt->saveSelectedTypes(1, array('email', 'web')));
- $types = $nt->getSelectedTypes(1);
- $this->assertNotEmpty($types);
- $this->assertEquals(array('email', 'web'), $types);
+ // No type defined
+ $this->assertEmpty($nt->getSelectedTypes(1));
+
+ // Hidden type
+ $nt->setType('baz', 'Baz', 'Something3', true);
+ $this->assertEmpty($nt->getSelectedTypes(1));
+
+ // User defined types but not registered
+ $this->assertTrue($nt->saveSelectedTypes(1, array('foo', 'bar')));
+ $this->assertEmpty($nt->getSelectedTypes(1));
+
+ // User defined types and registered
+ $nt->setType('bar', 'Bar', 'Something4');
+ $nt->setType('foo', 'Foo', 'Something3');
+ $this->assertEquals(array('bar', 'foo'), $nt->getSelectedTypes(1));
}
}
diff --git a/tests/units/Model/UserUnreadNotificationTest.php b/tests/units/Model/UserUnreadNotificationTest.php
index 130a6eba..bf274d95 100644
--- a/tests/units/Model/UserUnreadNotificationTest.php
+++ b/tests/units/Model/UserUnreadNotificationTest.php
@@ -11,52 +11,9 @@ use Kanboard\Model\File;
use Kanboard\Model\Task;
use Kanboard\Model\Project;
use Kanboard\Model\UserUnreadNotification;
-use Kanboard\Subscriber\NotificationSubscriber;
class UserUnreadNotificationTest extends Base
{
- public function testGetTitle()
- {
- $wn = new UserUnreadNotification($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 (NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
- $title = $wn->getTitleFromEvent($event_name, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array()
- ));
-
- $this->assertNotEmpty($title);
- }
-
- $this->assertNotEmpty($wn->getTitleFromEvent(Task::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
- $this->assertNotEmpty($wn->getTitleFromEvent('unkown', array()));
- }
-
public function testHasNotification()
{
$wn = new UserUnreadNotification($this->container);