summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/configtest/DefaultConfigFileTest.php9
-rw-r--r--tests/integration/CommentProcedureTest.php3
-rw-r--r--tests/integration/TagProcedureTest.php58
-rw-r--r--tests/integration/TaskMetadataProcedureTest.php45
-rw-r--r--tests/integration/TaskTagProcedureTest.php54
-rw-r--r--tests/units.postgres.xml2
-rw-r--r--tests/units/Action/BaseActionTest.php10
-rw-r--r--tests/units/Action/CommentCreationMoveTaskColumnTest.php6
-rw-r--r--tests/units/Action/TaskAssignCategoryColorTest.php18
-rw-r--r--tests/units/Action/TaskAssignCategoryLinkTest.php92
-rw-r--r--tests/units/Action/TaskAssignColorCategoryTest.php18
-rw-r--r--tests/units/Action/TaskAssignColorColumnTest.php18
-rw-r--r--tests/units/Action/TaskAssignColorLinkTest.php45
-rw-r--r--tests/units/Action/TaskAssignColorPriorityTest.php18
-rw-r--r--tests/units/Action/TaskAssignColorSwimlaneTest.php70
-rw-r--r--tests/units/Action/TaskAssignColorUserTest.php18
-rw-r--r--tests/units/Action/TaskAssignCurrentUserColumnTest.php26
-rw-r--r--tests/units/Action/TaskAssignDueDateOnCreationTest.php37
-rw-r--r--tests/units/Action/TaskAssignPrioritySwimlaneTest.php46
-rw-r--r--tests/units/Action/TaskAssignSpecificUserTest.php17
-rw-r--r--tests/units/Action/TaskCloseColumnTest.php18
-rw-r--r--tests/units/Action/TaskCloseNoActivityColumnTest.php49
-rw-r--r--tests/units/Action/TaskCloseNotMovedColumnTest.php49
-rw-r--r--tests/units/Action/TaskCloseTest.php15
-rw-r--r--tests/units/Action/TaskDuplicateAnotherProjectTest.php18
-rw-r--r--tests/units/Action/TaskEmailTest.php19
-rw-r--r--tests/units/Action/TaskMoveAnotherProjectTest.php17
-rw-r--r--tests/units/Action/TaskMoveColumnAssignedTest.php18
-rw-r--r--tests/units/Action/TaskMoveColumnCategoryChangeTest.php31
-rw-r--r--tests/units/Action/TaskMoveColumnClosedTest.php91
-rw-r--r--tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php50
-rw-r--r--tests/units/Action/TaskMoveColumnUnAssignedTest.php31
-rw-r--r--tests/units/Action/TaskOpenTest.php15
-rw-r--r--tests/units/Action/TaskUpdateStartDateTest.php20
-rw-r--r--tests/units/Auth/ApiAccessTokenAuthTest.php71
-rw-r--r--tests/units/Auth/TotpAuthTest.php5
-rw-r--r--tests/units/Base.php11
-rw-r--r--tests/units/Core/Action/ActionManagerTest.php40
-rw-r--r--tests/units/Core/Cache/FileCacheTest.php186
-rw-r--r--tests/units/Core/DateParserTest.php20
-rw-r--r--tests/units/Core/ExternalTask/ExternalTaskManagerTest.php50
-rw-r--r--tests/units/Core/Filter/LexerBuilderTest.php46
-rw-r--r--tests/units/Core/Filter/OrCriteriaTest.php5
-rw-r--r--tests/units/Core/Http/RequestTest.php6
-rw-r--r--tests/units/Core/ObjectStorage/FileStorageTest.php (renamed from tests/units/Core/FileStorageTest.php)4
-rw-r--r--tests/units/Core/Plugin/DirectoryTest.php5
-rw-r--r--tests/units/Core/Plugin/HookTest.php62
-rw-r--r--tests/units/Core/Plugin/VersionTest.php29
-rw-r--r--tests/units/Core/Security/RoleTest.php37
-rw-r--r--tests/units/Core/TranslatorTest.php45
-rw-r--r--tests/units/Core/User/UserSessionTest.php21
-rw-r--r--tests/units/Decorator/MetadataCacheDecoratorTest.php127
-rw-r--r--tests/units/EventBuilder/CommentEventBuilderTest.php39
-rw-r--r--tests/units/EventBuilder/ProjectFileEventBuilderTest.php35
-rw-r--r--tests/units/EventBuilder/SubtaskEventBuilderTest.php64
-rw-r--r--tests/units/EventBuilder/TaskEventBuilderTest.php102
-rw-r--r--tests/units/EventBuilder/TaskFileEventBuilderTest.php38
-rw-r--r--tests/units/EventBuilder/TaskLinkEventBuilderTest.php72
-rw-r--r--tests/units/Export/TaskExportTest.php104
-rw-r--r--tests/units/ExternalLink/FileLinkProviderTest.php15
-rw-r--r--tests/units/Filter/TaskMovedDateFilterTest.php43
-rw-r--r--tests/units/Filter/TaskPriorityFilterTest.php47
-rw-r--r--tests/units/Filter/TaskStartsWithIdFilterTest.php103
-rw-r--r--tests/units/Filter/TaskStatusFilterTest.php118
-rw-r--r--tests/units/Filter/TaskTagFilterTest.php27
-rw-r--r--tests/units/Formatter/BoardFormatterTest.php7
-rw-r--r--tests/units/Formatter/TaskAutoCompleteFormatterTest.php34
-rw-r--r--tests/units/Formatter/TaskSuggestMenuFormatterTest.php39
-rw-r--r--tests/units/Formatter/UserMentionFormatterTest.php42
-rw-r--r--tests/units/FunctionTest.php32
-rw-r--r--tests/units/Helper/FileHelperTest.php (renamed from tests/units/Helper/FileHelperText.php)9
-rw-r--r--tests/units/Helper/HookHelperTest.php91
-rw-r--r--tests/units/Helper/ProjectRoleHelperTest.php375
-rw-r--r--tests/units/Helper/TaskHelperTest.php5
-rw-r--r--tests/units/Helper/TextHelperTest.php90
-rw-r--r--tests/units/Helper/UserHelperTest.php129
-rw-r--r--tests/units/Job/CommentEventJobTest.php94
-rw-r--r--tests/units/Job/ProjectFileEventJobTest.php43
-rw-r--r--tests/units/Job/ProjectMetricJobTest.php47
-rw-r--r--tests/units/Job/SubtaskEventJobTest.php52
-rw-r--r--tests/units/Job/TaskEventJobTest.php229
-rw-r--r--tests/units/Job/TaskFileEventJobTest.php46
-rw-r--r--tests/units/Job/TaskLinkEventJobTest.php65
-rw-r--r--tests/units/Job/UserMentionJobTest.php (renamed from tests/units/Model/UserMentionTest.php)80
-rw-r--r--tests/units/Locale/LocaleTest.php8
-rw-r--r--tests/units/Model/ColumnMoveRestrictionModelTest.php92
-rw-r--r--tests/units/Model/ColumnRestrictionModelTest.php100
-rw-r--r--tests/units/Model/CommentModelTest.php (renamed from tests/units/Model/CommentTest.php)7
-rw-r--r--tests/units/Model/ConfigModelTest.php125
-rw-r--r--tests/units/Model/ConfigTest.php116
-rw-r--r--tests/units/Model/GroupModelTest.php (renamed from tests/units/Model/GroupTest.php)11
-rw-r--r--tests/units/Model/InviteModelTest.php27
-rw-r--r--tests/units/Model/NotificationModelTest.php39
-rw-r--r--tests/units/Model/ProjectModelTest.php18
-rw-r--r--tests/units/Model/ProjectPermissionModelTest.php (renamed from tests/units/Model/ProjectPermissionTest.php)46
-rw-r--r--tests/units/Model/ProjectRoleModelTest.php159
-rw-r--r--tests/units/Model/ProjectRoleRestrictionModelTest.php96
-rw-r--r--tests/units/Model/SubtaskModelTest.php291
-rw-r--r--tests/units/Model/SubtaskPositionModelTest.php77
-rw-r--r--tests/units/Model/SubtaskStatusModelTest.php123
-rw-r--r--tests/units/Model/SubtaskTaskConversionModelTest.php37
-rw-r--r--tests/units/Model/SubtaskTimeTrackingModelTest.php277
-rw-r--r--tests/units/Model/SubtaskTimeTrackingTest.php240
-rw-r--r--tests/units/Model/TaskCreationModelTest.php2
-rw-r--r--tests/units/Model/TaskFinderModelTest.php204
-rw-r--r--tests/units/Model/TaskFinderTest.php115
-rw-r--r--tests/units/Model/TaskLinkModelTest.php28
-rw-r--r--tests/units/Model/TaskModificationModelTest.php13
-rw-r--r--tests/units/Model/TaskPositionModelTest.php (renamed from tests/units/Model/TaskPositionTest.php)394
-rw-r--r--tests/units/Model/TaskProjectMoveModelTest.php2
-rw-r--r--tests/units/Model/UserModelTest.php384
-rw-r--r--tests/units/Model/UserTest.php400
-rw-r--r--tests/units/Notification/MailNotificationTest.php122
-rw-r--r--tests/units/Notification/MailTest.php117
-rw-r--r--tests/units/Notification/WebhookNotificationTest.php (renamed from tests/units/Notification/WebhookTest.php)14
-rw-r--r--tests/units/Pagination/ProjectPaginationTest.php35
-rw-r--r--tests/units/Pagination/SubtaskPaginationTest.php36
-rw-r--r--tests/units/Pagination/TaskPaginationTest.php30
-rw-r--r--tests/units/Pagination/UserPaginationTest.php27
-rw-r--r--tests/units/ServiceProvider/ClassProviderTest.php21
-rw-r--r--tests/units/ServiceProvider/FormatterProviderTest.php21
-rw-r--r--tests/units/Subscriber/RecurringTaskSubscriberTest.php164
-rw-r--r--tests/units/Validator/CommentValidatorTest.php30
-rw-r--r--tests/units/Validator/CurrencyValidatorTest.php12
-rw-r--r--tests/units/Validator/CustomFilterValidatorTest.php8
-rw-r--r--tests/units/Validator/ExternalLinkValidatorTest.php16
-rw-r--r--tests/units/Validator/GroupValidatorTest.php6
-rw-r--r--tests/units/Validator/LinkValidatorTest.php12
-rw-r--r--tests/units/Validator/PasswordResetValidatorTest.php28
-rw-r--r--tests/units/Validator/ProjectValidatorTest.php44
-rw-r--r--tests/units/Validator/TaskLinkValidatorTest.php50
-rw-r--r--tests/units/Validator/TaskValidatorTest.php42
-rw-r--r--tests/units/Validator/UserValidatorTest.php16
133 files changed, 6420 insertions, 1999 deletions
diff --git a/tests/configtest/DefaultConfigFileTest.php b/tests/configtest/DefaultConfigFileTest.php
new file mode 100644
index 00000000..0840925b
--- /dev/null
+++ b/tests/configtest/DefaultConfigFileTest.php
@@ -0,0 +1,9 @@
+<?php
+
+class DefaultConfigFileTest extends PHPUnit_Framework_TestCase
+{
+ public function testThatFileCanBeImported()
+ {
+ $this->assertNotFalse(include __DIR__.'/../../config.default.php');
+ }
+}
diff --git a/tests/integration/CommentProcedureTest.php b/tests/integration/CommentProcedureTest.php
index 881d938c..0a969420 100644
--- a/tests/integration/CommentProcedureTest.php
+++ b/tests/integration/CommentProcedureTest.php
@@ -35,10 +35,12 @@ class CommentProcedureTest extends BaseProcedureTest
$this->assertNotEmpty($comment);
$this->assertEquals(1, $comment['user_id']);
$this->assertEquals('foobar', $comment['comment']);
+ $this->assertEquals($comment['date_creation'], $comment['date_modification']);
}
public function assertUpdateComment()
{
+ sleep(1); // Integration test fails because its too fast
$this->assertTrue($this->app->execute('updateComment', array(
'id' => $this->commentId,
'content' => 'test',
@@ -46,6 +48,7 @@ class CommentProcedureTest extends BaseProcedureTest
$comment = $this->app->getComment($this->commentId);
$this->assertEquals('test', $comment['comment']);
+ $this->assertNotEquals($comment['date_creation'], $comment['date_modification']);
}
public function assertGetAllComments()
diff --git a/tests/integration/TagProcedureTest.php b/tests/integration/TagProcedureTest.php
new file mode 100644
index 00000000..f15efa3c
--- /dev/null
+++ b/tests/integration/TagProcedureTest.php
@@ -0,0 +1,58 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class TagProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project with tags';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTag();
+ $this->assertGetProjectTags();
+ $this->assertGetAllTags();
+ $this->assertUpdateTag();
+ $this->assertRemoveTag();
+ }
+
+ public function assertCreateTag()
+ {
+ $this->assertNotFalse($this->app->createTag($this->projectId, 'some tag'));
+ }
+
+ public function assertGetProjectTags()
+ {
+ $tags = $this->app->getTagsByProject($this->projectId);
+ $this->assertCount(1, $tags);
+ $this->assertEquals('some tag', $tags[0]['name']);
+ }
+
+ public function assertGetAllTags()
+ {
+ $tags = $this->app->getAllTags();
+ $this->assertCount(1, $tags);
+ $this->assertEquals('some tag', $tags[0]['name']);
+ }
+
+ public function assertUpdateTag()
+ {
+ $tags = $this->app->getAllTags();
+ $this->assertCount(1, $tags);
+ $this->assertTrue($this->app->updateTag($tags[0]['id'], 'another tag'));
+
+ $tags = $this->app->getAllTags();
+ $this->assertCount(1, $tags);
+ $this->assertEquals('another tag', $tags[0]['name']);
+ }
+
+ public function assertRemoveTag()
+ {
+ $tags = $this->app->getAllTags();
+ $this->assertCount(1, $tags);
+ $this->assertTrue($this->app->removeTag($tags[0]['id']));
+
+ $tags = $this->app->getAllTags();
+ $this->assertCount(0, $tags);
+ }
+}
diff --git a/tests/integration/TaskMetadataProcedureTest.php b/tests/integration/TaskMetadataProcedureTest.php
new file mode 100644
index 00000000..9b9b2f39
--- /dev/null
+++ b/tests/integration/TaskMetadataProcedureTest.php
@@ -0,0 +1,45 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class TaskMetadataProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test tasks metadata';
+ protected $metaKey = 'MyTestMetaKey';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTask();
+ $this->assertSaveTaskMetadata();
+ $this->assertGetTaskMetadata();
+ $this->assertGetTaskMetadataByName();
+ $this->assertRemoveTaskMetadata();
+ }
+
+ public function assertSaveTaskMetadata()
+ {
+ $this->assertTrue($this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')));
+ }
+
+ public function assertGetTaskMetadata()
+ {
+ $metaData = $this->app->getTaskMetadata(($this->taskId));
+ $this->assertArrayHasKey($this->metaKey, $metaData);
+ $this->assertEquals('metaValue1', $metaData[$this->metaKey]);
+ }
+
+ public function assertGetTaskMetadataByName()
+ {
+ $metaValue = $this->app->getTaskMetadataByName($this->taskId, $this->metaKey);
+ $this->assertEquals('metaValue1', $metaValue, 'Did not return correct metadata value');
+ }
+
+ public function assertRemoveTaskMetadata()
+ {
+ $result = $this->app->removeTaskMetadata($this->taskId, $this->metaKey);
+ $this->assertTrue($result, 'Did not remove metakey with success');
+ $metaValue = $this->app->getTaskMetadataByName($this->taskId, $this->metaKey);
+ $this->assertEquals('', $metaValue, 'Did not return an empty string due to metadata being deleted');
+ }
+}
diff --git a/tests/integration/TaskTagProcedureTest.php b/tests/integration/TaskTagProcedureTest.php
new file mode 100644
index 00000000..4b820c9a
--- /dev/null
+++ b/tests/integration/TaskTagProcedureTest.php
@@ -0,0 +1,54 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class TaskTagProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project with tasks and tags';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTask();
+ $this->assertSetTaskTags();
+ $this->assertGetTaskTags();
+ $this->assertCreateTaskWithTags();
+ $this->assertUpdateTaskWithTags();
+ }
+
+ public function assertSetTaskTags()
+ {
+ $this->assertTrue($this->app->setTaskTags($this->projectId, $this->taskId, array('tag1', 'tag2')));
+ }
+
+ public function assertGetTaskTags()
+ {
+ $tags = $this->app->getTaskTags($this->taskId);
+ $this->assertEquals(array('tag1', 'tag2'), array_values($tags));
+ }
+
+ public function assertCreateTaskWithTags()
+ {
+ $this->taskId = $this->app->createTask(array(
+ 'title' => $this->taskTitle,
+ 'project_id' => $this->projectId,
+ 'tags' => array('tag A', 'tag B'),
+ ));
+
+ $this->assertNotFalse($this->taskId);
+
+ $tags = $this->app->getTaskTags($this->taskId);
+ $this->assertEquals(array('tag A', 'tag B'), array_values($tags));
+ }
+
+ public function assertUpdateTaskWithTags()
+ {
+ $this->assertTrue($this->app->updateTask(array(
+ 'id' => $this->taskId,
+ 'tags' => array('tag C'),
+ )));
+
+ $tags = $this->app->getTaskTags($this->taskId);
+ $this->assertEquals(array('tag C'), array_values($tags));
+ }
+}
diff --git a/tests/units.postgres.xml b/tests/units.postgres.xml
index 3442db1c..cf538a82 100644
--- a/tests/units.postgres.xml
+++ b/tests/units.postgres.xml
@@ -10,4 +10,4 @@
<const name="DB_PASSWORD" value="" />
<const name="DB_NAME" value="kanboard_unit_test" />
</php>
-</phpunit> \ No newline at end of file
+</phpunit>
diff --git a/tests/units/Action/BaseActionTest.php b/tests/units/Action/BaseActionTest.php
index 1d50c70e..feeba3f9 100644
--- a/tests/units/Action/BaseActionTest.php
+++ b/tests/units/Action/BaseActionTest.php
@@ -23,7 +23,7 @@ class DummyAction extends Kanboard\Action\Base
public function getEventRequiredParameters()
{
- return array('p1', 'p2');
+ return array('p1', 'p2', 'p3' => array('p4'));
}
public function doAction(array $data)
@@ -60,7 +60,7 @@ class BaseActionTest extends Base
public function testGetEventRequiredParameters()
{
$dummyAction = new DummyAction($this->container);
- $this->assertEquals(array('p1', 'p2'), $dummyAction->getEventRequiredParameters());
+ $this->assertEquals(array('p1', 'p2', 'p3' => array('p4')), $dummyAction->getEventRequiredParameters());
}
public function testGetCompatibleEvents()
@@ -113,7 +113,7 @@ class BaseActionTest extends Base
$dummyAction = new DummyAction($this->container);
$dummyAction->setProjectId(1234);
- $this->assertTrue($dummyAction->hasRequiredParameters(array('p1' => 12, 'p2' => 34)));
+ $this->assertTrue($dummyAction->hasRequiredParameters(array('p1' => 12, 'p2' => 34, 'p3' => array('p4' => 'foobar'))));
$this->assertFalse($dummyAction->hasRequiredParameters(array('p1' => 12)));
$this->assertFalse($dummyAction->hasRequiredParameters(array()));
}
@@ -125,7 +125,7 @@ class BaseActionTest extends Base
$dummyAction->addEvent('my.event', 'My Event Overrided');
$events = $dummyAction->getEvents();
- $this->assertcount(2, $events);
+ $this->assertCount(2, $events);
$this->assertEquals(array('my.event', 'foobar'), $events);
}
@@ -136,7 +136,7 @@ class BaseActionTest extends Base
$dummyAction->setParam('p1', 'something');
$dummyAction->addEvent('foobar', 'FooBar');
- $event = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc'));
+ $event = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc', 'p3' => array('p4' => 'a')));
$this->assertTrue($dummyAction->execute($event, 'foobar'));
$this->assertFalse($dummyAction->execute($event, 'foobar'));
diff --git a/tests/units/Action/CommentCreationMoveTaskColumnTest.php b/tests/units/Action/CommentCreationMoveTaskColumnTest.php
index 5eaf515e..b3d21287 100644
--- a/tests/units/Action/CommentCreationMoveTaskColumnTest.php
+++ b/tests/units/Action/CommentCreationMoveTaskColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\CommentModel;
@@ -22,7 +22,7 @@ class CommentCreationMoveTaskColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array('task' => array('project_id' => 1, 'column_id' => 2), 'task_id' => 1));
$action = new CommentCreationMoveTaskColumn($this->container);
$action->setProjectId(1);
@@ -45,7 +45,7 @@ class CommentCreationMoveTaskColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array('task' => array('project_id' => 1, 'column_id' => 3), 'task_id' => 1));
$action = new CommentCreationMoveTaskColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignCategoryColorTest.php b/tests/units/Action/TaskAssignCategoryColorTest.php
index 09c08264..5a0f7d03 100644
--- a/tests/units/Action/TaskAssignCategoryColorTest.php
+++ b/tests/units/Action/TaskAssignCategoryColorTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -23,7 +23,13 @@ class TaskAssignCategoryColorTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'color_id' => 'red'));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'color_id' => 'red',
+ )
+ ));
$action = new TaskAssignCategoryColor($this->container);
$action->setProjectId(1);
@@ -47,7 +53,13 @@ class TaskAssignCategoryColorTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'color_id' => 'blue'));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'color_id' => 'blue',
+ )
+ ));
$action = new TaskAssignCategoryColor($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignCategoryLinkTest.php b/tests/units/Action/TaskAssignCategoryLinkTest.php
index 712c3c02..1576f81b 100644
--- a/tests/units/Action/TaskAssignCategoryLinkTest.php
+++ b/tests/units/Action/TaskAssignCategoryLinkTest.php
@@ -2,94 +2,100 @@
require_once __DIR__.'/../Base.php';
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskLinkModel;
use Kanboard\Model\CategoryModel;
-use Kanboard\Event\TaskLinkEvent;
use Kanboard\Action\TaskAssignCategoryLink;
class TaskAssignCategoryLinkTest extends Base
{
public function testAssignCategory()
{
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
$action->setParam('category_id', 1);
$action->setParam('link_id', 2);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['category_id']);
}
public function testWhenLinkDontMatch()
{
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
$action->setParam('category_id', 1);
- $action->setParam('link_id', 1);
+ $action->setParam('link_id', 2);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['category_id']);
}
public function testThatExistingCategoryWillNotChange()
{
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
- $action->setParam('category_id', 2);
+ $action->setParam('category_id', 1);
$action->setParam('link_id', 2);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['category_id']);
}
}
diff --git a/tests/units/Action/TaskAssignColorCategoryTest.php b/tests/units/Action/TaskAssignColorCategoryTest.php
index 6502035f..16ad1290 100644
--- a/tests/units/Action/TaskAssignColorCategoryTest.php
+++ b/tests/units/Action/TaskAssignColorCategoryTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -23,7 +23,13 @@ class TaskAssignColorCategoryTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'category_id' => 1,
+ )
+ ));
$action = new TaskAssignColorCategory($this->container);
$action->setProjectId(1);
@@ -45,7 +51,13 @@ class TaskAssignColorCategoryTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'category_id' => 2,
+ )
+ ));
$action = new TaskAssignColorCategory($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignColorColumnTest.php b/tests/units/Action/TaskAssignColorColumnTest.php
index d4ba8e01..ccfb9e88 100644
--- a/tests/units/Action/TaskAssignColorColumnTest.php
+++ b/tests/units/Action/TaskAssignColorColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +20,13 @@ class TaskAssignColorColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignColorColumn($this->container);
$action->setProjectId(1);
@@ -42,7 +48,13 @@ class TaskAssignColorColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskAssignColorColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php
index 07d0969b..77a6c90e 100644
--- a/tests/units/Action/TaskAssignColorLinkTest.php
+++ b/tests/units/Action/TaskAssignColorLinkTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -13,42 +13,55 @@ class TaskAssignColorLinkTest extends Base
{
public function testChangeColor()
{
- $projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
-
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 1));
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignColorLink($this->container);
$action->setProjectId(1);
+ $action->setParam('link_id', 2);
$action->setParam('color_id', 'red');
- $action->setParam('link_id', 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
$task = $taskFinderModel->getById(1);
- $this->assertNotEmpty($task);
$this->assertEquals('red', $task['color_id']);
}
public function testWithWrongLink()
{
- $projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
-
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 2));
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignColorLink($this->container);
$action->setProjectId(1);
+ $action->setParam('link_id', 2);
$action->setParam('color_id', 'red');
- $action->setParam('link_id', 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('yellow', $task['color_id']);
}
}
diff --git a/tests/units/Action/TaskAssignColorPriorityTest.php b/tests/units/Action/TaskAssignColorPriorityTest.php
index 2fce8e66..0ea874cd 100644
--- a/tests/units/Action/TaskAssignColorPriorityTest.php
+++ b/tests/units/Action/TaskAssignColorPriorityTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -23,7 +23,13 @@ class TaskAssignColorPriorityTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'priority' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'priority' => 1,
+ )
+ ));
$action = new TaskAssignColorPriority($this->container);
$action->setProjectId(1);
@@ -45,7 +51,13 @@ class TaskAssignColorPriorityTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'priority' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'priority' => 2,
+ )
+ ));
$action = new TaskAssignColorPriority($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignColorSwimlaneTest.php b/tests/units/Action/TaskAssignColorSwimlaneTest.php
new file mode 100644
index 00000000..811ffac3
--- /dev/null
+++ b/tests/units/Action/TaskAssignColorSwimlaneTest.php
@@ -0,0 +1,70 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\TaskEvent;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Action\TaskAssignColorSwimlane;
+
+class TaskAssignColorSwimlaneTest extends Base
+{
+ public function testChangeSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'swimlane_id' => 2,
+ )
+ ));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotEquals('red', $task['color_id']);
+
+ $action = new TaskAssignColorSwimlane($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('swimlane_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('red', $task['color_id']);
+ }
+
+ public function testWithWrongSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'swimlane_id' => 3,
+ )
+ ));
+
+ $action = new TaskAssignColorSwimlane($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('swimlane_id', 2);
+
+ $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE));
+ }
+}
diff --git a/tests/units/Action/TaskAssignColorUserTest.php b/tests/units/Action/TaskAssignColorUserTest.php
index 370f9070..45faa3ff 100644
--- a/tests/units/Action/TaskAssignColorUserTest.php
+++ b/tests/units/Action/TaskAssignColorUserTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +20,13 @@ class TaskAssignColorUserTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'owner_id' => 1,
+ )
+ ));
$action = new TaskAssignColorUser($this->container);
$action->setProjectId(1);
@@ -42,7 +48,13 @@ class TaskAssignColorUserTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'owner_id' => 2,
+ )
+ ));
$action = new TaskAssignColorUser($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignCurrentUserColumnTest.php b/tests/units/Action/TaskAssignCurrentUserColumnTest.php
index 6fdbda63..3b64d718 100644
--- a/tests/units/Action/TaskAssignCurrentUserColumnTest.php
+++ b/tests/units/Action/TaskAssignCurrentUserColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -22,7 +22,13 @@ class TaskAssignCurrentUserColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignCurrentUserColumn($this->container);
$action->setProjectId(1);
@@ -45,7 +51,13 @@ class TaskAssignCurrentUserColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskAssignCurrentUserColumn($this->container);
$action->setProjectId(1);
@@ -62,7 +74,13 @@ class TaskAssignCurrentUserColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignCurrentUserColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignDueDateOnCreationTest.php b/tests/units/Action/TaskAssignDueDateOnCreationTest.php
new file mode 100644
index 00000000..26c0584e
--- /dev/null
+++ b/tests/units/Action/TaskAssignDueDateOnCreationTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\Action\TaskAssignDueDateOnCreation;
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskAssignDueDateOnCreationTest extends Base
+{
+ public function testAction()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskAssignDueDateOnCreation($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 4);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(date('Y-m-d', strtotime('+4days')), date('Y-m-d', $task['date_due']));
+ }
+}
diff --git a/tests/units/Action/TaskAssignPrioritySwimlaneTest.php b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php
new file mode 100644
index 00000000..39c833bf
--- /dev/null
+++ b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php
@@ -0,0 +1,46 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\TaskEvent;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Action\TaskAssignPrioritySwimlane;
+
+class TaskAssignPrioritySwimlaneTest extends Base
+{
+ public function testChangeSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'priority' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['priority']);
+
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'swimlane_id' => 2,
+ )
+ ));
+
+ $action = new TaskAssignPrioritySwimlane($this->container);
+ $action->setProjectId(1);
+ $action->setParam('priority', 2);
+ $action->setParam('swimlane_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['priority']);
+ }
+}
diff --git a/tests/units/Action/TaskAssignSpecificUserTest.php b/tests/units/Action/TaskAssignSpecificUserTest.php
index 78ec314f..0e63fc13 100644
--- a/tests/units/Action/TaskAssignSpecificUserTest.php
+++ b/tests/units/Action/TaskAssignSpecificUserTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +21,13 @@ class TaskAssignSpecificUserTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignSpecificUser($this->container);
$action->setProjectId(1);
@@ -42,7 +49,13 @@ class TaskAssignSpecificUserTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskAssignSpecificUser($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskCloseColumnTest.php b/tests/units/Action/TaskCloseColumnTest.php
index f9a938f0..7afb0478 100644
--- a/tests/units/Action/TaskCloseColumnTest.php
+++ b/tests/units/Action/TaskCloseColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +20,13 @@ class TaskCloseColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskCloseColumn($this->container);
$action->setProjectId(1);
@@ -41,7 +47,13 @@ class TaskCloseColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskCloseColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskCloseNoActivityColumnTest.php b/tests/units/Action/TaskCloseNoActivityColumnTest.php
new file mode 100644
index 00000000..243d3359
--- /dev/null
+++ b/tests/units/Action/TaskCloseNoActivityColumnTest.php
@@ -0,0 +1,49 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Action\TaskCloseNoActivityColumn;
+use Kanboard\Event\TaskListEvent;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+
+class TaskCloseNoActivityColumnTest extends Base
+{
+ public function testClose()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $this->container['db']->table(TaskModel::TABLE)->in('id', array(1, 3))->update(array('date_modification' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskCloseNoActivityColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 2);
+ $action->setParam('column_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['is_active']);
+ }
+}
diff --git a/tests/units/Action/TaskCloseNotMovedColumnTest.php b/tests/units/Action/TaskCloseNotMovedColumnTest.php
new file mode 100644
index 00000000..63aedee6
--- /dev/null
+++ b/tests/units/Action/TaskCloseNotMovedColumnTest.php
@@ -0,0 +1,49 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Action\TaskCloseNotMovedColumn;
+use Kanboard\Event\TaskListEvent;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+
+class TaskCloseNotMovedColumnTest extends Base
+{
+ public function testClose()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $this->container['db']->table(TaskModel::TABLE)->in('id', array(1, 3))->update(array('date_moved' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskCloseNotMovedColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 2);
+ $action->setParam('column_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['is_active']);
+ }
+}
diff --git a/tests/units/Action/TaskCloseTest.php b/tests/units/Action/TaskCloseTest.php
index 3df10cb8..589ef133 100644
--- a/tests/units/Action/TaskCloseTest.php
+++ b/tests/units/Action/TaskCloseTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -19,7 +19,12 @@ class TaskCloseTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskClose($this->container);
$action->setProjectId(1);
@@ -40,7 +45,11 @@ class TaskCloseTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1));
+ $event = new TaskEvent(array(
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskClose($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskDuplicateAnotherProjectTest.php b/tests/units/Action/TaskDuplicateAnotherProjectTest.php
index 98ff187f..5cd0c977 100644
--- a/tests/units/Action/TaskDuplicateAnotherProjectTest.php
+++ b/tests/units/Action/TaskDuplicateAnotherProjectTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -21,7 +21,13 @@ class TaskDuplicateAnotherProjectTest extends Base
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskDuplicateAnotherProject($this->container);
$action->setProjectId(1);
@@ -43,7 +49,13 @@ class TaskDuplicateAnotherProjectTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskDuplicateAnotherProject($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskEmailTest.php b/tests/units/Action/TaskEmailTest.php
index df71aaf8..421c89ca 100644
--- a/tests/units/Action/TaskEmailTest.php
+++ b/tests/units/Action/TaskEmailTest.php
@@ -2,7 +2,8 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
+use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
@@ -16,16 +17,20 @@ class TaskEmailTest extends Base
$userModel = new UserModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertTrue($userModel->update(array('id' => 1, 'email' => 'admin@localhost')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => $taskFinderModel->getDetails(1)
+ ));
$action = new TaskEmail($this->container);
$action->setProjectId(1);
- $action->setParam('column_id', 2);
+ $action->setParam('column_id', 1);
$action->setParam('user_id', 1);
$action->setParam('subject', 'My email subject');
@@ -47,7 +52,13 @@ class TaskEmailTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskEmail($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveAnotherProjectTest.php b/tests/units/Action/TaskMoveAnotherProjectTest.php
index d36df47b..a41fd03f 100644
--- a/tests/units/Action/TaskMoveAnotherProjectTest.php
+++ b/tests/units/Action/TaskMoveAnotherProjectTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -21,7 +22,13 @@ class TaskMoveAnotherProjectTest extends Base
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskMoveAnotherProject($this->container);
$action->setProjectId(1);
@@ -44,7 +51,13 @@ class TaskMoveAnotherProjectTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskMoveAnotherProject($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveColumnAssignedTest.php b/tests/units/Action/TaskMoveColumnAssignedTest.php
index f8982969..aa9d3592 100644
--- a/tests/units/Action/TaskMoveColumnAssignedTest.php
+++ b/tests/units/Action/TaskMoveColumnAssignedTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -19,9 +19,12 @@ class TaskMoveColumnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => $taskFinderModel->getDetails(1),
+ ));
$action = new TaskMoveColumnAssigned($this->container);
$action->setProjectId(1);
@@ -43,7 +46,14 @@ class TaskMoveColumnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ 'owner_id' => 1,
+ )
+ ));
$action = new TaskMoveColumnAssigned($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
index c42383f8..7e0856df 100644
--- a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
+++ b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
@@ -24,7 +24,16 @@ class TaskMoveColumnCategoryChangeTest extends Base
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'category_id' => 1,
+ 'position' => 1,
+ 'swimlane_id' => 0,
+ )
+ ));
$action = new TaskMoveColumnCategoryChange($this->container);
$action->setProjectId(1);
@@ -50,7 +59,14 @@ class TaskMoveColumnCategoryChangeTest extends Base
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'category_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ 'category_id' => 1,
+ )
+ ));
$action = new TaskMoveColumnCategoryChange($this->container);
$action->setProjectId(1);
@@ -72,7 +88,14 @@ class TaskMoveColumnCategoryChangeTest extends Base
$this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'category_id' => 2,
+ )
+ ));
$action = new TaskMoveColumnCategoryChange($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveColumnClosedTest.php b/tests/units/Action/TaskMoveColumnClosedTest.php
new file mode 100644
index 00000000..318b995d
--- /dev/null
+++ b/tests/units/Action/TaskMoveColumnClosedTest.php
@@ -0,0 +1,91 @@
+<?php
+
+use Kanboard\Action\TaskMoveColumnClosed;
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMoveColumnClosedTest extends Base
+{
+ public function testSuccess()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskMoveColumnClosed($this->container);
+ $action->setProjectId(1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['column_id']);
+ }
+
+ public function testWhenTaskIsOpen()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskMoveColumnClosed($this->container);
+ $action->setProjectId(1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(1, $task['column_id']);
+ }
+
+ public function testWhenTaskIsAlreadyInDestinationColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0, 'column_id' => 2)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskMoveColumnClosed($this->container);
+ $action->setProjectId(1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['column_id']);
+ }
+}
diff --git a/tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php b/tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php
new file mode 100644
index 00000000..7fa16cf2
--- /dev/null
+++ b/tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php
@@ -0,0 +1,50 @@
+<?php
+
+use Kanboard\Action\TaskMoveColumnNotMovedPeriod;
+use Kanboard\Event\TaskListEvent;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMoveColumnNotMovedPeriodTest extends Base
+{
+ public function testAction()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 3)));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $this->container['db']->table(TaskModel::TABLE)->in('id', array(2, 3))->update(array('date_moved' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskMoveColumnNotMovedPeriod($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 2);
+ $action->setParam('src_column_id', 2);
+ $action->setParam('dest_column_id', 3);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['column_id']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['column_id']);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['column_id']);
+ }
+}
diff --git a/tests/units/Action/TaskMoveColumnUnAssignedTest.php b/tests/units/Action/TaskMoveColumnUnAssignedTest.php
index befae36b..b45dec08 100644
--- a/tests/units/Action/TaskMoveColumnUnAssignedTest.php
+++ b/tests/units/Action/TaskMoveColumnUnAssignedTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -21,7 +21,16 @@ class TaskMoveColumnUnAssignedTest extends Base
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 0));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'owner_id' => 0,
+ 'position' => 1,
+ 'swimlane_id' => 0,
+ )
+ ));
$action = new TaskMoveColumnUnAssigned($this->container);
$action->setProjectId(1);
@@ -43,7 +52,14 @@ class TaskMoveColumnUnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'owner_id' => 0));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ 'owner_id' => 0,
+ )
+ ));
$action = new TaskMoveColumnUnAssigned($this->container);
$action->setProjectId(1);
@@ -60,7 +76,14 @@ class TaskMoveColumnUnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'owner_id' => 1,
+ )
+ ));
$action = new TaskMoveColumnUnAssigned($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskOpenTest.php b/tests/units/Action/TaskOpenTest.php
index 1018e2ea..825c6ac9 100644
--- a/tests/units/Action/TaskOpenTest.php
+++ b/tests/units/Action/TaskOpenTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -19,7 +19,12 @@ class TaskOpenTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskOpen($this->container);
$action->setProjectId(1);
@@ -40,7 +45,11 @@ class TaskOpenTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1));
+ $event = new TaskEvent(array(
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskOpen($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php
index ddd9eafd..05fac100 100644
--- a/tests/units/Action/TaskUpdateStartDateTest.php
+++ b/tests/units/Action/TaskUpdateStartDateTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -11,7 +11,7 @@ use Kanboard\Action\TaskUpdateStartDate;
class TaskUpdateStartDateTest extends Base
{
- public function testClose()
+ public function testAction()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
@@ -20,7 +20,13 @@ class TaskUpdateStartDateTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskUpdateStartDate($this->container);
$action->setProjectId(1);
@@ -41,7 +47,13 @@ class TaskUpdateStartDateTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskUpdateStartDate($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Auth/ApiAccessTokenAuthTest.php b/tests/units/Auth/ApiAccessTokenAuthTest.php
new file mode 100644
index 00000000..22852805
--- /dev/null
+++ b/tests/units/Auth/ApiAccessTokenAuthTest.php
@@ -0,0 +1,71 @@
+<?php
+
+use Kanboard\Auth\ApiAccessTokenAuth;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ApiAccessTokenAuthTest extends Base
+{
+ public function testGetName()
+ {
+ $provider = new ApiAccessTokenAuth($this->container);
+ $this->assertEquals('API Access Token', $provider->getName());
+ }
+
+ public function testAuthenticateWithoutToken()
+ {
+ $provider = new ApiAccessTokenAuth($this->container);
+
+ $provider->setUsername('admin');
+ $provider->setPassword('admin');
+ $this->assertFalse($provider->authenticate());
+ $this->assertNull($provider->getUser());
+ }
+
+ public function testAuthenticateWithEmptyPassword()
+ {
+ $provider = new ApiAccessTokenAuth($this->container);
+
+ $provider->setUsername('admin');
+ $provider->setPassword('');
+ $this->assertFalse($provider->authenticate());
+ }
+
+ public function testAuthenticateWithTokenAndNoScope()
+ {
+ $provider = new ApiAccessTokenAuth($this->container);
+ $userModel = new UserModel($this->container);
+
+ $userModel->update(array(
+ 'id' => 1,
+ 'api_access_token' => 'test',
+ ));
+
+ $provider->setUsername('admin');
+ $provider->setPassword('test');
+ $this->assertFalse($provider->authenticate());
+ }
+
+ public function testAuthenticateWithToken()
+ {
+ $this->container['sessionStorage']->scope = 'API';
+
+ $provider = new ApiAccessTokenAuth($this->container);
+ $userModel = new UserModel($this->container);
+
+ $userModel->update(array(
+ 'id' => 1,
+ 'api_access_token' => 'test',
+ ));
+
+ $provider->setUsername('admin');
+ $provider->setPassword('test');
+ $this->assertTrue($provider->authenticate());
+ $this->assertInstanceOf('Kanboard\User\DatabaseUserProvider', $provider->getUser());
+
+ $provider->setUsername('admin');
+ $provider->setPassword('something else');
+ $this->assertFalse($provider->authenticate());
+ }
+}
diff --git a/tests/units/Auth/TotpAuthTest.php b/tests/units/Auth/TotpAuthTest.php
index c8dcfb28..3a82c01c 100644
--- a/tests/units/Auth/TotpAuthTest.php
+++ b/tests/units/Auth/TotpAuthTest.php
@@ -35,16 +35,17 @@ class TotpAuthTest extends Base
public function testGetUrl()
{
$provider = new TotpAuth($this->container);
+
$this->assertEmpty($provider->getQrCodeUrl('me'));
$this->assertEmpty($provider->getKeyUrl('me'));
$provider->setSecret('mySecret');
$this->assertEquals(
- 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret',
+ 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret%26issuer%3DKanboard',
$provider->getQrCodeUrl('me')
);
- $this->assertEquals('otpauth://totp/me?secret=mySecret', $provider->getKeyUrl('me'));
+ $this->assertEquals('otpauth://totp/me?secret=mySecret&issuer=Kanboard', $provider->getKeyUrl('me'));
}
public function testAuthentication()
diff --git a/tests/units/Base.php b/tests/units/Base.php
index 9dbfb280..1c93e9b8 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -16,6 +16,11 @@ abstract class Base extends PHPUnit_Framework_TestCase
{
protected $container;
+ /**
+ * @var EventDispatcher
+ */
+ protected $dispatcher;
+
public function setUp()
{
date_default_timezone_set('UTC');
@@ -33,6 +38,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
}
$this->container = new Pimple\Container;
+ $this->container->register(new Kanboard\ServiceProvider\CacheProvider());
$this->container->register(new Kanboard\ServiceProvider\HelperProvider());
$this->container->register(new Kanboard\ServiceProvider\AuthenticationProvider());
$this->container->register(new Kanboard\ServiceProvider\DatabaseProvider());
@@ -41,13 +47,18 @@ abstract class Base extends PHPUnit_Framework_TestCase
$this->container->register(new Kanboard\ServiceProvider\RouteProvider());
$this->container->register(new Kanboard\ServiceProvider\AvatarProvider());
$this->container->register(new Kanboard\ServiceProvider\FilterProvider());
+ $this->container->register(new Kanboard\ServiceProvider\FormatterProvider());
+ $this->container->register(new Kanboard\ServiceProvider\JobProvider());
$this->container->register(new Kanboard\ServiceProvider\QueueProvider());
+ $this->container->register(new Kanboard\ServiceProvider\ExternalTaskProvider());
$this->container['dispatcher'] = new TraceableEventDispatcher(
new EventDispatcher,
new Stopwatch
);
+ $this->dispatcher = $this->container['dispatcher'];
+
$this->container['db']->getStatementHandler()->withLogging();
$this->container['logger'] = new Logger();
diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php
index e7c2071f..4878c0c9 100644
--- a/tests/units/Core/Action/ActionManagerTest.php
+++ b/tests/units/Core/Action/ActionManagerTest.php
@@ -96,7 +96,7 @@ class ActionManagerTest extends Base
$actions = $actionManager->getAvailableActions();
$actionManager->attachEvents();
- $this->assertEmpty($this->container['dispatcher']->getListeners());
+ $this->assertEmpty($this->dispatcher->getListeners());
$this->assertEquals(1, $projectModel->create(array('name' =>'test')));
$this->assertEquals(1, $actionModel->create(array(
@@ -107,7 +107,7 @@ class ActionManagerTest extends Base
)));
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_CREATE);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
$this->assertCount(1, $listeners);
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
@@ -148,7 +148,7 @@ class ActionManagerTest extends Base
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN);
$this->assertCount(1, $listeners);
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
@@ -158,7 +158,6 @@ class ActionManagerTest extends Base
public function testThatEachListenerAreDifferentInstance()
{
$projectModel = new ProjectModel($this->container);
- $projectUserRoleModel = new ProjectUserRoleModel($this->container);
$actionModel = new ActionModel($this->container);
$actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
$actionManager = new ActionManager($this->container);
@@ -183,7 +182,7 @@ class ActionManagerTest extends Base
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN);
$this->assertCount(2, $listeners);
$this->assertFalse($listeners[0][0] === $listeners[1][0]);
@@ -193,4 +192,35 @@ class ActionManagerTest extends Base
$this->assertEquals(1, $listeners[1][0]->getParam('column_id'));
$this->assertEquals('red', $listeners[1][0]->getParam('color_id'));
}
+
+ public function testRemoveEvents()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+ $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
+ $actionManager = new ActionManager($this->container);
+ $actionManager->register($actionTaskAssignColorColumn);
+
+ $actions = $actionManager->getAvailableActions();
+
+ $this->assertEquals(1, $projectModel->create(array('name' =>'test')));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE,
+ 'action_name' => key($actions),
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $actionManager->attachEvents();
+ $this->dispatcher->addListener(TaskModel::EVENT_CREATE, function () {});
+
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
+ $this->assertCount(2, $listeners);
+
+ $actionManager->removeEvents();
+
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
+ $this->assertCount(1, $listeners);
+ $this->assertNotInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0]);
+ }
}
diff --git a/tests/units/Core/Cache/FileCacheTest.php b/tests/units/Core/Cache/FileCacheTest.php
new file mode 100644
index 00000000..b6336581
--- /dev/null
+++ b/tests/units/Core/Cache/FileCacheTest.php
@@ -0,0 +1,186 @@
+<?php
+
+namespace Kanboard\Core\Cache;
+
+require_once __DIR__.'/../../Base.php';
+
+function file_put_contents($filename, $data)
+{
+ return FileCacheTest::$functions->file_put_contents($filename, $data);
+}
+
+function file_get_contents($filename)
+{
+ return FileCacheTest::$functions->file_get_contents($filename);
+}
+
+function mkdir($filename, $mode = 0777, $recursif = false)
+{
+ return FileCacheTest::$functions->mkdir($filename, $mode, $recursif);
+}
+
+function is_dir($filename)
+{
+ return FileCacheTest::$functions->is_dir($filename);
+}
+
+function file_exists($filename)
+{
+ return FileCacheTest::$functions->file_exists($filename);
+}
+
+function unlink($filename)
+{
+ return FileCacheTest::$functions->unlink($filename);
+}
+
+class FileCacheTest extends \Base
+{
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ public static $functions;
+
+ public function setUp()
+ {
+ parent::setup();
+
+ self::$functions = $this
+ ->getMockBuilder('stdClass')
+ ->setMethods(array(
+ 'file_put_contents',
+ 'file_get_contents',
+ 'file_exists',
+ 'mkdir',
+ 'is_dir',
+ 'unlink',
+ ))
+ ->getMock();
+ }
+
+ public function tearDown()
+ {
+ parent::tearDown();
+ self::$functions = null;
+ }
+
+ public function testSet()
+ {
+ $key = 'mykey';
+ $data = 'data';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('is_dir')
+ ->with(
+ $this->equalTo(CACHE_DIR)
+ )
+ ->will($this->returnValue(false));
+
+ self::$functions
+ ->expects($this->at(1))
+ ->method('mkdir')
+ ->with(
+ $this->equalTo(CACHE_DIR),
+ 0755
+ )
+ ->will($this->returnValue(true));
+
+ self::$functions
+ ->expects($this->at(2))
+ ->method('file_put_contents')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key),
+ $this->equalTo(serialize($data))
+ )
+ ->will($this->returnValue(true));
+
+ $cache->set($key, $data);
+ }
+
+ public function testGet()
+ {
+ $key = 'mykey';
+ $data = 'data';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('file_exists')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(true));
+
+ self::$functions
+ ->expects($this->at(1))
+ ->method('file_get_contents')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(serialize($data)));
+
+ $this->assertSame($data, $cache->get($key));
+ }
+
+ public function testGetWithKeyNotFound()
+ {
+ $key = 'mykey';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('file_exists')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(false));
+
+ $this->assertNull($cache->get($key));
+ }
+
+ public function testRemoveWithKeyNotFound()
+ {
+ $key = 'mykey';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('file_exists')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(false));
+
+ self::$functions
+ ->expects($this->never())
+ ->method('unlink');
+
+ $cache->remove($key);
+ }
+
+ public function testRemove()
+ {
+ $key = 'mykey';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('file_exists')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(true));
+
+ self::$functions
+ ->expects($this->at(1))
+ ->method('unlink')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(true));
+
+ $cache->remove($key);
+ }
+}
diff --git a/tests/units/Core/DateParserTest.php b/tests/units/Core/DateParserTest.php
index fbde8bd5..e0dfb4c1 100644
--- a/tests/units/Core/DateParserTest.php
+++ b/tests/units/Core/DateParserTest.php
@@ -64,7 +64,7 @@ class DateParserTest extends Base
$dates = $dateParser->getDateTimeFormats(true);
$this->assertEquals('m/d/Y H:i', $dates[0]);
- $this->container['configModel']->save(array('application_datetime_format' => 'd/m/Y g:i a'));
+ $this->container['configModel']->save(array('application_date_format' => 'd/m/Y', 'application_time_format' => 'g:i a'));
$this->container['memoryCache']->flush();
$dates = $dateParser->getDateTimeFormats();
@@ -121,7 +121,7 @@ class DateParserTest extends Base
{
$this->container['configModel']->save(array(
'application_date_format' => 'd/m/Y',
- 'application_datetime_format' => 'd/m/Y g:i a',
+ 'application_time_format' => 'g:i a',
));
$dateParser = new DateParser($this->container);
@@ -138,7 +138,7 @@ class DateParserTest extends Base
{
$this->container['configModel']->save(array(
'application_date_format' => 'd.m.Y',
- 'application_datetime_format' => 'd.m.Y H:i',
+ 'application_time_format' => 'H:i',
));
$dateParser = new DateParser($this->container);
@@ -166,17 +166,9 @@ class DateParserTest extends Base
$this->assertEquals(1, $dateParser->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00')));
$this->assertEquals(2.5, $dateParser->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:30:00')));
$this->assertEquals(2.75, $dateParser->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:45:00')));
- $this->assertEquals(3, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 17:58:00')));
- $this->assertEquals(3, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 11:58:00')));
- }
-
- public function testRoundSeconds()
- {
- $dateParser = new DateParser($this->container);
- $this->assertEquals('16:30', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:28'))));
- $this->assertEquals('16:00', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:02'))));
- $this->assertEquals('16:15', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:14'))));
- $this->assertEquals('17:00', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:58'))));
+ $this->assertEquals(3.02, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 17:58:00')));
+ $this->assertEquals(2.98, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 11:58:00')));
+ $this->assertEquals(0, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 14:57:10')));
}
public function testGetIsoDate()
diff --git a/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php b/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php
new file mode 100644
index 00000000..8eec64de
--- /dev/null
+++ b/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php
@@ -0,0 +1,50 @@
+<?php
+
+use Kanboard\Core\ExternalTask\ExternalTaskManager;
+
+require_once __DIR__.'/../../Base.php';
+
+class ExternalTaskManagerTest extends Base
+{
+ public function testProviderNotFound()
+ {
+ $this->setExpectedException('Kanboard\Core\ExternalTask\ProviderNotFoundException');
+
+ $manager = new ExternalTaskManager();
+ $manager->getProvider('foobar');
+ }
+
+ public function testRegister()
+ {
+ $provider = $this->getMock('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface');
+ $provider->expects($this->any())->method('getName')->willReturn('MyProvider');
+
+ $manager = new ExternalTaskManager();
+ $manager->register($provider);
+
+ $this->assertInstanceOf('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface', $manager->getProvider('MyProvider'));
+ }
+
+ public function testGetList()
+ {
+ $provider1 = $this->getMock('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface');
+ $provider1->expects($this->any())->method('getName')->willReturn('MyProvider1');
+
+ $provider2 = $this->getMock('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface');
+ $provider2->expects($this->any())->method('getName')->willReturn('MyProvider2');
+
+ $manager = new ExternalTaskManager();
+ $manager->register($provider1);
+ $manager->register($provider2);
+ $providers = $manager->getProvidersList();
+
+ $expected = array('MyProvider1' => 'MyProvider1', 'MyProvider2' => 'MyProvider2');
+ $this->assertEquals($expected, $providers);
+ }
+
+ public function testGetProviderListWithNoProviders()
+ {
+ $manager = new ExternalTaskManager();
+ $this->assertSame(array(), $manager->getProvidersList());
+ }
+}
diff --git a/tests/units/Core/Filter/LexerBuilderTest.php b/tests/units/Core/Filter/LexerBuilderTest.php
index 23726f32..31e237dc 100644
--- a/tests/units/Core/Filter/LexerBuilderTest.php
+++ b/tests/units/Core/Filter/LexerBuilderTest.php
@@ -8,6 +8,7 @@ use Kanboard\Filter\TaskTitleFilter;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\UserModel;
class LexerBuilderTest extends Base
{
@@ -103,4 +104,49 @@ class LexerBuilderTest extends Base
$this->assertFalse($builder === $clone);
$this->assertFalse($builder->build('test')->getQuery() === $clone->build('test')->getQuery());
}
+
+ public function testBuilderWithMixedCaseSearchAttribute()
+ {
+ $project = new ProjectModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $taskFinder = new TaskFinderModel($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $project->create(array('name' => 'Project')));
+ $this->assertNotFalse($taskCreation->create(array('project_id' => 1, 'title' => 'Test')));
+
+ $builder = new LexerBuilder();
+ $builder->withFilter(new TaskAssigneeFilter());
+ $builder->withFilter(new TaskTitleFilter(), true);
+ $builder->withQuery($query);
+ $tasks = $builder->build('AsSignEe:nobody')->toArray();
+
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Test', $tasks[0]['title']);
+ }
+
+ public function testWithOrCriteria()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $userModel = new UserModel($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test 1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test 3', 'project_id' => 1, 'owner_id' => 0)));
+
+ $builder = new LexerBuilder();
+ $builder->withFilter(new TaskAssigneeFilter());
+ $builder->withFilter(new TaskTitleFilter(), true);
+ $builder->withQuery($query);
+ $tasks = $builder->build('assignee:admin assignee:foobar')->toArray();
+
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('Test 1', $tasks[0]['title']);
+ $this->assertEquals('Test 2', $tasks[1]['title']);
+ }
}
diff --git a/tests/units/Core/Filter/OrCriteriaTest.php b/tests/units/Core/Filter/OrCriteriaTest.php
index a46726c3..cf520f36 100644
--- a/tests/units/Core/Filter/OrCriteriaTest.php
+++ b/tests/units/Core/Filter/OrCriteriaTest.php
@@ -22,8 +22,9 @@ class OrCriteriaTest extends Base
$this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar')));
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
- $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 2)));
- $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test 1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test 3', 'project_id' => 1, 'owner_id' => 0)));
$criteria = new OrCriteria();
$criteria->withQuery($query);
diff --git a/tests/units/Core/Http/RequestTest.php b/tests/units/Core/Http/RequestTest.php
index 6fa796f7..697c3c0f 100644
--- a/tests/units/Core/Http/RequestTest.php
+++ b/tests/units/Core/Http/RequestTest.php
@@ -43,6 +43,9 @@ class RequestTest extends Base
$request = new Request($this->container, array(), array(), array('myvar' => 'myvalue', 'csrf_token' => $this->container['token']->getCSRFToken()), array(), array());
$this->assertEquals(array('myvar' => 'myvalue'), $request->getValues());
+
+ $request = new Request($this->container, array(), array(), array('myvar' => 'myvalue', '-----------------------------7e1c32510025c--' => '', 'csrf_token' => $this->container['token']->getCSRFToken()), array(), array());
+ $this->assertEquals(array('myvar' => 'myvalue'), $request->getValues());
}
public function testGetFileContent()
@@ -169,6 +172,9 @@ class RequestTest extends Base
$request = new Request($this->container, array(), array(), array(), array(), array());
$this->assertEquals('Unknown', $request->getIpAddress());
+ $request = new Request($this->container, array('HTTP_X_REAL_IP' => '192.168.1.1,127.0.0.1'), array(), array(), array(), array());
+ $this->assertEquals('192.168.1.1', $request->getIpAddress());
+
$request = new Request($this->container, array('HTTP_X_FORWARDED_FOR' => '192.168.0.1,127.0.0.1'), array(), array(), array(), array());
$this->assertEquals('192.168.0.1', $request->getIpAddress());
diff --git a/tests/units/Core/FileStorageTest.php b/tests/units/Core/ObjectStorage/FileStorageTest.php
index a3ad2448..ed77dedd 100644
--- a/tests/units/Core/FileStorageTest.php
+++ b/tests/units/Core/ObjectStorage/FileStorageTest.php
@@ -2,7 +2,7 @@
namespace Kanboard\Core\ObjectStorage;
-require_once __DIR__.'/../Base.php';
+require_once __DIR__.'/../../Base.php';
function file_put_contents($filename, $data)
{
@@ -105,7 +105,7 @@ class FileStorageTest extends \Base
->method('file_put_contents')
->with(
$this->equalTo('somewhere'.DIRECTORY_SEPARATOR.'mykey'),
- $this->equalTo('data')
+ $this->equalTo($data)
)
->will($this->returnValue(true));
diff --git a/tests/units/Core/Plugin/DirectoryTest.php b/tests/units/Core/Plugin/DirectoryTest.php
index 13aef4b9..302bd6f6 100644
--- a/tests/units/Core/Plugin/DirectoryTest.php
+++ b/tests/units/Core/Plugin/DirectoryTest.php
@@ -12,6 +12,11 @@ class DirectoryTest extends Base
$this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '1.0.29'), '1.0.28'));
$this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), '1.0.28'));
$this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), 'master.1234'));
+ $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), 'master'));
+ $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), '1.0.32'));
+ $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), '1.0.33'));
+ $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>1.0.32'), '1.0.33'));
+ $this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '>1.0.32'), '1.0.32'));
}
public function testGetAvailablePlugins()
diff --git a/tests/units/Core/Plugin/HookTest.php b/tests/units/Core/Plugin/HookTest.php
index d1c139b3..acadede0 100644
--- a/tests/units/Core/Plugin/HookTest.php
+++ b/tests/units/Core/Plugin/HookTest.php
@@ -8,89 +8,103 @@ class HookTest extends Base
{
public function testGetListeners()
{
- $h = new Hook;
- $this->assertEmpty($h->getListeners('myhook'));
+ $hook = new Hook;
+ $this->assertEmpty($hook->getListeners('myhook'));
- $h->on('myhook', 'A');
- $h->on('myhook', 'B');
+ $hook->on('myhook', 'A');
+ $hook->on('myhook', 'B');
- $this->assertEquals(array('A', 'B'), $h->getListeners('myhook'));
+ $this->assertEquals(array('A', 'B'), $hook->getListeners('myhook'));
}
public function testExists()
{
- $h = new Hook;
- $this->assertFalse($h->exists('myhook'));
+ $hook = new Hook;
+ $this->assertFalse($hook->exists('myhook'));
- $h->on('myhook', 'A');
+ $hook->on('myhook', 'A');
- $this->assertTrue($h->exists('myhook'));
+ $this->assertTrue($hook->exists('myhook'));
}
public function testMergeWithNoBinding()
{
- $h = new Hook;
+ $hook = new Hook;
$values = array('A', 'B');
- $result = $h->merge('myhook', $values, array('p' => 'c'));
+ $result = $hook->merge('myhook', $values, array('p' => 'c'));
$this->assertEquals($values, $result);
}
public function testMergeWithBindings()
{
- $h = new Hook;
+ $hook = new Hook;
$values = array('A', 'B');
$expected = array('A', 'B', 'c', 'D');
- $h->on('myhook', function ($p) {
+ $hook->on('myhook', function ($p) {
return array($p);
});
- $h->on('myhook', function () {
+ $hook->on('myhook', function () {
return array('D');
});
- $result = $h->merge('myhook', $values, array('p' => 'c'));
+ $result = $hook->merge('myhook', $values, array('p' => 'c'));
$this->assertEquals($expected, $result);
$this->assertEquals($expected, $values);
}
public function testMergeWithBindingButReturningBadData()
{
- $h = new Hook;
+ $hook = new Hook;
$values = array('A', 'B');
$expected = array('A', 'B');
- $h->on('myhook', function () {
+ $hook->on('myhook', function () {
return 'string';
});
- $result = $h->merge('myhook', $values);
+ $result = $hook->merge('myhook', $values);
$this->assertEquals($expected, $result);
$this->assertEquals($expected, $values);
}
public function testFirstWithNoBinding()
{
- $h = new Hook;
+ $hook = new Hook;
- $result = $h->first('myhook', array('p' => 2));
+ $result = $hook->first('myhook', array('p' => 2));
$this->assertEquals(null, $result);
}
public function testFirstWithMultipleBindings()
{
- $h = new Hook;
+ $hook = new Hook;
- $h->on('myhook', function ($p) {
+ $hook->on('myhook', function ($p) {
return $p + 1;
});
- $h->on('myhook', function ($p) {
+ $hook->on('myhook', function ($p) {
return $p;
});
- $result = $h->first('myhook', array('p' => 3));
+ $result = $hook->first('myhook', array('p' => 3));
$this->assertEquals(4, $result);
}
+
+ public function testHookWithReference()
+ {
+ $hook = new Hook();
+
+ $hook->on('myhook', function (&$p) {
+ $p = 2;
+ });
+
+ $param = 123;
+ $result = $hook->reference('myhook', $param);
+ $this->assertSame(2, $result);
+ $this->assertSame(2, $param);
+ }
}
diff --git a/tests/units/Core/Plugin/VersionTest.php b/tests/units/Core/Plugin/VersionTest.php
new file mode 100644
index 00000000..78f10d95
--- /dev/null
+++ b/tests/units/Core/Plugin/VersionTest.php
@@ -0,0 +1,29 @@
+<?php
+
+use Kanboard\Core\Plugin\Version;
+
+require_once __DIR__.'/../../Base.php';
+
+class VersionTest extends Base
+{
+ public function testIsCompatible()
+ {
+ $this->assertFalse(Version::isCompatible('1.0.29', '1.0.28'));
+ $this->assertTrue(Version::isCompatible('1.0.28', '1.0.28'));
+ $this->assertTrue(Version::isCompatible('1.0.28', 'master.1234'));
+ $this->assertTrue(Version::isCompatible('>=1.0.32', 'master'));
+ $this->assertTrue(Version::isCompatible('>=1.0.32', '1.0.32'));
+ $this->assertTrue(Version::isCompatible('>=1.0.32', '1.0.33'));
+ $this->assertTrue(Version::isCompatible('>1.0.32', '1.0.33'));
+ $this->assertFalse(Version::isCompatible('>1.0.32', '1.0.32'));
+ $this->assertTrue(Version::isCompatible('1.0.32', 'v1.0.32'));
+ $this->assertTrue(Version::isCompatible('>=v1.0.32', 'v1.0.32'));
+ $this->assertTrue(Version::isCompatible('<=v1.0.36', 'v1.0.36'));
+ $this->assertFalse(Version::isCompatible('<1.0.36', 'v1.0.36'));
+ $this->assertTrue(Version::isCompatible('<1.0.40', '1.0.36'));
+ $this->assertTrue(Version::isCompatible('<=1.0.40', '1.0.36'));
+ $this->assertFalse(Version::isCompatible('<1.0.40', '1.0.40'));
+ $this->assertFalse(Version::isCompatible('1.0.40', 'v1.0.36'));
+ $this->assertTrue(Version::isCompatible('<1.1.0', 'v1.0.36'));
+ }
+}
diff --git a/tests/units/Core/Security/RoleTest.php b/tests/units/Core/Security/RoleTest.php
new file mode 100644
index 00000000..10b9c409
--- /dev/null
+++ b/tests/units/Core/Security/RoleTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\Core\Security\Role;
+
+require_once __DIR__.'/../../Base.php';
+
+class RoleTest extends Base
+{
+ public function testIsCustomRole()
+ {
+ $role = new Role();
+ $this->assertFalse($role->isCustomProjectRole(Role::PROJECT_MANAGER));
+ $this->assertFalse($role->isCustomProjectRole(Role::PROJECT_MEMBER));
+ $this->assertFalse($role->isCustomProjectRole(Role::PROJECT_VIEWER));
+ $this->assertFalse($role->isCustomProjectRole(''));
+ $this->assertTrue($role->isCustomProjectRole('Custom Role'));
+ }
+
+ public function testGetRoleName()
+ {
+ $role = new Role();
+ $this->assertEquals('Project Manager', $role->getRoleName(Role::PROJECT_MANAGER));
+ $this->assertEquals('Project Member', $role->getRoleName(Role::PROJECT_MEMBER));
+ $this->assertEquals('Project Viewer', $role->getRoleName(Role::PROJECT_VIEWER));
+ $this->assertEquals('Administrator', $role->getRoleName(Role::APP_ADMIN));
+ $this->assertEquals('Manager', $role->getRoleName(Role::APP_MANAGER));
+ $this->assertEquals('User', $role->getRoleName(Role::APP_USER));
+ $this->assertEquals('Unknown', $role->getRoleName('Foobar'));
+ }
+
+ public function testGetters()
+ {
+ $role = new Role();
+ $this->assertCount(3, $role->getApplicationRoles());
+ $this->assertCount(3, $role->getProjectRoles());
+ }
+}
diff --git a/tests/units/Core/TranslatorTest.php b/tests/units/Core/TranslatorTest.php
new file mode 100644
index 00000000..6aa480e1
--- /dev/null
+++ b/tests/units/Core/TranslatorTest.php
@@ -0,0 +1,45 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Core\Translator;
+
+class TranslatorTest extends Base
+{
+ public function setUp()
+ {
+ parent::setUp();
+ Translator::unload();
+ }
+
+ public function testLoading()
+ {
+ $translator = new Translator();
+ $this->assertSame('Yes', $translator->translate('Yes'));
+
+ Translator::load('fr_FR');
+ $this->assertSame('Oui', $translator->translate('Yes'));
+
+ Translator::unload();
+ $this->assertSame('Yes', $translator->translate('Yes'));
+
+ Translator::load('de_DE', Translator::getDefaultFolder());
+ $this->assertSame('Ja', $translator->translate('Yes'));
+ }
+
+ public function testNumberFormatting()
+ {
+ $translator = new Translator();
+ $this->assertSame('1,024.42', $translator->number(1024.42));
+
+ Translator::load('fr_FR');
+ $this->assertSame('1 024,42', $translator->number(1024.42));
+ }
+
+ public function testTranslateEscaping()
+ {
+ $translator = new Translator();
+ $this->assertSame('&lt;b&gt;', $translator->translate('<b>'));
+ $this->assertSame('<b>', $translator->translateNoEscaping('<b>'));
+ }
+}
diff --git a/tests/units/Core/User/UserSessionTest.php b/tests/units/Core/User/UserSessionTest.php
index 64413f98..2a118079 100644
--- a/tests/units/Core/User/UserSessionTest.php
+++ b/tests/units/Core/User/UserSessionTest.php
@@ -83,27 +83,6 @@ class UserSessionTest extends Base
$this->assertFalse($us->isAdmin());
}
- public function testCommentSorting()
- {
- $us = new UserSession($this->container);
- $this->assertEquals('ASC', $us->getCommentSorting());
-
- $us->setCommentSorting('DESC');
- $this->assertEquals('DESC', $us->getCommentSorting());
- }
-
- public function testBoardCollapseMode()
- {
- $us = new UserSession($this->container);
- $this->assertFalse($us->isBoardCollapsed(2));
-
- $us->setBoardDisplayMode(3, false);
- $this->assertFalse($us->isBoardCollapsed(3));
-
- $us->setBoardDisplayMode(3, true);
- $this->assertTrue($us->isBoardCollapsed(3));
- }
-
public function testFilters()
{
$us = new UserSession($this->container);
diff --git a/tests/units/Decorator/MetadataCacheDecoratorTest.php b/tests/units/Decorator/MetadataCacheDecoratorTest.php
new file mode 100644
index 00000000..3e4dd320
--- /dev/null
+++ b/tests/units/Decorator/MetadataCacheDecoratorTest.php
@@ -0,0 +1,127 @@
+<?php
+
+use Kanboard\Decorator\MetadataCacheDecorator;
+
+require_once __DIR__.'/../Base.php';
+
+class MetadataCacheDecoratorTest extends Base
+{
+ protected $cachePrefix = 'cache_prefix';
+ protected $entityId = 123;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $cacheMock;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $metadataModelMock;
+
+ /**
+ * @var MetadataCacheDecorator
+ */
+ protected $metadataCacheDecorator;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->cacheMock = $this
+ ->getMockBuilder('\Kanboard\Core\Cache\MemoryCache')
+ ->setMethods(array(
+ 'set',
+ 'get',
+ ))
+ ->getMock();
+
+ $this->metadataModelMock = $this
+ ->getMockBuilder('\Kanboard\Model\UserMetadataModel')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array(
+ 'getAll',
+ 'save',
+ ))
+ ->getMock()
+ ;
+
+ $this->metadataCacheDecorator = new MetadataCacheDecorator(
+ $this->cacheMock,
+ $this->metadataModelMock,
+ $this->cachePrefix,
+ $this->entityId
+ );
+ }
+
+ public function testSet()
+ {
+ $this->cacheMock
+ ->expects($this->once())
+ ->method('set');
+
+ $this->metadataModelMock
+ ->expects($this->at(0))
+ ->method('save');
+
+ $this->metadataModelMock
+ ->expects($this->at(1))
+ ->method('getAll')
+ ->with($this->entityId)
+ ;
+
+ $this->metadataCacheDecorator->set('key', 'value');
+ }
+
+ public function testGetWithCache()
+ {
+ $this->cacheMock
+ ->expects($this->once())
+ ->method('get')
+ ->with($this->cachePrefix.$this->entityId)
+ ->will($this->returnValue(array('key' => 'foobar')))
+ ;
+
+ $this->assertEquals('foobar', $this->metadataCacheDecorator->get('key', 'default'));
+ }
+
+ public function testGetWithCacheAndDefaultValue()
+ {
+ $this->cacheMock
+ ->expects($this->once())
+ ->method('get')
+ ->with($this->cachePrefix.$this->entityId)
+ ->will($this->returnValue(array('key1' => 'foobar')))
+ ;
+
+ $this->assertEquals('default', $this->metadataCacheDecorator->get('key', 'default'));
+ }
+
+ public function testGetWithoutCache()
+ {
+ $this->cacheMock
+ ->expects($this->at(0))
+ ->method('get')
+ ->with($this->cachePrefix.$this->entityId)
+ ->will($this->returnValue(null))
+ ;
+
+ $this->cacheMock
+ ->expects($this->at(1))
+ ->method('set')
+ ->with(
+ $this->cachePrefix.$this->entityId,
+ array('key' => 'something')
+ )
+ ;
+
+ $this->metadataModelMock
+ ->expects($this->once())
+ ->method('getAll')
+ ->with($this->entityId)
+ ->will($this->returnValue(array('key' => 'something')))
+ ;
+
+ $this->assertEquals('something', $this->metadataCacheDecorator->get('key', 'default'));
+ }
+}
diff --git a/tests/units/EventBuilder/CommentEventBuilderTest.php b/tests/units/EventBuilder/CommentEventBuilderTest.php
new file mode 100644
index 00000000..ff1c630e
--- /dev/null
+++ b/tests/units/EventBuilder/CommentEventBuilderTest.php
@@ -0,0 +1,39 @@
+<?php
+
+use Kanboard\EventBuilder\CommentEventBuilder;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class CommentEventBuilderTest extends Base
+{
+ public function testWithMissingComment()
+ {
+ $commentEventBuilder = new CommentEventBuilder($this->container);
+ $commentEventBuilder->withCommentId(42);
+ $this->assertNull($commentEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $commentEventBuilder = new CommentEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
+
+ $commentEventBuilder->withCommentId(1);
+ $event = $commentEventBuilder->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\CommentEvent', $event);
+ $this->assertNotEmpty($event['comment']);
+ $this->assertNotEmpty($event['task']);
+ $this->assertEquals(1, $event->getTaskId());
+ $this->assertEquals(1, $event->getProjectId());
+ }
+}
diff --git a/tests/units/EventBuilder/ProjectFileEventBuilderTest.php b/tests/units/EventBuilder/ProjectFileEventBuilderTest.php
new file mode 100644
index 00000000..c3595029
--- /dev/null
+++ b/tests/units/EventBuilder/ProjectFileEventBuilderTest.php
@@ -0,0 +1,35 @@
+<?php
+
+use Kanboard\EventBuilder\ProjectFileEventBuilder;
+use Kanboard\Model\ProjectFileModel;
+use Kanboard\Model\ProjectModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectFileEventBuilderTest extends Base
+{
+ public function testWithMissingFile()
+ {
+ $projectFileEventBuilder = new ProjectFileEventBuilder($this->container);
+ $projectFileEventBuilder->withFileId(42);
+ $this->assertNull($projectFileEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectFileModel = new ProjectFileModel($this->container);
+ $projectFileEventBuilder = new ProjectFileEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $projectFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $event = $projectFileEventBuilder->withFileId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\ProjectFileEvent', $event);
+ $this->assertNotEmpty($event['file']);
+ $this->assertNotEmpty($event['project']);
+ $this->assertNull($event->getTaskId());
+ $this->assertEquals(1, $event->getProjectId());
+ }
+}
diff --git a/tests/units/EventBuilder/SubtaskEventBuilderTest.php b/tests/units/EventBuilder/SubtaskEventBuilderTest.php
new file mode 100644
index 00000000..215b1ed2
--- /dev/null
+++ b/tests/units/EventBuilder/SubtaskEventBuilderTest.php
@@ -0,0 +1,64 @@
+<?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->buildEvent());
+ }
+
+ 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)->buildEvent();
+
+ $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))
+ ->buildEvent();
+
+ $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']);
+ $this->assertEquals(1, $event->getTaskId());
+ $this->assertEquals(1, $event->getProjectId());
+ }
+}
diff --git a/tests/units/EventBuilder/TaskEventBuilderTest.php b/tests/units/EventBuilder/TaskEventBuilderTest.php
new file mode 100644
index 00000000..446b862b
--- /dev/null
+++ b/tests/units/EventBuilder/TaskEventBuilderTest.php
@@ -0,0 +1,102 @@
+<?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(1, $event->getTaskId());
+ $this->assertEquals(1, $event->getProjectId());
+ $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']);
+ }
+}
diff --git a/tests/units/EventBuilder/TaskFileEventBuilderTest.php b/tests/units/EventBuilder/TaskFileEventBuilderTest.php
new file mode 100644
index 00000000..1e88b6fb
--- /dev/null
+++ b/tests/units/EventBuilder/TaskFileEventBuilderTest.php
@@ -0,0 +1,38 @@
+<?php
+
+use Kanboard\EventBuilder\TaskFileEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFileModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskFileEventBuilderTest extends Base
+{
+ public function testWithMissingFile()
+ {
+ $taskFileEventBuilder = new TaskFileEventBuilder($this->container);
+ $taskFileEventBuilder->withFileId(42);
+ $this->assertNull($taskFileEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFileEventBuilder = new TaskFileEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $event = $taskFileEventBuilder->withFileId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskFileEvent', $event);
+ $this->assertNotEmpty($event['file']);
+ $this->assertNotEmpty($event['task']);
+ $this->assertEquals(1, $event->getTaskId());
+ $this->assertEquals(1, $event->getProjectId());
+ }
+}
diff --git a/tests/units/EventBuilder/TaskLinkEventBuilderTest.php b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
new file mode 100644
index 00000000..4e38eeb6
--- /dev/null
+++ b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
@@ -0,0 +1,72 @@
+<?php
+
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskLinkModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskLinkEventBuilderTest extends Base
+{
+ public function testWithMissingLink()
+ {
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+ $taskLinkEventBuilder->withTaskLinkId(42);
+ $this->assertNull($taskLinkEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $event = $taskLinkEventBuilder->withTaskLinkId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskLinkEvent', $event);
+ $this->assertNotEmpty($event['task_link']);
+ $this->assertNotEmpty($event['task']);
+ $this->assertEquals(1, $event->getTaskId());
+ $this->assertEquals(1, $event->getProjectId());
+ }
+
+ public function testBuildTitle()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $eventData = $taskLinkEventBuilder->withTaskLinkId(1)->buildEvent();
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', TaskLinkModel::EVENT_CREATE_UPDATE, $eventData->getAll());
+ $this->assertEquals('Foobar set a new internal link for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', TaskLinkModel::EVENT_DELETE, $eventData->getAll());
+ $this->assertEquals('Foobar removed an internal link for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', 'not found', $eventData->getAll());
+ $this->assertSame('', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor(TaskLinkModel::EVENT_CREATE_UPDATE, $eventData->getAll());
+ $this->assertEquals('A new internal link for the task #1 have been defined', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor(TaskLinkModel::EVENT_DELETE, $eventData->getAll());
+ $this->assertEquals('Internal link removed for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor('not found', $eventData->getAll());
+ $this->assertSame('', $title);
+ }
+}
diff --git a/tests/units/Export/TaskExportTest.php b/tests/units/Export/TaskExportTest.php
index c142cde9..ae6ca308 100644
--- a/tests/units/Export/TaskExportTest.php
+++ b/tests/units/Export/TaskExportTest.php
@@ -12,44 +12,70 @@ class TaskExportTest extends Base
{
public function testExport()
{
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
- $e = new TaskExport($this->container);
- $s = new SwimlaneModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Export Project')));
-
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
- $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
-
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
- $this->assertNotFalse($c->create(array('name' => 'Category #3', 'project_id' => 1)));
-
- for ($i = 1; $i <= 100; $i++) {
- $task = array(
- 'title' => 'Task #'.$i,
- 'project_id' => 1,
- 'column_id' => rand(1, 3),
- 'creator_id' => rand(0, 1),
- 'owner_id' => rand(0, 1),
- 'color_id' => rand(0, 1) === 0 ? 'green' : 'purple',
- 'category_id' => rand(0, 3),
- 'date_due' => array_rand(array(0, date('Y-m-d'), date('Y-m-d', strtotime('+'.$i.'day')))),
- 'score' => rand(0, 21),
- 'swimlane_id' => rand(0, 2),
- );
-
- $this->assertEquals($i, $tc->create($task));
- }
-
- $rows = $e->export(1, strtotime('-1 day'), strtotime('+1 day'));
-
- $this->assertEquals($i, count($rows));
- $this->assertEquals('Task Id', $rows[0][0]);
- $this->assertEquals(1, $rows[1][0]);
- $this->assertEquals('Task #'.($i - 1), $rows[$i - 1][13]);
- $this->assertTrue(in_array($rows[$i - 1][4], array('Default swimlane', 'S1', 'S2')));
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskExport = new TaskExport($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Export Project')));
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ 'category_id' => 1,
+ 'reference' => 'REF1',
+ 'title' => 'Task 1',
+ 'time_estimated' => 2.5,
+ 'time_spent' => 3,
+ )));
+
+ $this->assertEquals(2, $taskCreationModel->create(array(
+ 'project_id' => 1,
+ 'swimlane_id' => 1,
+ 'title' => 'Task 2',
+ 'date_due' => time(),
+ )));
+
+ $report = $taskExport->export(1, date('Y-m-d'), date('Y-m-d'));
+
+ $this->assertCount(3, $report);
+ $this->assertCount(22, $report[0]);
+ $this->assertEquals('Task Id', $report[0][0]);
+
+ $this->assertEquals(1, $report[1][0]);
+ $this->assertEquals(2, $report[2][0]);
+
+ $this->assertEquals('REF1', $report[1][1]);
+ $this->assertEquals('', $report[2][1]);
+
+ $this->assertEquals('Export Project', $report[1][2]);
+ $this->assertEquals('Export Project', $report[2][2]);
+
+ $this->assertEquals('Open', $report[1][3]);
+ $this->assertEquals('Open', $report[2][3]);
+
+ $this->assertEquals('Category #1', $report[1][4]);
+ $this->assertEquals('', $report[2][4]);
+
+ $this->assertEquals('Default swimlane', $report[1][5]);
+ $this->assertEquals('S1', $report[2][5]);
+
+ $this->assertEquals('Ready', $report[1][6]);
+ $this->assertEquals('Backlog', $report[2][6]);
+
+ $this->assertEquals('Yellow', $report[1][8]);
+ $this->assertEquals('Yellow', $report[2][8]);
+
+ $this->assertEquals('', $report[1][9]);
+ $this->assertEquals(date('m/d/Y').' 00:00', $report[2][9]);
+
+ $this->assertEquals(3, $report[1][21]);
+ $this->assertEquals(0, $report[2][21]);
+
+ $this->assertEquals(2.5, $report[1][20]);
+ $this->assertEquals(0, $report[2][20]);
}
}
diff --git a/tests/units/ExternalLink/FileLinkProviderTest.php b/tests/units/ExternalLink/FileLinkProviderTest.php
index 8cef82f8..8698e174 100644
--- a/tests/units/ExternalLink/FileLinkProviderTest.php
+++ b/tests/units/ExternalLink/FileLinkProviderTest.php
@@ -31,6 +31,21 @@ class FileLinkProviderTest extends Base
$attachmentLinkProvider->setUserTextInput('file:///tmp/test.txt');
$this->assertTrue($attachmentLinkProvider->match());
+ $attachmentLinkProvider->setUserTextInput('owncloud:///tmp/test.txt');
+ $this->assertTrue($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('notebooks:///tmp/test.txt');
+ $this->assertTrue($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('http://google.com/');
+ $this->assertFalse($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('https://google.com/');
+ $this->assertFalse($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('ftp://google.com/');
+ $this->assertFalse($attachmentLinkProvider->match());
+
$attachmentLinkProvider->setUserTextInput('');
$this->assertFalse($attachmentLinkProvider->match());
}
diff --git a/tests/units/Filter/TaskMovedDateFilterTest.php b/tests/units/Filter/TaskMovedDateFilterTest.php
new file mode 100644
index 00000000..9b721913
--- /dev/null
+++ b/tests/units/Filter/TaskMovedDateFilterTest.php
@@ -0,0 +1,43 @@
+<?php
+
+use Kanboard\Filter\TaskMovedDateFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModificationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMovedDateFilterTest extends Base
+{
+ public function test()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $taskModification = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 1, 'date_moved' => time())));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 2, 'date_moved' => strtotime('-1days'))));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test3', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 3, 'date_moved' => strtotime('-3days'))));
+
+ $query = $taskFinder->getExtendedQuery();
+ $filter = new TaskMovedDateFilter('>='.date('Y-m-d', strtotime('-1days')));
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $this->assertCount(2, $query->findAll());
+
+ $query = $taskFinder->getExtendedQuery();
+ $filter = new TaskMovedDateFilter('<yesterday');
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $this->assertCount(1, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/TaskPriorityFilterTest.php b/tests/units/Filter/TaskPriorityFilterTest.php
new file mode 100644
index 00000000..4c95ddce
--- /dev/null
+++ b/tests/units/Filter/TaskPriorityFilterTest.php
@@ -0,0 +1,47 @@
+<?php
+
+use Kanboard\Filter\TaskPriorityFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskPriorityFilterTest extends Base
+{
+ public function testWithDefinedPriority()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'priority' => 2)));
+
+ $filter = new TaskPriorityFilter();
+ $filter->withQuery($query);
+ $filter->withValue(2);
+ $filter->apply();
+
+ $this->assertCount(1, $query->findAll());
+ }
+
+ public function testWithNoPriority()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+
+ $filter = new TaskPriorityFilter();
+ $filter->withQuery($query);
+ $filter->withValue(2);
+ $filter->apply();
+
+ $this->assertCount(0, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/TaskStartsWithIdFilterTest.php b/tests/units/Filter/TaskStartsWithIdFilterTest.php
new file mode 100644
index 00000000..e911a6a1
--- /dev/null
+++ b/tests/units/Filter/TaskStartsWithIdFilterTest.php
@@ -0,0 +1,103 @@
+<?php
+
+use Kanboard\Filter\TaskStartsWithIdFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskStartsWithIdFilterTest extends Base
+{
+ public function testManyResults()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ for ($i = 1; $i <= 20; $i++) {
+ $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i)));
+ }
+
+ $filter = new TaskStartsWithIdFilter();
+ $filter->withQuery($query);
+ $filter->withValue(1);
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(11, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ $this->assertEquals('Task #19', $tasks[10]['title']);
+ }
+
+ public function testOneResult()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ for ($i = 1; $i <= 20; $i++) {
+ $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i)));
+ }
+
+ $filter = new TaskStartsWithIdFilter();
+ $filter->withQuery($query);
+ $filter->withValue(3);
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #3', $tasks[0]['title']);
+ }
+
+ public function testEmptyResult()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ for ($i = 1; $i <= 20; $i++) {
+ $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i)));
+ }
+
+ $filter = new TaskStartsWithIdFilter();
+ $filter->withQuery($query);
+ $filter->withValue(30);
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(0, $tasks);
+ }
+
+ public function testWithTwoDigits()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ for ($i = 1; $i <= 20; $i++) {
+ $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i)));
+ }
+
+ $filter = new TaskStartsWithIdFilter();
+ $filter->withQuery($query);
+ $filter->withValue(11);
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #11', $tasks[0]['title']);
+ }
+}
diff --git a/tests/units/Filter/TaskStatusFilterTest.php b/tests/units/Filter/TaskStatusFilterTest.php
new file mode 100644
index 00000000..ea8d669b
--- /dev/null
+++ b/tests/units/Filter/TaskStatusFilterTest.php
@@ -0,0 +1,118 @@
+<?php
+
+use Kanboard\Filter\TaskStatusFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskStatusFilterTest extends Base
+{
+ public function testWithOpenValue()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue('open');
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ }
+
+ public function testWithOpenNumericValue()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue(1);
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ }
+
+ public function testWithClosedValue()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue('closed');
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test2', $tasks[0]['title']);
+ }
+
+ public function testWithClosedNumericValue()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue(0);
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test2', $tasks[0]['title']);
+ }
+
+ public function testWithAllValue()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'is_active' => TaskModel::STATUS_CLOSED)));
+
+ $filter = new TaskStatusFilter();
+ $filter->withQuery($query);
+ $filter->withValue('all');
+ $filter->apply();
+
+ $tasks = $query->asc(TaskModel::TABLE.'.title')->findAll();
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ $this->assertEquals('test2', $tasks[1]['title']);
+ }
+}
diff --git a/tests/units/Filter/TaskTagFilterTest.php b/tests/units/Filter/TaskTagFilterTest.php
index 72ed9904..2e235222 100644
--- a/tests/units/Filter/TaskTagFilterTest.php
+++ b/tests/units/Filter/TaskTagFilterTest.php
@@ -119,4 +119,31 @@ class TaskTagFilterTest extends Base
$this->assertEquals('test1', $tasks[0]['title']);
$this->assertEquals('test2', $tasks[1]['title']);
}
+
+ public function testWithNone()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $filter = new TaskTagFilter();
+ $filter->setDatabase($this->container['db']);
+ $filter->withQuery($query);
+ $filter->withValue('none');
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test3', $tasks[0]['title']);
+ }
}
diff --git a/tests/units/Formatter/BoardFormatterTest.php b/tests/units/Formatter/BoardFormatterTest.php
index c107eaf5..4d469eac 100644
--- a/tests/units/Formatter/BoardFormatterTest.php
+++ b/tests/units/Formatter/BoardFormatterTest.php
@@ -46,12 +46,17 @@ class BoardFormatterTest extends Base
$this->assertCount(3, $board);
+ $this->assertSame(0, $board[0]['id']);
$this->assertEquals('Default swimlane', $board[0]['name']);
$this->assertCount(4, $board[0]['columns']);
$this->assertEquals(3, $board[0]['nb_swimlanes']);
$this->assertEquals(4, $board[0]['nb_columns']);
$this->assertEquals(6, $board[0]['nb_tasks']);
$this->assertEquals(10, $board[0]['score']);
+ $this->assertSame(1, $board[0]['columns'][0]['id']);
+ $this->assertSame(2, $board[0]['columns'][1]['id']);
+ $this->assertSame(3, $board[0]['columns'][2]['id']);
+ $this->assertSame(4, $board[0]['columns'][3]['id']);
$this->assertEquals(4, $board[0]['columns'][0]['column_nb_tasks']);
$this->assertEquals(1, $board[0]['columns'][1]['column_nb_tasks']);
@@ -80,6 +85,7 @@ class BoardFormatterTest extends Base
$this->assertEquals('Task 5', $board[0]['columns'][1]['tasks'][0]['title']);
$this->assertEquals('Task 6', $board[0]['columns'][2]['tasks'][0]['title']);
+ $this->assertSame(1, $board[1]['id']);
$this->assertEquals('Swimlane 1', $board[1]['name']);
$this->assertCount(4, $board[1]['columns']);
$this->assertEquals(3, $board[1]['nb_swimlanes']);
@@ -117,6 +123,7 @@ class BoardFormatterTest extends Base
$this->assertSame(0, $board[2]['columns'][3]['nb_tasks']);
$this->assertEquals('Task 8', $board[2]['columns'][2]['tasks'][0]['title']);
+ $this->assertArrayHasKey('is_draggable', $board[2]['columns'][2]['tasks'][0]);
}
public function testFormatWithoutDefaultSwimlane()
diff --git a/tests/units/Formatter/TaskAutoCompleteFormatterTest.php b/tests/units/Formatter/TaskAutoCompleteFormatterTest.php
new file mode 100644
index 00000000..20baf549
--- /dev/null
+++ b/tests/units/Formatter/TaskAutoCompleteFormatterTest.php
@@ -0,0 +1,34 @@
+<?php
+
+use Kanboard\Formatter\TaskAutoCompleteFormatter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskAutoCompleteFormatterTest extends Base
+{
+ public function testFormat()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'My Project')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1)));
+
+ $tasks = TaskAutoCompleteFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->format();
+
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('My Project > #1 Task 1', $tasks[0]['label']);
+ $this->assertEquals('Task 1', $tasks[0]['value']);
+ $this->assertEquals(1, $tasks[0]['id']);
+ $this->assertEquals('My Project > #2 Task 2', $tasks[1]['label']);
+ $this->assertEquals('Task 2', $tasks[1]['value']);
+ $this->assertEquals(2, $tasks[1]['id']);
+ }
+}
diff --git a/tests/units/Formatter/TaskSuggestMenuFormatterTest.php b/tests/units/Formatter/TaskSuggestMenuFormatterTest.php
new file mode 100644
index 00000000..d247d670
--- /dev/null
+++ b/tests/units/Formatter/TaskSuggestMenuFormatterTest.php
@@ -0,0 +1,39 @@
+<?php
+
+use Kanboard\Formatter\TaskSuggestMenuFormatter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskSuggestMenuFormatterTest extends Base
+{
+ public function testFormat()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskSuggestMenuFormatter = new TaskSuggestMenuFormatter($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'My Project')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1)));
+
+ $result = $taskSuggestMenuFormatter
+ ->withQuery($this->container['taskFinderModel']->getExtendedQuery())
+ ->format()
+ ;
+
+ $expected = array(
+ array(
+ 'value' => '1',
+ 'html' => '#1 Task 1 <small>My Project</small>',
+ ),
+ array(
+ 'value' => '2',
+ 'html' => '#2 Task 2 <small>My Project</small>',
+ ),
+ );
+
+ $this->assertSame($expected, $result);
+ }
+}
diff --git a/tests/units/Formatter/UserMentionFormatterTest.php b/tests/units/Formatter/UserMentionFormatterTest.php
new file mode 100644
index 00000000..6338e80f
--- /dev/null
+++ b/tests/units/Formatter/UserMentionFormatterTest.php
@@ -0,0 +1,42 @@
+<?php
+
+use Kanboard\Formatter\UserMentionFormatter;
+
+require_once __DIR__.'/../Base.php';
+
+class UserMentionFormatterTest extends Base
+{
+ public function testFormat()
+ {
+ $userMentionFormatter = new UserMentionFormatter($this->container);
+ $users = array(
+ array(
+ 'id' => 1,
+ 'username' => 'someone',
+ 'name' => 'Someone',
+ 'email' => 'test@localhost',
+ 'avatar_path' => 'avatar_image',
+ ),
+ array(
+ 'id' => 2,
+ 'username' => 'somebody',
+ 'name' => '',
+ 'email' => '',
+ 'avatar_path' => '',
+ )
+ );
+
+ $expected = array(
+ array(
+ 'value' => 'someone',
+ 'html' => '<div class="avatar avatar-20 avatar-inline"><img src="?controller=AvatarFileController&amp;action=image&amp;user_id=1&amp;size=20" alt="Someone" title="Someone"></div> someone <small>Someone</small>',
+ ),
+ array(
+ 'value' => 'somebody',
+ 'html' => '<div class="avatar avatar-20 avatar-inline"><div class="avatar-letter" style="background-color: rgb(191, 210, 121)" title="somebody">S</div></div> somebody',
+ ),
+ );
+
+ $this->assertSame($expected, $userMentionFormatter->withUsers($users)->format());
+ }
+}
diff --git a/tests/units/FunctionTest.php b/tests/units/FunctionTest.php
index 1c5f971d..0709f1fb 100644
--- a/tests/units/FunctionTest.php
+++ b/tests/units/FunctionTest.php
@@ -59,6 +59,38 @@ class FunctionTest extends Base
$this->assertSame($expected, array_column_index($input, 'k1'));
}
+ public function testArrayColumnIndexUnique()
+ {
+ $input = array(
+ array(
+ 'k1' => 11,
+ 'k2' => 22,
+ ),
+ array(
+ 'k1' => 11,
+ 'k2' => 55,
+ ),
+ array(
+ 'k1' => 33,
+ 'k2' => 44,
+ ),
+ array()
+ );
+
+ $expected = array(
+ 11 => array(
+ 'k1' => 11,
+ 'k2' => 22,
+ ),
+ 33 => array(
+ 'k1' => 33,
+ 'k2' => 44,
+ )
+ );
+
+ $this->assertSame($expected, array_column_index_unique($input, 'k1'));
+ }
+
public function testArrayMergeRelation()
{
$relations = array(
diff --git a/tests/units/Helper/FileHelperText.php b/tests/units/Helper/FileHelperTest.php
index 215b024b..7db43460 100644
--- a/tests/units/Helper/FileHelperText.php
+++ b/tests/units/Helper/FileHelperTest.php
@@ -30,7 +30,14 @@ class FileHelperTest extends Base
$helper = new FileHelper($this->container);
$this->assertEquals('text', $helper->getPreviewType('test.txt'));
$this->assertEquals('markdown', $helper->getPreviewType('test.markdown'));
- $this->assertEquals('md', $helper->getPreviewType('test.md'));
+ $this->assertEquals('markdown', $helper->getPreviewType('test.md'));
$this->assertEquals(null, $helper->getPreviewType('test.doc'));
}
+
+ public function testGetBrowserViewType()
+ {
+ $fileHelper = new FileHelper($this->container);
+ $this->assertSame('application/pdf', $fileHelper->getBrowserViewType('SomeFile.PDF'));
+ $this->assertSame(null, $fileHelper->getBrowserViewType('SomeFile.doc'));
+ }
}
diff --git a/tests/units/Helper/HookHelperTest.php b/tests/units/Helper/HookHelperTest.php
index 6e03acd1..a67eaed9 100644
--- a/tests/units/Helper/HookHelperTest.php
+++ b/tests/units/Helper/HookHelperTest.php
@@ -6,6 +6,79 @@ use Kanboard\Helper\HookHelper;
class HookHelperTest extends Base
{
+ public function testAttachCallable()
+ {
+ $this->container['template'] = $this
+ ->getMockBuilder('\Kanboard\Core\Template')
+ ->setConstructorArgs(array($this->container['helper']))
+ ->setMethods(array('render'))
+ ->getMock();
+
+ $this->container['template']
+ ->expects($this->once())
+ ->method('render')
+ ->with(
+ $this->equalTo('tpl1'),
+ $this->equalTo(array('k0' => 'v0', 'k1' => 'v1'))
+ )
+ ->will($this->returnValue('tpl1_content'));
+
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attachCallable('test', 'tpl1', function() {
+ return array(
+ 'k1' => 'v1',
+ );
+ });
+
+ $this->assertEquals('tpl1_content', $hookHelper->render('test', array('k0' => 'v0')));
+ }
+
+ public function testAttachCallableWithNoResult()
+ {
+ $this->container['template'] = $this
+ ->getMockBuilder('\Kanboard\Core\Template')
+ ->setConstructorArgs(array($this->container['helper']))
+ ->setMethods(array('render'))
+ ->getMock();
+
+ $this->container['template']
+ ->expects($this->once())
+ ->method('render')
+ ->with(
+ $this->equalTo('tpl1'),
+ $this->equalTo(array('k0' => 'v0'))
+ )
+ ->will($this->returnValue('tpl1_content'));
+
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attachCallable('test', 'tpl1', function() {
+ });
+
+ $this->assertEquals('tpl1_content', $hookHelper->render('test', array('k0' => 'v0')));
+ }
+
+ public function testAttachLocalVariables()
+ {
+ $this->container['template'] = $this
+ ->getMockBuilder('\Kanboard\Core\Template')
+ ->setConstructorArgs(array($this->container['helper']))
+ ->setMethods(array('render'))
+ ->getMock();
+
+ $this->container['template']
+ ->expects($this->once())
+ ->method('render')
+ ->with(
+ $this->equalTo('tpl1'),
+ $this->equalTo(array('k0' => 'v0', 'k1' => 'v1'))
+ )
+ ->will($this->returnValue('tpl1_content'));
+
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attach('test', 'tpl1', array('k1' => 'v1'));
+ $this->assertEquals('tpl1_content', $hookHelper->render('test', array('k0' => 'v0')));
+ }
+
public function testMultipleHooks()
{
$this->container['template'] = $this
@@ -32,10 +105,10 @@ class HookHelperTest extends Base
)
->will($this->returnValue('tpl2_content'));
- $h = new HookHelper($this->container);
- $h->attach('test', 'tpl1');
- $h->attach('test', 'tpl2');
- $this->assertEquals('tpl1_contenttpl2_content', $h->render('test'));
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attach('test', 'tpl1');
+ $hookHelper->attach('test', 'tpl2');
+ $this->assertEquals('tpl1_contenttpl2_content', $hookHelper->render('test'));
}
public function testAssetHooks()
@@ -64,11 +137,11 @@ class HookHelperTest extends Base
)
->will($this->returnValue('<script src="skin.js"></script>'));
- $h = new HookHelper($this->container);
- $h->attach('test1', 'skin.css');
- $h->attach('test2', 'skin.js');
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attach('test1', 'skin.css');
+ $hookHelper->attach('test2', 'skin.js');
- $this->assertContains('<link rel="stylesheet" href="skin.css"></link>', $h->asset('css', 'test1'));
- $this->assertContains('<script src="skin.js"></script>', $h->asset('js', 'test2'));
+ $this->assertContains('<link rel="stylesheet" href="skin.css"></link>', $hookHelper->asset('css', 'test1'));
+ $this->assertContains('<script src="skin.js"></script>', $hookHelper->asset('js', 'test2'));
}
}
diff --git a/tests/units/Helper/ProjectRoleHelperTest.php b/tests/units/Helper/ProjectRoleHelperTest.php
new file mode 100644
index 00000000..eb9b320c
--- /dev/null
+++ b/tests/units/Helper/ProjectRoleHelperTest.php
@@ -0,0 +1,375 @@
+<?php
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Core\User\UserSession;
+use Kanboard\Helper\ProjectRoleHelper;
+use Kanboard\Model\ColumnMoveRestrictionModel;
+use Kanboard\Model\ColumnRestrictionModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectRoleModel;
+use Kanboard\Model\ProjectRoleRestrictionModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskStatusModel;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectRoleHelperTest extends Base
+{
+ public function testCanCreateTaskInColumnWithProjectViewer()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_VIEWER));
+
+ $this->assertFalse($projectRoleHelper->canCreateTaskInColumn(1, 1));
+ }
+
+ public function testCanCreateTaskInColumnWithProjectMember()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER));
+
+ $this->assertTrue($projectRoleHelper->canCreateTaskInColumn(1, 1));
+ }
+
+ public function testCanCreateTaskInColumnWithCustomProjectRole()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertTrue($projectRoleHelper->canCreateTaskInColumn(1, 1));
+ }
+
+ public function testCanCreateTaskInColumnWithCustomProjectRoleAndRestrictions()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+ $columnRestrictionModel = new ColumnRestrictionModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_CREATION));
+ $this->assertEquals(1, $columnRestrictionModel->create(1, 1, 1, ColumnRestrictionModel::RULE_ALLOW_TASK_CREATION));
+
+ $this->assertTrue($projectRoleHelper->canCreateTaskInColumn(1, 1));
+ $this->assertFalse($projectRoleHelper->canCreateTaskInColumn(1, 2));
+ }
+
+ public function testCanChangeTaskStatusInColumnWithProjectViewer()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_VIEWER));
+
+ $this->assertFalse($projectRoleHelper->canChangeTaskStatusInColumn(1, 1));
+ }
+
+ public function testCanChangeTaskStatusInColumnWithProjectMember()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER));
+
+ $this->assertTrue($projectRoleHelper->canChangeTaskStatusInColumn(1, 1));
+ }
+
+ public function testCanChangeTaskStatusInColumnWithCustomProjectRole()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertTrue($projectRoleHelper->canChangeTaskStatusInColumn(1, 1));
+ }
+
+ public function testCanChangeTaskStatusInColumnWithCustomProjectRoleAndRestrictions()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+ $columnRestrictionModel = new ColumnRestrictionModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_OPEN_CLOSE));
+ $this->assertEquals(1, $columnRestrictionModel->create(1, 1, 1, ColumnRestrictionModel::RULE_ALLOW_TASK_OPEN_CLOSE));
+
+ $this->assertTrue($projectRoleHelper->canChangeTaskStatusInColumn(1, 1));
+ $this->assertFalse($projectRoleHelper->canChangeTaskStatusInColumn(1, 2));
+ }
+
+ public function testIsDraggableWithProjectMember()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertTrue($projectRoleHelper->isDraggable($task));
+ }
+
+ public function testIsDraggableWithClosedTask()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertTrue($taskStatusModel->close(1));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertFalse($projectRoleHelper->isDraggable($task));
+ }
+
+ public function testIsDraggableWithColumnRestrictions()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 3)));
+ $this->assertEquals(4, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 4)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertFalse($projectRoleHelper->isDraggable($task));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertTrue($projectRoleHelper->isDraggable($task));
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertTrue($projectRoleHelper->isDraggable($task));
+
+ $task = $taskFinderModel->getById(4);
+ $this->assertFalse($projectRoleHelper->isDraggable($task));
+ }
+
+ public function testCanRemoveTask()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $userModel = new UserModel($this->container);
+ $userSessionModel = new UserSession($this->container);
+
+ $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456')));
+ $this->assertNotFalse($userModel->create(array('username' => 'toto2', 'password' => '123456')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'TaskViewController #1', 'project_id' => 1, 'creator_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'TaskViewController #2', 'project_id' => 1, 'creator_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'TaskViewController #3', 'project_id' => 1, 'creator_id' => 3)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'TaskViewController #4', 'project_id' => 1)));
+
+ // User #1 can remove everything
+ $user = $userModel->getById(1);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($projectRoleHelper->canRemoveTask($task));
+
+ // User #2 can't remove the TaskViewController #1
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertFalse($projectRoleHelper->canRemoveTask($task));
+
+ // User #1 can remove everything
+ $user = $userModel->getById(1);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($projectRoleHelper->canRemoveTask($task));
+
+ // User #2 can remove his own TaskViewController
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($projectRoleHelper->canRemoveTask($task));
+
+ // User #1 can remove everything
+ $user = $userModel->getById(1);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($projectRoleHelper->canRemoveTask($task));
+
+ // User #2 can't remove the TaskViewController #3
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertFalse($projectRoleHelper->canRemoveTask($task));
+
+ // User #1 can remove everything
+ $user = $userModel->getById(1);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(4);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($projectRoleHelper->canRemoveTask($task));
+
+ // User #2 can't remove the TaskViewController #4
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(4);
+ $this->assertNotEmpty($task);
+ $this->assertFalse($projectRoleHelper->canRemoveTask($task));
+ }
+}
diff --git a/tests/units/Helper/TaskHelperTest.php b/tests/units/Helper/TaskHelperTest.php
index 454da553..8609983e 100644
--- a/tests/units/Helper/TaskHelperTest.php
+++ b/tests/units/Helper/TaskHelperTest.php
@@ -9,8 +9,9 @@ class TaskHelperTest extends Base
public function testSelectPriority()
{
$helper = new TaskHelper($this->container);
- $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array()));
- $this->assertEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array()));
+ $this->assertNotEmpty($helper->renderPriorityField(array('priority_end' => '1', 'priority_start' => '5', 'priority_default' => '2'), array()));
+ $this->assertNotEmpty($helper->renderPriorityField(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array()));
+ $this->assertEmpty($helper->renderPriorityField(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array()));
}
public function testFormatPriority()
diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php
index c9447abb..5c8a10f6 100644
--- a/tests/units/Helper/TextHelperTest.php
+++ b/tests/units/Helper/TextHelperTest.php
@@ -5,12 +5,13 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Helper\TextHelper;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\UserModel;
class TextHelperTest extends Base
{
public function testMarkdownTaskLink()
{
- $helper = new TextHelper($this->container);
+ $textHelper = new TextHelper($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
@@ -19,26 +20,26 @@ class TextHelperTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
$project = $projectModel->getById(1);
- $this->assertEquals('<p>Test</p>', $helper->markdown('Test'));
+ $this->assertEquals('<p>Test</p>', $textHelper->markdown('Test'));
$this->assertEquals(
'<p>Task <a href="?controller=TaskViewController&amp;action=show&amp;task_id=123">#123</a></p>',
- $helper->markdown('Task #123')
+ $textHelper->markdown('Task #123')
);
$this->assertEquals(
'<p>Task #123</p>',
- $helper->markdown('Task #123', true)
+ $textHelper->markdown('Task #123', true)
);
$this->assertEquals(
- '<p>Task <a href="?controller=TaskViewController&amp;action=readonly&amp;token='.$project['token'].'&amp;task_id=1">#1</a></p>',
- $helper->markdown('Task #1', true)
+ '<p>Task <a href="http://localhost/?controller=TaskViewController&amp;action=readonly&amp;token='.$project['token'].'&amp;task_id=1">#1</a></p>',
+ $textHelper->markdown('Task #1', true)
);
$this->assertEquals(
'<p>Check that: <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454</a></p>',
- $helper->markdown(
+ $textHelper->markdown(
'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454'
)
);
@@ -46,39 +47,82 @@ class TextHelperTest extends Base
public function testMarkdownUserLink()
{
- $h = new TextHelper($this->container);
- $this->assertEquals('<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound'));
- $this->assertEquals('<p>Text @admin @notfound</p>', $h->markdown('Text @admin @notfound', true));
+ $textHelper = new TextHelper($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'firstname.lastname', 'name' => 'Firstname Lastname')));
+
+ $this->assertEquals(
+ '<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link" title="admin">@admin</a> @notfound</p>',
+ $textHelper->markdown('Text @admin @notfound')
+ );
+
+ $this->assertEquals(
+ '<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link" title="admin">@admin</a>,</p>',
+ $textHelper->markdown('Text @admin,')
+ );
+
+ $this->assertEquals(
+ '<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link" title="admin">@admin</a>!</p>',
+ $textHelper->markdown('Text @admin!')
+ );
+
+ $this->assertEquals(
+ '<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link" title="admin">@admin</a>? </p>',
+ $textHelper->markdown('Text @admin? ')
+ );
+
+ $this->assertEquals(
+ '<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link" title="admin">@admin</a>.</p>',
+ $textHelper->markdown('Text @admin.')
+ );
+
+ $this->assertEquals(
+ '<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link" title="admin">@admin</a>: test</p>',
+ $textHelper->markdown('Text @admin: test')
+ );
+
+ $this->assertEquals(
+ '<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link" title="admin">@admin</a>: test</p>',
+ $textHelper->markdown('Text @admin: test')
+ );
+
+ $this->assertEquals(
+ '<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=2" class="user-mention-link" title="Firstname Lastname">@firstname.lastname</a>. test</p>',
+ $textHelper->markdown('Text @firstname.lastname. test')
+ );
+
+ $this->assertEquals('<p>Text @admin @notfound</p>', $textHelper->markdown('Text @admin @notfound', true));
}
public function testMarkdownAttribute()
{
- $helper = new TextHelper($this->container);
- $this->assertEquals('&lt;p&gt;&Ccedil;a marche&lt;/p&gt;', $helper->markdownAttribute('Ça marche'));
- $this->assertEquals('&lt;p&gt;Test with &amp;quot;double quotes&amp;quot;&lt;/p&gt;', $helper->markdownAttribute('Test with "double quotes"'));
- $this->assertEquals('&lt;p&gt;Test with &#039;single quotes&#039;&lt;/p&gt;', $helper->markdownAttribute("Test with 'single quotes'"));
+ $textHelper = new TextHelper($this->container);
+ $this->assertEquals('&lt;p&gt;&Ccedil;a marche&lt;/p&gt;', $textHelper->markdownAttribute('Ça marche'));
+ $this->assertEquals('&lt;p&gt;Test with &amp;quot;double quotes&amp;quot;&lt;/p&gt;', $textHelper->markdownAttribute('Test with "double quotes"'));
+ $this->assertEquals('&lt;p&gt;Test with &#039;single quotes&#039;&lt;/p&gt;', $textHelper->markdownAttribute("Test with 'single quotes'"));
}
public function testFormatBytes()
{
- $h = new TextHelper($this->container);
+ $textHelper = new TextHelper($this->container);
- $this->assertEquals('1k', $h->bytes(1024));
- $this->assertEquals('33.71k', $h->bytes(34520));
+ $this->assertEquals('1k', $textHelper->bytes(1024));
+ $this->assertEquals('33.71k', $textHelper->bytes(34520));
}
public function testContains()
{
- $h = new TextHelper($this->container);
+ $textHelper = new TextHelper($this->container);
- $this->assertTrue($h->contains('abc', 'b'));
- $this->assertFalse($h->contains('abc', 'd'));
+ $this->assertTrue($textHelper->contains('abc', 'b'));
+ $this->assertFalse($textHelper->contains('abc', 'd'));
}
public function testInList()
{
- $h = new TextHelper($this->container);
- $this->assertEquals('?', $h->in('a', array('b' => 'c')));
- $this->assertEquals('c', $h->in('b', array('b' => 'c')));
+ $textHelper = new TextHelper($this->container);
+ $this->assertEquals('?', $textHelper->in('a', array('b' => 'c')));
+ $this->assertEquals('c', $textHelper->in('b', array('b' => 'c')));
}
}
diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php
index d5bd1789..b66acdba 100644
--- a/tests/units/Helper/UserHelperTest.php
+++ b/tests/units/Helper/UserHelperTest.php
@@ -5,6 +5,7 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Core\User\UserSession;
use Kanboard\Helper\UserHelper;
use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectRoleModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -13,6 +14,21 @@ use Kanboard\Model\UserModel;
class UserHelperTest extends Base
{
+ public function testGetFullname()
+ {
+ $userModel = new UserModel($this->container);
+ $userHelper = new UserHelper($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User #2')));
+
+ $user1 = $userModel->getById(2);
+ $user2 = $userModel->getById(3);
+
+ $this->assertEquals('user1', $userHelper->getFullname($user1));
+ $this->assertEquals('User #2', $userHelper->getFullname($user2));
+ }
+
public function testInitials()
{
$helper = new UserHelper($this->container);
@@ -248,93 +264,34 @@ class UserHelperTest extends Base
$this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2));
}
- public function testCanRemoveTask()
+ public function testHasProjectAccessForCustomProjectRole()
{
- $taskCreationModel = new TaskCreationModel($this->container);
- $taskFinderModel = new TaskFinderModel($this->container);
$helper = new UserHelper($this->container);
- $projectModel = new ProjectModel($this->container);
- $userModel = new UserModel($this->container);
- $userSessionModel = new UserSession($this->container);
-
- $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456')));
- $this->assertNotFalse($userModel->create(array('username' => 'toto2', 'password' => '123456')));
- $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'TaskViewController #1', 'project_id' => 1, 'creator_id' => 1)));
- $this->assertEquals(2, $taskCreationModel->create(array('title' => 'TaskViewController #2', 'project_id' => 1, 'creator_id' => 2)));
- $this->assertEquals(3, $taskCreationModel->create(array('title' => 'TaskViewController #3', 'project_id' => 1, 'creator_id' => 3)));
- $this->assertEquals(4, $taskCreationModel->create(array('title' => 'TaskViewController #4', 'project_id' => 1)));
-
- // User #1 can remove everything
- $user = $userModel->getById(1);
- $this->assertNotEmpty($user);
- $userSessionModel->initialize($user);
-
- $task = $taskFinderModel->getById(1);
- $this->assertNotEmpty($task);
- $this->assertTrue($helper->canRemoveTask($task));
-
- // User #2 can't remove the TaskViewController #1
- $user = $userModel->getById(2);
- $this->assertNotEmpty($user);
- $userSessionModel->initialize($user);
-
- $task = $taskFinderModel->getById(1);
- $this->assertNotEmpty($task);
- $this->assertFalse($helper->canRemoveTask($task));
-
- // User #1 can remove everything
- $user = $userModel->getById(1);
- $this->assertNotEmpty($user);
- $userSessionModel->initialize($user);
-
- $task = $taskFinderModel->getById(2);
- $this->assertNotEmpty($task);
- $this->assertTrue($helper->canRemoveTask($task));
-
- // User #2 can remove his own TaskViewController
- $user = $userModel->getById(2);
- $this->assertNotEmpty($user);
- $userSessionModel->initialize($user);
-
- $task = $taskFinderModel->getById(2);
- $this->assertNotEmpty($task);
- $this->assertTrue($helper->canRemoveTask($task));
-
- // User #1 can remove everything
- $user = $userModel->getById(1);
- $this->assertNotEmpty($user);
- $userSessionModel->initialize($user);
-
- $task = $taskFinderModel->getById(3);
- $this->assertNotEmpty($task);
- $this->assertTrue($helper->canRemoveTask($task));
-
- // User #2 can't remove the TaskViewController #3
- $user = $userModel->getById(2);
- $this->assertNotEmpty($user);
- $userSessionModel->initialize($user);
-
- $task = $taskFinderModel->getById(3);
- $this->assertNotEmpty($task);
- $this->assertFalse($helper->canRemoveTask($task));
-
- // User #1 can remove everything
- $user = $userModel->getById(1);
- $this->assertNotEmpty($user);
- $userSessionModel->initialize($user);
-
- $task = $taskFinderModel->getById(4);
- $this->assertNotEmpty($task);
- $this->assertTrue($helper->canRemoveTask($task));
-
- // User #2 can't remove the TaskViewController #4
- $user = $userModel->getById(2);
- $this->assertNotEmpty($user);
- $userSessionModel->initialize($user);
-
- $task = $taskFinderModel->getById(4);
- $this->assertNotEmpty($task);
- $this->assertFalse($helper->canRemoveTask($task));
+ $user = new UserModel($this->container);
+ $project = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $projectRole = new ProjectRoleModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(1, $project->create(array('name' => 'My project')));
+ $this->assertEquals(2, $project->create(array('name' => 'My project')));
+ $this->assertEquals(2, $user->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectRole->create(1, 'Custom Role'));
+
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1));
+ $this->assertTrue($helper->hasProjectAccess('BoardViewController', 'show', 1));
+ $this->assertTrue($helper->hasProjectAccess('TaskViewController', 'show', 1));
+ $this->assertTrue($helper->hasProjectAccess('TaskCreationController', 'save', 1));
+
+ $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 2));
+ $this->assertFalse($helper->hasProjectAccess('BoardViewController', 'show', 2));
+ $this->assertFalse($helper->hasProjectAccess('TaskViewController', 'show', 2));
+ $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2));
}
}
diff --git a/tests/units/Job/CommentEventJobTest.php b/tests/units/Job/CommentEventJobTest.php
new file mode 100644
index 00000000..b830b2b8
--- /dev/null
+++ b/tests/units/Job/CommentEventJobTest.php
@@ -0,0 +1,94 @@
+<?php
+
+use Kanboard\Job\CommentEventJob;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class CommentEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $commentEventJob = new CommentEventJob($this->container);
+ $commentEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $commentEventJob->getJobParams());
+ }
+
+ public function testWithMissingComment()
+ {
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {});
+
+ $commentEventJob = new CommentEventJob($this->container);
+ $commentEventJob->execute(42, CommentModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_DELETE, function() {});
+
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'foobar', 'user_id' => 1)));
+ $this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'test')));
+ $this->assertTrue($commentModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(CommentModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(CommentModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(CommentModel::EVENT_DELETE.'.closure', $called);
+ }
+
+ public function testThatUserMentionJobIsCalled()
+ {
+ $comment = 'some comment';
+
+ $this->container['queueManager'] = $this
+ ->getMockBuilder('\Kanboard\Core\Queue\QueueManager')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array(
+ 'push',
+ ))
+ ->getMock();
+
+ $this->container['userMentionJob'] = $this
+ ->getMockBuilder('\Kanboard\Job\UserMentionJob')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array(
+ 'withParams',
+ ))
+ ->getMock();
+
+ $this->container['queueManager']
+ ->expects($this->any())
+ ->method('push');
+
+ $this->container['userMentionJob']
+ ->expects($this->once())
+ ->method('withParams')
+ ->with($comment, CommentModel::EVENT_USER_MENTION, $this->anything())
+ ->will($this->returnValue($this->container['userMentionJob']));
+
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $commentEventJob = new CommentEventJob($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => $comment, 'user_id' => 1)));
+
+ $commentEventJob->execute(1, CommentModel::EVENT_CREATE);
+ }
+}
diff --git a/tests/units/Job/ProjectFileEventJobTest.php b/tests/units/Job/ProjectFileEventJobTest.php
new file mode 100644
index 00000000..f266d293
--- /dev/null
+++ b/tests/units/Job/ProjectFileEventJobTest.php
@@ -0,0 +1,43 @@
+<?php
+
+use Kanboard\Job\ProjectFileEventJob;
+use Kanboard\Model\ProjectFileModel;
+use Kanboard\Model\ProjectModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectFileEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $projectFileEventJob = new ProjectFileEventJob($this->container);
+ $projectFileEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $projectFileEventJob->getJobParams());
+ }
+
+ public function testWithMissingFile()
+ {
+ $this->container['dispatcher']->addListener(ProjectFileModel::EVENT_CREATE, function() {});
+
+ $projectFileEventJob = new ProjectFileEventJob($this->container);
+ $projectFileEventJob->execute(42, ProjectFileModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(ProjectFileModel::EVENT_CREATE, function() {});
+
+ $projectModel = new ProjectModel($this->container);
+ $projectFileModel = new ProjectFileModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $projectFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(ProjectFileModel::EVENT_CREATE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/ProjectMetricJobTest.php b/tests/units/Job/ProjectMetricJobTest.php
new file mode 100644
index 00000000..e5b0474d
--- /dev/null
+++ b/tests/units/Job/ProjectMetricJobTest.php
@@ -0,0 +1,47 @@
+<?php
+
+use Kanboard\Job\ProjectMetricJob;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectMetricJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $projectMetricJob = new ProjectMetricJob($this->container);
+ $projectMetricJob->withParams(123);
+
+ $this->assertSame(
+ array(123),
+ $projectMetricJob->getJobParams()
+ );
+ }
+
+ public function testJob()
+ {
+ $this->container['projectDailyColumnStatsModel'] = $this
+ ->getMockBuilder('\Kanboard\Model\ProjectDailyColumnStatsModel')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('updateTotals'))
+ ->getMock();
+
+ $this->container['projectDailyStatsModel'] = $this
+ ->getMockBuilder('\Kanboard\Model\ProjectDailyStatsModel')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('updateTotals'))
+ ->getMock();
+
+ $this->container['projectDailyColumnStatsModel']
+ ->expects($this->once())
+ ->method('updateTotals')
+ ->with(42, date('Y-m-d'));
+
+ $this->container['projectDailyStatsModel']
+ ->expects($this->once())
+ ->method('updateTotals')
+ ->with(42, date('Y-m-d'));
+
+ $job = new ProjectMetricJob($this->container);
+ $job->execute(42);
+ }
+}
diff --git a/tests/units/Job/SubtaskEventJobTest.php b/tests/units/Job/SubtaskEventJobTest.php
new file mode 100644
index 00000000..bdc30b51
--- /dev/null
+++ b/tests/units/Job/SubtaskEventJobTest.php
@@ -0,0 +1,52 @@
+<?php
+
+use Kanboard\Job\SubtaskEventJob;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $subtaskEventJob = new SubtaskEventJob($this->container);
+ $subtaskEventJob->withParams(123, 'foobar', array('k' => 'v'));
+
+ $this->assertSame(array(123, 'foobar', array('k' => 'v')), $subtaskEventJob->getJobParams());
+ }
+
+ public function testWithMissingSubtask()
+ {
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});
+
+ $subtaskEventJob = new SubtaskEventJob($this->container);
+ $subtaskEventJob->execute(42, SubtaskModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, function() {});
+
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($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' => 'before')));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'title' => 'after')));
+ $this->assertTrue($subtaskModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(SubtaskModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(SubtaskModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(SubtaskModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/TaskEventJobTest.php b/tests/units/Job/TaskEventJobTest.php
new file mode 100644
index 00000000..bfd7bc55
--- /dev/null
+++ b/tests/units/Job/TaskEventJobTest.php
@@ -0,0 +1,229 @@
+<?php
+
+use Kanboard\Job\TaskEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskModificationModel;
+use Kanboard\Model\TaskPositionModel;
+use Kanboard\Model\TaskProjectMoveModel;
+use Kanboard\Model\TaskStatusModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskEventJob = new TaskEventJob($this->container);
+ $taskEventJob->withParams(123, array('foobar'), array('k' => 'v'), array('k1' => 'v1'), array('k2' => 'v2'));
+
+ $this->assertSame(
+ array(123, array('foobar'), array('k' => 'v'), array('k1' => 'v1'), array('k2' => 'v2')),
+ $taskEventJob->getJobParams()
+ );
+ }
+
+ public function testWithMissingTask()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function() {});
+
+ $taskEventJob = new TaskEventJob($this->container);
+ $taskEventJob->execute(42, array(TaskModel::EVENT_CREATE));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerCreateEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerUpdateEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'new title')));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerAssigneeChangeEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_ASSIGNEE_CHANGE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'owner_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_ASSIGNEE_CHANGE.'.closure', $called);
+ }
+
+ public function testTriggerCloseEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CLOSE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskStatusModel->close(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CLOSE.'.closure', $called);
+ }
+
+ public function testTriggerOpenEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_OPEN, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskStatusModel->close(1));
+ $this->assertTrue($taskStatusModel->open(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_OPEN.'.closure', $called);
+ }
+
+ public function testTriggerMovePositionEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_POSITION, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.closure', $called);
+ }
+
+ public function testTriggerMoveColumnEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_COLUMN, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.closure', $called);
+ }
+
+ public function testTriggerMoveSwimlaneEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_SWIMLANE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('name' => 'S1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 1, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.closure', $called);
+ }
+
+ public function testTriggerMoveProjectEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.closure', $called);
+ }
+
+ public function testThatUserMentionJobIsCalled()
+ {
+ $description = 'something';
+
+ $this->container['queueManager'] = $this
+ ->getMockBuilder('\Kanboard\Core\Queue\QueueManager')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array(
+ 'push',
+ ))
+ ->getMock();
+
+ $this->container['userMentionJob'] = $this
+ ->getMockBuilder('\Kanboard\Job\UserMentionJob')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array(
+ 'withParams',
+ ))
+ ->getMock();
+
+ $this->container['queueManager']
+ ->expects($this->any())
+ ->method('push');
+
+ $this->container['userMentionJob']
+ ->expects($this->once())
+ ->method('withParams')
+ ->with($description, TaskModel::EVENT_USER_MENTION, $this->anything())
+ ->will($this->returnValue($this->container['userMentionJob']));
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventJob = new TaskEventJob($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'description' => $description, 'project_id' => 1)));
+
+ $taskEventJob->execute(1, array(TaskModel::EVENT_CREATE));
+ }
+}
diff --git a/tests/units/Job/TaskFileEventJobTest.php b/tests/units/Job/TaskFileEventJobTest.php
new file mode 100644
index 00000000..921fe801
--- /dev/null
+++ b/tests/units/Job/TaskFileEventJobTest.php
@@ -0,0 +1,46 @@
+<?php
+
+use Kanboard\Job\TaskFileEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFileModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskFileEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskFileEventJob = new TaskFileEventJob($this->container);
+ $taskFileEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $taskFileEventJob->getJobParams());
+ }
+
+ public function testWithMissingFile()
+ {
+ $this->container['dispatcher']->addListener(TaskFileModel::EVENT_CREATE, function() {});
+
+ $taskFileEventJob = new TaskFileEventJob($this->container);
+ $taskFileEventJob->execute(42, TaskFileModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskFileModel::EVENT_CREATE, function() {});
+
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskFileModel::EVENT_CREATE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/TaskLinkEventJobTest.php b/tests/units/Job/TaskLinkEventJobTest.php
new file mode 100644
index 00000000..1949316a
--- /dev/null
+++ b/tests/units/Job/TaskLinkEventJobTest.php
@@ -0,0 +1,65 @@
+<?php
+
+use Kanboard\Job\TaskLinkEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskLinkModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskLinkEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskLinkEventJob = new TaskLinkEventJob($this->container);
+ $taskLinkEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $taskLinkEventJob->getJobParams());
+ }
+
+ public function testWithMissingLink()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskLinkEventJob = new TaskLinkEventJob($this->container);
+ $taskLinkEventJob->execute(42, TaskLinkModel::EVENT_CREATE_UPDATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerCreationEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskLinkModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerDeleteEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_DELETE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+ $this->assertTrue($taskLinkModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskLinkModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Model/UserMentionTest.php b/tests/units/Job/UserMentionJobTest.php
index b41c92cd..04ffa0d3 100644
--- a/tests/units/Model/UserMentionTest.php
+++ b/tests/units/Job/UserMentionJobTest.php
@@ -1,45 +1,44 @@
<?php
-require_once __DIR__.'/../Base.php';
-
use Kanboard\Core\Security\Role;
-use Kanboard\Event\GenericEvent;
-use Kanboard\Model\UserModel;
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\TaskCreationModel;
+use Kanboard\Event\TaskEvent;
+use Kanboard\Job\UserMentionJob;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectUserRoleModel;
-use Kanboard\Model\UserMentionModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
-class UserMentionTest extends Base
+class UserMentionJobTest extends Base
{
public function testGetMentionedUsersWithNoMentions()
{
$userModel = new UserModel($this->container);
- $userMentionModel = new UserMentionModel($this->container);
+ $userMentionJob = new UserMentionJob($this->container);
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
- $this->assertEmpty($userMentionModel->getMentionedUsers('test'));
+ $this->assertEmpty($userMentionJob->getMentionedUsers('test'));
}
public function testGetMentionedUsersWithNotficationDisabled()
{
$userModel = new UserModel($this->container);
- $userMentionModel = new UserMentionModel($this->container);
+ $userMentionJob = new UserMentionJob($this->container);
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
- $this->assertEmpty($userMentionModel->getMentionedUsers('test @user1'));
+ $this->assertEmpty($userMentionJob->getMentionedUsers('test @user1'));
}
public function testGetMentionedUsersWithNotficationEnabled()
{
$userModel = new UserModel($this->container);
- $userMentionModel = new UserMentionModel($this->container);
+ $userMentionJob = new UserMentionJob($this->container);
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
$this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1)));
- $users = $userMentionModel->getMentionedUsers('test @user2');
+ $users = $userMentionJob->getMentionedUsers('test @user2');
$this->assertCount(1, $users);
$this->assertEquals('user2', $users[0]['username']);
$this->assertEquals('Foobar', $users[0]['name']);
@@ -47,48 +46,47 @@ class UserMentionTest extends Base
$this->assertEquals('', $users[0]['language']);
}
- public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn()
+ public function testGetMentionedUsersWithNotficationEnabledAndPunctuationMarks()
{
- $this->container['sessionStorage']->user = array('id' => 3);
$userModel = new UserModel($this->container);
- $userMentionModel = new UserMentionModel($this->container);
+ $userMentionJob = new UserMentionJob($this->container);
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
$this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($userModel->create(array('username' => 'user3.with.dot', 'notifications_enabled' => 1)));
+
+ $users = $userMentionJob->getMentionedUsers('test @user2, test, @user3.with.dot.');
+ $this->assertCount(2, $users);
+ $this->assertEquals('user2', $users[0]['username']);
+ $this->assertEquals('Foobar', $users[0]['name']);
+ $this->assertEquals('', $users[0]['email']);
+ $this->assertEquals('', $users[0]['language']);
- $this->assertEmpty($userMentionModel->getMentionedUsers('test @user2'));
+ $this->assertEquals('user3.with.dot', $users[1]['username']);
+ $this->assertEquals('', $users[1]['name']);
+ $this->assertEquals('', $users[1]['email']);
+ $this->assertEquals('', $users[1]['language']);
}
- public function testFireEventsWithMultipleMentions()
+ public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn()
{
- $projectUserRoleModel = new ProjectUserRoleModel($this->container);
- $projectModel = new ProjectModel($this->container);
+ $this->container['sessionStorage']->user = array('id' => 3);
$userModel = new UserModel($this->container);
- $userMentionModel = new UserMentionModel($this->container);
- $event = new GenericEvent(array('project_id' => 1));
-
- $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1)));
- $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1)));
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
- $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
-
- $this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention'));
+ $userMentionJob = new UserMentionJob($this->container);
- $userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1)));
- $called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called);
+ $this->assertEmpty($userMentionJob->getMentionedUsers('test @user2'));
}
- public function testFireEventsWithNoProjectId()
+ public function testFireEventsWithMultipleMentions()
{
$projectUserRoleModel = new ProjectUserRoleModel($this->container);
$projectModel = new ProjectModel($this->container);
- $taskCreationModel = new TaskCreationModel($this->container);
$userModel = new UserModel($this->container);
- $userMentionModel = new UserMentionModel($this->container);
- $event = new GenericEvent(array('task_id' => 1));
+ $userMentionJob = new UserMentionJob($this->container);
+ $event = new TaskEvent(array('task' => array('project_id' => 1)));
$this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1)));
$this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1)));
@@ -96,14 +94,12 @@ class UserMentionTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
$this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'Task 1')));
-
$this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention'));
- $userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event);
+ $userMentionJob->execute('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event->getAll());
$called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionJobTest::onUserMention', $called);
}
public function onUserMention($event)
diff --git a/tests/units/Locale/LocaleTest.php b/tests/units/Locale/LocaleTest.php
index 976dfc58..c10b1bc9 100644
--- a/tests/units/Locale/LocaleTest.php
+++ b/tests/units/Locale/LocaleTest.php
@@ -10,13 +10,7 @@ class LocaleTest extends Base
$locale = require($file . '/translations.php');
foreach ($locale as $k => $v) {
- if (strpos($k, '%B %e, %Y') !== false) {
- continue;
- }
-
- if (strpos($k, '%b %e, %Y') !== false) {
- continue;
- }
+ $this->assertNotEmpty($v, 'Empty value for the key "'.$k.'" in translation '.basename($file));
foreach (array('%s', '%d') as $placeholder) {
$this->assertEquals(
diff --git a/tests/units/Model/ColumnMoveRestrictionModelTest.php b/tests/units/Model/ColumnMoveRestrictionModelTest.php
new file mode 100644
index 00000000..0fc1d470
--- /dev/null
+++ b/tests/units/Model/ColumnMoveRestrictionModelTest.php
@@ -0,0 +1,92 @@
+<?php
+
+use Kanboard\Model\ColumnMoveRestrictionModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectRoleModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ColumnMoveRestrictionModelTest extends Base
+{
+ public function testCreation()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+ $this->assertFalse($columnMoveRestrictionModel->create(1, 1, 2, 3));
+ }
+
+ public function testRemove()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+ $this->assertTrue($columnMoveRestrictionModel->remove(1));
+ }
+
+ public function testGetById()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+
+ $restriction = $columnMoveRestrictionModel->getById(1, 1);
+ $this->assertEquals(1, $restriction['restriction_id']);
+ $this->assertEquals('Role A', $restriction['role']);
+ $this->assertEquals(1, $restriction['role_id']);
+ $this->assertEquals(1, $restriction['project_id']);
+ $this->assertEquals('Ready', $restriction['src_column_title']);
+ $this->assertEquals('Work in progress', $restriction['dst_column_title']);
+ $this->assertEquals(2, $restriction['src_column_id']);
+ $this->assertEquals(3, $restriction['dst_column_id']);
+ }
+
+ public function testGetAll()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Test')));
+
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertEquals(2, $projectRoleModel->create(1, 'Role B'));
+ $this->assertEquals(3, $projectRoleModel->create(2, 'Role C'));
+
+ $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+ $this->assertEquals(2, $columnMoveRestrictionModel->create(1, 2, 3, 4));
+
+ $restrictions = $columnMoveRestrictionModel->getAll(1);
+ $this->assertCount(2, $restrictions);
+
+ $this->assertEquals(1, $restrictions[0]['restriction_id']);
+ $this->assertEquals('Role A', $restrictions[0]['role']);
+ $this->assertEquals(1, $restrictions[0]['role_id']);
+ $this->assertEquals(1, $restrictions[0]['project_id']);
+ $this->assertEquals('Ready', $restrictions[0]['src_column_title']);
+ $this->assertEquals('Work in progress', $restrictions[0]['dst_column_title']);
+ $this->assertEquals(2, $restrictions[0]['src_column_id']);
+ $this->assertEquals(3, $restrictions[0]['dst_column_id']);
+
+ $this->assertEquals(2, $restrictions[1]['restriction_id']);
+ $this->assertEquals('Role B', $restrictions[1]['role']);
+ $this->assertEquals('Work in progress', $restrictions[1]['src_column_title']);
+ $this->assertEquals('Done', $restrictions[1]['dst_column_title']);
+ $this->assertEquals(3, $restrictions[1]['src_column_id']);
+ $this->assertEquals(4, $restrictions[1]['dst_column_id']);
+ }
+}
diff --git a/tests/units/Model/ColumnRestrictionModelTest.php b/tests/units/Model/ColumnRestrictionModelTest.php
new file mode 100644
index 00000000..6f66c258
--- /dev/null
+++ b/tests/units/Model/ColumnRestrictionModelTest.php
@@ -0,0 +1,100 @@
+<?php
+
+use Kanboard\Model\ColumnRestrictionModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectRoleModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ColumnRestrictionModelTest extends Base
+{
+ public function testCreation()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnRestrictionModel = new ColumnRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $columnRestrictionModel->create(1, 1, 2, ColumnRestrictionModel::RULE_BLOCK_TASK_CREATION));
+ }
+
+ public function testRemove()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ColumnRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, 2, ColumnRestrictionModel::RULE_ALLOW_TASK_OPEN_CLOSE));
+ $this->assertTrue($projectRoleRestrictionModel->remove(1));
+ $this->assertFalse($projectRoleRestrictionModel->remove(1));
+ }
+
+ public function testGetById()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ColumnRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, 2, ColumnRestrictionModel::RULE_ALLOW_TASK_CREATION));
+
+ $restriction = $projectRoleRestrictionModel->getById(1, 1);
+ $this->assertEquals(ColumnRestrictionModel::RULE_ALLOW_TASK_CREATION, $restriction['rule']);
+ $this->assertEquals(1, $restriction['project_id']);
+ $this->assertEquals(1, $restriction['restriction_id']);
+ $this->assertEquals('Ready', $restriction['column_title']);
+ }
+
+ public function testGetAll()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ColumnRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, 2, ColumnRestrictionModel::RULE_ALLOW_TASK_CREATION));
+
+ $restrictions = $projectRoleRestrictionModel->getAll(1);
+ $this->assertCount(1, $restrictions);
+ $this->assertEquals(ColumnRestrictionModel::RULE_ALLOW_TASK_CREATION, $restrictions[0]['rule']);
+ $this->assertEquals(1, $restrictions[0]['project_id']);
+ $this->assertEquals(1, $restrictions[0]['restriction_id']);
+ $this->assertEquals(1, $restrictions[0]['role_id']);
+ $this->assertEquals(2, $restrictions[0]['column_id']);
+ $this->assertEquals('Ready', $restrictions[0]['column_title']);
+ }
+
+ public function testGetByRole()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnRestrictionModel = new ColumnRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $columnRestrictionModel->create(1, 1, 2, ColumnRestrictionModel::RULE_BLOCK_TASK_CREATION));
+
+ $restrictions = $columnRestrictionModel->getAllByRole(1, 'my-custom-role');
+ $this->assertCount(1, $restrictions);
+ $this->assertEquals(ColumnRestrictionModel::RULE_BLOCK_TASK_CREATION, $restrictions[0]['rule']);
+ $this->assertEquals(1, $restrictions[0]['project_id']);
+ $this->assertEquals(1, $restrictions[0]['restriction_id']);
+ $this->assertEquals(1, $restrictions[0]['role_id']);
+ $this->assertEquals(2, $restrictions[0]['column_id']);
+ $this->assertEquals('my-custom-role', $restrictions[0]['role']);
+ }
+
+ public function testGetRules()
+ {
+ $columnRestrictionModel = new ColumnRestrictionModel($this->container);
+ $rules = $columnRestrictionModel->getRules();
+
+ $this->assertCount(4, $rules);
+ $this->assertArrayHasKey(ColumnRestrictionModel::RULE_ALLOW_TASK_CREATION, $rules);
+ }
+}
diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentModelTest.php
index 574b5a87..c75401cc 100644
--- a/tests/units/Model/CommentTest.php
+++ b/tests/units/Model/CommentModelTest.php
@@ -6,7 +6,7 @@ use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\CommentModel;
-class CommentTest extends Base
+class CommentModelTest extends Base
{
public function testCreate()
{
@@ -26,6 +26,7 @@ class CommentTest extends Base
$this->assertEquals(1, $comment['user_id']);
$this->assertEquals('admin', $comment['username']);
$this->assertEquals(time(), $comment['date_creation'], '', 3);
+ $this->assertEquals(time(), $comment['date_modification'], '', 3);
$comment = $commentModel->getById(2);
$this->assertNotEmpty($comment);
@@ -34,6 +35,7 @@ class CommentTest extends Base
$this->assertEquals(0, $comment['user_id']);
$this->assertEquals('', $comment['username']);
$this->assertEquals(time(), $comment['date_creation'], '', 3);
+ $this->assertEquals(time(), $comment['date_modification'], '', 3);
}
public function testGetAll()
@@ -73,9 +75,10 @@ class CommentTest extends Base
$comment = $commentModel->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals('bla', $comment['comment']);
+ $this->assertEquals(time(), $comment['date_modification'], '', 3);
}
- public function validateRemove()
+ public function testRemove()
{
$commentModel = new CommentModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
diff --git a/tests/units/Model/ConfigModelTest.php b/tests/units/Model/ConfigModelTest.php
new file mode 100644
index 00000000..bbc792e3
--- /dev/null
+++ b/tests/units/Model/ConfigModelTest.php
@@ -0,0 +1,125 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ConfigModel;
+
+class ConfigModelTest extends Base
+{
+ public function testRegenerateToken()
+ {
+ $configModel = new ConfigModel($this->container);
+ $token = $configModel->getOption('api_token');
+ $this->assertTrue($configModel->regenerateToken('api_token'));
+ $this->assertNotEquals($token, $configModel->getOption('api_token'));
+ }
+
+ public function testCRUDOperations()
+ {
+ $configModel = new ConfigModel($this->container);
+
+ $this->assertTrue($configModel->save(array('key1' => 'value1')));
+ $this->assertTrue($configModel->save(array('key1' => 'value2')));
+ $this->assertTrue($configModel->save(array('key2' => 'value2')));
+
+ $this->assertEquals('value2', $configModel->getOption('key1'));
+ $this->assertEquals('value2', $configModel->getOption('key2'));
+ $this->assertEquals('', $configModel->getOption('key3'));
+ $this->assertEquals('default', $configModel->getOption('key3', 'default'));
+
+ $this->assertTrue($configModel->exists('key1'));
+ $this->assertFalse($configModel->exists('key3'));
+
+ $this->assertTrue($configModel->save(array('key1' => 'value1')));
+
+ $this->assertArrayHasKey('key1', $configModel->getAll());
+ $this->assertArrayHasKey('key2', $configModel->getAll());
+
+ $this->assertContains('value1', $configModel->getAll());
+ $this->assertContains('value2', $configModel->getAll());
+ }
+
+ public function testSaveApplicationUrl()
+ {
+ $configModel = new ConfigModel($this->container);
+
+ $this->assertTrue($configModel->save(array('application_url' => 'http://localhost/')));
+ $this->assertEquals('http://localhost/', $configModel->getOption('application_url'));
+
+ $this->assertTrue($configModel->save(array('application_url' => 'http://localhost')));
+ $this->assertEquals('http://localhost/', $configModel->getOption('application_url'));
+
+ $this->assertTrue($configModel->save(array('application_url' => '')));
+ $this->assertEquals('', $configModel->getOption('application_url'));
+ }
+
+ public function testDefaultValues()
+ {
+ $configModel = new ConfigModel($this->container);
+
+ $this->assertEquals(172800, $configModel->getOption('board_highlight_period'));
+ $this->assertEquals(60, $configModel->getOption('board_public_refresh_interval'));
+ $this->assertEquals(10, $configModel->getOption('board_private_refresh_interval'));
+ $this->assertEmpty($configModel->getOption('board_columns'));
+
+ $this->assertEquals('yellow', $configModel->getOption('default_color'));
+ $this->assertEquals('en_US', $configModel->getOption('application_language'));
+ $this->assertEquals('UTC', $configModel->getOption('application_timezone'));
+ $this->assertEquals('m/d/Y', $configModel->getOption('application_date_format'));
+ $this->assertEmpty($configModel->getOption('application_url'));
+ $this->assertEmpty($configModel->getOption('application_stylesheet'));
+ $this->assertEquals('USD', $configModel->getOption('application_currency'));
+
+ $this->assertEquals(0, $configModel->getOption('calendar_user_subtasks_time_tracking'));
+ $this->assertEquals('date_started', $configModel->getOption('calendar_user_tasks'));
+ $this->assertEquals('date_started', $configModel->getOption('calendar_user_tasks'));
+
+ $this->assertEquals(0, $configModel->getOption('integration_gravatar'));
+ $this->assertEquals(1, $configModel->getOption('cfd_include_closed_tasks'));
+ $this->assertEquals(1, $configModel->getOption('password_reset'));
+
+ $this->assertEquals(1, $configModel->getOption('subtask_time_tracking'));
+ $this->assertEquals(0, $configModel->getOption('subtask_restriction'));
+ $this->assertEmpty($configModel->getOption('project_categories'));
+
+ $this->assertEmpty($configModel->getOption('webhook_url_task_modification'));
+ $this->assertEmpty($configModel->getOption('webhook_url_task_creation'));
+ $this->assertNotEmpty($configModel->getOption('webhook_token'));
+ $this->assertEmpty($configModel->getOption('webhook_url'));
+
+ $this->assertNotEmpty($configModel->getOption('api_token'));
+ }
+
+ public function testGetOption()
+ {
+ $configModel = new ConfigModel($this->container);
+
+ $this->assertEquals('', $configModel->getOption('board_columns'));
+ $this->assertEquals('test', $configModel->getOption('board_columns', 'test'));
+ $this->assertEquals(0, $configModel->getOption('board_columns', 0));
+ }
+
+ public function testGetWithCaching()
+ {
+ $configModel = new ConfigModel($this->container);
+
+ $this->assertEquals('UTC', $configModel->get('application_timezone'));
+ $this->assertTrue($configModel->save(array('application_timezone' => 'Europe/Paris')));
+
+ $this->assertEquals('UTC', $configModel->get('application_timezone')); // cached value
+ $this->assertEquals('Europe/Paris', $configModel->getOption('application_timezone'));
+
+ $this->assertEquals('', $configModel->get('board_columns'));
+ $this->assertEquals('test', $configModel->get('board_columns', 'test'));
+ $this->assertEquals('test', $configModel->get('empty_value', 'test'));
+ }
+
+ public function testValueLength()
+ {
+ $configModel = new ConfigModel($this->container);
+ $string = str_repeat('a', 65535);
+
+ $this->assertTrue($configModel->save(array('application_stylesheet' => $string)));
+ $this->assertSame($string, $configModel->getOption('application_stylesheet'));
+ }
+}
diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php
deleted file mode 100644
index 3345ee3e..00000000
--- a/tests/units/Model/ConfigTest.php
+++ /dev/null
@@ -1,116 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\ConfigModel;
-
-class ConfigTest extends Base
-{
- public function testRegenerateToken()
- {
- $configModel = new ConfigModel($this->container);
- $token = $configModel->getOption('api_token');
- $this->assertTrue($configModel->regenerateToken('api_token'));
- $this->assertNotEquals($token, $configModel->getOption('api_token'));
- }
-
- public function testCRUDOperations()
- {
- $c = new ConfigModel($this->container);
-
- $this->assertTrue($c->save(array('key1' => 'value1')));
- $this->assertTrue($c->save(array('key1' => 'value2')));
- $this->assertTrue($c->save(array('key2' => 'value2')));
-
- $this->assertEquals('value2', $c->getOption('key1'));
- $this->assertEquals('value2', $c->getOption('key2'));
- $this->assertEquals('', $c->getOption('key3'));
- $this->assertEquals('default', $c->getOption('key3', 'default'));
-
- $this->assertTrue($c->exists('key1'));
- $this->assertFalse($c->exists('key3'));
-
- $this->assertTrue($c->save(array('key1' => 'value1')));
-
- $this->assertArrayHasKey('key1', $c->getAll());
- $this->assertArrayHasKey('key2', $c->getAll());
-
- $this->assertContains('value1', $c->getAll());
- $this->assertContains('value2', $c->getAll());
- }
-
- public function testSaveApplicationUrl()
- {
- $c = new ConfigModel($this->container);
-
- $this->assertTrue($c->save(array('application_url' => 'http://localhost/')));
- $this->assertEquals('http://localhost/', $c->getOption('application_url'));
-
- $this->assertTrue($c->save(array('application_url' => 'http://localhost')));
- $this->assertEquals('http://localhost/', $c->getOption('application_url'));
-
- $this->assertTrue($c->save(array('application_url' => '')));
- $this->assertEquals('', $c->getOption('application_url'));
- }
-
- public function testDefaultValues()
- {
- $c = new ConfigModel($this->container);
-
- $this->assertEquals(172800, $c->getOption('board_highlight_period'));
- $this->assertEquals(60, $c->getOption('board_public_refresh_interval'));
- $this->assertEquals(10, $c->getOption('board_private_refresh_interval'));
- $this->assertEmpty($c->getOption('board_columns'));
-
- $this->assertEquals('yellow', $c->getOption('default_color'));
- $this->assertEquals('en_US', $c->getOption('application_language'));
- $this->assertEquals('UTC', $c->getOption('application_timezone'));
- $this->assertEquals('m/d/Y', $c->getOption('application_date_format'));
- $this->assertEmpty($c->getOption('application_url'));
- $this->assertEmpty($c->getOption('application_stylesheet'));
- $this->assertEquals('USD', $c->getOption('application_currency'));
-
- $this->assertEquals(0, $c->getOption('calendar_user_subtasks_time_tracking'));
- $this->assertEquals('date_started', $c->getOption('calendar_user_tasks'));
- $this->assertEquals('date_started', $c->getOption('calendar_user_tasks'));
-
- $this->assertEquals(0, $c->getOption('integration_gravatar'));
- $this->assertEquals(1, $c->getOption('cfd_include_closed_tasks'));
- $this->assertEquals(1, $c->getOption('password_reset'));
-
- $this->assertEquals(1, $c->getOption('subtask_time_tracking'));
- $this->assertEquals(0, $c->getOption('subtask_restriction'));
- $this->assertEmpty($c->getOption('project_categories'));
-
- $this->assertEmpty($c->getOption('webhook_url_task_modification'));
- $this->assertEmpty($c->getOption('webhook_url_task_creation'));
- $this->assertNotEmpty($c->getOption('webhook_token'));
- $this->assertEmpty($c->getOption('webhook_url'));
-
- $this->assertNotEmpty($c->getOption('api_token'));
- }
-
- public function testGetOption()
- {
- $c = new ConfigModel($this->container);
-
- $this->assertEquals('', $c->getOption('board_columns'));
- $this->assertEquals('test', $c->getOption('board_columns', 'test'));
- $this->assertEquals(0, $c->getOption('board_columns', 0));
- }
-
- public function testGetWithCaching()
- {
- $c = new ConfigModel($this->container);
-
- $this->assertEquals('UTC', $c->get('application_timezone'));
- $this->assertTrue($c->save(array('application_timezone' => 'Europe/Paris')));
-
- $this->assertEquals('UTC', $c->get('application_timezone')); // cached value
- $this->assertEquals('Europe/Paris', $c->getOption('application_timezone'));
-
- $this->assertEquals('', $c->get('board_columns'));
- $this->assertEquals('test', $c->get('board_columns', 'test'));
- $this->assertEquals('test', $c->get('empty_value', 'test'));
- }
-}
diff --git a/tests/units/Model/GroupTest.php b/tests/units/Model/GroupModelTest.php
index 85c2c5d9..4ad0a167 100644
--- a/tests/units/Model/GroupTest.php
+++ b/tests/units/Model/GroupModelTest.php
@@ -4,7 +4,7 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Model\GroupModel;
-class GroupTest extends Base
+class GroupModelTest extends Base
{
public function testCreation()
{
@@ -57,4 +57,13 @@ class GroupTest extends Base
$this->assertTrue($groupModel->remove(1));
$this->assertEmpty($groupModel->getById(1));
}
+
+ public function testGetOrCreateExternalGroupId()
+ {
+ $groupModel = new GroupModel($this->container);
+ $this->assertEquals(1, $groupModel->create('Group 1', 'ExternalId1'));
+ $this->assertEquals(1, $groupModel->getOrCreateExternalGroupId('Group 1', 'ExternalId1'));
+ $this->assertEquals(1, $groupModel->getOrCreateExternalGroupId('Group 2', 'ExternalId1'));
+ $this->assertEquals(2, $groupModel->getOrCreateExternalGroupId('Group 2', 'ExternalId2'));
+ }
}
diff --git a/tests/units/Model/InviteModelTest.php b/tests/units/Model/InviteModelTest.php
new file mode 100644
index 00000000..3a0519fb
--- /dev/null
+++ b/tests/units/Model/InviteModelTest.php
@@ -0,0 +1,27 @@
+<?php
+
+use Kanboard\Model\InviteModel;
+
+require_once __DIR__.'/../Base.php';
+
+class InviteModelTest extends Base
+{
+ public function testCreation()
+ {
+ $inviteModel = new InviteModel($this->container);
+
+ $this->container['emailClient']
+ ->expects($this->exactly(2))
+ ->method('send');
+
+ $inviteModel->createInvites(array('user@domain1.tld', '', 'user@domain2.tld'), 1);
+ }
+
+ public function testRemove()
+ {
+ $inviteModel = new InviteModel($this->container);
+ $inviteModel->createInvites(array('user@domain1.tld', 'user@domain2.tld'), 0);
+ $this->assertTrue($inviteModel->remove('user@domain1.tld'));
+ $this->assertFalse($inviteModel->remove('foobar'));
+ }
+}
diff --git a/tests/units/Model/NotificationModelTest.php b/tests/units/Model/NotificationModelTest.php
index 889f3349..0bd9db6e 100644
--- a/tests/units/Model/NotificationModelTest.php
+++ b/tests/units/Model/NotificationModelTest.php
@@ -7,6 +7,7 @@ use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\SubtaskModel;
use Kanboard\Model\CommentModel;
use Kanboard\Model\TaskFileModel;
+use Kanboard\Model\TaskLinkModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\NotificationModel;
@@ -23,47 +24,38 @@ class NotificationModelTest extends Base
$subtaskModel = new SubtaskModel($this->container);
$commentModel = new CommentModel($this->container);
$taskFileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
$this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
$this->assertEquals(1, $taskFileModel->create(1, 'test', 'blah', 123));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
$task = $taskFinderModel->getDetails(1);
$subtask = $subtaskModel->getById(1, true);
$comment = $commentModel->getById(1);
$file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
- $this->assertNotEmpty($task);
- $this->assertNotEmpty($subtask);
- $this->assertNotEmpty($comment);
- $this->assertNotEmpty($file);
-
- foreach (NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
- $title = $notificationModel->getTitleWithoutAuthor($event_name, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array()
- ));
-
- $this->assertNotEmpty($title);
-
- $title = $notificationModel->getTitleWithAuthor('foobar', $event_name, array(
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $eventData = array(
'task' => $task,
'comment' => $comment,
'subtask' => $subtask,
'file' => $file,
+ 'task_link' => $tasklink,
'changes' => array()
- ));
+ );
- $this->assertNotEmpty($title);
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor($eventName, $eventData));
+ $this->assertNotEmpty($notificationModel->getTitleWithAuthor('Foobar', $eventName, $eventData));
}
$this->assertNotEmpty($notificationModel->getTitleWithoutAuthor(TaskModel::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
- $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor('unkown', array()));
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor('unknown', array()));
}
public function testGetTaskIdFromEvent()
@@ -75,6 +67,7 @@ class NotificationModelTest extends Base
$subtaskModel = new SubtaskModel($this->container);
$commentModel = new CommentModel($this->container);
$taskFileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
@@ -86,18 +79,20 @@ class NotificationModelTest extends Base
$subtask = $subtaskModel->getById(1, true);
$comment = $commentModel->getById(1);
$file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
$this->assertNotEmpty($task);
$this->assertNotEmpty($subtask);
$this->assertNotEmpty($comment);
$this->assertNotEmpty($file);
- foreach (NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
- $task_id = $notificationModel->getTaskIdFromEvent($event_name, array(
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $task_id = $notificationModel->getTaskIdFromEvent($eventName, array(
'task' => $task,
'comment' => $comment,
'subtask' => $subtask,
'file' => $file,
+ 'task_link' => $tasklink,
'changes' => array()
));
diff --git a/tests/units/Model/ProjectModelTest.php b/tests/units/Model/ProjectModelTest.php
index 81e0dd57..cd86b654 100644
--- a/tests/units/Model/ProjectModelTest.php
+++ b/tests/units/Model/ProjectModelTest.php
@@ -39,6 +39,24 @@ class ProjectModelTest extends Base
$this->assertEquals(0, $project['is_private']);
$this->assertEquals(time(), $project['last_modified'], '', 1);
$this->assertEmpty($project['token']);
+ $this->assertEmpty($project['start_date']);
+ $this->assertEmpty($project['end_date']);
+ }
+
+ public function testProjectDate()
+ {
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->update(array(
+ 'id' => 1,
+ 'start_date' => '2016-08-31',
+ 'end_date' => '08/31/2016',
+ )));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals('2016-08-31', $project['start_date']);
+ $this->assertEquals('2016-08-31', $project['end_date']);
}
public function testCreationWithDuplicateName()
diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionModelTest.php
index c9e0a481..7f604374 100644
--- a/tests/units/Model/ProjectPermissionTest.php
+++ b/tests/units/Model/ProjectPermissionModelTest.php
@@ -11,7 +11,7 @@ use Kanboard\Model\ProjectGroupRoleModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Core\Security\Role;
-class ProjectPermissionTest extends Base
+class ProjectPermissionModelTest extends Base
{
public function testFindByUsernames()
{
@@ -26,7 +26,7 @@ class ProjectPermissionTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
$this->assertEquals(2, $userModel->create(array('username' => 'user1')));
- $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'email' => 'test@here', 'avatar_path' => 'test')));
$this->assertEquals(4, $userModel->create(array('username' => 'user3')));
$this->assertEquals(1, $groupModel->create('Group A'));
@@ -35,7 +35,24 @@ class ProjectPermissionTest extends Base
$this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_MEMBER));
$this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MANAGER));
- $this->assertEquals(array('user1', 'user2'), $projectPermissionModel->findUsernames(1, 'us'));
+ $expected = array(
+ 'user1' => array(
+ 'username' => 'user1',
+ 'name' => null,
+ 'email' => null,
+ 'avatar_path' => null,
+ 'id' => '2',
+ ),
+ 'user2' => array(
+ 'username' => 'user2',
+ 'name' => 'User 2',
+ 'email' => 'test@here',
+ 'avatar_path' => 'test',
+ 'id' => '3',
+ )
+ );
+
+ $this->assertEquals($expected, $projectPermissionModel->findUsernames(1, 'us'));
$this->assertEmpty($projectPermissionModel->findUsernames(1, 'a'));
$this->assertEmpty($projectPermissionModel->findUsernames(2, 'user'));
}
@@ -267,6 +284,29 @@ class ProjectPermissionTest extends Base
$this->assertEquals(array(1), $projectPermission->getActiveProjectIds(3));
}
+ public function testGetProjectIds()
+ {
+ $userModel = new UserModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $userRoleModel = new ProjectUserRoleModel($this->container);
+ $projectPermission = new ProjectPermissionModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user 1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user 2')));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_active' => 0)));
+
+ $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(2, 3, Role::PROJECT_MEMBER));
+
+ $this->assertEmpty($projectPermission->getProjectIds(1));
+ $this->assertEquals(array(1, 2), $projectPermission->getProjectIds(2));
+ $this->assertEquals(array(1, 2), $projectPermission->getProjectIds(3));
+ }
+
public function testDuplicate()
{
$userModel = new UserModel($this->container);
diff --git a/tests/units/Model/ProjectRoleModelTest.php b/tests/units/Model/ProjectRoleModelTest.php
new file mode 100644
index 00000000..65208e6a
--- /dev/null
+++ b/tests/units/Model/ProjectRoleModelTest.php
@@ -0,0 +1,159 @@
+<?php
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\GroupMemberModel;
+use Kanboard\Model\GroupModel;
+use Kanboard\Model\ProjectGroupRoleModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectRoleModel;
+use Kanboard\Model\ProjectUserRoleModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectRoleModelTest extends Base
+{
+ public function testCreation()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertFalse($projectRoleModel->create(1, 'my-custom-role'));
+ }
+
+ public function testGetAll()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertEquals(2, $projectRoleModel->create(1, 'Role B'));
+
+ $roles = $projectRoleModel->getAll(1);
+ $this->assertCount(2, $roles);
+
+ $this->assertEquals(1, $roles[0]['role_id']);
+ $this->assertEquals('Role A', $roles[0]['role']);
+
+ $this->assertEquals(2, $roles[1]['role_id']);
+ $this->assertEquals('Role B', $roles[1]['role']);
+ }
+
+ public function testModificationWithUserRole()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $groupModel = new GroupModel($this->container);
+ $groupMemberModel = new GroupMemberModel($this->container);
+
+ $this->assertEquals(1, $groupModel->create('Group A'));
+ $this->assertTrue($groupMemberModel->addUser(1, 1));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 1, 'Role A'));
+ $this->assertEquals('Role A', $projectUserRoleModel->getUserRole(1, 1));
+
+ $this->assertTrue($projectRoleModel->update(1, 1, 'Role B'));
+ $this->assertEquals('Role B', $projectUserRoleModel->getUserRole(1, 1));
+ }
+
+ public function testModificationWithGroupRole()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectGroupRoleModel = new ProjectGroupRoleModel($this->container);
+ $groupModel = new GroupModel($this->container);
+ $groupMemberModel = new GroupMemberModel($this->container);
+
+ $this->assertEquals(1, $groupModel->create('Group A'));
+ $this->assertTrue($groupMemberModel->addUser(1, 1));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, 'Role A'));
+ $this->assertEquals('Role A', $projectGroupRoleModel->getUserRole(1, 1));
+
+ $this->assertTrue($projectRoleModel->update(1, 1, 'Role B'));
+ $this->assertEquals('Role B', $projectGroupRoleModel->getUserRole(1, 1));
+ }
+
+ public function testRemoveWithUserRole()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 1, 'Role A'));
+ $this->assertEquals('Role A', $projectUserRoleModel->getUserRole(1, 1));
+
+ $this->assertTrue($projectRoleModel->remove(1, 1));
+ $this->assertEmpty($projectRoleModel->getAll(1));
+ $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(1, 1));
+ }
+
+ public function testRemoveWithGroupRole()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectGroupRoleModel = new ProjectGroupRoleModel($this->container);
+ $groupModel = new GroupModel($this->container);
+ $groupMemberModel = new GroupMemberModel($this->container);
+
+ $this->assertEquals(1, $groupModel->create('Group A'));
+ $this->assertTrue($groupMemberModel->addUser(1, 1));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, 'Role A'));
+ $this->assertEquals('Role A', $projectGroupRoleModel->getUserRole(1, 1));
+
+ $this->assertTrue($projectRoleModel->remove(1, 1));
+ $this->assertEmpty($projectRoleModel->getAll(1));
+ $this->assertEquals(Role::PROJECT_MEMBER, $projectGroupRoleModel->getUserRole(1, 1));
+ }
+
+ public function testGetRoleListWithoutCustomRoles()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ $roles = $projectRoleModel->getList(1);
+ $this->assertCount(3, $roles);
+ $this->assertEquals('Project Manager', $roles[Role::PROJECT_MANAGER]);
+ }
+
+ public function testGetRoleListWithCustomRoles()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+
+ $roles = $projectRoleModel->getList(1);
+ $this->assertCount(4, $roles);
+ $this->assertEquals('Role A', $roles['Role A']);
+ }
+
+ public function testGetById()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+
+ $role = $projectRoleModel->getById(1, 1);
+ $this->assertEquals(1, $role['role_id']);
+ $this->assertEquals(1, $role['project_id']);
+ $this->assertEquals('Role A', $role['role']);
+ }
+}
diff --git a/tests/units/Model/ProjectRoleRestrictionModelTest.php b/tests/units/Model/ProjectRoleRestrictionModelTest.php
new file mode 100644
index 00000000..af0f9bf9
--- /dev/null
+++ b/tests/units/Model/ProjectRoleRestrictionModelTest.php
@@ -0,0 +1,96 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectRoleModel;
+use Kanboard\Model\ProjectRoleRestrictionModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectRoleRestrictionModelTest extends Base
+{
+ public function testCreation()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_CREATION));
+ }
+
+ public function testRemove()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_CREATION));
+ $this->assertTrue($projectRoleRestrictionModel->remove(1));
+ $this->assertFalse($projectRoleRestrictionModel->remove(1));
+ }
+
+ public function testGetById()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_CREATION));
+
+ $restriction = $projectRoleRestrictionModel->getById(1, 1);
+ $this->assertEquals(ProjectRoleRestrictionModel::RULE_TASK_CREATION, $restriction['rule']);
+ $this->assertEquals(1, $restriction['project_id']);
+ $this->assertEquals(1, $restriction['restriction_id']);
+ }
+
+ public function testGetAll()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_CREATION));
+
+ $restrictions = $projectRoleRestrictionModel->getAll(1);
+ $this->assertCount(1, $restrictions);
+ $this->assertEquals(ProjectRoleRestrictionModel::RULE_TASK_CREATION, $restrictions[0]['rule']);
+ $this->assertEquals(1, $restrictions[0]['project_id']);
+ $this->assertEquals(1, $restrictions[0]['restriction_id']);
+ $this->assertEquals(1, $restrictions[0]['role_id']);
+ }
+
+ public function testGetByRole()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_CREATION));
+
+ $restrictions = $projectRoleRestrictionModel->getAllByRole(1, 'my-custom-role');
+ $this->assertCount(1, $restrictions);
+ $this->assertEquals(ProjectRoleRestrictionModel::RULE_TASK_CREATION, $restrictions[0]['rule']);
+ $this->assertEquals(1, $restrictions[0]['project_id']);
+ $this->assertEquals(1, $restrictions[0]['restriction_id']);
+ $this->assertEquals(1, $restrictions[0]['role_id']);
+ $this->assertEquals('my-custom-role', $restrictions[0]['role']);
+ }
+
+ public function testGetRules()
+ {
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+ $rules = $projectRoleRestrictionModel->getRules();
+
+ $this->assertCount(3, $rules);
+ $this->assertArrayHasKey(ProjectRoleRestrictionModel::RULE_TASK_OPEN_CLOSE, $rules);
+ }
+}
diff --git a/tests/units/Model/SubtaskModelTest.php b/tests/units/Model/SubtaskModelTest.php
index 6451189d..eed37cf3 100644
--- a/tests/units/Model/SubtaskModelTest.php
+++ b/tests/units/Model/SubtaskModelTest.php
@@ -9,64 +9,6 @@ use Kanboard\Model\TaskFinderModel;
class SubtaskModelTest extends Base
{
- public function onSubtaskCreated($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertNotEmpty($data['task_id']);
- $this->assertNotEmpty($data['id']);
- }
-
- public function onSubtaskUpdated($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertArrayHasKey('changes', $data);
- $this->assertArrayHasKey('user_id', $data['changes']);
- $this->assertArrayHasKey('status', $data['changes']);
-
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $data['changes']['status']);
- $this->assertEquals(1, $data['changes']['user_id']);
- }
-
- public function onSubtaskDeleted($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertNotEmpty($data['task_id']);
- $this->assertNotEmpty($data['id']);
- }
-
public function testCreation()
{
$taskCreationModel = new TaskCreationModel($this->container);
@@ -75,9 +17,6 @@ class SubtaskModelTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, array($this, 'onSubtaskCreated'));
-
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
$subtask = $subtaskModel->getById(1);
@@ -92,33 +31,25 @@ class SubtaskModelTest extends Base
$this->assertEquals(1, $subtask['position']);
}
- public function testModification()
+ public function testCreationUpdateTaskTimeTracking()
{
$taskCreationModel = new TaskCreationModel($this->container);
$subtaskModel = new SubtaskModel($this->container);
$projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
- $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, array($this, 'onSubtaskUpdated'));
-
- $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->assertTrue($subtaskModel->update(array('id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 2, 'time_spent' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 5)));
- $subtask = $subtaskModel->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(1, $subtask['id']);
- $this->assertEquals(1, $subtask['task_id']);
- $this->assertEquals('subtask #1', $subtask['title']);
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
- $this->assertEquals(0, $subtask['time_estimated']);
- $this->assertEquals(0, $subtask['time_spent']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['position']);
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(7, $task['time_estimated']);
+ $this->assertEquals(6, $task['time_spent']);
}
- public function testRemove()
+ public function testModification()
{
$taskCreationModel = new TaskCreationModel($this->container);
$subtaskModel = new SubtaskModel($this->container);
@@ -126,126 +57,60 @@ class SubtaskModelTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
- $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
-
- $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, array($this, 'onSubtaskDeleted'));
-
- $subtask = $subtaskModel->getById(1);
- $this->assertNotEmpty($subtask);
-
- $this->assertTrue($subtaskModel->remove(1));
-
- $subtask = $subtaskModel->getById(1);
- $this->assertEmpty($subtask);
- }
-
- public function testToggleStatusWithoutSession()
- {
- $taskCreationModel = new TaskCreationModel($this->container);
- $subtaskModel = new SubtaskModel($this->container);
- $projectModel = new ProjectModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS)));
$subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['id']);
$this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskModel->toggleStatus(1));
-
- $subtask = $subtaskModel->getById(1);
- $this->assertNotEmpty($subtask);
+ $this->assertEquals('subtask #1', $subtask['title']);
$this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskModel->toggleStatus(1));
-
- $subtask = $subtaskModel->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskModel->toggleStatus(1));
-
- $subtask = $subtaskModel->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
+ $this->assertEquals(0, $subtask['time_estimated']);
+ $this->assertEquals(0, $subtask['time_spent']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['position']);
}
- public function testToggleStatusWithSession()
+ public function testModificationUpdateTaskTimeTracking()
{
$taskCreationModel = new TaskCreationModel($this->container);
$subtaskModel = new SubtaskModel($this->container);
$projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'time_estimated' => 2, 'time_spent' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 2, 'task_id' => 1, 'time_estimated' => 2, 'time_spent' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 5)));
- $subtask = $subtaskModel->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- // Set the current logged user
- $this->container['sessionStorage']->user = array('id' => 1);
-
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskModel->toggleStatus(1));
-
- $subtask = $subtaskModel->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskModel->toggleStatus(1));
-
- $subtask = $subtaskModel->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskModel->toggleStatus(1));
-
- $subtask = $subtaskModel->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(7, $task['time_estimated']);
+ $this->assertEquals(6, $task['time_spent']);
}
- public function testCloseAll()
+ public function testRemove()
{
$taskCreationModel = new TaskCreationModel($this->container);
$subtaskModel = new SubtaskModel($this->container);
$projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
-
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
- $this->assertTrue($subtaskModel->closeAll(1));
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
- $subtasks = $subtaskModel->getAll(1);
- $this->assertNotEmpty($subtasks);
+ $this->assertTrue($subtaskModel->remove(1));
- foreach ($subtasks as $subtask) {
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
- }
+ $subtask = $subtaskModel->getById(1);
+ $this->assertEmpty($subtask);
}
public function testDuplicate()
@@ -269,7 +134,6 @@ class SubtaskModelTest extends Base
$this->assertTrue($subtaskModel->duplicate(1, 2));
$subtasks = $subtaskModel->getAll(2);
- $this->assertNotFalse($subtasks);
$this->assertNotEmpty($subtasks);
$this->assertEquals(2, count($subtasks));
@@ -295,95 +159,6 @@ class SubtaskModelTest extends Base
$this->assertEquals(2, $subtasks[1]['position']);
}
- public function testChangePosition()
- {
- $taskCreationModel = new TaskCreationModel($this->container);
- $subtaskModel = new SubtaskModel($this->container);
- $projectModel = new ProjectModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
- $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 1)));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(1, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(2, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(3, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 3, 2));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(1, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(3, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(2, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 2, 1));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(2, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(1, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(3, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 2, 2));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(1, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(2, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(3, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 1, 3));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(2, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(3, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(1, $subtasks[2]['id']);
-
- $this->assertFalse($subtaskModel->changePosition(1, 2, 0));
- $this->assertFalse($subtaskModel->changePosition(1, 2, 4));
- }
-
- public function testConvertToTask()
- {
- $taskCreationModel = new TaskCreationModel($this->container);
- $taskFinderModel = new TaskFinderModel($this->container);
- $subtaskModel = new SubtaskModel($this->container);
- $projectModel = new ProjectModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3)));
- $task_id = $subtaskModel->convertToTask(1, 1);
-
- $this->assertNotFalse($task_id);
- $this->assertEmpty($subtaskModel->getById(1));
-
- $task = $taskFinderModel->getById($task_id);
- $this->assertEquals('subtask #1', $task['title']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(2, $task['time_spent']);
- $this->assertEquals(3, $task['time_estimated']);
- }
-
public function testGetProjectId()
{
$taskCreationModel = new TaskCreationModel($this->container);
@@ -393,7 +168,7 @@ class SubtaskModelTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
-
+
$this->assertEquals(1, $subtaskModel->getProjectId(1));
$this->assertEquals(0, $subtaskModel->getProjectId(2));
}
diff --git a/tests/units/Model/SubtaskPositionModelTest.php b/tests/units/Model/SubtaskPositionModelTest.php
new file mode 100644
index 00000000..92412392
--- /dev/null
+++ b/tests/units/Model/SubtaskPositionModelTest.php
@@ -0,0 +1,77 @@
+<?php
+
+use Kanboard\Model\SubtaskPositionModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\ProjectModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskPositionModelTest extends Base
+{
+ public function testChangePosition()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskPositionModel = new SubtaskPositionModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 1)));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(1, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(2, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(3, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 3, 2));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(1, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(3, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(2, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 2, 1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(2, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(1, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(3, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 2, 2));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(1, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(2, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(3, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 1, 3));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(2, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(3, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(1, $subtasks[2]['id']);
+
+ $this->assertFalse($subtaskPositionModel->changePosition(1, 2, 0));
+ $this->assertFalse($subtaskPositionModel->changePosition(1, 2, 4));
+ }
+}
diff --git a/tests/units/Model/SubtaskStatusModelTest.php b/tests/units/Model/SubtaskStatusModelTest.php
new file mode 100644
index 00000000..af4c3955
--- /dev/null
+++ b/tests/units/Model/SubtaskStatusModelTest.php
@@ -0,0 +1,123 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskStatusModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskStatusModelTest extends Base
+{
+ public function testToggleStatusWithoutSession()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ }
+
+ public function testToggleStatusWithSession()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ // Set the current logged user
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ }
+
+ public function testCloseAll()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+
+ $this->assertTrue($subtaskStatusModel->closeAll(1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+
+ foreach ($subtasks as $subtask) {
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ }
+ }
+}
diff --git a/tests/units/Model/SubtaskTaskConversionModelTest.php b/tests/units/Model/SubtaskTaskConversionModelTest.php
new file mode 100644
index 00000000..51a623b2
--- /dev/null
+++ b/tests/units/Model/SubtaskTaskConversionModelTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskTaskConversionModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskTaskConversionModelTest extends Base
+{
+ public function testConvertToTask()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskConversion = new SubtaskTaskConversionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3)));
+ $task_id = $subtaskConversion->convertToTask(1, 1);
+
+ $this->assertNotFalse($task_id);
+ $this->assertEmpty($subtaskModel->getById(1));
+
+ $task = $taskFinderModel->getById($task_id);
+ $this->assertEquals('subtask #1', $task['title']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(2, $task['time_spent']);
+ $this->assertEquals(3, $task['time_estimated']);
+ }
+}
diff --git a/tests/units/Model/SubtaskTimeTrackingModelTest.php b/tests/units/Model/SubtaskTimeTrackingModelTest.php
new file mode 100644
index 00000000..8b0fe698
--- /dev/null
+++ b/tests/units/Model/SubtaskTimeTrackingModelTest.php
@@ -0,0 +1,277 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ConfigModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskTimeTrackingModel;
+use Kanboard\Model\ProjectModel;
+
+class SubtaskTimeTrackingModelTest extends Base
+{
+ public function testToggleTimer()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_TODO));
+ $this->assertTrue($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_INPROGRESS));
+ $this->assertTrue($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_DONE));
+ }
+
+ public function testToggleTimerWhenFeatureDisabled()
+ {
+ $configModel = new ConfigModel($this->container);
+ $configModel->save(array('subtask_time_tracking' => '0'));
+ $this->container['memoryCache']->flush();
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_TODO));
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_INPROGRESS));
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_DONE));
+ }
+
+ public function testHasTimer()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertFalse($subtaskTimeTrackingModel->hasTimer(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->hasTimer(1, 1));
+ $this->assertFalse($subtaskTimeTrackingModel->logStartTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $this->assertFalse($subtaskTimeTrackingModel->hasTimer(1, 1));
+ }
+
+ public function testGetTimerStatus()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1)));
+
+ // Nothing started
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(0, $subtasks[0]['timer_start_date']);
+ $this->assertFalse($subtasks[0]['is_timer_started']);
+
+ $subtask = $subtaskModel->getById(1, true);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(0, $subtask['timer_start_date']);
+ $this->assertFalse($subtask['is_timer_started']);
+
+ // Start the clock
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(time(), $subtasks[0]['timer_start_date'], '', 3);
+ $this->assertTrue($subtasks[0]['is_timer_started']);
+
+ $subtask = $subtaskModel->getById(1, true);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(time(), $subtask['timer_start_date'], '', 3);
+ $this->assertTrue($subtask['is_timer_started']);
+
+ // Stop the clock
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(0, $subtasks[0]['timer_start_date']);
+ $this->assertFalse($subtasks[0]['is_timer_started']);
+
+ $subtask = $subtaskModel->getById(1, true);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(0, $subtask['timer_start_date']);
+ $this->assertFalse($subtask['is_timer_started']);
+ }
+
+ public function testLogStartTime()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+
+ $timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(1, $timesheet);
+ $this->assertNotEmpty($timesheet[0]['start']);
+ $this->assertEmpty($timesheet[0]['end']);
+ $this->assertEquals(1, $timesheet[0]['user_id']);
+ $this->assertEquals(1, $timesheet[0]['subtask_id']);
+ }
+
+ public function testLogStartEnd()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ // No start time
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
+ $this->assertEmpty($timesheet);
+
+ // Log start and end time
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+ sleep(1);
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+
+ $timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(1, $timesheet);
+ $this->assertNotEmpty($timesheet[0]['start']);
+ $this->assertNotEmpty($timesheet[0]['end']);
+ $this->assertEquals(1, $timesheet[0]['user_id']);
+ $this->assertEquals(1, $timesheet[0]['subtask_id']);
+ $this->assertNotEquals($timesheet[0]['start'], $timesheet[0]['end']);
+ }
+
+ public function testCalculateSubtaskTime()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2, 'time_estimated' => 3.3)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 1.1, 'time_estimated' => 4.4)));
+
+ $time = $subtaskTimeTrackingModel->calculateSubtaskTime(1);
+ $this->assertCount(2, $time);
+ $this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01);
+ }
+
+ public function testUpdateSubtaskTimeSpent()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(2, 1));
+
+ // Fake start time
+ $this->container['db']->table(SubtaskTimeTrackingModel::TABLE)->update(array('start' => time() - 3600));
+
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(2, 1));
+
+ $timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(2, $timesheet);
+ $this->assertEquals(3600, $timesheet[0]['end'] - $timesheet[0]['start'], 'Wrong timestamps', 1);
+ $this->assertEquals(3600, $timesheet[1]['end'] - $timesheet[1]['start'], 'Wrong timestamps', 1);
+
+ $time = $subtaskTimeTrackingModel->calculateSubtaskTime(1);
+ $this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
+
+ $time = $subtaskTimeTrackingModel->calculateSubtaskTime(2);
+ $this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
+ }
+
+ public function testUpdateTaskTimeTracking()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
+
+ $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 2, 'time_spent' => 3.4)));
+ $this->assertEquals(4, $subtaskModel->create(array('title' => 'subtask #4', 'task_id' => 2, 'time_estimated' => 1.25)));
+
+ $this->assertEquals(5, $subtaskModel->create(array('title' => 'subtask #5', 'task_id' => 3, 'time_spent' => 8)));
+
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(1);
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(2);
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(3);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2.2, $task['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(1, $task['time_estimated'], 'Total estimated', 0.01);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3.4, $task['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(1.25, $task['time_estimated'], 'Total estimated', 0.01);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(8, $task['time_spent']);
+
+ $this->assertTrue($subtaskModel->remove(3));
+ $this->assertTrue($subtaskModel->remove(4));
+
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(2);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
+ }
+}
diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php
deleted file mode 100644
index d5ae62ae..00000000
--- a/tests/units/Model/SubtaskTimeTrackingTest.php
+++ /dev/null
@@ -1,240 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Model\SubtaskTimeTrackingModel;
-use Kanboard\Model\ProjectModel;
-
-class SubtaskTimeTrackingTest extends Base
-{
- public function testHasTimer()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
-
- $this->assertFalse($st->hasTimer(1, 1));
- $this->assertTrue($st->logStartTime(1, 1));
- $this->assertTrue($st->hasTimer(1, 1));
- $this->assertFalse($st->logStartTime(1, 1));
- $this->assertTrue($st->logEndTime(1, 1));
- $this->assertFalse($st->hasTimer(1, 1));
- }
-
- public function testGetTimerStatus()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->container['sessionStorage']->user = array('id' => 1);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1)));
-
- // Nothing started
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(0, $subtasks[0]['timer_start_date']);
- $this->assertFalse($subtasks[0]['is_timer_started']);
-
- $subtask = $s->getById(1, true);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(0, $subtask['timer_start_date']);
- $this->assertFalse($subtask['is_timer_started']);
-
- // Start the clock
- $this->assertTrue($st->logStartTime(1, 1));
-
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(time(), $subtasks[0]['timer_start_date'], '', 3);
- $this->assertTrue($subtasks[0]['is_timer_started']);
-
- $subtask = $s->getById(1, true);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(time(), $subtask['timer_start_date'], '', 3);
- $this->assertTrue($subtask['is_timer_started']);
-
- // Stop the clock
- $this->assertTrue($st->logEndTime(1, 1));
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(0, $subtasks[0]['timer_start_date']);
- $this->assertFalse($subtasks[0]['is_timer_started']);
-
- $subtask = $s->getById(1, true);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(0, $subtask['timer_start_date']);
- $this->assertFalse($subtask['is_timer_started']);
- }
-
- public function testLogStartTime()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
-
- $this->assertTrue($st->logStartTime(1, 1));
-
- $timesheet = $st->getUserTimesheet(1);
- $this->assertNotEmpty($timesheet);
- $this->assertCount(1, $timesheet);
- $this->assertNotEmpty($timesheet[0]['start']);
- $this->assertEmpty($timesheet[0]['end']);
- $this->assertEquals(1, $timesheet[0]['user_id']);
- $this->assertEquals(1, $timesheet[0]['subtask_id']);
- }
-
- public function testLogStartEnd()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
-
- // No start time
- $this->assertTrue($st->logEndTime(1, 1));
- $timesheet = $st->getUserTimesheet(1);
- $this->assertEmpty($timesheet);
-
- // Log start and end time
- $this->assertTrue($st->logStartTime(1, 1));
- sleep(1);
- $this->assertTrue($st->logEndTime(1, 1));
-
- $timesheet = $st->getUserTimesheet(1);
- $this->assertNotEmpty($timesheet);
- $this->assertCount(1, $timesheet);
- $this->assertNotEmpty($timesheet[0]['start']);
- $this->assertNotEmpty($timesheet[0]['end']);
- $this->assertEquals(1, $timesheet[0]['user_id']);
- $this->assertEquals(1, $timesheet[0]['subtask_id']);
- $this->assertNotEquals($timesheet[0]['start'], $timesheet[0]['end']);
- }
-
- public function testCalculateSubtaskTime()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2, 'time_estimated' => 3.3)));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 1.1, 'time_estimated' => 4.4)));
-
- $time = $st->calculateSubtaskTime(1);
- $this->assertCount(2, $time);
- $this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01);
- }
-
- public function testUpdateSubtaskTimeSpent()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2)));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
-
- $this->assertTrue($st->logStartTime(1, 1));
- $this->assertTrue($st->logStartTime(2, 1));
-
- // Fake start time
- $this->container['db']->table(SubtaskTimeTrackingModel::TABLE)->update(array('start' => time() - 3600));
-
- $this->assertTrue($st->logEndTime(1, 1));
- $this->assertTrue($st->logEndTime(2, 1));
-
- $timesheet = $st->getUserTimesheet(1);
- $this->assertNotEmpty($timesheet);
- $this->assertCount(2, $timesheet);
- $this->assertEquals(3600, $timesheet[0]['end'] - $timesheet[0]['start'], 'Wrong timestamps', 1);
- $this->assertEquals(3600, $timesheet[1]['end'] - $timesheet[1]['start'], 'Wrong timestamps', 1);
-
- $time = $st->calculateSubtaskTime(1);
- $this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
-
- $time = $st->calculateSubtaskTime(2);
- $this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
- }
-
- public function testUpdateTaskTimeTracking()
- {
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
-
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
- $this->assertEquals(3, $tc->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
-
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
-
- $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 2, 'time_spent' => 3.4)));
- $this->assertEquals(4, $s->create(array('title' => 'subtask #4', 'task_id' => 2, 'time_estimated' => 1.25)));
-
- $this->assertEquals(5, $s->create(array('title' => 'subtask #5', 'task_id' => 3, 'time_spent' => 8)));
-
- $st->updateTaskTimeTracking(1);
- $st->updateTaskTimeTracking(2);
- $st->updateTaskTimeTracking(3);
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(2.2, $task['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(1, $task['time_estimated'], 'Total estimated', 0.01);
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(3.4, $task['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(1.25, $task['time_estimated'], 'Total estimated', 0.01);
-
- $task = $tf->getById(3);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['time_estimated']);
- $this->assertEquals(8, $task['time_spent']);
-
- $this->assertTrue($s->remove(3));
- $this->assertTrue($s->remove(4));
-
- $st->updateTaskTimeTracking(2);
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['time_estimated']);
- $this->assertEquals(0, $task['time_spent']);
- }
-}
diff --git a/tests/units/Model/TaskCreationModelTest.php b/tests/units/Model/TaskCreationModelTest.php
index f97c61dc..ce9996d9 100644
--- a/tests/units/Model/TaskCreationModelTest.php
+++ b/tests/units/Model/TaskCreationModelTest.php
@@ -17,7 +17,7 @@ class TaskCreationModelTest extends Base
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals('test', $event_data['title']);
+ $this->assertEquals('test', $event_data['task']['title']);
}
public function testNoTitle()
diff --git a/tests/units/Model/TaskFinderModelTest.php b/tests/units/Model/TaskFinderModelTest.php
new file mode 100644
index 00000000..9e0369ce
--- /dev/null
+++ b/tests/units/Model/TaskFinderModelTest.php
@@ -0,0 +1,204 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ColumnModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+
+class TaskFinderModelTest extends Base
+{
+ public function testGetDetails()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new \Kanboard\Model\CategoryModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $categoryModel->create(array('project_id' => 1, 'name' => 'C1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'project_id' => 1,
+ 'title' => 'Task #1',
+ 'reference' => 'test',
+ 'description' => 'desc',
+ 'owner_id' => 1,
+ 'category_id' => 1,
+ )));
+
+ $task = $taskFinderModel->getDetails(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('test', $task['reference']);
+ $this->assertEquals('Task #1', $task['title']);
+ $this->assertEquals('desc', $task['description']);
+ $this->assertEquals(time(), $task['date_creation'], 'Delta', 1);
+ $this->assertEquals(time(), $task['date_modification'], 'Delta', 1);
+ $this->assertEquals(time(), $task['date_moved'], 'Delta', 1);
+ $this->assertEquals(0, $task['date_completed']);
+ $this->assertEquals(0, $task['date_due']);
+ $this->assertEquals(0, $task['date_started']);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
+ $this->assertEquals('yellow', $task['color_id']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(0, $task['creator_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']);
+ $this->assertEquals(0, $task['score']);
+ $this->assertEquals(1, $task['category_id']);
+ $this->assertEquals(0, $task['priority']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(TaskModel::RECURRING_STATUS_NONE, $task['recurrence_status']);
+ $this->assertEquals(TaskModel::RECURRING_TRIGGER_FIRST_COLUMN, $task['recurrence_trigger']);
+ $this->assertEquals(0, $task['recurrence_factor']);
+ $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
+ $this->assertEquals(TaskModel::RECURRING_BASEDATE_DUEDATE, $task['recurrence_basedate']);
+ $this->assertEquals(0, $task['recurrence_parent']);
+ $this->assertEquals(0, $task['recurrence_child']);
+ $this->assertEquals('C1', $task['category_name']);
+ $this->assertNull($task['swimlane_name']);
+ $this->assertEquals('Default swimlane', $task['default_swimlane']);
+ $this->assertEquals('Project #1', $task['project_name']);
+ $this->assertEquals('Backlog', $task['column_title']);
+ $this->assertEquals('admin', $task['assignee_username']);
+ $this->assertEquals('', $task['assignee_name']);
+ $this->assertEquals('', $task['creator_username']);
+ $this->assertEquals('', $task['creator_name']);
+ }
+
+ public function testGetTasksForDashboardWithHiddenColumn()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $columnModel = new ColumnModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+
+ $tasks = $taskFinderModel->getUserQuery(1)->findAll();
+ $this->assertCount(2, $tasks);
+
+ $this->assertTrue($columnModel->update(2, 'Test', 0, '', 1));
+
+ $tasks = $taskFinderModel->getUserQuery(1)->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ $this->assertEquals(1, $tasks[0]['column_id']);
+
+ $this->assertTrue($columnModel->update(2, 'Test', 0, '', 0));
+
+ $tasks = $taskFinderModel->getUserQuery(1)->findAll();
+ $this->assertCount(2, $tasks);
+ }
+
+ public function testGetOverdueTasks()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1)));
+
+ $tasks = $taskFinderModel->getOverdueTasks();
+ $this->assertNotEmpty($tasks);
+ $this->assertTrue(is_array($tasks));
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ }
+
+ public function testGetOverdueTasksByProject()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1)));
+
+ $tasks = $taskFinderModel->getOverdueTasksByProject(1);
+ $this->assertNotEmpty($tasks);
+ $this->assertTrue(is_array($tasks));
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ }
+
+ public function testGetOverdueTasksByUser()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1)));
+
+ $tasks = $taskFinderModel->getOverdueTasksByUser(1);
+ $this->assertNotEmpty($tasks);
+ $this->assertTrue(is_array($tasks));
+ $this->assertCount(2, $tasks);
+
+ $this->assertEquals(1, $tasks[0]['id']);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ $this->assertEquals(1, $tasks[0]['owner_id']);
+ $this->assertEquals(1, $tasks[0]['project_id']);
+ $this->assertEquals('Project #1', $tasks[0]['project_name']);
+ $this->assertEquals('admin', $tasks[0]['assignee_username']);
+ $this->assertEquals('', $tasks[0]['assignee_name']);
+
+ $this->assertEquals('Task #2', $tasks[1]['title']);
+ }
+
+ public function testCountByProject()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 2)));
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(2));
+ }
+
+ public function testGetProjectToken()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
+
+ $this->assertTrue($projectModel->enablePublicAccess(1));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2)));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals($project['token'], $taskFinderModel->getProjectToken(1));
+ $this->assertEmpty($taskFinderModel->getProjectToken(2));
+ }
+}
diff --git a/tests/units/Model/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php
deleted file mode 100644
index 46792baf..00000000
--- a/tests/units/Model/TaskFinderTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskFinderTest extends Base
-{
- public function testGetOverdueTasks()
- {
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #3', 'project_id' => 1)));
-
- $tasks = $tf->getOverdueTasks();
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertCount(1, $tasks);
- $this->assertEquals('Task #1', $tasks[0]['title']);
- }
-
- public function testGetOverdueTasksByProject()
- {
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(2, $p->create(array('name' => 'Project #2')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1)));
-
- $tasks = $tf->getOverdueTasksByProject(1);
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertCount(1, $tasks);
- $this->assertEquals('Task #1', $tasks[0]['title']);
- }
-
- public function testGetOverdueTasksByUser()
- {
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(2, $p->create(array('name' => 'Project #2')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1)));
-
- $tasks = $tf->getOverdueTasksByUser(1);
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertCount(2, $tasks);
-
- $this->assertEquals(1, $tasks[0]['id']);
- $this->assertEquals('Task #1', $tasks[0]['title']);
- $this->assertEquals(1, $tasks[0]['owner_id']);
- $this->assertEquals(1, $tasks[0]['project_id']);
- $this->assertEquals('Project #1', $tasks[0]['project_name']);
- $this->assertEquals('admin', $tasks[0]['assignee_username']);
- $this->assertEquals('', $tasks[0]['assignee_name']);
-
- $this->assertEquals('Task #2', $tasks[1]['title']);
- }
-
- public function testCountByProject()
- {
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(2, $p->create(array('name' => 'Project #2')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 2)));
-
- $this->assertEquals(1, $tf->countByProjectId(1));
- $this->assertEquals(2, $tf->countByProjectId(2));
- }
-
- public function testGetProjectToken()
- {
- $taskCreationModel = new TaskCreationModel($this->container);
- $taskFinderModel = new TaskFinderModel($this->container);
- $projectModel = new ProjectModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
- $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
-
- $this->assertTrue($projectModel->enablePublicAccess(1));
-
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
- $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2)));
-
- $project = $projectModel->getById(1);
- $this->assertEquals($project['token'], $taskFinderModel->getProjectToken(1));
- $this->assertEmpty($taskFinderModel->getProjectToken(2));
- }
-}
diff --git a/tests/units/Model/TaskLinkModelTest.php b/tests/units/Model/TaskLinkModelTest.php
index 78590891..01a7888b 100644
--- a/tests/units/Model/TaskLinkModelTest.php
+++ b/tests/units/Model/TaskLinkModelTest.php
@@ -9,6 +9,34 @@ use Kanboard\Model\ProjectModel;
class TaskLinkModelTest extends Base
{
+ public function testGeyById()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 6));
+
+ $taskLink = $taskLinkModel->getById(1);
+ $this->assertEquals(1, $taskLink['id']);
+ $this->assertEquals(1, $taskLink['task_id']);
+ $this->assertEquals(2, $taskLink['opposite_task_id']);
+ $this->assertEquals(6, $taskLink['link_id']);
+ $this->assertEquals(7, $taskLink['opposite_link_id']);
+ $this->assertEquals('is a child of', $taskLink['label']);
+
+ $taskLink = $taskLinkModel->getById(2);
+ $this->assertEquals(2, $taskLink['id']);
+ $this->assertEquals(2, $taskLink['task_id']);
+ $this->assertEquals(1, $taskLink['opposite_task_id']);
+ $this->assertEquals(7, $taskLink['link_id']);
+ $this->assertEquals(6, $taskLink['opposite_link_id']);
+ $this->assertEquals('is a parent of', $taskLink['label']);
+ }
+
// Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression"
public function testGetTaskWithMultipleMilestoneLink()
{
diff --git a/tests/units/Model/TaskModificationModelTest.php b/tests/units/Model/TaskModificationModelTest.php
index c81f968b..f70561b3 100644
--- a/tests/units/Model/TaskModificationModelTest.php
+++ b/tests/units/Model/TaskModificationModelTest.php
@@ -18,7 +18,8 @@ class TaskModificationModelTest extends Base
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals('Task #1', $event_data['title']);
+ $this->assertEquals('After', $event_data['task']['title']);
+ $this->assertEquals('After', $event_data['changes']['title']);
}
public function onUpdate($event)
@@ -28,7 +29,7 @@ class TaskModificationModelTest extends Base
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals('Task #1', $event_data['title']);
+ $this->assertEquals('After', $event_data['task']['title']);
}
public function onAssigneeChange($event)
@@ -38,7 +39,7 @@ class TaskModificationModelTest extends Base
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals(1, $event_data['owner_id']);
+ $this->assertEquals(1, $event_data['changes']['owner_id']);
}
public function testThatNoEventAreFiredWhenNoChanges()
@@ -66,19 +67,19 @@ class TaskModificationModelTest extends Base
$taskFinderModel = new TaskFinderModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test')));
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Before', 'project_id' => 1)));
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
$this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate'));
- $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'Task #1')));
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'After')));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.TaskModificationModelTest::onCreateUpdate', $called);
$this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.TaskModificationModelTest::onUpdate', $called);
$task = $taskFinderModel->getById(1);
- $this->assertEquals('Task #1', $task['title']);
+ $this->assertEquals('After', $task['title']);
}
public function testChangeAssignee()
diff --git a/tests/units/Model/TaskPositionTest.php b/tests/units/Model/TaskPositionModelTest.php
index 7ab6950e..03caf7ed 100644
--- a/tests/units/Model/TaskPositionTest.php
+++ b/tests/units/Model/TaskPositionModelTest.php
@@ -11,57 +11,57 @@ use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\SwimlaneModel;
-class TaskPositionTest extends Base
+class TaskPositionModelTest extends Base
{
public function testGetTaskProgression()
{
- $t = new TaskModel($this->container);
- $ts = new TaskStatusModel($this->container);
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskModel = new TaskModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
$columnModel = new ColumnModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(0, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(0, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($tp->movePosition(1, 1, 2, 1));
- $this->assertEquals(25, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 1));
+ $this->assertEquals(25, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($tp->movePosition(1, 1, 3, 1));
- $this->assertEquals(50, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 3, 1));
+ $this->assertEquals(50, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($tp->movePosition(1, 1, 4, 1));
- $this->assertEquals(75, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 4, 1));
+ $this->assertEquals(75, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($ts->close(1));
- $this->assertEquals(100, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskStatusModel->close(1));
+ $this->assertEquals(100, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
}
public function testMoveTaskToWrongPosition()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 2 to the position 0
- $this->assertFalse($tp->movePosition(1, 1, 3, 0));
+ $this->assertFalse($taskPositionModel->movePosition(1, 1, 3, 0));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
@@ -69,26 +69,26 @@ class TaskPositionTest extends Base
public function testMoveTaskToGreaterPosition()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 2 to the position 42
- $this->assertTrue($tp->movePosition(1, 1, 1, 42));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 42));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -96,26 +96,26 @@ class TaskPositionTest extends Base
public function testMoveTaskToEmptyColumn()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 1 to the column 3
- $this->assertTrue($tp->movePosition(1, 1, 3, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 3, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -123,62 +123,62 @@ class TaskPositionTest extends Base
public function testMoveTaskToAnotherColumn()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
-
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(7, $tc->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
- $this->assertEquals(8, $tc->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 1)));
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(6, $taskCreationModel->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(7, $taskCreationModel->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
+ $this->assertEquals(8, $taskCreationModel->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 1)));
// We move the task 3 to the column 3
- $this->assertTrue($tp->movePosition(1, 3, 3, 2));
+ $this->assertTrue($taskPositionModel->movePosition(1, 3, 3, 2));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(6);
+ $task = $taskFinderModel->getById(6);
$this->assertEquals(6, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $tf->getById(7);
+ $task = $taskFinderModel->getById(7);
$this->assertEquals(7, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(8);
+ $task = $taskFinderModel->getById(8);
$this->assertEquals(8, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -186,37 +186,37 @@ class TaskPositionTest extends Base
public function testMoveTaskTop()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
// Move the last task to the top
- $this->assertTrue($tp->movePosition(1, 4, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 4, 1, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -224,37 +224,37 @@ class TaskPositionTest extends Base
public function testMoveTaskBottom()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
// Move the first task to the bottom
- $this->assertTrue($tp->movePosition(1, 1, 1, 4));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 4));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -262,12 +262,12 @@ class TaskPositionTest extends Base
public function testMovePosition()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$counter = 1;
$task_per_column = 5;
@@ -280,240 +280,240 @@ class TaskPositionTest extends Base
'owner_id' => 0,
);
- $this->assertEquals($counter, $tc->create($task));
+ $this->assertEquals($counter, $taskCreationModel->create($task));
- $task = $tf->getById($counter);
+ $task = $taskFinderModel->getById($counter);
$this->assertNotEmpty($task);
$this->assertEquals($i, $task['position']);
}
}
// We move task id #4, column 1, position 4 to the column 2, position 3
- $this->assertTrue($tp->movePosition(1, 4, 2, 3));
+ $this->assertTrue($taskPositionModel->movePosition(1, 4, 2, 3));
// We check the new position of the task
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
// The tasks before have the correct position
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $tf->getById(7);
+ $task = $taskFinderModel->getById(7);
$this->assertEquals(7, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
// The tasks after have the correct position
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $tf->getById(8);
+ $task = $taskFinderModel->getById(8);
$this->assertEquals(8, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(4, $task['position']);
// The number of tasks per column
- $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column - 1, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 4));
// We move task id #1, column 1, position 1 to the column 4, position 6 (last position)
- $this->assertTrue($tp->movePosition(1, 1, 4, $task_per_column + 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 4, $task_per_column + 1));
// We check the new position of the task
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(4, $task['column_id']);
$this->assertEquals($task_per_column + 1, $task['position']);
// The tasks before have the correct position
- $task = $tf->getById(20);
+ $task = $taskFinderModel->getById(20);
$this->assertEquals(20, $task['id']);
$this->assertEquals(4, $task['column_id']);
$this->assertEquals($task_per_column, $task['position']);
// The tasks after have the correct position
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
// The number of tasks per column
- $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column - 2, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 4));
// Our previous moved task should stay at the same place
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
// Test wrong position number
- $this->assertFalse($tp->movePosition(1, 2, 3, 0));
- $this->assertFalse($tp->movePosition(1, 2, 3, -2));
+ $this->assertFalse($taskPositionModel->movePosition(1, 2, 3, 0));
+ $this->assertFalse($taskPositionModel->movePosition(1, 2, 3, -2));
// Wrong column
- $this->assertFalse($tp->movePosition(1, 2, 22, 2));
+ $this->assertFalse($taskPositionModel->movePosition(1, 2, 22, 2));
// Test position greater than the last position
- $this->assertTrue($tp->movePosition(1, 11, 1, 22));
+ $this->assertTrue($taskPositionModel->movePosition(1, 11, 1, 22));
- $task = $tf->getById(11);
+ $task = $taskFinderModel->getById(11);
$this->assertEquals(11, $task['id']);
$this->assertEquals(1, $task['column_id']);
- $this->assertEquals($tf->countByColumnId(1, 1), $task['position']);
+ $this->assertEquals($taskFinderModel->countByColumnId(1, 1), $task['position']);
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(1, $task['column_id']);
- $this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']);
+ $this->assertEquals($taskFinderModel->countByColumnId(1, 1) - 1, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column - 1, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 1, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 4));
// Our previous moved task should stay at the same place
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
// Test moving task to position 1
- $this->assertTrue($tp->movePosition(1, 14, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 14, 1, 1));
- $task = $tf->getById(14);
+ $task = $taskFinderModel->getById(14);
$this->assertEquals(14, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 2, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 4));
}
public function testMoveTaskSwimlane()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 1)));
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'test 1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 1)));
// Move the task to the swimlane
- $this->assertTrue($tp->movePosition(1, 1, 2, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 1, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
// Move the task to the swimlane
- $this->assertTrue($tp->movePosition(1, 2, 2, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 2, 2, 1, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
// Move the task 5 to the last column
- $this->assertTrue($tp->movePosition(1, 5, 4, 1, 0));
+ $this->assertTrue($taskPositionModel->movePosition(1, 5, 4, 1, 0));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(4, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -522,73 +522,73 @@ class TaskPositionTest extends Base
public function testEvents()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'test 1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2)));
$this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn'));
$this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_POSITION, array($this, 'onMovePosition'));
$this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane'));
// We move the task 1 to the column 2
- $this->assertTrue($tp->movePosition(1, 1, 2, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 1));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
$called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.TaskPositionModelTest::onMoveColumn', $called);
$this->assertEquals(1, count($called));
// We move the task 1 to the position 2
- $this->assertTrue($tp->movePosition(1, 1, 2, 2));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 2));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.TaskPositionModelTest::onMovePosition', $called);
$this->assertEquals(2, count($called));
// Move to another swimlane
- $this->assertTrue($tp->movePosition(1, 1, 3, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 3, 1, 1));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
$called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.TaskPositionModelTest::onMoveSwimlane', $called);
$this->assertEquals(3, count($called));
}
diff --git a/tests/units/Model/TaskProjectMoveModelTest.php b/tests/units/Model/TaskProjectMoveModelTest.php
index c4282638..52f61b28 100644
--- a/tests/units/Model/TaskProjectMoveModelTest.php
+++ b/tests/units/Model/TaskProjectMoveModelTest.php
@@ -24,7 +24,7 @@ class TaskProjectMoveModelTest extends Base
$event_data = $event->getAll();
$this->assertNotEmpty($event_data);
$this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals('test', $event_data['title']);
+ $this->assertEquals('test', $event_data['task']['title']);
}
public function testMoveAnotherProject()
diff --git a/tests/units/Model/UserModelTest.php b/tests/units/Model/UserModelTest.php
new file mode 100644
index 00000000..a0c9c575
--- /dev/null
+++ b/tests/units/Model/UserModelTest.php
@@ -0,0 +1,384 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\UserModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Core\Security\Role;
+
+class UserModelTest extends Base
+{
+ public function testGetByEmail()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'password' => '123456', 'email' => '')));
+
+ $this->assertNotEmpty($userModel->getByEmail('user1@localhost'));
+ $this->assertEmpty($userModel->getByEmail(''));
+ }
+
+ public function testGetByExternalId()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234')));
+
+ $this->assertNotEmpty($userModel->getByExternalId('gitlab_id', '1234'));
+ $this->assertEmpty($userModel->getByExternalId('gitlab_id', ''));
+
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'password' => '123456', 'github_id' => 'plop')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user3', 'password' => '123456', 'github_id' => '')));
+
+ $this->assertNotEmpty($userModel->getByExternalId('github_id', 'plop'));
+ $this->assertEmpty($userModel->getByExternalId('github_id', ''));
+
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user4', 'password' => '123456', 'google_id' => '1234')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user5', 'password' => '123456', 'google_id' => '')));
+
+ $this->assertNotEmpty($userModel->getByExternalId('google_id', '1234'));
+ $this->assertEmpty($userModel->getByExternalId('google_id', ''));
+ }
+
+ public function testGetByToken()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1', 'token' => 'random')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'token' => '')));
+
+ $this->assertNotEmpty($userModel->getByToken('random'));
+ $this->assertEmpty($userModel->getByToken(''));
+ }
+
+ public function testGetByUsername()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+
+ $this->assertNotEmpty($userModel->getByUsername('user1'));
+ $this->assertEmpty($userModel->getByUsername('user2'));
+ $this->assertEmpty($userModel->getByUsername(''));
+ }
+
+ public function testExists()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($userModel->exists(1));
+ $this->assertTrue($userModel->exists(2));
+ $this->assertFalse($userModel->exists(3));
+ }
+
+ public function testCount()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+ $this->assertEquals(2, $userModel->count());
+ }
+
+ public function testGetAll()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'you')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'me', 'name' => 'Me')));
+
+ $users = $userModel->getAll();
+ $this->assertCount(3, $users);
+ $this->assertEquals('admin', $users[0]['username']);
+ $this->assertEquals('me', $users[1]['username']);
+ $this->assertEquals('you', $users[2]['username']);
+ }
+
+ public function testGetActiveUsersList()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'you')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'me', 'name' => 'Me too')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'foobar', 'is_active' => 0)));
+
+ $users = $userModel->getActiveUsersList();
+
+ $expected = array(
+ 1 => 'admin',
+ 3 => 'Me too',
+ 2 => 'you',
+ );
+
+ $this->assertEquals($expected, $users);
+
+ $users = $userModel->getActiveUsersList(true);
+
+ $expected = array(
+ UserModel::EVERYBODY_ID => 'Everybody',
+ 1 => 'admin',
+ 3 => 'Me too',
+ 2 => 'you',
+ );
+
+ $this->assertEquals($expected, $users);
+ }
+
+ public function testIsAdmin()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($userModel->isAdmin(1));
+ $this->assertFalse($userModel->isAdmin(2));
+ }
+
+ public function testPassword()
+ {
+ $password = 'test123';
+ $hash = password_hash($password, PASSWORD_BCRYPT);
+
+ $this->assertNotEmpty($hash);
+ $this->assertTrue(password_verify($password, $hash));
+ }
+
+ public function testPrepare()
+ {
+ $userModel = new UserModel($this->container);
+
+ $input = array(
+ 'username' => 'user1',
+ 'password' => '1234',
+ 'confirmation' => '1234',
+ 'name' => 'me',
+ 'role' => Role::APP_ADMIN,
+ );
+
+ $userModel->prepare($input);
+ $this->assertArrayNotHasKey('confirmation', $input);
+
+ $this->assertArrayHasKey('password', $input);
+ $this->assertNotEquals('1234', $input['password']);
+ $this->assertNotEmpty($input['password']);
+
+ $input = array(
+ 'username' => 'user1',
+ 'password' => '1234',
+ 'current_password' => 'bla',
+ 'confirmation' => '1234',
+ 'name' => 'me',
+ 'is_ldap_user' => '1',
+ );
+
+ $userModel->prepare($input);
+ $this->assertArrayNotHasKey('confirmation', $input);
+ $this->assertArrayNotHasKey('current_password', $input);
+
+ $this->assertArrayHasKey('password', $input);
+ $this->assertNotEquals('1234', $input['password']);
+ $this->assertNotEmpty($input['password']);
+
+ $this->assertArrayHasKey('is_ldap_user', $input);
+ $this->assertEquals(1, $input['is_ldap_user']);
+
+ $input = array(
+ 'id' => 2,
+ 'name' => 'me',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('id' => 2, 'name' => 'me'), $input);
+
+ $input = array(
+ 'gitlab_id' => '1234',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('gitlab_id' => 1234), $input);
+
+ $input = array(
+ 'gitlab_id' => '',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('gitlab_id' => null), $input);
+
+ $input = array(
+ 'gitlab_id' => 'something',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('gitlab_id' => 0), $input);
+
+ $input = array(
+ 'username' => 'something',
+ 'password' => ''
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('username' => 'something'), $input);
+ }
+
+ public function testCreate()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'user #1', 'password' => '123456', 'name' => 'User')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user #2', 'is_ldap_user' => 1)));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user #3', 'role' => Role::APP_MANAGER)));
+ $this->assertEquals(5, $userModel->create(array('username' => 'user #4', 'gitlab_id' => '', 'role' => Role::APP_ADMIN)));
+ $this->assertEquals(6, $userModel->create(array('username' => 'user #5', 'gitlab_id' => '1234')));
+ $this->assertFalse($userModel->create(array('username' => 'user #1')));
+
+ $user = $userModel->getById(1);
+ $this->assertEquals('admin', $user['username']);
+ $this->assertEquals('', $user['name']);
+ $this->assertEquals(Role::APP_ADMIN, $user['role']);
+ $this->assertEquals(0, $user['is_ldap_user']);
+
+ $user = $userModel->getById(2);
+ $this->assertEquals('user #1', $user['username']);
+ $this->assertEquals('User', $user['name']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ $this->assertEquals(0, $user['is_ldap_user']);
+
+ $user = $userModel->getById(3);
+ $this->assertEquals('user #2', $user['username']);
+ $this->assertEquals('', $user['name']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ $this->assertEquals(1, $user['is_ldap_user']);
+
+ $user = $userModel->getById(4);
+ $this->assertEquals('user #3', $user['username']);
+ $this->assertEquals(Role::APP_MANAGER, $user['role']);
+
+ $user = $userModel->getById(5);
+ $this->assertEquals('user #4', $user['username']);
+ $this->assertEquals('', $user['gitlab_id']);
+ $this->assertEquals(Role::APP_ADMIN, $user['role']);
+
+ $user = $userModel->getById(6);
+ $this->assertEquals('user #5', $user['username']);
+ $this->assertEquals('1234', $user['gitlab_id']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ }
+
+ public function testUpdate()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'plop', 'gitlab_id' => '123')));
+
+ $this->assertTrue($userModel->update(array('id' => 2, 'username' => 'biloute')));
+ $this->assertTrue($userModel->update(array('id' => 3, 'gitlab_id' => '')));
+
+ $user = $userModel->getById(2);
+ $this->assertEquals('biloute', $user['username']);
+ $this->assertEquals('Toto', $user['name']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ $this->assertEquals(0, $user['is_ldap_user']);
+
+ $user = $userModel->getById(3);
+ $this->assertNotEmpty($user);
+ $this->assertEquals(null, $user['gitlab_id']);
+ }
+
+ public function testRemove()
+ {
+ $userModel = new UserModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+
+ $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['owner_id']);
+
+ $this->assertTrue($userModel->remove(1));
+ $this->assertTrue($userModel->remove(2));
+ $this->assertFalse($userModel->remove(2));
+ $this->assertFalse($userModel->remove(55));
+
+ // Make sure that assigned tasks are unassigned after removing the user
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(0, $task['owner_id']);
+
+ // Make sure that assigned subtasks are unassigned after removing the user
+ $subtask = $subtaskModel->getById(1);
+ $this->assertEquals(1, $subtask['id']);
+ $this->assertEquals(0, $subtask['user_id']);
+
+ // Make sure that comments are not related to the user anymore
+ $comment = $commentModel->getById(1);
+ $this->assertEquals(1, $comment['id']);
+ $this->assertEquals(0, $comment['user_id']);
+
+ // Make sure that private projects are also removed
+ $user_id1 = $userModel->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto'));
+ $user_id2 = $userModel->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto'));
+ $this->assertNotFalse($user_id1);
+ $this->assertNotFalse($user_id2);
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true));
+
+ $this->assertTrue($userModel->remove($user_id1));
+
+ $this->assertNotEmpty($projectModel->getById(1));
+ $this->assertNotEmpty($projectModel->getById(3));
+
+ $this->assertEmpty($projectModel->getById(2));
+ }
+
+ public function testEnableDisablePublicAccess()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456')));
+
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertEmpty($user['token']);
+
+ $this->assertTrue($userModel->enablePublicAccess(2));
+
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertNotEmpty($user['token']);
+
+ $this->assertTrue($userModel->disablePublicAccess(2));
+
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertEmpty($user['token']);
+ }
+
+ public function testEnableDisable()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'toto')));
+
+ $this->assertTrue($userModel->isActive(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(1, $user['is_active']);
+
+ $this->assertTrue($userModel->disable(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(0, $user['is_active']);
+ $this->assertFalse($userModel->isActive(2));
+
+ $this->assertTrue($userModel->enable(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(1, $user['is_active']);
+ $this->assertTrue($userModel->isActive(2));
+ }
+}
diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php
deleted file mode 100644
index 0be6172e..00000000
--- a/tests/units/Model/UserTest.php
+++ /dev/null
@@ -1,400 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\UserModel;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Model\CommentModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Core\Security\Role;
-
-class UserTest extends Base
-{
- public function testGetByEmail()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost')));
- $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'email' => '')));
-
- $this->assertNotEmpty($u->getByEmail('user1@localhost'));
- $this->assertEmpty($u->getByEmail(''));
- }
-
- public function testGetByExternalId()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234')));
-
- $this->assertNotEmpty($u->getByExternalId('gitlab_id', '1234'));
- $this->assertEmpty($u->getByExternalId('gitlab_id', ''));
-
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'github_id' => 'plop')));
- $this->assertNotFalse($u->create(array('username' => 'user3', 'password' => '123456', 'github_id' => '')));
-
- $this->assertNotEmpty($u->getByExternalId('github_id', 'plop'));
- $this->assertEmpty($u->getByExternalId('github_id', ''));
-
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user4', 'password' => '123456', 'google_id' => '1234')));
- $this->assertNotFalse($u->create(array('username' => 'user5', 'password' => '123456', 'google_id' => '')));
-
- $this->assertNotEmpty($u->getByExternalId('google_id', '1234'));
- $this->assertEmpty($u->getByExternalId('google_id', ''));
- }
-
- public function testGetByToken()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1', 'token' => 'random')));
- $this->assertNotFalse($u->create(array('username' => 'user2', 'token' => '')));
-
- $this->assertNotEmpty($u->getByToken('random'));
- $this->assertEmpty($u->getByToken(''));
- }
-
- public function testGetByUsername()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1')));
-
- $this->assertNotEmpty($u->getByUsername('user1'));
- $this->assertEmpty($u->getByUsername('user2'));
- $this->assertEmpty($u->getByUsername(''));
- }
-
- public function testExists()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1')));
-
- $this->assertTrue($u->exists(1));
- $this->assertTrue($u->exists(2));
- $this->assertFalse($u->exists(3));
- }
-
- public function testCount()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1')));
- $this->assertEquals(2, $u->count());
- }
-
- public function testGetAll()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'you')));
- $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me')));
-
- $users = $u->getAll();
- $this->assertCount(3, $users);
- $this->assertEquals('admin', $users[0]['username']);
- $this->assertEquals('me', $users[1]['username']);
- $this->assertEquals('you', $users[2]['username']);
- }
-
- public function testGetActiveUsersList()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'you')));
- $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me too')));
- $this->assertEquals(4, $u->create(array('username' => 'foobar', 'is_active' => 0)));
-
- $users = $u->getActiveUsersList();
-
- $expected = array(
- 1 => 'admin',
- 3 => 'Me too',
- 2 => 'you',
- );
-
- $this->assertEquals($expected, $users);
-
- $users = $u->getActiveUsersList(true);
-
- $expected = array(
- UserModel::EVERYBODY_ID => 'Everybody',
- 1 => 'admin',
- 3 => 'Me too',
- 2 => 'you',
- );
-
- $this->assertEquals($expected, $users);
- }
-
- public function testGetFullname()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'user1')));
- $this->assertEquals(3, $u->create(array('username' => 'user2', 'name' => 'User #2')));
-
- $user1 = $u->getById(2);
- $user2 = $u->getById(3);
-
- $this->assertNotEmpty($user1);
- $this->assertNotEmpty($user2);
-
- $this->assertEquals('user1', $u->getFullname($user1));
- $this->assertEquals('User #2', $u->getFullname($user2));
- }
-
- public function testIsAdmin()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'user1')));
-
- $this->assertTrue($u->isAdmin(1));
- $this->assertFalse($u->isAdmin(2));
- }
-
- public function testPassword()
- {
- $password = 'test123';
- $hash = password_hash($password, PASSWORD_BCRYPT);
-
- $this->assertNotEmpty($hash);
- $this->assertTrue(password_verify($password, $hash));
- }
-
- public function testPrepare()
- {
- $u = new UserModel($this->container);
-
- $input = array(
- 'username' => 'user1',
- 'password' => '1234',
- 'confirmation' => '1234',
- 'name' => 'me',
- 'role' => Role::APP_ADMIN,
- );
-
- $u->prepare($input);
- $this->assertArrayNotHasKey('confirmation', $input);
-
- $this->assertArrayHasKey('password', $input);
- $this->assertNotEquals('1234', $input['password']);
- $this->assertNotEmpty($input['password']);
-
- $input = array(
- 'username' => 'user1',
- 'password' => '1234',
- 'current_password' => 'bla',
- 'confirmation' => '1234',
- 'name' => 'me',
- 'is_ldap_user' => '1',
- );
-
- $u->prepare($input);
- $this->assertArrayNotHasKey('confirmation', $input);
- $this->assertArrayNotHasKey('current_password', $input);
-
- $this->assertArrayHasKey('password', $input);
- $this->assertNotEquals('1234', $input['password']);
- $this->assertNotEmpty($input['password']);
-
- $this->assertArrayHasKey('is_ldap_user', $input);
- $this->assertEquals(1, $input['is_ldap_user']);
-
- $input = array(
- 'id' => 2,
- 'name' => 'me',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('id' => 2, 'name' => 'me'), $input);
-
- $input = array(
- 'gitlab_id' => '1234',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('gitlab_id' => 1234), $input);
-
- $input = array(
- 'gitlab_id' => '',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('gitlab_id' => null), $input);
-
- $input = array(
- 'gitlab_id' => 'something',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('gitlab_id' => 0), $input);
-
- $input = array(
- 'username' => 'something',
- 'password' => ''
- );
-
- $u->prepare($input);
- $this->assertEquals(array('username' => 'something'), $input);
- }
-
- public function testCreate()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'user #1', 'password' => '123456', 'name' => 'User')));
- $this->assertEquals(3, $u->create(array('username' => 'user #2', 'is_ldap_user' => 1)));
- $this->assertEquals(4, $u->create(array('username' => 'user #3', 'role' => Role::APP_MANAGER)));
- $this->assertEquals(5, $u->create(array('username' => 'user #4', 'gitlab_id' => '', 'role' => Role::APP_ADMIN)));
- $this->assertEquals(6, $u->create(array('username' => 'user #5', 'gitlab_id' => '1234')));
- $this->assertFalse($u->create(array('username' => 'user #1')));
-
- $user = $u->getById(1);
- $this->assertEquals('admin', $user['username']);
- $this->assertEquals('', $user['name']);
- $this->assertEquals(Role::APP_ADMIN, $user['role']);
- $this->assertEquals(0, $user['is_ldap_user']);
-
- $user = $u->getById(2);
- $this->assertEquals('user #1', $user['username']);
- $this->assertEquals('User', $user['name']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- $this->assertEquals(0, $user['is_ldap_user']);
-
- $user = $u->getById(3);
- $this->assertEquals('user #2', $user['username']);
- $this->assertEquals('', $user['name']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- $this->assertEquals(1, $user['is_ldap_user']);
-
- $user = $u->getById(4);
- $this->assertEquals('user #3', $user['username']);
- $this->assertEquals(Role::APP_MANAGER, $user['role']);
-
- $user = $u->getById(5);
- $this->assertEquals('user #4', $user['username']);
- $this->assertEquals('', $user['gitlab_id']);
- $this->assertEquals(Role::APP_ADMIN, $user['role']);
-
- $user = $u->getById(6);
- $this->assertEquals('user #5', $user['username']);
- $this->assertEquals('1234', $user['gitlab_id']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- }
-
- public function testUpdate()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
- $this->assertEquals(3, $u->create(array('username' => 'plop', 'gitlab_id' => '123')));
-
- $this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute')));
- $this->assertTrue($u->update(array('id' => 3, 'gitlab_id' => '')));
-
- $user = $u->getById(2);
- $this->assertEquals('biloute', $user['username']);
- $this->assertEquals('Toto', $user['name']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- $this->assertEquals(0, $user['is_ldap_user']);
-
- $user = $u->getById(3);
- $this->assertNotEmpty($user);
- $this->assertEquals(null, $user['gitlab_id']);
- }
-
- public function testRemove()
- {
- $u = new UserModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SubtaskModel($this->container);
- $c = new CommentModel($this->container);
-
- $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
- $this->assertEquals(1, $s->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
- $this->assertEquals(1, $c->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
-
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(2, $task['owner_id']);
-
- $this->assertTrue($u->remove(1));
- $this->assertTrue($u->remove(2));
- $this->assertFalse($u->remove(2));
- $this->assertFalse($u->remove(55));
-
- // Make sure that assigned tasks are unassigned after removing the user
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(0, $task['owner_id']);
-
- // Make sure that assigned subtasks are unassigned after removing the user
- $subtask = $s->getById(1);
- $this->assertEquals(1, $subtask['id']);
- $this->assertEquals(0, $subtask['user_id']);
-
- // Make sure that comments are not related to the user anymore
- $comment = $c->getById(1);
- $this->assertEquals(1, $comment['id']);
- $this->assertEquals(0, $comment['user_id']);
-
- // Make sure that private projects are also removed
- $user_id1 = $u->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto'));
- $user_id2 = $u->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto'));
- $this->assertNotFalse($user_id1);
- $this->assertNotFalse($user_id2);
- $this->assertEquals(2, $p->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true));
- $this->assertEquals(3, $p->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true));
-
- $this->assertTrue($u->remove($user_id1));
-
- $this->assertNotEmpty($p->getById(1));
- $this->assertNotEmpty($p->getById(3));
-
- $this->assertEmpty($p->getById(2));
- }
-
- public function testEnableDisablePublicAccess()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456')));
-
- $user = $u->getById(2);
- $this->assertNotEmpty($user);
- $this->assertEquals('toto', $user['username']);
- $this->assertEmpty($user['token']);
-
- $this->assertTrue($u->enablePublicAccess(2));
-
- $user = $u->getById(2);
- $this->assertNotEmpty($user);
- $this->assertEquals('toto', $user['username']);
- $this->assertNotEmpty($user['token']);
-
- $this->assertTrue($u->disablePublicAccess(2));
-
- $user = $u->getById(2);
- $this->assertNotEmpty($user);
- $this->assertEquals('toto', $user['username']);
- $this->assertEmpty($user['token']);
- }
-
- public function testEnableDisable()
- {
- $userModel = new UserModel($this->container);
- $this->assertEquals(2, $userModel->create(array('username' => 'toto')));
-
- $this->assertTrue($userModel->isActive(2));
- $user = $userModel->getById(2);
- $this->assertEquals(1, $user['is_active']);
-
- $this->assertTrue($userModel->disable(2));
- $user = $userModel->getById(2);
- $this->assertEquals(0, $user['is_active']);
- $this->assertFalse($userModel->isActive(2));
-
- $this->assertTrue($userModel->enable(2));
- $user = $userModel->getById(2);
- $this->assertEquals(1, $user['is_active']);
- $this->assertTrue($userModel->isActive(2));
- }
-}
diff --git a/tests/units/Notification/MailNotificationTest.php b/tests/units/Notification/MailNotificationTest.php
new file mode 100644
index 00000000..93eeef0c
--- /dev/null
+++ b/tests/units/Notification/MailNotificationTest.php
@@ -0,0 +1,122 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\TaskLinkModel;
+use Kanboard\Model\UserModel;
+use Kanboard\Model\TaskFileModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Notification\MailNotification;
+use Kanboard\Subscriber\NotificationSubscriber;
+
+class MailNotificationTest extends Base
+{
+ public function testGetMailContent()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $fileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $fileModel->create(1, 'test', 'blah', 123));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $task = $taskFinderModel->getDetails(1);
+ $subtask = $subtaskModel->getById(1, true);
+ $comment = $commentModel->getById(1);
+ $file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
+
+ $this->assertNotEmpty($task);
+ $this->assertNotEmpty($subtask);
+ $this->assertNotEmpty($comment);
+ $this->assertNotEmpty($file);
+
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $eventData = array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'task_link' => $tasklink,
+ 'changes' => array()
+ );
+ $this->assertNotEmpty($mailNotification->getMailContent($eventName, $eventData));
+ $this->assertStringStartsWith('[test] ', $mailNotification->getMailSubject($eventName, $eventData));
+ }
+
+ $this->assertStringStartsWith('[Test1, Test2] ', $mailNotification->getMailSubject(TaskModel::EVENT_OVERDUE, array(
+ 'tasks' => array(array('id' => 123), array('id' => 456)),
+ 'project_name' => 'Test1, Test2',
+ )));
+ }
+
+ public function testSendWithEmailAddress()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($userModel->update(array('id' => 1, 'email' => 'test@localhost')));
+
+ $this->container['emailClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('send'))
+ ->getMock();
+
+ $this->container['emailClient']
+ ->expects($this->once())
+ ->method('send')
+ ->with(
+ $this->equalTo('test@localhost'),
+ $this->equalTo('admin'),
+ $this->equalTo('[test] New task #1: test'),
+ $this->stringContains('test')
+ );
+
+ $mailNotification->notifyUser($userModel->getById(1), TaskModel::EVENT_CREATE, array('task' => $taskFinderModel->getDetails(1)));
+ }
+
+ public function testSendWithoutEmailAddress()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $this->container['emailClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('send'))
+ ->getMock();
+
+ $this->container['emailClient']
+ ->expects($this->never())
+ ->method('send');
+
+ $mailNotification->notifyUser($userModel->getById(1), TaskModel::EVENT_CREATE, array('task' => $taskFinderModel->getDetails(1)));
+ }
+}
diff --git a/tests/units/Notification/MailTest.php b/tests/units/Notification/MailTest.php
deleted file mode 100644
index 9f077ac8..00000000
--- a/tests/units/Notification/MailTest.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Model\CommentModel;
-use Kanboard\Model\UserModel;
-use Kanboard\Model\TaskFileModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Model\TaskModel;
-use Kanboard\Notification\MailNotification;
-use Kanboard\Subscriber\NotificationSubscriber;
-
-class MailTest extends Base
-{
- public function testGetMailContent()
- {
- $en = new MailNotification($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $c = new CommentModel($this->container);
- $f = new TaskFileModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
- $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
- $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
-
- $task = $tf->getDetails(1);
- $subtask = $s->getById(1, true);
- $comment = $c->getById(1);
- $file = $c->getById(1);
-
- $this->assertNotEmpty($task);
- $this->assertNotEmpty($subtask);
- $this->assertNotEmpty($comment);
- $this->assertNotEmpty($file);
-
- foreach (NotificationSubscriber::getSubscribedEvents() as $event => $values) {
- $this->assertNotEmpty($en->getMailContent($event, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array())
- ));
-
- $this->assertNotEmpty($en->getMailSubject($event, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array())
- ));
- }
- }
-
- public function testSendWithEmailAddress()
- {
- $en = new MailNotification($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $u = new UserModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
- $this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost')));
-
- $this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\Mail\Client')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array('send'))
- ->getMock();
-
- $this->container['emailClient']
- ->expects($this->once())
- ->method('send')
- ->with(
- $this->equalTo('test@localhost'),
- $this->equalTo('admin'),
- $this->equalTo('[test][New task] test (#1)'),
- $this->stringContains('test')
- );
-
- $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1)));
- }
-
- public function testSendWithoutEmailAddress()
- {
- $en = new MailNotification($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $u = new UserModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
-
- $this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\Mail\Client')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array('send'))
- ->getMock();
-
- $this->container['emailClient']
- ->expects($this->never())
- ->method('send');
-
- $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1)));
- }
-}
diff --git a/tests/units/Notification/WebhookTest.php b/tests/units/Notification/WebhookNotificationTest.php
index 5a9eb1c7..6fbc349c 100644
--- a/tests/units/Notification/WebhookTest.php
+++ b/tests/units/Notification/WebhookNotificationTest.php
@@ -7,23 +7,23 @@ use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Subscriber\NotificationSubscriber;
-class WebhookTest extends Base
+class WebhookNotificationTest extends Base
{
public function testTaskCreation()
{
- $c = new ConfigModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $configModel = new ConfigModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
$this->container['dispatcher']->addSubscriber(new NotificationSubscriber($this->container));
- $c->save(array('webhook_url' => 'http://localhost/?task-creation'));
+ $configModel->save(array('webhook_url' => 'http://localhost/?task-creation'));
$this->container['httpClient']
->expects($this->once())
->method('postJson')
->with($this->stringContains('http://localhost/?task-creation&token='), $this->anything());
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
}
}
diff --git a/tests/units/Pagination/ProjectPaginationTest.php b/tests/units/Pagination/ProjectPaginationTest.php
new file mode 100644
index 00000000..35532d0d
--- /dev/null
+++ b/tests/units/Pagination/ProjectPaginationTest.php
@@ -0,0 +1,35 @@
+<?php
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\UserModel;
+use Kanboard\Pagination\ProjectPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectPaginationTest extends Base
+{
+ public function testDashboardPagination()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectPagination = new ProjectPagination($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2', 'is_private' => 1)));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'Project #3')));
+ $this->assertEquals(4, $projectModel->create(array('name' => 'Project #4', 'is_private' => 1)));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'test')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MANAGER));
+
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->getCollection());
+ $this->assertCount(0, $projectPagination->getDashboardPaginator(3, 'projects', 5)->getCollection());
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->setOrder(ProjectModel::TABLE.'.id')->getCollection());
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->setOrder(ProjectModel::TABLE.'.is_private')->getCollection());
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->setOrder(ProjectModel::TABLE.'.name')->getCollection());
+ }
+}
diff --git a/tests/units/Pagination/SubtaskPaginationTest.php b/tests/units/Pagination/SubtaskPaginationTest.php
new file mode 100644
index 00000000..26a51a8b
--- /dev/null
+++ b/tests/units/Pagination/SubtaskPaginationTest.php
@@ -0,0 +1,36 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Pagination\SubtaskPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskPaginationTest extends Base
+{
+ public function testDashboardPagination()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskPagination = new SubtaskPagination($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1', 'user_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask #1', 'user_id' => 1)));
+ $this->assertEquals(3, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1', 'user_id' => 1)));
+ $this->assertEquals(4, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask #1')));
+ $this->assertEquals(5, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1')));
+
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->getCollection());
+ $this->assertCount(0, $subtaskPagination->getDashboardPaginator(2, 'subtasks', 5)->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder(TaskModel::TABLE.'.id')->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder('project_name')->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder('task_name')->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder(SubtaskModel::TABLE.'.title')->getCollection());
+ }
+}
diff --git a/tests/units/Pagination/TaskPaginationTest.php b/tests/units/Pagination/TaskPaginationTest.php
new file mode 100644
index 00000000..027212e2
--- /dev/null
+++ b/tests/units/Pagination/TaskPaginationTest.php
@@ -0,0 +1,30 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Pagination\TaskPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskPaginationTest extends Base
+{
+ public function testDashboardPagination()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskPagination = new TaskPagination($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->getCollection());
+ $this->assertCount(0, $taskPagination->getDashboardPaginator(2, 'tasks', 5)->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.id')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder('project_name')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.title')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.priority')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.date_due')->getCollection());
+ }
+}
diff --git a/tests/units/Pagination/UserPaginationTest.php b/tests/units/Pagination/UserPaginationTest.php
new file mode 100644
index 00000000..c475aacd
--- /dev/null
+++ b/tests/units/Pagination/UserPaginationTest.php
@@ -0,0 +1,27 @@
+<?php
+
+use Kanboard\Model\UserModel;
+use Kanboard\Pagination\UserPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class UserPaginationTest extends Base
+{
+ public function testListingPagination()
+ {
+ $userModel = new UserModel($this->container);
+ $userPagination = new UserPagination($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'test1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'test2')));
+
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('id')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('username')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('name')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('email')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('role')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('twofactor_activated')->setDirection('DESC')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('is_ldap_user')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('is_active')->getCollection());
+ }
+}
diff --git a/tests/units/ServiceProvider/ClassProviderTest.php b/tests/units/ServiceProvider/ClassProviderTest.php
new file mode 100644
index 00000000..f6528918
--- /dev/null
+++ b/tests/units/ServiceProvider/ClassProviderTest.php
@@ -0,0 +1,21 @@
+<?php
+
+use Kanboard\ServiceProvider\ClassProvider;
+use Pimple\Container;
+
+require_once __DIR__.'/../Base.php';
+
+class ModelProviderTest extends Base
+{
+ public function testServiceInstance()
+ {
+ $container = new Container();
+ $serviceProvider = new ClassProvider($container);
+ $serviceProvider->register($container);
+
+ $instance1 = $container['userModel'];
+ $instance2 = $container['userModel'];
+
+ $this->assertSame($instance1, $instance2);
+ }
+}
diff --git a/tests/units/ServiceProvider/FormatterProviderTest.php b/tests/units/ServiceProvider/FormatterProviderTest.php
new file mode 100644
index 00000000..7984a12b
--- /dev/null
+++ b/tests/units/ServiceProvider/FormatterProviderTest.php
@@ -0,0 +1,21 @@
+<?php
+
+use Kanboard\ServiceProvider\FormatterProvider;
+use Pimple\Container;
+
+require_once __DIR__.'/../Base.php';
+
+class FormatterProviderTest extends Base
+{
+ public function testServiceInstance()
+ {
+ $container = new Container();
+ $serviceProvider = new FormatterProvider($container);
+ $serviceProvider->register($container);
+
+ $instance1 = $container['userAutoCompleteFormatter'];
+ $instance2 = $container['userAutoCompleteFormatter'];
+
+ $this->assertNotSame($instance1, $instance2);
+ }
+}
diff --git a/tests/units/Subscriber/RecurringTaskSubscriberTest.php b/tests/units/Subscriber/RecurringTaskSubscriberTest.php
new file mode 100644
index 00000000..d6aba7cf
--- /dev/null
+++ b/tests/units/Subscriber/RecurringTaskSubscriberTest.php
@@ -0,0 +1,164 @@
+<?php
+
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Subscriber\RecurringTaskSubscriber;
+
+require_once __DIR__.'/../Base.php';
+
+class RecurringTaskSubscriberTest extends Base
+{
+ public function testWithNoRecurrence()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceFirstColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_FIRST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('src_column_id' => 1))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceFirstColumnWithWrongColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_FIRST_COLUMN,
+ 'column_id' => 2,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('src_column_id' => 2))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceLastColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_LAST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('dst_column_id' => 4))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceLastColumnWithWrongColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_LAST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('dst_column_id' => 2))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceOnClose()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withChanges(array('is_active' => 0))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+}
diff --git a/tests/units/Validator/CommentValidatorTest.php b/tests/units/Validator/CommentValidatorTest.php
index 378fe924..ce65e7a3 100644
--- a/tests/units/Validator/CommentValidatorTest.php
+++ b/tests/units/Validator/CommentValidatorTest.php
@@ -8,50 +8,50 @@ class CommentValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new CommentValidator($this->container);
+ $commentValidator = new CommentValidator($this->container);
- $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla'));
+ $result = $commentValidator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]);
- $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => ''));
+ $result = $commentValidator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => ''));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla'));
+ $result = $commentValidator->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla'));
+ $result = $commentValidator->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('user_id' => 1, 'comment' => 'bla'));
+ $result = $commentValidator->validateCreation(array('user_id' => 1, 'comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('task_id' => 1, 'comment' => 'bla'));
+ $result = $commentValidator->validateCreation(array('task_id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]);
- $result = $validator->validateCreation(array('comment' => 'bla'));
+ $result = $commentValidator->validateCreation(array('comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array());
+ $result = $commentValidator->validateCreation(array());
$this->assertFalse($result[0]);
}
public function testValidateModification()
{
- $validator = new CommentValidator($this->container);
+ $commentValidator = new CommentValidator($this->container);
- $result = $validator->validateModification(array('id' => 1, 'comment' => 'bla'));
+ $result = $commentValidator->validateModification(array('id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]);
- $result = $validator->validateModification(array('id' => 1, 'comment' => ''));
+ $result = $commentValidator->validateModification(array('id' => 1, 'comment' => ''));
$this->assertFalse($result[0]);
- $result = $validator->validateModification(array('comment' => 'bla'));
+ $result = $commentValidator->validateModification(array('comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateModification(array('id' => 'b', 'comment' => 'bla'));
+ $result = $commentValidator->validateModification(array('id' => 'b', 'comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateModification(array());
+ $result = $commentValidator->validateModification(array());
$this->assertFalse($result[0]);
}
}
diff --git a/tests/units/Validator/CurrencyValidatorTest.php b/tests/units/Validator/CurrencyValidatorTest.php
index 39c06d44..0b646732 100644
--- a/tests/units/Validator/CurrencyValidatorTest.php
+++ b/tests/units/Validator/CurrencyValidatorTest.php
@@ -8,20 +8,20 @@ class CurrencyValidatorTest extends Base
{
public function testValidation()
{
- $validator = new CurrencyValidator($this->container);
- $result = $validator->validateCreation(array());
+ $currencyValidator = new CurrencyValidator($this->container);
+ $result = $currencyValidator->validateCreation(array());
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('currency' => 'EUR'));
+ $result = $currencyValidator->validateCreation(array('currency' => 'EUR'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('rate' => 1.9));
+ $result = $currencyValidator->validateCreation(array('rate' => 1.9));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar'));
+ $result = $currencyValidator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 1.25));
+ $result = $currencyValidator->validateCreation(array('currency' => 'EUR', 'rate' => 1.25));
$this->assertTrue($result[0]);
}
}
diff --git a/tests/units/Validator/CustomFilterValidatorTest.php b/tests/units/Validator/CustomFilterValidatorTest.php
index 3b70e42c..4e107f7f 100644
--- a/tests/units/Validator/CustomFilterValidatorTest.php
+++ b/tests/units/Validator/CustomFilterValidatorTest.php
@@ -8,16 +8,16 @@ class CustomFilterValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new CustomFilterValidator($this->container);
+ $customFilterValidator = new CustomFilterValidator($this->container);
// Validate creation
- $r = $validator->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $r = $customFilterValidator->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
$this->assertTrue($r[0]);
- $r = $validator->validateCreation(array('filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $r = $customFilterValidator->validateCreation(array('filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $r = $customFilterValidator->validateCreation(array('name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
$this->assertFalse($r[0]);
}
diff --git a/tests/units/Validator/ExternalLinkValidatorTest.php b/tests/units/Validator/ExternalLinkValidatorTest.php
index b41b779a..c94c31db 100644
--- a/tests/units/Validator/ExternalLinkValidatorTest.php
+++ b/tests/units/Validator/ExternalLinkValidatorTest.php
@@ -8,27 +8,27 @@ class ExternalLinkValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new ExternalLinkValidator($this->container);
+ $externalLinkValidator = new ExternalLinkValidator($this->container);
- $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertTrue($result[0]);
- $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 'abc', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 'abc', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink'));
+ $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'dependency' => 'related'));
+ $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'dependency' => 'related'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'link_type' => 'weblink', 'dependency' => 'related'));
+ $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('url' => 'http://somewhere', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $result = $externalLinkValidator->validateCreation(array('task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertFalse($result[0]);
}
diff --git a/tests/units/Validator/GroupValidatorTest.php b/tests/units/Validator/GroupValidatorTest.php
index 879f99ce..020a8bc6 100644
--- a/tests/units/Validator/GroupValidatorTest.php
+++ b/tests/units/Validator/GroupValidatorTest.php
@@ -8,12 +8,12 @@ class GroupValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new GroupValidator($this->container);
+ $groupValidator = new GroupValidator($this->container);
- $result = $validator->validateCreation(array('name' => 'Test'));
+ $result = $groupValidator->validateCreation(array('name' => 'Test'));
$this->assertTrue($result[0]);
- $result = $validator->validateCreation(array('name' => ''));
+ $result = $groupValidator->validateCreation(array('name' => ''));
$this->assertFalse($result[0]);
}
diff --git a/tests/units/Validator/LinkValidatorTest.php b/tests/units/Validator/LinkValidatorTest.php
index 8b7b182c..a4ec170e 100644
--- a/tests/units/Validator/LinkValidatorTest.php
+++ b/tests/units/Validator/LinkValidatorTest.php
@@ -8,21 +8,21 @@ class LinkValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new LinkValidator($this->container);
+ $linkValidator = new LinkValidator($this->container);
- $r = $validator->validateCreation(array('label' => 'a'));
+ $r = $linkValidator->validateCreation(array('label' => 'a'));
$this->assertTrue($r[0]);
- $r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
+ $r = $linkValidator->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
$this->assertTrue($r[0]);
- $r = $validator->validateCreation(array('label' => 'relates to'));
+ $r = $linkValidator->validateCreation(array('label' => 'relates to'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
+ $r = $linkValidator->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('label' => ''));
+ $r = $linkValidator->validateCreation(array('label' => ''));
$this->assertFalse($r[0]);
}
diff --git a/tests/units/Validator/PasswordResetValidatorTest.php b/tests/units/Validator/PasswordResetValidatorTest.php
index d26ad422..eed77e42 100644
--- a/tests/units/Validator/PasswordResetValidatorTest.php
+++ b/tests/units/Validator/PasswordResetValidatorTest.php
@@ -8,22 +8,22 @@ class PasswordResetValidatorTest extends Base
{
public function testValidateModification()
{
- $validator = new PasswordResetValidator($this->container);
- list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test123'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test123', 'confirmation' => 'test123'));
$this->assertTrue($valid);
}
public function testValidateModificationWithWrongPasswords()
{
- $validator = new PasswordResetValidator($this->container);
- list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test456'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test123', 'confirmation' => 'test456'));
$this->assertFalse($valid);
}
public function testValidateModificationWithPasswordTooShort()
{
- $validator = new PasswordResetValidator($this->container);
- list($valid, ) = $validator->validateModification(array('password' => 'test', 'confirmation' => 'test'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test', 'confirmation' => 'test'));
$this->assertFalse($valid);
}
@@ -31,8 +31,8 @@ class PasswordResetValidatorTest extends Base
{
$this->container['sessionStorage']->captcha = 'test';
- $validator = new PasswordResetValidator($this->container);
- list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
$this->assertTrue($valid);
}
@@ -40,8 +40,8 @@ class PasswordResetValidatorTest extends Base
{
$this->container['sessionStorage']->captcha = 'test';
- $validator = new PasswordResetValidator($this->container);
- list($valid,) = $validator->validateCreation(array('captcha' => 'test'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid,) = $passwordResetValidator->validateCreation(array('captcha' => 'test'));
$this->assertFalse($valid);
}
@@ -49,15 +49,15 @@ class PasswordResetValidatorTest extends Base
{
$this->container['sessionStorage']->captcha = 'test123';
- $validator = new PasswordResetValidator($this->container);
- list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
$this->assertFalse($valid);
}
public function testValidateCreationWithMissingCaptcha()
{
- $validator = new PasswordResetValidator($this->container);
- list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
$this->assertFalse($valid);
}
}
diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php
index e1e2f077..212c5317 100644
--- a/tests/units/Validator/ProjectValidatorTest.php
+++ b/tests/units/Validator/ProjectValidatorTest.php
@@ -9,65 +9,65 @@ class ProjectValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new ProjectValidator($this->container);
- $p = new ProjectModel($this->container);
+ $projectValidator = new ProjectValidator($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']);
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
$this->assertEquals('', $project['identifier']);
- $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1'));
+ $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test1'));
+ $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'test1'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c'));
+ $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test 123'));
+ $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'test 123'));
$this->assertFalse($r[0]);
}
public function testValidateModification()
{
- $validator = new ProjectValidator($this->container);
- $p = new ProjectModel($this->container);
+ $projectValidator = new ProjectValidator($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']);
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
$this->assertEquals('TEST2', $project['identifier']);
- $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
+ $r = $projectValidator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'identifier' => 'test3'));
+ $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => 'test3'));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'identifier' => ''));
+ $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => ''));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'identifier' => 'TEST2'));
+ $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => 'TEST2'));
$this->assertFalse($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => ''));
+ $r = $projectValidator->validateModification(array('id' => 1, 'name' => ''));
$this->assertFalse($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => null));
+ $r = $projectValidator->validateModification(array('id' => 1, 'name' => null));
$this->assertFalse($r[0]);
}
}
diff --git a/tests/units/Validator/TaskLinkValidatorTest.php b/tests/units/Validator/TaskLinkValidatorTest.php
index 5fc50e3e..414cf696 100644
--- a/tests/units/Validator/TaskLinkValidatorTest.php
+++ b/tests/units/Validator/TaskLinkValidatorTest.php
@@ -11,62 +11,62 @@ class TaskLinkValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new TaskLinkValidator($this->container);
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $taskLinkValidator = new TaskLinkValidator($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
- $links = $tl->getAll(1);
+ $links = $taskLinkModel->getAll(1);
$this->assertEmpty($links);
- $links = $tl->getAll(2);
+ $links = $taskLinkModel->getAll(2);
$this->assertEmpty($links);
// Check creation
- $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
+ $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
$this->assertTrue($r[0]);
- $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1));
+ $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'link_id' => 1));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
+ $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
+ $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
+ $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
$this->assertFalse($r[0]);
}
public function testValidateModification()
{
- $validator = new TaskLinkValidator($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $taskLinkValidator = new TaskLinkValidator($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
// Check modification
- $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
+ $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1));
+ $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1));
$this->assertFalse($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2));
+ $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2));
$this->assertFalse($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2));
+ $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2));
$this->assertFalse($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
+ $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
$this->assertFalse($r[0]);
}
}
diff --git a/tests/units/Validator/TaskValidatorTest.php b/tests/units/Validator/TaskValidatorTest.php
new file mode 100644
index 00000000..f6530027
--- /dev/null
+++ b/tests/units/Validator/TaskValidatorTest.php
@@ -0,0 +1,42 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\TaskValidator;
+
+class TaskValidatorTest extends Base
+{
+ public function testRequiredFields()
+ {
+ $taskValidator = new TaskValidator($this->container);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test'));
+ $this->assertTrue($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1));
+ $this->assertFalse($result[0]);
+
+ $result = $taskValidator->validateCreation(array('title' => 'test'));
+ $this->assertFalse($result[0]);
+ }
+
+ public function testRangeFields()
+ {
+ $taskValidator = new TaskValidator($this->container);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 2147483647));
+ $this->assertTrue($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => -2147483647));
+ $this->assertTrue($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 0));
+ $this->assertTrue($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 2147483648));
+ $this->assertFalse($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => -2147483648));
+ $this->assertFalse($result[0]);
+ }
+}
diff --git a/tests/units/Validator/UserValidatorTest.php b/tests/units/Validator/UserValidatorTest.php
index 6d904ade..64c76175 100644
--- a/tests/units/Validator/UserValidatorTest.php
+++ b/tests/units/Validator/UserValidatorTest.php
@@ -9,7 +9,7 @@ class UserValidatorTest extends Base
{
public function testValidatePasswordModification()
{
- $validator = new UserValidator($this->container);
+ $userValidator = new UserValidator($this->container);
$this->container['sessionStorage']->user = array(
'id' => 1,
@@ -17,25 +17,25 @@ class UserValidatorTest extends Base
'username' => 'admin',
);
- $result = $validator->validatePasswordModification(array());
+ $result = $userValidator->validatePasswordModification(array());
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1));
+ $result = $userValidator->validatePasswordModification(array('id' => 1));
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456'));
+ $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456'));
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong'));
+ $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong'));
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456'));
+ $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456'));
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'wrong'));
+ $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'wrong'));
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'admin'));
+ $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'admin'));
$this->assertTrue($result[0]);
}
}