summaryrefslogtreecommitdiff
path: root/tests/units/EventBuilder
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-07-17 20:33:27 -0400
committerFrederic Guillot <fred@kanboard.net>2016-07-17 20:33:27 -0400
commitd9d37882228771bca0c7f53f5ffcef90ba7ac1c5 (patch)
treef5df4446273878fc0bc9bf6e6db4bef1535b9de3 /tests/units/EventBuilder
parentcbe52e57200a66522d88dfc5d5f46de8eb87ffb2 (diff)
Subtasks events refactoring and show delete in activity stream
Diffstat (limited to 'tests/units/EventBuilder')
-rw-r--r--tests/units/EventBuilder/SubtaskEventBuilderTest.php62
1 files changed, 62 insertions, 0 deletions
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']);
+ }
+}