We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

UserRightsTest.php 1.64 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1 2 3 4 5 6 7 8
<?php

if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
    print "This script must be run from the command line\n";
    exit();
}

define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 10
define('GNUSOCIAL', true);
define('STATUSNET', true);  // compatibility
Evan Prodromou's avatar
Evan Prodromou committed
11 12 13 14 15 16 17 18 19

require_once INSTALLDIR . '/lib/common.php';

class UserRightsTest extends PHPUnit_Framework_TestCase
{
    protected $user = null;

    function setUp()
    {
20
        $user = User::getKV('nickname', 'userrightstestuser');
Brion Vibber's avatar
Brion Vibber committed
21 22 23 24 25 26
        if ($user) {
            // Leftover from a broken test run?
            $profile = $user->getProfile();
            $user->delete();
            $profile->delete();
        }
Evan Prodromou's avatar
Evan Prodromou committed
27
        $this->user = User::register(array('nickname' => 'userrightstestuser'));
Brion Vibber's avatar
Brion Vibber committed
28 29 30
        if (!$this->user) {
            throw new Exception("Couldn't register userrightstestuser");
        }
Evan Prodromou's avatar
Evan Prodromou committed
31 32 33 34
    }

    function tearDown()
    {
Brion Vibber's avatar
Brion Vibber committed
35 36 37 38 39
        if ($this->user) {
            $profile = $this->user->getProfile();
            $this->user->delete();
            $profile->delete();
        }
Evan Prodromou's avatar
Evan Prodromou committed
40 41 42 43 44 45 46 47 48
    }

    function testInvalidRole()
    {
        $this->assertFalse($this->user->hasRole('invalidrole'));
    }

    function standardRoles()
    {
Brion Vibber's avatar
Brion Vibber committed
49 50
        return array(array('admin'),
                     array('moderator'));
Evan Prodromou's avatar
Evan Prodromou committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    }

    /**
     * @dataProvider standardRoles
     *
     */

    function testUngrantedRole($role)
    {
        $this->assertFalse($this->user->hasRole($role));
    }

    /**
     * @dataProvider standardRoles
     *
     */

    function testGrantedRole($role)
    {
        $this->user->grantRole($role);
Brion Vibber's avatar
Brion Vibber committed
71
        $this->assertTrue($this->user->hasRole($role));
Evan Prodromou's avatar
Evan Prodromou committed
72
    }
73
}