Move slack, hipchat and jabber integrations to plugins
This commit is contained in:
69
tests/units/Model/NotificationTest.php
Normal file
69
tests/units/Model/NotificationTest.php
Normal file
@@ -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()));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user