]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/UserRightsTest.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / tests / UserRightsTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('GNUSOCIAL', true);
10 define('STATUSNET', true);  // compatibility
11
12 require_once INSTALLDIR . '/lib/common.php';
13
14 class UserRightsTest extends PHPUnit_Framework_TestCase
15 {
16     protected $user = null;
17
18     function setUp()
19     {
20         $user = User::getKV('nickname', 'userrightstestuser');
21
22         if ($user instanceof User) {
23             // Leftover from a broken test run?
24             $profile = $user->getProfile();
25             $user->delete();
26             $profile->delete();
27         }
28
29         $this->user = User::register(array('nickname' => 'userrightstestuser'));
30
31         if (!$this->user) {
32             throw new Exception("Couldn't register userrightstestuser");
33         }
34     }
35
36     function tearDown()
37     {
38         if ($this->user) {
39             $profile = $this->user->getProfile();
40             $this->user->delete();
41             $profile->delete();
42         }
43     }
44
45     function testInvalidRole()
46     {
47         $this->assertFalse($this->user->hasRole('invalidrole'));
48     }
49
50     function standardRoles()
51     {
52         return array(array('admin'),
53                      array('moderator'));
54     }
55
56     /**
57      * @dataProvider standardRoles
58      *
59      */
60
61     function testUngrantedRole($role)
62     {
63         $this->assertFalse($this->user->hasRole($role));
64     }
65
66     /**
67      * @dataProvider standardRoles
68      *
69      */
70
71     function testGrantedRole($role)
72     {
73         $this->user->grantRole($role);
74         $this->assertTrue($this->user->hasRole($role));
75     }
76 }