summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Filter/ProjectActivityCreationDateFilterTest.php117
-rw-r--r--tests/units/Filter/ProjectActivityCreatorFilterTest.php91
-rw-r--r--tests/units/Filter/ProjectActivityProjectIdFilterTest.php35
-rw-r--r--tests/units/Filter/ProjectActivityProjectIdsFilterTest.php63
-rw-r--r--tests/units/Filter/ProjectActivityProjectNameFilterTest.php35
-rw-r--r--tests/units/Filter/ProjectActivityTaskIdFilterTest.php34
-rw-r--r--tests/units/Filter/ProjectActivityTaskStatusFilterTest.php49
-rw-r--r--tests/units/Filter/ProjectActivityTaskTitleFilterTest.php79
-rw-r--r--tests/units/Helper/ProjectActivityHelperTest.php97
-rw-r--r--tests/units/Model/ProjectActivityTest.php83
10 files changed, 622 insertions, 61 deletions
diff --git a/tests/units/Filter/ProjectActivityCreationDateFilterTest.php b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php
new file mode 100644
index 00000000..d679f285
--- /dev/null
+++ b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php
@@ -0,0 +1,117 @@
+<?php
+
+use Kanboard\Filter\ProjectActivityCreationDateFilter;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectActivity;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Task;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectActivityCreationDateFilterTest extends Base
+{
+ public function testWithToday()
+ {
+ $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->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreationDateFilter('today');
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(1, $events);
+ }
+
+ public function testWithYesterday()
+ {
+ $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->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreationDateFilter('yesterday');
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(0, $events);
+ }
+
+ public function testWithIsoDate()
+ {
+ $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->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreationDateFilter(date('Y-m-d'));
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(1, $events);
+ }
+
+ public function testWithOperatorAndIsoDate()
+ {
+ $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->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreationDateFilter('>='.date('Y-m-d'));
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(1, $events);
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreationDateFilter('<'.date('Y-m-d'));
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(0, $events);
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreationDateFilter('>'.date('Y-m-d'));
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(0, $events);
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreationDateFilter('>='.date('Y-m-d'));
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(1, $events);
+ }
+}
diff --git a/tests/units/Filter/ProjectActivityCreatorFilterTest.php b/tests/units/Filter/ProjectActivityCreatorFilterTest.php
new file mode 100644
index 00000000..99c70322
--- /dev/null
+++ b/tests/units/Filter/ProjectActivityCreatorFilterTest.php
@@ -0,0 +1,91 @@
+<?php
+
+use Kanboard\Filter\ProjectActivityCreatorFilter;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectActivity;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Task;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectActivityCreatorFilterTest extends Base
+{
+ public function testWithUsername()
+ {
+ $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->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreatorFilter('admin');
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(1, $events);
+ }
+
+ public function testWithAnotherUsername()
+ {
+ $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->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreatorFilter('John Doe');
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(0, $events);
+ }
+
+ public function testWithCurrentUser()
+ {
+ $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->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreatorFilter('me');
+ $filter->setCurrentUserId(1);
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(1, $events);
+ }
+
+ public function testWithAnotherCurrentUser()
+ {
+ $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->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1))));
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityCreatorFilter('me');
+ $filter->setCurrentUserId(2);
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(0, $events);
+ }
+}
diff --git a/tests/units/Filter/ProjectActivityProjectIdFilterTest.php b/tests/units/Filter/ProjectActivityProjectIdFilterTest.php
new file mode 100644
index 00000000..193852e1
--- /dev/null
+++ b/tests/units/Filter/ProjectActivityProjectIdFilterTest.php
@@ -0,0 +1,35 @@
+<?php
+
+use Kanboard\Filter\ProjectActivityProjectIdFilter;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectActivity;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Task;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectActivityProjectIdFilterTest extends Base
+{
+ public function testFilterByProjectId()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+ $query = $projectActivityModel->getQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'P2')));
+
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2)));
+
+ $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))));
+
+ $filter = new ProjectActivityProjectIdFilter(1);
+ $filter->withQuery($query)->apply();
+ $this->assertCount(1, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php b/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php
new file mode 100644
index 00000000..e99d2e2f
--- /dev/null
+++ b/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php
@@ -0,0 +1,63 @@
+<?php
+
+use Kanboard\Filter\ProjectActivityProjectIdsFilter;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectActivity;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Task;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectActivityProjectIdsFilterTest extends Base
+{
+ public function testFilterByProjectIds()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+ $query = $projectActivityModel->getQuery();
+
+ $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))));
+
+ $filter = new ProjectActivityProjectIdsFilter(array(1, 2));
+ $filter->withQuery($query)->apply();
+ $this->assertCount(2, $query->findAll());
+ }
+
+ public function testWithEmptyArgument()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+ $query = $projectActivityModel->getQuery();
+
+ $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, $taskFinder->getById(1)));
+ $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, $taskFinder->getById(2)));
+ $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, $taskFinder->getById(3)));
+
+ $filter = new ProjectActivityProjectIdsFilter(array());
+ $filter->withQuery($query)->apply();
+ $this->assertCount(0, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/ProjectActivityProjectNameFilterTest.php b/tests/units/Filter/ProjectActivityProjectNameFilterTest.php
new file mode 100644
index 00000000..de9d7d59
--- /dev/null
+++ b/tests/units/Filter/ProjectActivityProjectNameFilterTest.php
@@ -0,0 +1,35 @@
+<?php
+
+use Kanboard\Filter\ProjectActivityProjectNameFilter;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectActivity;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Task;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectActivityProjectNameFilterTest extends Base
+{
+ public function testFilterByProjectName()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+ $query = $projectActivityModel->getQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'P2')));
+
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2)));
+
+ $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))));
+
+ $filter = new ProjectActivityProjectNameFilter('P1');
+ $filter->withQuery($query)->apply();
+ $this->assertCount(1, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/ProjectActivityTaskIdFilterTest.php b/tests/units/Filter/ProjectActivityTaskIdFilterTest.php
new file mode 100644
index 00000000..646cab1b
--- /dev/null
+++ b/tests/units/Filter/ProjectActivityTaskIdFilterTest.php
@@ -0,0 +1,34 @@
+<?php
+
+use Kanboard\Filter\ProjectActivityTaskIdFilter;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectActivity;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Task;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectActivityTaskIdFilterTest extends Base
+{
+ public function testFilterByTaskId()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+ $query = $projectActivityModel->getQuery();
+
+ $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))));
+
+ $filter = new ProjectActivityTaskIdFilter(1);
+ $filter->withQuery($query)->apply();
+ $this->assertCount(1, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php b/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php
new file mode 100644
index 00000000..b8df6338
--- /dev/null
+++ b/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php
@@ -0,0 +1,49 @@
+<?php
+
+use Kanboard\Filter\ProjectActivityTaskStatusFilter;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectActivity;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Task;
+use Kanboard\Model\TaskStatus;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectActivityTaskStatusFilterTest extends Base
+{
+ public function testFilterByTaskStatus()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $taskStatus = new TaskStatus($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))));
+
+ $this->assertTrue($taskStatus->close(1));
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityTaskStatusFilter('open');
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(1, $events);
+ $this->assertEquals(2, $events[0]['task_id']);
+
+ $query = $projectActivityModel->getQuery();
+ $filter = new ProjectActivityTaskStatusFilter('closed');
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(1, $events);
+ $this->assertEquals(1, $events[0]['task_id']);
+ }
+}
diff --git a/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php b/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php
new file mode 100644
index 00000000..925a1ab2
--- /dev/null
+++ b/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php
@@ -0,0 +1,79 @@
+<?php
+
+use Kanboard\Filter\ProjectActivityTaskTitleFilter;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectActivity;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Task;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectActivityTaskTitleFilterTest extends Base
+{
+ public function testWithFullTitle()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+ $query = $projectActivityModel->getQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', '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))));
+
+ $filter = new ProjectActivityTaskTitleFilter('test2');
+ $filter->withQuery($query)->apply();
+ $this->assertCount(1, $query->findAll());
+ }
+
+ public function testWithPartialTitle()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+ $query = $projectActivityModel->getQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', '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))));
+
+ $filter = new ProjectActivityTaskTitleFilter('test');
+ $filter->withQuery($query)->apply();
+ $this->assertCount(2, $query->findAll());
+ }
+
+ public function testWithId()
+ {
+ $taskFinder = new TaskFinder($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $projectActivityModel = new ProjectActivity($this->container);
+ $query = $projectActivityModel->getQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', '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))));
+
+ $filter = new ProjectActivityTaskTitleFilter('#2');
+ $filter->withQuery($query)->apply();
+
+ $events = $query->findAll();
+ $this->assertCount(1, $events);
+ $this->assertEquals(2, $events[0]['task_id']);
+ }
+}
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']);
+ }
+}
diff --git a/tests/units/Model/ProjectActivityTest.php b/tests/units/Model/ProjectActivityTest.php
index 27ea039d..a624cd86 100644
--- a/tests/units/Model/ProjectActivityTest.php
+++ b/tests/units/Model/ProjectActivityTest.php
@@ -10,90 +10,51 @@ use Kanboard\Model\Project;
class ProjectActivityTest extends Base
{
- public function testDecode()
- {
- $e = new ProjectActivity($this->container);
- $input = array('test');
- $serialized = serialize($input);
- $json = json_encode($input);
-
- $this->assertEquals($input, $e->decode($serialized));
- $this->assertEquals($input, $e->decode($json));
- }
-
public function testCreation()
{
- $e = new ProjectActivity($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
+ $projectActivity = new ProjectActivity($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $taskFinder = new TaskFinder($this->container);
+ $projectModel = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Task #2', 'project_id' => 1)));
- $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
- $this->assertTrue($e->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $tf->getById(2))));
- $this->assertFalse($e->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $tf->getbyId(1))));
+ $this->assertTrue($projectActivity->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $taskFinder->getbyId(1))));
+ $this->assertTrue($projectActivity->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $taskFinder->getById(2))));
+ $this->assertFalse($projectActivity->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $taskFinder->getbyId(1))));
- $events = $e->getProject(1);
+ $events = $projectActivity->getQuery()->desc('id')->findAll();
- $this->assertNotEmpty($events);
- $this->assertTrue(is_array($events));
- $this->assertEquals(2, count($events));
+ $this->assertCount(2, $events);
$this->assertEquals(time(), $events[0]['date_creation'], '', 1);
$this->assertEquals(Task::EVENT_UPDATE, $events[0]['event_name']);
$this->assertEquals(Task::EVENT_CLOSE, $events[1]['event_name']);
}
- public function testFetchAllContent()
- {
- $e = new ProjectActivity($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
-
- $nb_events = 80;
-
- for ($i = 0; $i < $nb_events; $i++) {
- $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_UPDATE, array('task' => $tf->getbyId(1))));
- }
-
- $events = $e->getProject(1);
-
- $this->assertNotEmpty($events);
- $this->assertTrue(is_array($events));
- $this->assertEquals(50, count($events));
- $this->assertEquals('admin', $events[0]['author']);
- $this->assertNotEmpty($events[0]['event_title']);
- $this->assertNotEmpty($events[0]['event_content']);
- }
-
public function testCleanup()
{
- $e = new ProjectActivity($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
+ $projectActivity = new ProjectActivity($this->container);
+ $taskCreation = new TaskCreation($this->container);
+ $taskFinder = new TaskFinder($this->container);
+ $projectModel = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Task #1', 'project_id' => 1)));
$max = 15;
$nb_events = 100;
- $task = $tf->getbyId(1);
+ $task = $taskFinder->getbyId(1);
for ($i = 0; $i < $nb_events; $i++) {
- $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $task)));
+ $this->assertTrue($projectActivity->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $task)));
}
$this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count());
- $e->cleanup($max);
+ $projectActivity->cleanup($max);
- $events = $e->getProject(1);
+ $events = $projectActivity->getQuery()->desc('id')->findAll();
$this->assertNotEmpty($events);
$this->assertCount($max, $events);