Add automatic action to send a task by email
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<phpunit>
|
||||
<phpunit stopOnError="true" stopOnFailure="true" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Kanboard">
|
||||
<directory>units</directory>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<phpunit>
|
||||
<phpunit stopOnError="true" stopOnFailure="true" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Kanboard">
|
||||
<directory>units</directory>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<phpunit>
|
||||
<phpunit stopOnError="true" stopOnFailure="true" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Kanboard">
|
||||
<directory>units</directory>
|
||||
|
||||
149
tests/units/ActionTaskEmailTest.php
Normal file
149
tests/units/ActionTaskEmailTest.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/Base.php';
|
||||
|
||||
use Event\GenericEvent;
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Project;
|
||||
use Model\User;
|
||||
|
||||
class ActionTaskEmailTest extends Base
|
||||
{
|
||||
public function testNoEmail()
|
||||
{
|
||||
$action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 2);
|
||||
$action->setParam('user_id', 1);
|
||||
$action->setParam('subject', 'My email subject');
|
||||
|
||||
// We create a task in the first column
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// We create an event to move the task to the 2nd column
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'column_id' => 2,
|
||||
);
|
||||
|
||||
// Email should be not be sent
|
||||
$this->container['emailClient']->expects($this->never())->method('send');
|
||||
|
||||
// Our event should be executed
|
||||
$this->assertFalse($action->execute(new GenericEvent($event)));
|
||||
}
|
||||
|
||||
public function testWrongColumn()
|
||||
{
|
||||
$action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 2);
|
||||
$action->setParam('user_id', 1);
|
||||
$action->setParam('subject', 'My email subject');
|
||||
|
||||
// We create a task in the first column
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
|
||||
|
||||
// We create an event to move the task to the 2nd column
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'column_id' => 3,
|
||||
);
|
||||
|
||||
// Email should be not be sent
|
||||
$this->container['emailClient']->expects($this->never())->method('send');
|
||||
|
||||
// Our event should be executed
|
||||
$this->assertFalse($action->execute(new GenericEvent($event)));
|
||||
}
|
||||
|
||||
public function testMoveColumn()
|
||||
{
|
||||
$action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN);
|
||||
$action->setParam('column_id', 2);
|
||||
$action->setParam('user_id', 1);
|
||||
$action->setParam('subject', 'My email subject');
|
||||
|
||||
// We create a task in the first column
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost')));
|
||||
|
||||
// We create an event to move the task to the 2nd column
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'column_id' => 2,
|
||||
);
|
||||
|
||||
// Email should be sent
|
||||
$this->container['emailClient']->expects($this->once())
|
||||
->method('send')
|
||||
->with(
|
||||
$this->equalTo('admin@localhost'),
|
||||
$this->equalTo('admin'),
|
||||
$this->equalTo('My email subject'),
|
||||
$this->stringContains('test')
|
||||
);
|
||||
|
||||
// Our event should be executed
|
||||
$this->assertTrue($action->execute(new GenericEvent($event)));
|
||||
}
|
||||
|
||||
public function testTaskClose()
|
||||
{
|
||||
$action = new Action\TaskEmail($this->container, 1, Task::EVENT_CLOSE);
|
||||
$action->setParam('column_id', 2);
|
||||
$action->setParam('user_id', 1);
|
||||
$action->setParam('subject', 'My email subject');
|
||||
|
||||
// We create a task in the first column
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
|
||||
$this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost')));
|
||||
|
||||
// We create an event
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'column_id' => 2,
|
||||
);
|
||||
|
||||
// Email should be sent
|
||||
$this->container['emailClient']->expects($this->once())
|
||||
->method('send')
|
||||
->with(
|
||||
$this->equalTo('admin@localhost'),
|
||||
$this->equalTo('admin'),
|
||||
$this->equalTo('My email subject'),
|
||||
$this->stringContains('test')
|
||||
);
|
||||
|
||||
// Our event should be executed
|
||||
$this->assertTrue($action->execute(new GenericEvent($event)));
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\TaskFinder;
|
||||
use Model\Project;
|
||||
use Integration\GithubWebhook;
|
||||
|
||||
class ActionTaskUpdateStartDateTest extends Base
|
||||
{
|
||||
|
||||
@@ -11,22 +11,6 @@ use SimpleLogger\File;
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
class FakeEmailClient
|
||||
{
|
||||
public $email;
|
||||
public $name;
|
||||
public $subject;
|
||||
public $html;
|
||||
|
||||
public function send($email, $name, $subject, $html)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->name = $name;
|
||||
$this->subject = $subject;
|
||||
$this->html = $html;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeHttpClient
|
||||
{
|
||||
private $url = '';
|
||||
@@ -103,7 +87,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
|
||||
$this->container['logger'] = new Logger;
|
||||
$this->container['logger']->setLogger(new File('/dev/null'));
|
||||
$this->container['httpClient'] = new FakeHttpClient;
|
||||
$this->container['emailClient'] = new FakeEmailClient;
|
||||
$this->container['emailClient'] = $this->getMockBuilder('EmailClient')->setMethods(array('send'))->getMock();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
|
||||
@@ -17,6 +17,7 @@ class ConfigTest extends Base
|
||||
$this->assertEmpty($c->get('webhook_url_task_modification'));
|
||||
$this->assertEmpty($c->get('webhook_url_task_creation'));
|
||||
$this->assertEmpty($c->get('board_columns'));
|
||||
$this->assertEmpty($c->get('application_url'));
|
||||
|
||||
$this->assertNotEmpty($c->get('webhook_token'));
|
||||
$this->assertNotEmpty($c->get('api_token'));
|
||||
@@ -55,4 +56,11 @@ class ConfigTest extends Base
|
||||
session_id('');
|
||||
unset($this->container['session']);
|
||||
}
|
||||
|
||||
public function testSave()
|
||||
{
|
||||
$c = new Config($this->container);
|
||||
$this->assertTrue($c->save(array('application_url' => 'http://localhost/')));
|
||||
$this->assertEquals('http://localhost/', $c->get('application_url'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,14 +285,18 @@ class NotificationTest extends Base
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
$this->container['emailClient']->expects($this->once())
|
||||
->method('send')
|
||||
->with(
|
||||
$this->equalTo('user1@here'),
|
||||
$this->equalTo('user1'),
|
||||
$this->equalTo('[test][Task opened] blah (#2)'),
|
||||
$this->stringContains('blah')
|
||||
);
|
||||
|
||||
$n->sendNotifications('task.open', array('task' => array(
|
||||
'id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 0, 'creator_id' => 2
|
||||
)));
|
||||
|
||||
$this->assertEquals('user1@here', $this->container['emailClient']->email);
|
||||
$this->assertEquals('user1', $this->container['emailClient']->name);
|
||||
$this->assertEquals('[test][Task opened] blah (#2)', $this->container['emailClient']->subject);
|
||||
$this->assertNotEmpty($this->container['emailClient']->html);
|
||||
}
|
||||
|
||||
public function testSendNotificationsToAnotherAssignee()
|
||||
@@ -306,11 +310,11 @@ class NotificationTest extends Base
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
|
||||
$this->assertTrue($pp->addMember(1, 2));
|
||||
|
||||
$this->container['emailClient']->expects($this->never())->method('send');
|
||||
|
||||
$n->sendNotifications('task.open', array('task' => array(
|
||||
'id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 1, 'creator_id' => 1
|
||||
)));
|
||||
|
||||
$this->assertEmpty($this->container['emailClient']->email);
|
||||
}
|
||||
|
||||
public function testSendNotificationsToNotMember()
|
||||
@@ -323,10 +327,10 @@ class NotificationTest extends Base
|
||||
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
|
||||
$this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
|
||||
|
||||
$this->container['emailClient']->expects($this->never())->method('send');
|
||||
|
||||
$n->sendNotifications('task.open', array('task' => array(
|
||||
'id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 0, 'creator_id' => 2
|
||||
)));
|
||||
|
||||
$this->assertEmpty($this->container['emailClient']->email);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class ProjectTest extends Base
|
||||
$this->assertEquals(1, $project['is_active']);
|
||||
$this->assertEquals(0, $project['is_public']);
|
||||
$this->assertEquals(0, $project['is_private']);
|
||||
$this->assertEquals(time(), $project['last_modified']);
|
||||
$this->assertEquals(time(), $project['last_modified'], '', 1);
|
||||
$this->assertEmpty($project['token']);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user