]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/UserRightsTest.php
XSS vulnerability when remote-subscribing
[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         if ($user) {
22             // Leftover from a broken test run?
23             $profile = $user->getProfile();
24             $user->delete();
25             $profile->delete();
26         }
27         $this->user = User::register(array('nickname' => 'userrightstestuser'));
28         if (!$this->user) {
29             throw new Exception("Couldn't register userrightstestuser");
30         }
31     }
32
33     function tearDown()
34     {
35         if ($this->user) {
36             $profile = $this->user->getProfile();
37             $this->user->delete();
38             $profile->delete();
39         }
40     }
41
42     function testInvalidRole()
43     {
44         $this->assertFalse($this->user->hasRole('invalidrole'));
45     }
46
47     function standardRoles()
48     {
49         return array(array('admin'),
50                      array('moderator'));
51     }
52
53     /**
54      * @dataProvider standardRoles
55      *
56      */
57
58     function testUngrantedRole($role)
59     {
60         $this->assertFalse($this->user->hasRole($role));
61     }
62
63     /**
64      * @dataProvider standardRoles
65      *
66      */
67
68     function testGrantedRole($role)
69     {
70         $this->user->grantRole($role);
71         $this->assertTrue($this->user->hasRole($role));
72     }
73 }