summaryrefslogtreecommitdiff
path: root/tests/units/Model/TaskMovedDateSubscriberTest.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-09-05 23:30:56 -0400
committerFrederic Guillot <fred@kanboard.net>2015-09-05 23:30:56 -0400
commit710f2c7bb046b43ec9878ae795a181101f6d7515 (patch)
treeb62723b6b49c3b6bf2b3ca41a772f552464a9031 /tests/units/Model/TaskMovedDateSubscriberTest.php
parent94b38dd94bd819168163003beec8ef693f9d9839 (diff)
Improve unit tests
Diffstat (limited to 'tests/units/Model/TaskMovedDateSubscriberTest.php')
-rw-r--r--tests/units/Model/TaskMovedDateSubscriberTest.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/units/Model/TaskMovedDateSubscriberTest.php b/tests/units/Model/TaskMovedDateSubscriberTest.php
new file mode 100644
index 00000000..6e3fb3bd
--- /dev/null
+++ b/tests/units/Model/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(array('project_id' => 1, 'name' => 'S1')));
+ $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => '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']);
+ }
+}