]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/UserRightsTest.php
Give NoticeListItem its own class
[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('STATUSNET', true);
10
11 require_once INSTALLDIR . '/lib/common.php';
12
13 class UserRightsTest extends PHPUnit_Framework_TestCase
14 {
15     protected $user = null;
16
17     function setUp()
18     {
19         $user = User::staticGet('nickname', 'userrightstestuser');
20         if ($user) {
21             // Leftover from a broken test run?
22             $profile = $user->getProfile();
23             $user->delete();
24             $profile->delete();
25         }
26         $this->user = User::register(array('nickname' => 'userrightstestuser'));
27         if (!$this->user) {
28             throw new Exception("Couldn't register userrightstestuser");
29         }
30     }
31
32     function tearDown()
33     {
34         if ($this->user) {
35             $profile = $this->user->getProfile();
36             $this->user->delete();
37             $profile->delete();
38         }
39     }
40
41     function testInvalidRole()
42     {
43         $this->assertFalse($this->user->hasRole('invalidrole'));
44     }
45
46     function standardRoles()
47     {
48         return array(array('admin'),
49                      array('moderator'));
50     }
51
52     /**
53      * @dataProvider standardRoles
54      *
55      */
56
57     function testUngrantedRole($role)
58     {
59         $this->assertFalse($this->user->hasRole($role));
60     }
61
62     /**
63      * @dataProvider standardRoles
64      *
65      */
66
67     function testGrantedRole($role)
68     {
69         $this->user->grantRole($role);
70         $this->assertTrue($this->user->hasRole($role));
71     }
72 }