diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functionals.sqlite.xml | 2 | ||||
-rw-r--r-- | tests/functionals/ApiTest.php | 84 | ||||
-rw-r--r-- | tests/units/ActionTaskMoveColumnCategoryChangeTest.php | 61 | ||||
-rw-r--r-- | tests/units/ActionTaskUpdateStartDateTest.php | 2 | ||||
-rw-r--r-- | tests/units/Base.php | 35 | ||||
-rw-r--r-- | tests/units/FileTest.php | 163 | ||||
-rw-r--r-- | tests/units/MailgunTest.php (renamed from tests/units/MailgunWebhookTest.php) | 36 | ||||
-rw-r--r-- | tests/units/NotificationTest.php | 303 | ||||
-rw-r--r-- | tests/units/PostmarkTest.php (renamed from tests/units/PostmarkWebhookTest.php) | 45 | ||||
-rw-r--r-- | tests/units/SendgridTest.php (renamed from tests/units/SendgridWebhookTest.php) | 50 | ||||
-rw-r--r-- | tests/units/TaskDuplicationTest.php | 4 | ||||
-rw-r--r-- | tests/units/TaskMovedDateSubscriberTest.php | 77 | ||||
-rw-r--r-- | tests/units/TextHelperTest.php | 8 |
13 files changed, 765 insertions, 105 deletions
diff --git a/tests/functionals.sqlite.xml b/tests/functionals.sqlite.xml index bf5d4117..0d011ac3 100644 --- a/tests/functionals.sqlite.xml +++ b/tests/functionals.sqlite.xml @@ -5,7 +5,7 @@ </testsuite> </testsuites> <php> - <const name="API_URL" value="http://localhost:8000/jsonrpc.php" /> + <const name="API_URL" value="http://127.0.0.1:8000/jsonrpc.php" /> <const name="API_KEY" value="19ffd9709d03ce50675c3a43d1c49c1ac207f4bc45f06c5b2701fbdf8929" /> <const name="DB_DRIVER" value="sqlite" /> <const name="DB_FILENAME" value="data/db.sqlite" /> diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php index b5039759..642288b8 100644 --- a/tests/functionals/ApiTest.php +++ b/tests/functionals/ApiTest.php @@ -348,11 +348,6 @@ class Api extends PHPUnit_Framework_TestCase $this->assertEquals('Swimlane A', $swimlanes[2]['name']); } - public function testRemoveSwimlane() - { - $this->assertTrue($this->client->removeSwimlane(1, 2)); - } - public function testCreateTask() { $task = array( @@ -408,6 +403,42 @@ class Api extends PHPUnit_Framework_TestCase $this->assertEmpty($tasks); } + public function testMoveTaskSwimlane() + { + $task_id = $this->getTaskId(); + + $task = $this->client->getTask($task_id); + $this->assertNotFalse($task); + $this->assertTrue(is_array($task)); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['column_id']); + $this->assertEquals(0, $task['swimlane_id']); + + $moved_timestamp = $task['date_moved']; + sleep(1); + $this->assertTrue($this->client->moveTaskPosition(1, $task_id, 4, 1, 2)); + + $task = $this->client->getTask($task_id); + $this->assertNotFalse($task); + $this->assertTrue(is_array($task)); + $this->assertEquals(1, $task['position']); + $this->assertEquals(4, $task['column_id']); + $this->assertEquals(2, $task['swimlane_id']); + $this->assertNotEquals($moved_timestamp, $task['date_moved']); + } + + public function testRemoveSwimlane() + { + $this->assertTrue($this->client->removeSwimlane(1, 2)); + + $task = $this->client->getTask($this->getTaskId()); + $this->assertNotFalse($task); + $this->assertTrue(is_array($task)); + $this->assertEquals(1, $task['position']); + $this->assertEquals(4, $task['column_id']); + $this->assertEquals(0, $task['swimlane_id']); + } + public function testUpdateTask() { $task = $this->client->getTask(1); @@ -415,7 +446,6 @@ class Api extends PHPUnit_Framework_TestCase $values = array(); $values['id'] = $task['id']; $values['color_id'] = 'green'; - $values['column_id'] = 1; $values['description'] = 'test'; $values['date_due'] = ''; @@ -937,7 +967,7 @@ class Api extends PHPUnit_Framework_TestCase public function testCreateFile() { - $this->assertTrue($this->client->createFile(1, 1, 'My file', false, base64_encode('plain text file'))); + $this->assertEquals(1, $this->client->createFile(1, 1, 'My file', base64_encode('plain text file'))); } public function testGetAllFiles() @@ -962,4 +992,44 @@ class Api extends PHPUnit_Framework_TestCase $this->assertTrue($this->client->removeFile($file['id'])); $this->assertEmpty($this->client->getAllFiles(1)); } + + public function testRemoveAllFiles() + { + $this->assertEquals(1, $this->client->createFile(1, 1, 'My file 1', base64_encode('plain text file'))); + $this->assertEquals(2, $this->client->createFile(1, 1, 'My file 2', base64_encode('plain text file'))); + + $files = $this->client->getAllFiles(array('task_id' => 1)); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + + $this->assertTrue($this->client->removeAllFiles(array('task_id' => 1))); + + $files = $this->client->getAllFiles(array('task_id' => 1)); + $this->assertEmpty($files); + } + + public function testCreateTaskWithReference() + { + $task = array( + 'title' => 'Task with external ticket number', + 'reference' => 'TICKET-1234', + 'project_id' => 1, + 'description' => '[Link to my ticket](http://my-ticketing-system/1234)', + ); + + $task_id = $this->client->createTask($task); + + $this->assertNotFalse($task_id); + $this->assertInternalType('int', $task_id); + $this->assertTrue($task_id > 0); + } + + public function testGetTaskByReference() + { + $task = $this->client->getTaskByReference(array('project_id' => 1, 'reference' => 'TICKET-1234')); + + $this->assertNotEmpty($task); + $this->assertEquals('Task with external ticket number', $task['title']); + $this->assertEquals('TICKET-1234', $task['reference']); + } }
\ No newline at end of file diff --git a/tests/units/ActionTaskMoveColumnCategoryChangeTest.php b/tests/units/ActionTaskMoveColumnCategoryChangeTest.php new file mode 100644 index 00000000..0ddee786 --- /dev/null +++ b/tests/units/ActionTaskMoveColumnCategoryChangeTest.php @@ -0,0 +1,61 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Model\Category; +use Integration\GithubWebhook; + +class ActionTaskMoveColumnCategoryChangeTest extends Base +{ + public function testExecute() + { + $action = new Action\TaskMoveColumnCategoryChange($this->container, 1, Task::EVENT_UPDATE); + $action->setParam('dest_column_id', 3); + $action->setParam('category_id', 1); + + $this->assertEquals(3, $action->getParam('dest_column_id')); + $this->assertEquals(1, $action->getParam('category_id')); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $c = new Category($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $c->create(array('name' => 'bug', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // No category should be assigned + column_id=1 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEmpty($task['category_id']); + $this->assertEquals(1, $task['column_id']); + + // We create an event to move the task to the 2nd column + $event = array( + 'task_id' => 1, + 'column_id' => 1, + 'project_id' => 1, + 'category_id' => 1, + ); + + // Our event should be executed + $this->assertTrue($action->hasCompatibleEvent()); + $this->assertTrue($action->hasRequiredProject($event)); + $this->assertTrue($action->hasRequiredParameters($event)); + $this->assertTrue($action->hasRequiredCondition($event)); + $this->assertTrue($action->isExecutable($event)); + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be moved to the other column + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(3, $task['column_id']); + } +} diff --git a/tests/units/ActionTaskUpdateStartDateTest.php b/tests/units/ActionTaskUpdateStartDateTest.php index da36551d..4bf87452 100644 --- a/tests/units/ActionTaskUpdateStartDateTest.php +++ b/tests/units/ActionTaskUpdateStartDateTest.php @@ -38,7 +38,7 @@ class ActionTaskUpdateStartDateTest extends Base // Our event should be executed $this->assertTrue($action->execute(new GenericEvent($event))); - // Our task should be closed + // Our task should be updated $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(time(), $task['date_started'], '', 2); diff --git a/tests/units/Base.php b/tests/units/Base.php index 20f4a8cc..bc6518fb 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -11,10 +11,27 @@ 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 = ''; private $data = array(); + private $headers = array(); public function getUrl() { @@ -26,16 +43,29 @@ class FakeHttpClient return $this->data; } + public function getHeaders() + { + return $this->headers; + } + public function toPrettyJson() { return json_encode($this->data, JSON_PRETTY_PRINT); } - public function post($url, array $data) + public function postJson($url, array $data, array $headers = array()) + { + $this->url = $url; + $this->data = $data; + $this->headers = $headers; + return true; + } + + public function postForm($url, array $data, array $headers = array()) { $this->url = $url; $this->data = $data; - //echo $this->toPrettyJson(); + $this->headers = $headers; return true; } } @@ -73,6 +103,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; } public function tearDown() diff --git a/tests/units/FileTest.php b/tests/units/FileTest.php index 5e882fdb..4ea7f386 100644 --- a/tests/units/FileTest.php +++ b/tests/units/FileTest.php @@ -9,6 +9,36 @@ use Model\Project; class FileTest extends Base { + public function testCreation() + { + $p = new Project($this->container); + $f = new File($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $f->create(1, 'test', '/tmp/foo', 10)); + + $file = $f->getById(1); + $this->assertNotEmpty($file); + $this->assertEquals('test', $file['name']); + $this->assertEquals('/tmp/foo', $file['path']); + $this->assertEquals(0, $file['is_image']); + $this->assertEquals(1, $file['task_id']); + $this->assertEquals(time(), $file['date'], '', 2); + $this->assertEquals(0, $file['user_id']); + $this->assertEquals(10, $file['size']); + + $this->assertEquals(2, $f->create(1, 'test2.png', '/tmp/foobar', 10)); + + $file = $f->getById(2); + $this->assertNotEmpty($file); + $this->assertEquals('test2.png', $file['name']); + $this->assertEquals('/tmp/foobar', $file['path']); + $this->assertEquals(1, $file['is_image']); + } + public function testCreationFileNameTooLong() { $p = new Project($this->container); @@ -18,8 +48,8 @@ class FileTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertTrue($f->create(1, 'test', '/tmp/foo', false, 10)); - $this->assertTrue($f->create(1, str_repeat('a', 1000), '/tmp/foo', false, 10)); + $this->assertNotFalse($f->create(1, 'test', '/tmp/foo', 10)); + $this->assertNotFalse($f->create(1, str_repeat('a', 1000), '/tmp/foo', 10)); $files = $f->getAll(1); $this->assertNotEmpty($files); @@ -28,4 +58,133 @@ class FileTest extends Base $this->assertEquals(str_repeat('a', 255), $files[0]['name']); $this->assertEquals('test', $files[1]['name']); } + + public function testIsImage() + { + $f = new File($this->container); + + $this->assertTrue($f->isImage('test.png')); + $this->assertTrue($f->isImage('test.jpeg')); + $this->assertTrue($f->isImage('test.gif')); + $this->assertTrue($f->isImage('test.jpg')); + $this->assertTrue($f->isImage('test.JPG')); + + $this->assertFalse($f->isImage('test.bmp')); + $this->assertFalse($f->isImage('test')); + $this->assertFalse($f->isImage('test.pdf')); + } + + public function testGeneratePath() + { + $f = new File($this->container); + + $this->assertStringStartsWith('12/34/', $f->generatePath(12, 34, 'test.png')); + $this->assertNotEquals($f->generatePath(12, 34, 'test1.png'), $f->generatePath(12, 34, 'test2.png')); + } + + public function testUploadScreenshot() + { + $p = new Project($this->container); + $f = new File($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $f->uploadScreenshot(1, 1, base64_encode('image data'))); + + $file = $f->getById(1); + $this->assertNotEmpty($file); + $this->assertStringStartsWith('Screenshot taken ', $file['name']); + $this->assertStringStartsWith('1/1/', $file['path']); + $this->assertEquals(1, $file['is_image']); + $this->assertEquals(1, $file['task_id']); + $this->assertEquals(time(), $file['date'], '', 2); + $this->assertEquals(0, $file['user_id']); + $this->assertEquals(10, $file['size']); + } + + public function testUploadFileContent() + { + $p = new Project($this->container); + $f = new File($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $f->uploadContent(1, 1, 'my file.pdf', base64_encode('file data'))); + + $file = $f->getById(1); + $this->assertNotEmpty($file); + $this->assertEquals('my file.pdf', $file['name']); + $this->assertStringStartsWith('1/1/', $file['path']); + $this->assertEquals(0, $file['is_image']); + $this->assertEquals(1, $file['task_id']); + $this->assertEquals(time(), $file['date'], '', 2); + $this->assertEquals(0, $file['user_id']); + $this->assertEquals(9, $file['size']); + } + + public function testGetAll() + { + $p = new Project($this->container); + $f = new File($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10)); + $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10)); + $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10)); + $this->assertEquals(4, $f->create(1, 'C.JPG', '/tmp/foo', 10)); + + $files = $f->getAll(1); + $this->assertNotEmpty($files); + $this->assertCount(4, $files); + $this->assertEquals('A.png', $files[0]['name']); + $this->assertEquals('B.pdf', $files[1]['name']); + $this->assertEquals('C.JPG', $files[2]['name']); + $this->assertEquals('D.doc', $files[3]['name']); + + $files = $f->getAllImages(1); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + $this->assertEquals('A.png', $files[0]['name']); + $this->assertEquals('C.JPG', $files[1]['name']); + + $files = $f->getAllDocuments(1); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + $this->assertEquals('B.pdf', $files[0]['name']); + $this->assertEquals('D.doc', $files[1]['name']); + } + + public function testRemove() + { + $p = new Project($this->container); + $f = new File($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10)); + $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10)); + $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10)); + + $this->assertTrue($f->remove(2)); + + $files = $f->getAll(1); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + $this->assertEquals('B.pdf', $files[0]['name']); + $this->assertEquals('D.doc', $files[1]['name']); + + $this->assertTrue($f->removeAll(1)); + + $files = $f->getAll(1); + $this->assertEmpty($files); + } } diff --git a/tests/units/MailgunWebhookTest.php b/tests/units/MailgunTest.php index c2745180..b33a66fe 100644 --- a/tests/units/MailgunWebhookTest.php +++ b/tests/units/MailgunTest.php @@ -2,18 +2,38 @@ require_once __DIR__.'/Base.php'; -use Integration\MailgunWebhook; +use Integration\Mailgun; use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\ProjectPermission; use Model\User; -class MailgunWebhookTest extends Base +class MailgunTest extends Base { + public function testSendEmail() + { + $pm = new Mailgun($this->container); + $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); + + $this->assertStringStartsWith('https://api.mailgun.net/v3/', $this->container['httpClient']->getUrl()); + + $data = $this->container['httpClient']->getData(); + + $this->assertArrayHasKey('from', $data); + $this->assertArrayHasKey('to', $data); + $this->assertArrayHasKey('subject', $data); + $this->assertArrayHasKey('html', $data); + + $this->assertEquals('Me <test@localhost>', $data['to']); + $this->assertEquals('Bob <notifications@kanboard.local>', $data['from']); + $this->assertEquals('Test', $data['subject']); + $this->assertEquals('Content', $data['html']); + } + public function testHandlePayload() { - $w = new MailgunWebhook($this->container); + $w = new Mailgun($this->container); $p = new Project($this->container); $pp = new ProjectPermission($this->container); $u = new User($this->container); @@ -26,20 +46,20 @@ class MailgunWebhookTest extends Base $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); // Empty payload - $this->assertFalse($w->parsePayload(array())); + $this->assertFalse($w->receiveEmail(array())); // Unknown user - $this->assertFalse($w->parsePayload(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo'))); + $this->assertFalse($w->receiveEmail(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo'))); // Project not found - $this->assertFalse($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo'))); + $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo'))); // User is not member - $this->assertFalse($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); + $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); $this->assertTrue($pp->addMember(2, 2)); // The task must be created - $this->assertTrue($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); + $this->assertTrue($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); $task = $tf->getById(1); $this->assertNotEmpty($task); diff --git a/tests/units/NotificationTest.php b/tests/units/NotificationTest.php index 37285212..92b839c4 100644 --- a/tests/units/NotificationTest.php +++ b/tests/units/NotificationTest.php @@ -2,14 +2,168 @@ require_once __DIR__.'/Base.php'; +use Model\TaskFinder; +use Model\TaskCreation; +use Model\Subtask; +use Model\Comment; use Model\User; +use Model\File; use Model\Project; use Model\ProjectPermission; use Model\Notification; +use Subscriber\NotificationSubscriber; class NotificationTest extends Base { - public function testGetUsersWithNotification() + public function testFilterNone() + { + $u = new User($this->container); + $n = new Notification($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_NONE))); + $this->assertTrue($n->filterNone($u->getById(2), array())); + + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH))); + $this->assertFalse($n->filterNone($u->getById(3), array())); + } + + public function testFilterCreator() + { + $u = new User($this->container); + $n = new Notification($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_CREATOR))); + $this->assertTrue($n->filterCreator($u->getById(2), array('task' => array('creator_id' => 2)))); + + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_CREATOR))); + $this->assertFalse($n->filterCreator($u->getById(3), array('task' => array('creator_id' => 1)))); + + $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => Notification::FILTER_NONE))); + $this->assertFalse($n->filterCreator($u->getById(4), array('task' => array('creator_id' => 2)))); + } + + public function testFilterAssignee() + { + $u = new User($this->container); + $n = new Notification($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_ASSIGNEE))); + $this->assertTrue($n->filterAssignee($u->getById(2), array('task' => array('owner_id' => 2)))); + + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_ASSIGNEE))); + $this->assertFalse($n->filterAssignee($u->getById(3), array('task' => array('owner_id' => 1)))); + + $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => Notification::FILTER_NONE))); + $this->assertFalse($n->filterAssignee($u->getById(4), array('task' => array('owner_id' => 2)))); + } + + public function testFilterBoth() + { + $u = new User($this->container); + $n = new Notification($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_BOTH))); + $this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 2, 'creator_id' => 1)))); + $this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 0, 'creator_id' => 2)))); + + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH))); + $this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 1, 'creator_id' => 1)))); + $this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 2, 'creator_id' => 1)))); + + $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => Notification::FILTER_NONE))); + $this->assertFalse($n->filterBoth($u->getById(4), array('task' => array('owner_id' => 2, 'creator_id' => 1)))); + } + + public function testFilterProject() + { + $u = new User($this->container); + $n = new Notification($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + + // No project selected + $this->assertTrue($n->filterProject($u->getById(1), array())); + + // User that select only some projects + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_NONE))); + $n->saveSettings(2, array('notifications_enabled' => 1, 'projects' => array(2 => true))); + + $this->assertFalse($n->filterProject($u->getById(2), array('task' => array('project_id' => 1)))); + $this->assertTrue($n->filterProject($u->getById(2), array('task' => array('project_id' => 2)))); + } + + public function testFilterUserWithNoFilter() + { + $u = new User($this->container); + $n = new Notification($this->container); + $p = new Project($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_NONE))); + + $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1)))); + } + + public function testFilterUserWithAssigneeFilter() + { + $u = new User($this->container); + $n = new Notification($this->container); + $p = new Project($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_ASSIGNEE))); + + $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 2)))); + $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 1)))); + } + + public function testFilterUserWithCreatorFilter() + { + $u = new User($this->container); + $n = new Notification($this->container); + $p = new Project($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_CREATOR))); + + $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2)))); + $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 1)))); + } + + public function testFilterUserWithBothFilter() + { + $u = new User($this->container); + $n = new Notification($this->container); + $p = new Project($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH))); + + $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3)))); + $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2)))); + $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 4, 'owner_id' => 1)))); + $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 5, 'owner_id' => 0)))); + } + + public function testFilterUserWithBothFilterAndProjectSelected() + { + $u = new User($this->container); + $n = new Notification($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH))); + + $n->saveSettings(2, array('notifications_enabled' => 1, 'projects' => array(2 => true))); + + $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3)))); + $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2)))); + + $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 2, 'owner_id' => 3)))); + $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 0, 'owner_id' => 2)))); + } + + public function testGetProjectMembersWithNotifications() { $u = new User($this->container); $p = new Project($this->container); @@ -32,7 +186,7 @@ class NotificationTest extends Base // Nobody is member of any projects $this->assertEmpty($pp->getMembers(1)); - $this->assertEmpty($n->getUsersWithNotification(1)); + $this->assertEmpty($n->getUsersWithNotificationEnabled(1)); // We allow all users to be member of our projects $this->assertTrue($pp->addMember(1, 1)); @@ -41,7 +195,7 @@ class NotificationTest extends Base $this->assertTrue($pp->addMember(1, 4)); $this->assertNotEmpty($pp->getMembers(1)); - $users = $n->getUsersWithNotification(1); + $users = $n->getUsersWithNotificationEnabled(1); $this->assertNotEmpty($users); $this->assertEquals(2, count($users)); @@ -49,16 +203,15 @@ class NotificationTest extends Base $this->assertEquals('user3@here', $users[1]['email']); } - public function testGetUserList() + public function testGetUsersWithNotificationsWhenEverybodyAllowed() { $u = new User($this->container); $p = new Project($this->container); - $pp = new ProjectPermission($this->container); $n = new Notification($this->container); + $pp = new ProjectPermission($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); - $this->assertEquals(3, $p->create(array('name' => 'UnitTest3', 'is_everybody_allowed' => 1))); + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1))); + $this->assertTrue($pp->isEverybodyAllowed(1)); // Email + Notifications enabled $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); @@ -72,62 +225,108 @@ class NotificationTest extends Base // No email + notifications disabled $this->assertNotFalse($u->create(array('username' => 'user4'))); - // We allow all users to be member of our projects - $this->assertTrue($pp->addMember(1, 1)); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->addMember(1, 3)); - $this->assertTrue($pp->addMember(1, 4)); - - $this->assertTrue($pp->addMember(2, 1)); - $this->assertTrue($pp->addMember(2, 2)); - $this->assertTrue($pp->addMember(2, 3)); - $this->assertTrue($pp->addMember(2, 4)); + $users = $n->getUsersWithNotificationEnabled(1); - $users = $n->getUsersList(1); $this->assertNotEmpty($users); $this->assertEquals(2, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $this->assertEquals('user3@here', $users[1]['email']); + } - $users = $n->getUsersList(2); - $this->assertNotEmpty($users); - $this->assertEquals(2, count($users)); - $this->assertEquals('user1@here', $users[0]['email']); - $this->assertEquals('user3@here', $users[1]['email']); + public function testGetMailContent() + { + $n = 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); - // User 3 choose to receive notification only for project 2 - $n->saveSettings(4, array('notifications_enabled' => 1, 'projects' => array(2 => true))); + $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)); - $users = $n->getUsersList(1); - $this->assertNotEmpty($users); - $this->assertEquals(1, count($users)); - $this->assertEquals('user1@here', $users[0]['email']); + $task = $tf->getDetails(1); + $subtask = $s->getById(1, true); + $comment = $c->getById(1); + $file = $c->getById(1); - $users = $n->getUsersList(2); - $this->assertNotEmpty($users); - $this->assertEquals(2, count($users)); - $this->assertEquals('user1@here', $users[0]['email']); - $this->assertEquals('user3@here', $users[1]['email']); + $this->assertNotEmpty($task); + $this->assertNotEmpty($subtask); + $this->assertNotEmpty($comment); + $this->assertNotEmpty($file); - // User 1 excluded - $users = $n->getUsersList(1, array(2)); - $this->assertEmpty($users); + foreach (Subscriber\NotificationSubscriber::getSubscribedEvents() as $event => $values) { + $this->assertNotEmpty($n->getMailContent($event, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array()))); + } + } - $users = $n->getUsersList(2, array(2)); - $this->assertNotEmpty($users); - $this->assertEquals(1, count($users)); - $this->assertEquals('user3@here', $users[0]['email']); + public function testGetEmailSubject() + { + $n = new Notification($this->container); - // Project #3 allow everybody - $users = $n->getUsersList(3); - $this->assertNotEmpty($users); - $this->assertEquals(1, count($users)); - $this->assertEquals('user1@here', $users[0]['email']); + $this->assertEquals( + '[test][Task opened] blah (#2)', + $n->getMailSubject('task.open', array('task' => array('id' => 2, 'title' => 'blah', 'project_name' => 'test'))) + ); + } - $users = $n->getUsersWithNotification(3); - $this->assertNotEmpty($users); - $this->assertEquals(2, count($users)); - $this->assertEquals('user1@here', $users[0]['email']); - $this->assertEquals('user3@here', $users[1]['email']); + public function testSendNotificationsToCreator() + { + $u = new User($this->container); + $p = new Project($this->container); + $n = new Notification($this->container); + $pp = new ProjectPermission($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); + $this->assertTrue($pp->addMember(1, 2)); + + $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() + { + $u = new User($this->container); + $p = new Project($this->container); + $n = new Notification($this->container); + $pp = new ProjectPermission($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); + $this->assertTrue($pp->addMember(1, 2)); + + $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() + { + $u = new User($this->container); + $p = new Project($this->container); + $n = new Notification($this->container); + $pp = new ProjectPermission($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); + + $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); } } diff --git a/tests/units/PostmarkWebhookTest.php b/tests/units/PostmarkTest.php index 34be8515..b708217d 100644 --- a/tests/units/PostmarkWebhookTest.php +++ b/tests/units/PostmarkTest.php @@ -2,18 +2,41 @@ require_once __DIR__.'/Base.php'; -use Integration\PostmarkWebhook; +use Integration\Postmark; use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\ProjectPermission; use Model\User; -class PostmarkWebhookTest extends Base +class PostmarkTest extends Base { + public function testSendEmail() + { + $pm = new Postmark($this->container); + $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); + + $this->assertEquals('https://api.postmarkapp.com/email', $this->container['httpClient']->getUrl()); + + $data = $this->container['httpClient']->getData(); + + $this->assertArrayHasKey('From', $data); + $this->assertArrayHasKey('To', $data); + $this->assertArrayHasKey('Subject', $data); + $this->assertArrayHasKey('HtmlBody', $data); + + $this->assertEquals('Me <test@localhost>', $data['To']); + $this->assertEquals('Bob <notifications@kanboard.local>', $data['From']); + $this->assertEquals('Test', $data['Subject']); + $this->assertEquals('Content', $data['HtmlBody']); + + $this->assertContains('Accept: application/json', $this->container['httpClient']->getHeaders()); + $this->assertContains('X-Postmark-Server-Token: ', $this->container['httpClient']->getHeaders()); + } + public function testHandlePayload() { - $w = new PostmarkWebhook($this->container); + $w = new Postmark($this->container); $p = new Project($this->container); $pp = new ProjectPermission($this->container); $u = new User($this->container); @@ -26,20 +49,20 @@ class PostmarkWebhookTest extends Base $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); // Empty payload - $this->assertFalse($w->parsePayload(array())); + $this->assertFalse($w->receiveEmail(array())); // Unknown user - $this->assertFalse($w->parsePayload(array('From' => 'a@b.c', 'Subject' => 'Email task', 'MailboxHash' => 'foobar', 'TextBody' => 'boo'))); + $this->assertFalse($w->receiveEmail(array('From' => 'a@b.c', 'Subject' => 'Email task', 'MailboxHash' => 'foobar', 'TextBody' => 'boo'))); // Project not found - $this->assertFalse($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test', 'TextBody' => 'boo'))); + $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test', 'TextBody' => 'boo'))); // User is not member - $this->assertFalse($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); + $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); $this->assertTrue($pp->addMember(2, 2)); // The task must be created - $this->assertTrue($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); + $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo'))); $task = $tf->getById(1); $this->assertNotEmpty($task); @@ -51,7 +74,7 @@ class PostmarkWebhookTest extends Base public function testHtml2Markdown() { - $w = new PostmarkWebhook($this->container); + $w = new Postmark($this->container); $p = new Project($this->container); $pp = new ProjectPermission($this->container); $u = new User($this->container); @@ -62,7 +85,7 @@ class PostmarkWebhookTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '<p><strong>boo</strong></p>'))); + $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '<p><strong>boo</strong></p>'))); $task = $tf->getById(1); $this->assertNotEmpty($task); @@ -71,7 +94,7 @@ class PostmarkWebhookTest extends Base $this->assertEquals('**boo**', $task['description']); $this->assertEquals(2, $task['creator_id']); - $this->assertTrue($w->parsePayload(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => ''))); + $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => ''))); $task = $tf->getById(2); $this->assertNotEmpty($task); diff --git a/tests/units/SendgridWebhookTest.php b/tests/units/SendgridTest.php index 3b30d212..1814c761 100644 --- a/tests/units/SendgridWebhookTest.php +++ b/tests/units/SendgridTest.php @@ -2,18 +2,46 @@ require_once __DIR__.'/Base.php'; -use Integration\SendgridWebhook; +use Integration\Sendgrid; use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\ProjectPermission; use Model\User; -class SendgridWebhookTest extends Base +class SendgridTest extends Base { + public function testSendEmail() + { + $pm = new Sendgrid($this->container); + $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob'); + + $this->assertEquals('https://api.sendgrid.com/api/mail.send.json', $this->container['httpClient']->getUrl()); + + $data = $this->container['httpClient']->getData(); + + $this->assertArrayHasKey('api_user', $data); + $this->assertArrayHasKey('api_key', $data); + $this->assertArrayHasKey('from', $data); + $this->assertArrayHasKey('fromname', $data); + $this->assertArrayHasKey('to', $data); + $this->assertArrayHasKey('toname', $data); + $this->assertArrayHasKey('subject', $data); + $this->assertArrayHasKey('html', $data); + + $this->assertEquals('test@localhost', $data['to']); + $this->assertEquals('Me', $data['toname']); + $this->assertEquals('notifications@kanboard.local', $data['from']); + $this->assertEquals('Bob', $data['fromname']); + $this->assertEquals('Test', $data['subject']); + $this->assertEquals('Content', $data['html']); + $this->assertEquals('', $data['api_key']); + $this->assertEquals('', $data['api_user']); + } + public function testHandlePayload() { - $w = new SendgridWebhook($this->container); + $w = new Sendgrid($this->container); $p = new Project($this->container); $pp = new ProjectPermission($this->container); $u = new User($this->container); @@ -26,22 +54,22 @@ class SendgridWebhookTest extends Base $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); // Empty payload - $this->assertFalse($w->parsePayload(array())); + $this->assertFalse($w->receiveEmail(array())); // Unknown user - $this->assertFalse($w->parsePayload(array( + $this->assertFalse($w->receiveEmail(array( 'envelope' => '{"to":["a@b.c"],"from":"a.b.c"}', 'subject' => 'Email task' ))); // Project not found - $this->assertFalse($w->parsePayload(array( + $this->assertFalse($w->receiveEmail(array( 'envelope' => '{"to":["a@b.c"],"from":"me@localhost"}', 'subject' => 'Email task' ))); // User is not member - $this->assertFalse($w->parsePayload(array( + $this->assertFalse($w->receiveEmail(array( 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task' ))); @@ -49,7 +77,7 @@ class SendgridWebhookTest extends Base $this->assertTrue($pp->addMember(2, 2)); // The task must be created - $this->assertTrue($w->parsePayload(array( + $this->assertTrue($w->receiveEmail(array( 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task' ))); @@ -62,7 +90,7 @@ class SendgridWebhookTest extends Base $this->assertEquals(2, $task['creator_id']); // Html content - $this->assertTrue($w->parsePayload(array( + $this->assertTrue($w->receiveEmail(array( 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> text', @@ -76,7 +104,7 @@ class SendgridWebhookTest extends Base $this->assertEquals(2, $task['creator_id']); // Text content - $this->assertTrue($w->parsePayload(array( + $this->assertTrue($w->receiveEmail(array( 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'text' => '**bold** text', @@ -90,7 +118,7 @@ class SendgridWebhookTest extends Base $this->assertEquals(2, $task['creator_id']); // Text + html content - $this->assertTrue($w->parsePayload(array( + $this->assertTrue($w->receiveEmail(array( 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> html', diff --git a/tests/units/TaskDuplicationTest.php b/tests/units/TaskDuplicationTest.php index f991efd6..cd791312 100644 --- a/tests/units/TaskDuplicationTest.php +++ b/tests/units/TaskDuplicationTest.php @@ -548,7 +548,7 @@ class TaskDuplicationTest extends Base $this->assertNotEmpty($task); $this->assertEquals(Task::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); $this->assertEquals(2, $task['recurrence_child']); - $this->assertEquals(1436561776, $task['date_due']); + $this->assertEquals(1436561776, $task['date_due'], '', 2); $task = $tf->getById(2); $this->assertNotEmpty($task); @@ -558,6 +558,6 @@ class TaskDuplicationTest extends Base $this->assertEquals(Task::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); $this->assertEquals(1, $task['recurrence_parent']); $this->assertEquals(2, $task['recurrence_factor']); - $this->assertEquals(strtotime('+2 days'), $task['date_due']); + $this->assertEquals(strtotime('+2 days'), $task['date_due'], '', 2); } } diff --git a/tests/units/TaskMovedDateSubscriberTest.php b/tests/units/TaskMovedDateSubscriberTest.php new file mode 100644 index 00000000..e0364918 --- /dev/null +++ b/tests/units/TaskMovedDateSubscriberTest.php @@ -0,0 +1,77 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Model\TaskPosition; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Model\Swimlane; +use Subscriber\TaskMovedDateSubscriber; +use Symfony\Component\EventDispatcher\EventDispatcher; + +class TaskMovedDateSubscriberTest extends Base +{ + public function testMoveTaskAnotherColumn() + { + $tp = new TaskPosition($this->container); + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $tf = new TaskFinder($this->container); + + $this->container['dispatcher'] = new EventDispatcher; + $this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container)); + + $now = time(); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals($now, $task['date_moved'], '', 1); + + sleep(1); + + $this->assertTrue($tp->movePosition(1, 1, 2, 1)); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotEquals($now, $task['date_moved']); + } + + public function testMoveTaskAnotherSwimlane() + { + $tp = new TaskPosition($this->container); + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $tf = new TaskFinder($this->container); + $s = new Swimlane($this->container); + + $this->container['dispatcher'] = new EventDispatcher; + $this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container)); + + $now = time(); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $s->create(1, 'S1')); + $this->assertEquals(2, $s->create(1, 'S2')); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals($now, $task['date_moved'], '', 1); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(0, $task['swimlane_id']); + + sleep(1); + + $this->assertTrue($tp->movePosition(1, 1, 2, 1, 2)); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotEquals($now, $task['date_moved']); + $this->assertEquals(2, $task['column_id']); + $this->assertEquals(2, $task['swimlane_id']); + } +} diff --git a/tests/units/TextHelperTest.php b/tests/units/TextHelperTest.php index 20b89fa8..95c83e57 100644 --- a/tests/units/TextHelperTest.php +++ b/tests/units/TextHelperTest.php @@ -39,14 +39,6 @@ class TextHelperTest extends Base $this->assertEquals('33.71k', $h->bytes(34520)); } - public function testTruncate() - { - $h = new Text($this->container); - - $this->assertEquals('abc', $h->truncate('abc')); - $this->assertEquals(str_repeat('a', 85).' [...]', $h->truncate(str_repeat('a', 200))); - } - public function testContains() { $h = new Text($this->container); |