blob: d24a172f6f58adad60c030b1d0181b73eefac068 (
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
64
65
66
67
68
69
70
71
72
|
<?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__) . '/..'));
define('STATUSNET', true);
require_once INSTALLDIR . '/lib/common.php';
class UserRightsTest extends PHPUnit_Framework_TestCase
{
protected $user = null;
function setUp()
{
$user = User::staticGet('nickname', 'userrightstestuser');
if ($user) {
// Leftover from a broken test run?
$profile = $user->getProfile();
$user->delete();
$profile->delete();
}
$this->user = User::register(array('nickname' => 'userrightstestuser'));
if (!$this->user) {
throw new Exception("Couldn't register userrightstestuser");
}
}
function tearDown()
{
if ($this->user) {
$profile = $this->user->getProfile();
$this->user->delete();
$profile->delete();
}
}
function testInvalidRole()
{
$this->assertFalse($this->user->hasRole('invalidrole'));
}
function standardRoles()
{
return array(array('admin'),
array('moderator'));
}
/**
* @dataProvider standardRoles
*
*/
function testUngrantedRole($role)
{
$this->assertFalse($this->user->hasRole($role));
}
/**
* @dataProvider standardRoles
*
*/
function testGrantedRole($role)
{
$this->user->grantRole($role);
$this->assertTrue($this->user->hasRole($role));
}
}
|