summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Action/TaskAssignCurrentUserTest.php7
-rw-r--r--tests/units/Auth/LdapTest.php16
-rw-r--r--tests/units/Base.php8
-rw-r--r--tests/units/Core/Session/FlashMessageTest.php23
-rw-r--r--tests/units/Core/Session/SessionStorageTest.php38
-rw-r--r--tests/units/Helper/AppHelperTest.php10
-rw-r--r--tests/units/Helper/UserHelperTest.php19
-rw-r--r--tests/units/Model/AclTest.php24
-rw-r--r--tests/units/Model/ConfigTest.php10
-rw-r--r--tests/units/Model/SubtaskTest.php4
-rw-r--r--tests/units/Model/SubtaskTimeTrackingTest.php4
-rw-r--r--tests/units/Model/TaskCreationTest.php5
-rw-r--r--tests/units/Model/TaskDuplicationTest.php5
-rw-r--r--tests/units/Model/TaskPermissionTest.php16
-rw-r--r--tests/units/Model/UserSessionTest.php144
15 files changed, 247 insertions, 86 deletions
diff --git a/tests/units/Action/TaskAssignCurrentUserTest.php b/tests/units/Action/TaskAssignCurrentUserTest.php
index f8946577..08176b1c 100644
--- a/tests/units/Action/TaskAssignCurrentUserTest.php
+++ b/tests/units/Action/TaskAssignCurrentUserTest.php
@@ -43,19 +43,16 @@ class TaskAssignCurrentUserTest extends Base
public function testExecute()
{
+ $this->container['sessionStorage']->user = array('id' => 5);
+
$action = new TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
- $_SESSION = array(
- 'user' => array('id' => 5)
- );
// We create a task in the first column
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
- $us = new UserSession($this->container);
- $this->assertEquals(5, $us->getId());
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
diff --git a/tests/units/Auth/LdapTest.php b/tests/units/Auth/LdapTest.php
index 19e7d7e2..bf2cec35 100644
--- a/tests/units/Auth/LdapTest.php
+++ b/tests/units/Auth/LdapTest.php
@@ -402,7 +402,7 @@ class LdapTest extends \Base
$this->container['userSession'] = $this
->getMockBuilder('\Kanboard\Model\UserSession')
->setConstructorArgs(array($this->container))
- ->setMethods(array('refresh'))
+ ->setMethods(array('initialize'))
->getMock();
$this->container['user'] = $this
@@ -436,7 +436,7 @@ class LdapTest extends \Base
$this->container['userSession']
->expects($this->once())
- ->method('refresh');
+ ->method('initialize');
$this->assertTrue($ldap->authenticate('user', 'password'));
}
@@ -446,7 +446,7 @@ class LdapTest extends \Base
$this->container['userSession'] = $this
->getMockBuilder('\Kanboard\Model\UserSession')
->setConstructorArgs(array($this->container))
- ->setMethods(array('refresh'))
+ ->setMethods(array('initialize'))
->getMock();
$this->container['user'] = $this
@@ -480,7 +480,7 @@ class LdapTest extends \Base
$this->container['userSession']
->expects($this->never())
- ->method('refresh');
+ ->method('initialize');
$this->assertFalse($ldap->authenticate('user', 'password'));
}
@@ -492,7 +492,7 @@ class LdapTest extends \Base
$this->container['userSession'] = $this
->getMockBuilder('\Kanboard\Model\UserSession')
->setConstructorArgs(array($this->container))
- ->setMethods(array('refresh'))
+ ->setMethods(array('initialize'))
->getMock();
$this->container['user'] = $this
@@ -542,7 +542,7 @@ class LdapTest extends \Base
$this->container['userSession']
->expects($this->once())
- ->method('refresh');
+ ->method('initialize');
$this->assertTrue($ldap->authenticate('user', 'password'));
}
@@ -554,7 +554,7 @@ class LdapTest extends \Base
$this->container['userSession'] = $this
->getMockBuilder('\Kanboard\Model\UserSession')
->setConstructorArgs(array($this->container))
- ->setMethods(array('refresh'))
+ ->setMethods(array('initialize'))
->getMock();
$this->container['user'] = $this
@@ -596,7 +596,7 @@ class LdapTest extends \Base
$this->container['userSession']
->expects($this->never())
- ->method('refresh');
+ ->method('initialize');
$this->assertFalse($ldap->authenticate('user', 'password'));
}
diff --git a/tests/units/Base.php b/tests/units/Base.php
index 8112c954..6d7a97a3 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -8,6 +8,8 @@ use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
use Symfony\Component\Stopwatch\Stopwatch;
use SimpleLogger\Logger;
use SimpleLogger\File;
+use Kanboard\Core\Session\FlashMessage;
+use Kanboard\Core\Session\SessionStorage;
class FakeHttpClient
{
@@ -93,6 +95,12 @@ abstract class Base extends PHPUnit_Framework_TestCase
->setConstructorArgs(array($this->container))
->setMethods(array('getType', 'getSelectedTypes'))
->getMock();
+
+ $this->container['sessionStorage'] = new SessionStorage;
+
+ $this->container['flash'] = function($c) {
+ return new FlashMessage($c);
+ };
}
public function tearDown()
diff --git a/tests/units/Core/Session/FlashMessageTest.php b/tests/units/Core/Session/FlashMessageTest.php
new file mode 100644
index 00000000..25361343
--- /dev/null
+++ b/tests/units/Core/Session/FlashMessageTest.php
@@ -0,0 +1,23 @@
+<?php
+
+require_once __DIR__.'/../../Base.php';
+
+use Kanboard\Core\Session\FlashMessage;
+
+class FlashMessageTest extends Base
+{
+ public function testMessage()
+ {
+ $flash = new FlashMessage($this->container);
+
+ $flash->success('my message');
+ $this->assertEquals('my message', $flash->getMessage('success'));
+ $this->assertEmpty($flash->getMessage('success'));
+
+ $flash->failure('my error message');
+ $this->assertEquals('my error message', $flash->getMessage('failure'));
+ $this->assertEmpty($flash->getMessage('failure'));
+
+ $this->assertEmpty($flash->getMessage('not found'));
+ }
+}
diff --git a/tests/units/Core/Session/SessionStorageTest.php b/tests/units/Core/Session/SessionStorageTest.php
new file mode 100644
index 00000000..62495e5e
--- /dev/null
+++ b/tests/units/Core/Session/SessionStorageTest.php
@@ -0,0 +1,38 @@
+<?php
+
+require_once __DIR__.'/../../Base.php';
+
+use Kanboard\Core\Session\SessionStorage;
+
+class SessionStorageTest extends Base
+{
+ public function testNotPersistentStorage()
+ {
+ $storage = new SessionStorage();
+ $storage->something = array('a' => 'b');
+ $this->assertEquals(array('a' => 'b'), $storage->something);
+ $this->assertTrue(isset($storage->something));
+ $this->assertFalse(isset($storage->something->x));
+ $this->assertFalse(isset($storage->notFound));
+ $this->assertFalse(isset($storage->notFound->x));
+ $this->assertFalse(isset($storage->notFound['x']));
+ }
+
+ public function testPersistentStorage()
+ {
+ $session = array('d' => 'e');
+
+ $storage = new SessionStorage();
+ $storage->setStorage($session);
+ $storage->something = array('a' => 'b');
+
+ $this->assertEquals(array('a' => 'b'), $storage->something);
+ $this->assertEquals('e', $storage->d);
+
+ $storage->something['a'] = 'c';
+ $this->assertEquals('c', $storage->something['a']);
+
+ $storage = null;
+ $this->assertEquals(array('something' => array('a' => 'c'), 'd' => 'e'), $session);
+ }
+}
diff --git a/tests/units/Helper/AppHelperTest.php b/tests/units/Helper/AppHelperTest.php
index cbd8b8ab..0639b7aa 100644
--- a/tests/units/Helper/AppHelperTest.php
+++ b/tests/units/Helper/AppHelperTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Core\Session;
+use Kanboard\Core\Session\FlashMessage;
use Kanboard\Helper\App;
use Kanboard\Model\Config;
@@ -23,15 +23,15 @@ class AppHelperTest extends Base
public function testFlashMessage()
{
$h = new App($this->container);
- $s = new Session;
+ $f = new FlashMessage($this->container);
$this->assertEmpty($h->flashMessage());
- $s->flash('test & test');
+
+ $f->success('test & test');
$this->assertEquals('<div class="alert alert-success alert-fade-out">test &amp; test</div>', $h->flashMessage());
$this->assertEmpty($h->flashMessage());
- $this->assertEmpty($h->flashMessage());
- $s->flashError('test & test');
+ $f->failure('test & test');
$this->assertEquals('<div class="alert alert-error">test &amp; test</div>', $h->flashMessage());
$this->assertEmpty($h->flashMessage());
}
diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php
index 4cc9fa65..eba977ee 100644
--- a/tests/units/Helper/UserHelperTest.php
+++ b/tests/units/Helper/UserHelperTest.php
@@ -6,7 +6,6 @@ use Kanboard\Helper\User;
use Kanboard\Model\Project;
use Kanboard\Model\ProjectPermission;
use Kanboard\Model\User as UserModel;
-use Kanboard\Core\Session;
class UserHelperTest extends Base
{
@@ -24,7 +23,6 @@ class UserHelperTest extends Base
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new UserModel($this->container);
- $session = new Session;
// We create our user
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
@@ -36,7 +34,7 @@ class UserHelperTest extends Base
$this->assertFalse($pp->isManager(1, 2));
// We fake a session for him
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
'is_project_admin' => true,
@@ -51,7 +49,6 @@ class UserHelperTest extends Base
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new UserModel($this->container);
- $session = new Session;
// We create our user
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
@@ -63,7 +60,7 @@ class UserHelperTest extends Base
$this->assertFalse($pp->isManager(1, 2));
// We fake a session for him
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
'is_project_admin' => false,
@@ -78,7 +75,6 @@ class UserHelperTest extends Base
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new UserModel($this->container);
- $session = new Session;
// We create our user
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
@@ -90,7 +86,7 @@ class UserHelperTest extends Base
$this->assertTrue($pp->isManager(1, 2));
// We fake a session for him
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
'is_project_admin' => false,
@@ -105,7 +101,6 @@ class UserHelperTest extends Base
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new UserModel($this->container);
- $session = new Session;
// We create our user
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
@@ -117,7 +112,7 @@ class UserHelperTest extends Base
$this->assertFalse($pp->isManager(1, 2));
// We fake a session for him
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
'is_project_admin' => true,
@@ -132,7 +127,6 @@ class UserHelperTest extends Base
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new UserModel($this->container);
- $session = new Session;
// We create our user
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
@@ -144,7 +138,7 @@ class UserHelperTest extends Base
$this->assertFalse($pp->isManager(1, 2));
// We fake a session for him
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
'is_project_admin' => false,
@@ -159,7 +153,6 @@ class UserHelperTest extends Base
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new UserModel($this->container);
- $session = new Session;
// We create our user
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
@@ -171,7 +164,7 @@ class UserHelperTest extends Base
$this->assertTrue($pp->isManager(1, 2));
// We fake a session for him
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
'is_project_admin' => false,
diff --git a/tests/units/Model/AclTest.php b/tests/units/Model/AclTest.php
index 28687a5c..afda446b 100644
--- a/tests/units/Model/AclTest.php
+++ b/tests/units/Model/AclTest.php
@@ -2,7 +2,6 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Core\Session;
use Kanboard\Model\Acl;
use Kanboard\Model\Project;
use Kanboard\Model\ProjectPermission;
@@ -86,8 +85,6 @@ class AclTest extends Base
public function testPageAccessNoSession()
{
$acl = new Acl($this->container);
- $session = new Session;
- $session = array();
$this->assertFalse($acl->isAllowed('board', 'readonly'));
$this->assertFalse($acl->isAllowed('task', 'show'));
@@ -100,8 +97,7 @@ class AclTest extends Base
public function testPageAccessEmptySession()
{
$acl = new Acl($this->container);
- $session = new Session;
- $session['user'] = array();
+ $this->container['sessionStorage']->user = array();
$this->assertFalse($acl->isAllowed('board', 'readonly'));
$this->assertFalse($acl->isAllowed('task', 'show'));
@@ -114,9 +110,7 @@ class AclTest extends Base
public function testPageAccessAdminUser()
{
$acl = new Acl($this->container);
- $session = new Session;
-
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'is_admin' => true,
);
@@ -140,7 +134,6 @@ class AclTest extends Base
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new User($this->container);
- $session = new Session;
// We create our user
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
@@ -152,7 +145,7 @@ class AclTest extends Base
$this->assertFalse($pp->isManager(1, 2));
// We fake a session for him
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
'is_project_admin' => true,
@@ -184,7 +177,6 @@ class AclTest extends Base
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
$u = new User($this->container);
- $session = new Session;
// We create our user
$this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
@@ -195,7 +187,7 @@ class AclTest extends Base
$this->assertTrue($pp->isManager(1, 2));
// We fake a session for him
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
);
@@ -237,9 +229,7 @@ class AclTest extends Base
$this->assertTrue($pp->isMember(1, 2));
$this->assertFalse($pp->isManager(1, 2));
- $session = new Session;
-
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
);
@@ -276,9 +266,7 @@ class AclTest extends Base
$this->assertFalse($pp->isMember(1, 2));
$this->assertFalse($pp->isManager(1, 2));
- $session = new Session;
-
- $session['user'] = array(
+ $this->container['sessionStorage']->user = array(
'id' => 2,
'is_admin' => false,
);
diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php
index 17617ceb..0c108fd1 100644
--- a/tests/units/Model/ConfigTest.php
+++ b/tests/units/Model/ConfigTest.php
@@ -3,7 +3,7 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Model\Config;
-use Kanboard\Core\Session;
+use Kanboard\Core\Session\SessionManager;
class ConfigTest extends Base
{
@@ -73,17 +73,15 @@ class ConfigTest extends Base
public function testGetWithSession()
{
- $this->container['session'] = new Session;
$c = new Config($this->container);
session_id('test');
-
- $this->assertTrue(Session::isOpen());
+ $this->assertTrue(SessionManager::isOpen());
$this->assertEquals('', $c->get('board_columns'));
$this->assertEquals('test', $c->get('board_columns', 'test'));
- $this->container['session']['config'] = array(
+ $this->container['sessionStorage']->config = array(
'board_columns' => 'foo',
'empty_value' => 0
);
@@ -93,6 +91,6 @@ class ConfigTest extends Base
$this->assertEquals('test', $c->get('empty_value', 'test'));
session_id('');
- unset($this->container['session']);
+ $this->assertFalse(SessionManager::isOpen());
}
}
diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php
index 04b274cc..e446e104 100644
--- a/tests/units/Model/SubtaskTest.php
+++ b/tests/units/Model/SubtaskTest.php
@@ -8,7 +8,6 @@ use Kanboard\Model\Subtask;
use Kanboard\Model\Project;
use Kanboard\Model\Category;
use Kanboard\Model\User;
-use Kanboard\Core\Session;
use Kanboard\Model\UserSession;
class SubtaskTest extends Base
@@ -190,7 +189,6 @@ class SubtaskTest extends Base
$tc = new TaskCreation($this->container);
$s = new Subtask($this->container);
$p = new Project($this->container);
- $ss = new Session;
$us = new UserSession($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test1')));
@@ -205,7 +203,7 @@ class SubtaskTest extends Base
$this->assertEquals(1, $subtask['task_id']);
// Set the current logged user
- $ss['user'] = array('id' => 1);
+ $this->container['sessionStorage']->user = array('id' => 1);
$this->assertTrue($s->toggleStatus(1));
diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php
index 309be64a..40461eea 100644
--- a/tests/units/Model/SubtaskTimeTrackingTest.php
+++ b/tests/units/Model/SubtaskTimeTrackingTest.php
@@ -9,7 +9,6 @@ use Kanboard\Model\SubtaskTimeTracking;
use Kanboard\Model\Project;
use Kanboard\Model\Category;
use Kanboard\Model\User;
-use Kanboard\Core\Session;
class SubtaskTimeTrackingTest extends Base
{
@@ -38,9 +37,8 @@ class SubtaskTimeTrackingTest extends Base
$s = new Subtask($this->container);
$st = new SubtaskTimeTracking($this->container);
$p = new Project($this->container);
- $ss = new Session;
- $ss['user'] = array('id' => 1);
+ $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)));
diff --git a/tests/units/Model/TaskCreationTest.php b/tests/units/Model/TaskCreationTest.php
index d76937b2..5de0a5cc 100644
--- a/tests/units/Model/TaskCreationTest.php
+++ b/tests/units/Model/TaskCreationTest.php
@@ -182,8 +182,7 @@ class TaskCreationTest extends Base
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
- $_SESSION = array();
- $_SESSION['user']['id'] = 1;
+ $this->container['sessionStorage']->user = array('id' => 1);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
@@ -194,8 +193,6 @@ class TaskCreationTest extends Base
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['creator_id']);
-
- $_SESSION = array();
}
public function testColumnId()
diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php
index 5273928c..d65e8f28 100644
--- a/tests/units/Model/TaskDuplicationTest.php
+++ b/tests/units/Model/TaskDuplicationTest.php
@@ -31,8 +31,7 @@ class TaskDuplicationTest extends Base
$this->assertEquals(1, $task['project_id']);
$this->assertEquals(0, $task['creator_id']);
- $_SESSION = array();
- $_SESSION['user']['id'] = 1;
+ $this->container['sessionStorage']->user = array('id' => 1);
// We duplicate our task
$this->assertEquals(2, $td->duplicate(1));
@@ -41,8 +40,6 @@ class TaskDuplicationTest extends Base
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['creator_id']);
-
- $_SESSION = array();
}
public function testDuplicateSameProject()
diff --git a/tests/units/Model/TaskPermissionTest.php b/tests/units/Model/TaskPermissionTest.php
index 52a36549..56886ee7 100644
--- a/tests/units/Model/TaskPermissionTest.php
+++ b/tests/units/Model/TaskPermissionTest.php
@@ -33,7 +33,7 @@ class TaskPermissionTest extends Base
// User #1 can remove everything
$user = $u->getbyId(1);
$this->assertNotEmpty($user);
- $us->refresh($user);
+ $us->initialize($user);
$task = $tf->getbyId(1);
$this->assertNotEmpty($task);
@@ -42,7 +42,7 @@ class TaskPermissionTest extends Base
// User #2 can't remove the task #1
$user = $u->getbyId(2);
$this->assertNotEmpty($user);
- $us->refresh($user);
+ $us->initialize($user);
$task = $tf->getbyId(1);
$this->assertNotEmpty($task);
@@ -51,7 +51,7 @@ class TaskPermissionTest extends Base
// User #1 can remove everything
$user = $u->getbyId(1);
$this->assertNotEmpty($user);
- $us->refresh($user);
+ $us->initialize($user);
$task = $tf->getbyId(2);
$this->assertNotEmpty($task);
@@ -60,7 +60,7 @@ class TaskPermissionTest extends Base
// User #2 can remove his own task
$user = $u->getbyId(2);
$this->assertNotEmpty($user);
- $us->refresh($user);
+ $us->initialize($user);
$task = $tf->getbyId(2);
$this->assertNotEmpty($task);
@@ -69,7 +69,7 @@ class TaskPermissionTest extends Base
// User #1 can remove everything
$user = $u->getbyId(1);
$this->assertNotEmpty($user);
- $us->refresh($user);
+ $us->initialize($user);
$task = $tf->getbyId(3);
$this->assertNotEmpty($task);
@@ -78,7 +78,7 @@ class TaskPermissionTest extends Base
// User #2 can't remove the task #3
$user = $u->getbyId(2);
$this->assertNotEmpty($user);
- $us->refresh($user);
+ $us->initialize($user);
$task = $tf->getbyId(3);
$this->assertNotEmpty($task);
@@ -87,7 +87,7 @@ class TaskPermissionTest extends Base
// User #1 can remove everything
$user = $u->getbyId(1);
$this->assertNotEmpty($user);
- $us->refresh($user);
+ $us->initialize($user);
$task = $tf->getbyId(4);
$this->assertNotEmpty($task);
@@ -96,7 +96,7 @@ class TaskPermissionTest extends Base
// User #2 can't remove the task #4
$user = $u->getbyId(2);
$this->assertNotEmpty($user);
- $us->refresh($user);
+ $us->initialize($user);
$task = $tf->getbyId(4);
$this->assertNotEmpty($task);
diff --git a/tests/units/Model/UserSessionTest.php b/tests/units/Model/UserSessionTest.php
index 66f6faa7..ba1f8aac 100644
--- a/tests/units/Model/UserSessionTest.php
+++ b/tests/units/Model/UserSessionTest.php
@@ -2,31 +2,157 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Core\Session;
use Kanboard\Model\UserSession;
class UserSessionTest extends Base
{
- public function testIsAdmin()
+ public function testInitialize()
{
- $s = new Session;
$us = new UserSession($this->container);
- $this->assertFalse($us->isAdmin());
+ $user = array(
+ 'id' => '123',
+ 'username' => 'john',
+ 'password' => 'something',
+ 'twofactor_secret' => 'something else',
+ 'is_admin' => '1',
+ 'is_project_admin' => '0',
+ 'is_ldap_user' => '0',
+ 'twofactor_activated' => '0',
+ );
+
+ $us->initialize($user);
+
+ $session = $this->container['sessionStorage']->getAll();
+
+ $this->assertNotEmpty($session);
+ $this->assertEquals(123, $session['user']['id']);
+ $this->assertEquals('john', $session['user']['username']);
+ $this->assertTrue($session['user']['is_admin']);
+ $this->assertFalse($session['user']['is_project_admin']);
+ $this->assertFalse($session['user']['is_ldap_user']);
+ $this->assertFalse($session['user']['twofactor_activated']);
+ $this->assertArrayNotHasKey('password', $session['user']);
+ $this->assertArrayNotHasKey('twofactor_secret', $session['user']);
+
+ $this->assertEquals('john', $us->getUsername());
+ }
+
+ public function testGetId()
+ {
+ $us = new UserSession($this->container);
+
+ $this->assertEquals(0, $us->getId());
+
+ $this->container['sessionStorage']->user = array('id' => 2);
+ $this->assertEquals(2, $us->getId());
+
+ $this->container['sessionStorage']->user = array('id' => '2');
+ $this->assertEquals(2, $us->getId());
+ }
+
+ public function testIsLogged()
+ {
+ $us = new UserSession($this->container);
+
+ $this->assertFalse($us->isLogged());
+
+ $this->container['sessionStorage']->user = array();
+ $this->assertFalse($us->isLogged());
+
+ $this->container['sessionStorage']->user = array('id' => 1);
+ $this->assertTrue($us->isLogged());
+ }
+
+ public function testIsAdmin()
+ {
+ $us = new UserSession($this->container);
- $s['user'] = array();
$this->assertFalse($us->isAdmin());
- $s['user'] = array('is_admin' => '1');
+ $this->container['sessionStorage']->user = array('is_admin' => '1');
$this->assertFalse($us->isAdmin());
- $s['user'] = array('is_admin' => false);
+ $this->container['sessionStorage']->user = array('is_admin' => '2');
$this->assertFalse($us->isAdmin());
- $s['user'] = array('is_admin' => '2');
+ $this->container['sessionStorage']->user = array('is_admin' => false);
$this->assertFalse($us->isAdmin());
- $s['user'] = array('is_admin' => true);
+ $this->container['sessionStorage']->user = array('is_admin' => true);
$this->assertTrue($us->isAdmin());
}
+
+ public function testIsProjectAdmin()
+ {
+ $us = new UserSession($this->container);
+
+ $this->assertFalse($us->isProjectAdmin());
+
+ $this->container['sessionStorage']->user = array('is_project_admin' => false);
+ $this->assertFalse($us->isProjectAdmin());
+
+ $this->container['sessionStorage']->user = array('is_project_admin' => true);
+ $this->assertTrue($us->isProjectAdmin());
+ }
+
+ 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);
+ $this->assertEquals('status:open', $us->getFilters(1));
+
+ $us->setFilters(1, 'assignee:me');
+ $this->assertEquals('assignee:me', $us->getFilters(1));
+
+ $this->assertEquals('status:open', $us->getFilters(2));
+
+ $us->setFilters(2, 'assignee:bob');
+ $this->assertEquals('assignee:bob', $us->getFilters(2));
+ }
+
+ public function test2FA()
+ {
+ $us = new UserSession($this->container);
+
+ $this->assertFalse($us->check2FA());
+
+ $this->container['sessionStorage']->postAuth = array('validated' => false);
+ $this->assertFalse($us->check2FA());
+
+ $this->container['sessionStorage']->postAuth = array('validated' => true);
+ $this->assertTrue($us->check2FA());
+
+ $this->container['sessionStorage']->user = array();
+ $this->assertFalse($us->has2FA());
+
+ $this->container['sessionStorage']->user = array('twofactor_activated' => false);
+ $this->assertFalse($us->has2FA());
+
+ $this->container['sessionStorage']->user = array('twofactor_activated' => true);
+ $this->assertTrue($us->has2FA());
+
+ $us->disable2FA();
+ $this->assertFalse($us->has2FA());
+ }
}