summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Auth/ApiAccessTokenAuthTest.php71
-rw-r--r--tests/units/Base.php1
-rw-r--r--tests/units/EventBuilder/CommentEventBuilderTest.php2
-rw-r--r--tests/units/EventBuilder/ProjectFileEventBuilderTest.php2
-rw-r--r--tests/units/EventBuilder/SubtaskEventBuilderTest.php2
-rw-r--r--tests/units/EventBuilder/TaskEventBuilderTest.php2
-rw-r--r--tests/units/EventBuilder/TaskFileEventBuilderTest.php2
-rw-r--r--tests/units/EventBuilder/TaskLinkEventBuilderTest.php2
-rw-r--r--tests/units/Filter/TaskStartsWithIdFilterTest.php103
-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/TextHelperTest.php7
-rw-r--r--tests/units/Job/CommentEventJobTest.php42
-rw-r--r--tests/units/Job/TaskEventJobTest.php40
-rw-r--r--tests/units/Job/UserMentionJobTest.php (renamed from tests/units/Model/UserMentionTest.php)74
-rw-r--r--tests/units/Model/ConfigModelTest.php125
-rw-r--r--tests/units/Model/ConfigTest.php116
-rw-r--r--tests/units/Model/ProjectPermissionModelTest.php21
19 files changed, 564 insertions, 161 deletions
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/Base.php b/tests/units/Base.php
index 722a1335..1b986fcb 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -49,6 +49,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
$this->container->register(new Kanboard\ServiceProvider\FilterProvider());
$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,
diff --git a/tests/units/EventBuilder/CommentEventBuilderTest.php b/tests/units/EventBuilder/CommentEventBuilderTest.php
index 2f6a90b5..ff1c630e 100644
--- a/tests/units/EventBuilder/CommentEventBuilderTest.php
+++ b/tests/units/EventBuilder/CommentEventBuilderTest.php
@@ -33,5 +33,7 @@ class CommentEventBuilderTest extends Base
$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
index 8f5eb87e..c3595029 100644
--- a/tests/units/EventBuilder/ProjectFileEventBuilderTest.php
+++ b/tests/units/EventBuilder/ProjectFileEventBuilderTest.php
@@ -29,5 +29,7 @@ class ProjectFileEventBuilderTest extends Base
$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
index fe425cb8..215b1ed2 100644
--- a/tests/units/EventBuilder/SubtaskEventBuilderTest.php
+++ b/tests/units/EventBuilder/SubtaskEventBuilderTest.php
@@ -58,5 +58,7 @@ class SubtaskEventBuilderTest extends Base
$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
index c89dcd85..446b862b 100644
--- a/tests/units/EventBuilder/TaskEventBuilderTest.php
+++ b/tests/units/EventBuilder/TaskEventBuilderTest.php
@@ -33,6 +33,8 @@ class TaskEventBuilderTest extends Base
$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']);
}
diff --git a/tests/units/EventBuilder/TaskFileEventBuilderTest.php b/tests/units/EventBuilder/TaskFileEventBuilderTest.php
index c90e18d3..1e88b6fb 100644
--- a/tests/units/EventBuilder/TaskFileEventBuilderTest.php
+++ b/tests/units/EventBuilder/TaskFileEventBuilderTest.php
@@ -32,5 +32,7 @@ class TaskFileEventBuilderTest extends Base
$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
index 18508146..4e38eeb6 100644
--- a/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
+++ b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
@@ -33,6 +33,8 @@ class TaskLinkEventBuilderTest extends Base
$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()
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/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/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php
index c9447abb..a54c5780 100644
--- a/tests/units/Helper/TextHelperTest.php
+++ b/tests/units/Helper/TextHelperTest.php
@@ -32,7 +32,7 @@ class TextHelperTest extends Base
);
$this->assertEquals(
- '<p>Task <a href="?controller=TaskViewController&amp;action=readonly&amp;token='.$project['token'].'&amp;task_id=1">#1</a></p>',
+ '<p>Task <a href="http://localhost/?controller=TaskViewController&amp;action=readonly&amp;token='.$project['token'].'&amp;task_id=1">#1</a></p>',
$helper->markdown('Task #1', true)
);
@@ -48,6 +48,11 @@ class TextHelperTest extends Base
{
$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 <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link">@admin</a>,</p>', $h->markdown('Text @admin,'));
+ $this->assertEquals('<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link">@admin</a>!</p>', $h->markdown('Text @admin!'));
+ $this->assertEquals('<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link">@admin</a>? </p>', $h->markdown('Text @admin? '));
+ $this->assertEquals('<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link">@admin</a>.</p>', $h->markdown('Text @admin.'));
+ $this->assertEquals('<p>Text <a href="?controller=UserViewController&amp;action=profile&amp;user_id=1" class="user-mention-link">@admin</a>: test</p>', $h->markdown('Text @admin: test'));
$this->assertEquals('<p>Text @admin @notfound</p>', $h->markdown('Text @admin @notfound', true));
}
diff --git a/tests/units/Job/CommentEventJobTest.php b/tests/units/Job/CommentEventJobTest.php
index 8571af8e..b830b2b8 100644
--- a/tests/units/Job/CommentEventJobTest.php
+++ b/tests/units/Job/CommentEventJobTest.php
@@ -49,4 +49,46 @@ class CommentEventJobTest extends Base
$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/TaskEventJobTest.php b/tests/units/Job/TaskEventJobTest.php
index c399faad..bfd7bc55 100644
--- a/tests/units/Job/TaskEventJobTest.php
+++ b/tests/units/Job/TaskEventJobTest.php
@@ -186,4 +186,44 @@ class TaskEventJobTest extends Base
$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/Model/UserMentionTest.php b/tests/units/Job/UserMentionJobTest.php
index b41c92cd..4cd4ac9b 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,41 @@ 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->assertEmpty($userMentionModel->getMentionedUsers('test @user2'));
+ $users = $userMentionJob->getMentionedUsers('test @user2, test');
+ $this->assertCount(1, $users);
+ $this->assertEquals('user2', $users[0]['username']);
+ $this->assertEquals('Foobar', $users[0]['name']);
+ $this->assertEquals('', $users[0]['email']);
+ $this->assertEquals('', $users[0]['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 +88,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/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/ProjectPermissionModelTest.php b/tests/units/Model/ProjectPermissionModelTest.php
index 3313cf2d..7f604374 100644
--- a/tests/units/Model/ProjectPermissionModelTest.php
+++ b/tests/units/Model/ProjectPermissionModelTest.php
@@ -26,7 +26,7 @@ class ProjectPermissionModelTest 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 ProjectPermissionModelTest 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'));
}