summaryrefslogtreecommitdiff
path: root/tests/units/Helper
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-04-10 12:13:42 -0400
committerFrederic Guillot <fred@kanboard.net>2016-04-10 12:13:42 -0400
commit2eadfb22912d94e76a479b694070735fbb0298f1 (patch)
tree4280c1bc33851da2188f4bc0aa49310a5923e021 /tests/units/Helper
parent7b74f55a285d2785f83be148abdeab95e2b4a7c6 (diff)
Refactor ProjectActivity model to use Filter and Formatter interface
Diffstat (limited to 'tests/units/Helper')
-rw-r--r--tests/units/Helper/ProjectActivityHelperTest.php97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/units/Helper/ProjectActivityHelperTest.php b/tests/units/Helper/ProjectActivityHelperTest.php
new file mode 100644
index 00000000..88b2d352
--- /dev/null
+++ b/tests/units/Helper/ProjectActivityHelperTest.php
@@ -0,0 +1,97 @@
+<?php
+
+use Kanboard\Helper\ProjectActivityHelper;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectActivity;
+use Kanboard\Model\Task;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectActivityHelperTest extends Base
+{
+ public function testGetProjectEvents()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+
+ $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+ $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2))));
+ $this->assertNotFalse($projectActivityModel->createEvent(1, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3))));
+
+ $helper = new ProjectActivityHelper($this->container);
+ $events = $helper->getProjectEvents(1);
+
+ $this->assertCount(3, $events);
+ $this->assertEquals(3, $events[0]['task_id']);
+ $this->assertNotEmpty($events[0]['event_content']);
+ $this->assertNotEmpty($events[0]['event_title']);
+ $this->assertNotEmpty($events[0]['author']);
+ $this->assertInternalType('array', $events[0]['task']);
+ }
+
+ public function testGetProjectsEvents()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'P2')));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'P3')));
+
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2)));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3)));
+
+ $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+ $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2))));
+ $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3))));
+
+ $helper = new ProjectActivityHelper($this->container);
+ $events = $helper->getProjectsEvents(array(1, 2));
+
+ $this->assertCount(2, $events);
+ $this->assertEquals(2, $events[0]['task_id']);
+ $this->assertNotEmpty($events[0]['event_content']);
+ $this->assertNotEmpty($events[0]['event_title']);
+ $this->assertNotEmpty($events[0]['author']);
+ $this->assertInternalType('array', $events[0]['task']);
+ }
+
+ public function testGetTaskEvents()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+
+ $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+ $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2))));
+
+ $helper = new ProjectActivityHelper($this->container);
+ $events = $helper->getTaskEvents(1);
+
+ $this->assertCount(1, $events);
+ $this->assertEquals(1, $events[0]['task_id']);
+ $this->assertNotEmpty($events[0]['event_content']);
+ $this->assertNotEmpty($events[0]['event_title']);
+ $this->assertNotEmpty($events[0]['author']);
+ $this->assertInternalType('array', $events[0]['task']);
+ }
+}