summaryrefslogtreecommitdiff
path: root/tests/ProjectTest.php
blob: 6eb39f52519a2a950b889ffa30cba86bcbe5d58b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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));
    }
}