summaryrefslogtreecommitdiff
path: root/tests/units/EventBuilder/TaskEventBuilderTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/EventBuilder/TaskEventBuilderTest.php')
-rw-r--r--tests/units/EventBuilder/TaskEventBuilderTest.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/units/EventBuilder/TaskEventBuilderTest.php b/tests/units/EventBuilder/TaskEventBuilderTest.php
new file mode 100644
index 00000000..c89dcd85
--- /dev/null
+++ b/tests/units/EventBuilder/TaskEventBuilderTest.php
@@ -0,0 +1,100 @@
+<?php
+
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskEventBuilderTest extends Base
+{
+ public function testWithMissingTask()
+ {
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+ $taskEventBuilder->withTaskId(42);
+ $this->assertNull($taskEventBuilder->buildEvent());
+ }
+
+ public function testBuildWithTask()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'before', 'project_id' => 1)));
+
+ $event = $taskEventBuilder
+ ->withTaskId(1)
+ ->withTask(array('title' => 'before'))
+ ->withChanges(array('title' => 'after'))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertEquals(1, $event['task_id']);
+ $this->assertEquals(array('title' => 'after'), $event['changes']);
+ }
+
+ public function testBuildWithoutChanges()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = $taskEventBuilder->withTaskId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertEquals(1, $event['task_id']);
+ $this->assertArrayNotHasKey('changes', $event);
+ }
+
+ public function testBuildWithChanges()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = $taskEventBuilder
+ ->withTaskId(1)
+ ->withChanges(array('title' => 'new title'))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertNotEmpty($event['changes']);
+ $this->assertEquals('new title', $event['changes']['title']);
+ }
+
+ public function testBuildWithChangesAndValues()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = $taskEventBuilder
+ ->withTaskId(1)
+ ->withChanges(array('title' => 'new title', 'project_id' => 1))
+ ->withValues(array('key' => 'value'))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertNotEmpty($event['changes']);
+ $this->assertNotEmpty($event['key']);
+ $this->assertEquals('value', $event['key']);
+
+ $this->assertCount(1, $event['changes']);
+ $this->assertEquals('new title', $event['changes']['title']);
+ }
+}