summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Base.php1
-rw-r--r--tests/units/EventBuilder/SubtaskEventBuilderTest.php62
-rw-r--r--tests/units/Job/SubtaskEventJobTest.php52
-rw-r--r--tests/units/Model/SubtaskModelTest.php70
4 files changed, 117 insertions, 68 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php
index 9dbfb280..c471ee31 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -41,6 +41,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
$this->container->register(new Kanboard\ServiceProvider\RouteProvider());
$this->container->register(new Kanboard\ServiceProvider\AvatarProvider());
$this->container->register(new Kanboard\ServiceProvider\FilterProvider());
+ $this->container->register(new Kanboard\ServiceProvider\JobProvider());
$this->container->register(new Kanboard\ServiceProvider\QueueProvider());
$this->container['dispatcher'] = new TraceableEventDispatcher(
diff --git a/tests/units/EventBuilder/SubtaskEventBuilderTest.php b/tests/units/EventBuilder/SubtaskEventBuilderTest.php
new file mode 100644
index 00000000..062bdfb4
--- /dev/null
+++ b/tests/units/EventBuilder/SubtaskEventBuilderTest.php
@@ -0,0 +1,62 @@
+<?php
+
+use Kanboard\EventBuilder\SubtaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskEventBuilderTest extends Base
+{
+ public function testWithMissingSubtask()
+ {
+ $subtaskEventBuilder = new SubtaskEventBuilder($this->container);
+ $subtaskEventBuilder->withSubtaskId(42);
+ $this->assertNull($subtaskEventBuilder->build());
+ }
+
+ public function testBuildWithoutChanges()
+ {
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskEventBuilder = new SubtaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'test')));
+
+ $event = $subtaskEventBuilder->withSubtaskId(1)->build();
+
+ $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
+ $this->assertNotEmpty($event['subtask']);
+ $this->assertNotEmpty($event['task']);
+ $this->assertArrayNotHasKey('changes', $event);
+ }
+
+ public function testBuildWithChanges()
+ {
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskEventBuilder = new SubtaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'test')));
+
+ $event = $subtaskEventBuilder
+ ->withSubtaskId(1)
+ ->withValues(array('title' => 'new title', 'user_id' => 1))
+ ->build();
+
+ $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
+ $this->assertNotEmpty($event['subtask']);
+ $this->assertNotEmpty($event['task']);
+ $this->assertNotEmpty($event['changes']);
+ $this->assertCount(2, $event['changes']);
+ $this->assertEquals('new title', $event['changes']['title']);
+ $this->assertEquals(1, $event['changes']['user_id']);
+ }
+}
diff --git a/tests/units/Job/SubtaskEventJobTest.php b/tests/units/Job/SubtaskEventJobTest.php
new file mode 100644
index 00000000..265a8e2d
--- /dev/null
+++ b/tests/units/Job/SubtaskEventJobTest.php
@@ -0,0 +1,52 @@
+<?php
+
+use Kanboard\Job\SubtaskEventJob;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $subtaskEventJob = new SubtaskEventJob($this->container);
+ $subtaskEventJob->withParams(123, 'foobar', array('k' => 'v'));
+
+ $this->assertSame(array(123, 'foobar', array('k' => 'v')), $subtaskEventJob->getJobParams());
+ }
+
+ public function testWithMissingSubtask()
+ {
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});
+
+ $SubtaskEventJob = new SubtaskEventJob($this->container);
+ $SubtaskEventJob->execute(42, SubtaskModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, function() {});
+
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'before')));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'title' => 'after')));
+ $this->assertTrue($subtaskModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(SubtaskModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(SubtaskModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(SubtaskModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Model/SubtaskModelTest.php b/tests/units/Model/SubtaskModelTest.php
index 6451189d..7e438651 100644
--- a/tests/units/Model/SubtaskModelTest.php
+++ b/tests/units/Model/SubtaskModelTest.php
@@ -9,64 +9,6 @@ use Kanboard\Model\TaskFinderModel;
class SubtaskModelTest extends Base
{
- public function onSubtaskCreated($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertNotEmpty($data['task_id']);
- $this->assertNotEmpty($data['id']);
- }
-
- public function onSubtaskUpdated($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertArrayHasKey('changes', $data);
- $this->assertArrayHasKey('user_id', $data['changes']);
- $this->assertArrayHasKey('status', $data['changes']);
-
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $data['changes']['status']);
- $this->assertEquals(1, $data['changes']['user_id']);
- }
-
- public function onSubtaskDeleted($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertNotEmpty($data['task_id']);
- $this->assertNotEmpty($data['id']);
- }
-
public function testCreation()
{
$taskCreationModel = new TaskCreationModel($this->container);
@@ -75,9 +17,6 @@ class SubtaskModelTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, array($this, 'onSubtaskCreated'));
-
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
$subtask = $subtaskModel->getById(1);
@@ -101,8 +40,6 @@ class SubtaskModelTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
- $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, array($this, 'onSubtaskUpdated'));
-
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
$this->assertTrue($subtaskModel->update(array('id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS)));
@@ -128,8 +65,6 @@ class SubtaskModelTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, array($this, 'onSubtaskDeleted'));
-
$subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
@@ -269,7 +204,6 @@ class SubtaskModelTest extends Base
$this->assertTrue($subtaskModel->duplicate(1, 2));
$subtasks = $subtaskModel->getAll(2);
- $this->assertNotFalse($subtasks);
$this->assertNotEmpty($subtasks);
$this->assertEquals(2, count($subtasks));
@@ -383,7 +317,7 @@ class SubtaskModelTest extends Base
$this->assertEquals(2, $task['time_spent']);
$this->assertEquals(3, $task['time_estimated']);
}
-
+
public function testGetProjectId()
{
$taskCreationModel = new TaskCreationModel($this->container);
@@ -393,7 +327,7 @@ class SubtaskModelTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
-
+
$this->assertEquals(1, $subtaskModel->getProjectId(1));
$this->assertEquals(0, $subtaskModel->getProjectId(2));
}