summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Core/Cache/MemoryCacheTest.php62
-rw-r--r--tests/units/Helper/UserHelperTest.php166
2 files changed, 228 insertions, 0 deletions
diff --git a/tests/units/Core/Cache/MemoryCacheTest.php b/tests/units/Core/Cache/MemoryCacheTest.php
new file mode 100644
index 00000000..b28604ed
--- /dev/null
+++ b/tests/units/Core/Cache/MemoryCacheTest.php
@@ -0,0 +1,62 @@
+<?php
+
+require_once __DIR__.'/../../Base.php';
+
+use Core\Cache\MemoryCache;
+
+class MemoryCacheTest extends Base
+{
+ public function testKeyNotFound()
+ {
+ $c = new MemoryCache;
+ $this->assertEquals(null, $c->get('mykey'));
+ }
+
+ public function testSetValue()
+ {
+ $c = new MemoryCache;
+ $c->set('mykey', 'myvalue');
+ $this->assertEquals('myvalue', $c->get('mykey'));
+ }
+
+ public function testRemoveValue()
+ {
+ $c = new MemoryCache;
+ $c->set('mykey', 'myvalue');
+ $c->remove('mykey');
+ $this->assertEquals(null, $c->get('mykey'));
+ }
+
+ public function testFlushAll()
+ {
+ $c = new MemoryCache;
+ $c->set('mykey', 'myvalue');
+ $c->flush();
+ $this->assertEquals(null, $c->get('mykey'));
+ }
+
+ public function testProxy()
+ {
+ $c = new MemoryCache;
+
+ $class = $this
+ ->getMockBuilder('stdClass')
+ ->setMethods(array('doSomething'))
+ ->getMock();
+
+ $class
+ ->expects($this->once())
+ ->method('doSomething')
+ ->with(
+ $this->equalTo(1),
+ $this->equalTo(2)
+ )
+ ->will($this->returnValue(3));
+
+ // First call will store the computed value
+ $this->assertEquals(3, $c->proxy($class, 'doSomething', 1, 2));
+
+ // Second call get directly the cached value
+ $this->assertEquals(3, $c->proxy($class, 'doSomething', 1, 2));
+ }
+}
diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php
index 947f606a..24f2b3b2 100644
--- a/tests/units/Helper/UserHelperTest.php
+++ b/tests/units/Helper/UserHelperTest.php
@@ -3,6 +3,10 @@
require_once __DIR__.'/../Base.php';
use Helper\User;
+use Model\Project;
+use Model\ProjectPermission;
+use Model\User as UserModel;
+use Core\Session;
class UserHelperTest extends Base
{
@@ -13,4 +17,166 @@ class UserHelperTest extends Base
$this->assertEquals('CN', $h->getInitials('chuck norris'));
$this->assertEquals('A', $h->getInitials('admin'));
}
+
+ public function testIsProjectAdministrationAllowedForProjectAdmin()
+ {
+ $h = new User($this->container);
+ $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')));
+
+ // We create a project and set our user as project manager
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertFalse($pp->isManager(1, 2));
+
+ // We fake a session for him
+ $session['user'] = array(
+ 'id' => 2,
+ 'is_admin' => false,
+ 'is_project_admin' => true,
+ );
+
+ $this->assertTrue($h->isProjectAdministrationAllowed(1));
+ }
+
+ public function testIsProjectAdministrationAllowedForProjectMember()
+ {
+ $h = new User($this->container);
+ $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')));
+
+ // We create a project and set our user as project member
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertFalse($pp->isManager(1, 2));
+
+ // We fake a session for him
+ $session['user'] = array(
+ 'id' => 2,
+ 'is_admin' => false,
+ 'is_project_admin' => false,
+ );
+
+ $this->assertFalse($h->isProjectAdministrationAllowed(1));
+ }
+
+ public function testIsProjectAdministrationAllowedForProjectManager()
+ {
+ $h = new User($this->container);
+ $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')));
+
+ // We create a project and set our user as project member
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertTrue($pp->addManager(1, 2));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertTrue($pp->isManager(1, 2));
+
+ // We fake a session for him
+ $session['user'] = array(
+ 'id' => 2,
+ 'is_admin' => false,
+ 'is_project_admin' => false,
+ );
+
+ $this->assertFalse($h->isProjectAdministrationAllowed(1));
+ }
+
+ public function testIsProjectManagementAllowedForProjectAdmin()
+ {
+ $h = new User($this->container);
+ $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')));
+
+ // We create a project and set our user as project manager
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertFalse($pp->isManager(1, 2));
+
+ // We fake a session for him
+ $session['user'] = array(
+ 'id' => 2,
+ 'is_admin' => false,
+ 'is_project_admin' => true,
+ );
+
+ $this->assertTrue($h->isProjectManagementAllowed(1));
+ }
+
+ public function testIsProjectManagementAllowedForProjectMember()
+ {
+ $h = new User($this->container);
+ $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')));
+
+ // We create a project and set our user as project member
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertFalse($pp->isManager(1, 2));
+
+ // We fake a session for him
+ $session['user'] = array(
+ 'id' => 2,
+ 'is_admin' => false,
+ 'is_project_admin' => false,
+ );
+
+ $this->assertFalse($h->isProjectManagementAllowed(1));
+ }
+
+ public function testIsProjectManagementAllowedForProjectManager()
+ {
+ $h = new User($this->container);
+ $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')));
+
+ // We create a project and set our user as project member
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertTrue($pp->addManager(1, 2));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertTrue($pp->isManager(1, 2));
+
+ // We fake a session for him
+ $session['user'] = array(
+ 'id' => 2,
+ 'is_admin' => false,
+ 'is_project_admin' => false,
+ );
+
+ $this->assertTrue($h->isProjectManagementAllowed(1));
+ }
}