diff options
author | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-01 19:51:09 -0500 |
---|---|---|
committer | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-01 19:51:09 -0500 |
commit | 28bc4246bff405367c9e5640bca356b307962026 (patch) | |
tree | 897fa49d471c1f4c6fc00bbd7e6d427239d01bd3 /tests/ProjectTest.php | |
parent | e7db71b593f2d9856a5b3aacde00a638d074d601 (diff) |
Add acl and access list for projects
Diffstat (limited to 'tests/ProjectTest.php')
-rw-r--r-- | tests/ProjectTest.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/ProjectTest.php b/tests/ProjectTest.php new file mode 100644 index 00000000..6eb39f52 --- /dev/null +++ b/tests/ProjectTest.php @@ -0,0 +1,63 @@ +<?php + +require_once __DIR__.'/../lib/translator.php'; +require_once __DIR__.'/../models/base.php'; +require_once __DIR__.'/../models/board.php'; +require_once __DIR__.'/../models/user.php'; +require_once __DIR__.'/../models/project.php'; + +use Model\Project; +use Model\User; + +class ProjectTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + defined('DB_FILENAME') or define('DB_FILENAME', ':memory:'); + } + + public function testCreation() + { + $p = new Project; + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $this->assertNotEmpty($p->getById(1)); + } + + public function testAllowUsers() + { + $p = new Project; + + // Everybody is allowed + $this->assertEmpty($p->getAllowedUsers(1)); + $this->assertTrue($p->isUserAllowed(1, 1)); + + // Allow one user + $this->assertTrue($p->allowUser(1, 1)); + $this->assertFalse($p->allowUser(50, 1)); + $this->assertFalse($p->allowUser(1, 50)); + $this->assertEquals(array('1' => 'admin'), $p->getAllowedUsers(1)); + $this->assertTrue($p->isUserAllowed(1, 1)); + + // Disallow one user + $this->assertTrue($p->revokeUser(1, 1)); + $this->assertEmpty($p->getAllowedUsers(1)); + $this->assertTrue($p->isUserAllowed(1, 1)); + + // Allow/disallow many users + $user = new User; + $user->create(array('username' => 'unittest', 'password' => 'unittest')); + + $this->assertTrue($p->allowUser(1, 1)); + $this->assertTrue($p->allowUser(1, 2)); + + $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $p->getAllowedUsers(1)); + $this->assertTrue($p->isUserAllowed(1, 1)); + $this->assertTrue($p->isUserAllowed(1, 2)); + + $this->assertTrue($p->revokeUser(1, 1)); + + $this->assertEquals(array('2' => 'unittest'), $p->getAllowedUsers(1)); + $this->assertFalse($p->isUserAllowed(1, 1)); + $this->assertTrue($p->isUserAllowed(1, 2)); + } +} |