ef03e835475b64a277b614869a8c9cf310ce9d1d
3 define( 'NS_UNITTEST', 5600 );
4 define( 'NS_UNITTEST_TALK', 5601 );
9 class UserTest
extends MediaWikiTestCase
{
10 protected $savedGroupPermissions, $savedRevokedPermissions;
17 public function setUp() {
20 $this->savedGroupPermissions
= $GLOBALS['wgGroupPermissions'];
21 $this->savedRevokedPermissions
= $GLOBALS['wgRevokePermissions'];
23 $this->setUpPermissionGlobals();
26 private function setUpPermissionGlobals() {
27 global $wgGroupPermissions, $wgRevokePermissions;
29 # Data for regular $wgGroupPermissions test
30 $wgGroupPermissions['unittesters'] = array(
36 $wgGroupPermissions['testwriters'] = array(
41 # Data for regular $wgRevokePermissions test
42 $wgRevokePermissions['formertesters'] = array(
46 private function setUpUser() {
47 $this->user
= new User
;
48 $this->user
->addGroup( 'unittesters' );
51 public function tearDown() {
54 $GLOBALS['wgGroupPermissions'] = $this->savedGroupPermissions
;
55 $GLOBALS['wgRevokePermissions'] = $this->savedRevokedPermissions
;
58 public function testGroupPermissions() {
59 $rights = User
::getGroupPermissions( array( 'unittesters' ) );
60 $this->assertContains( 'runtest', $rights );
61 $this->assertNotContains( 'writetest', $rights );
62 $this->assertNotContains( 'modifytest', $rights );
63 $this->assertNotContains( 'nukeworld', $rights );
65 $rights = User
::getGroupPermissions( array( 'unittesters', 'testwriters' ) );
66 $this->assertContains( 'runtest', $rights );
67 $this->assertContains( 'writetest', $rights );
68 $this->assertContains( 'modifytest', $rights );
69 $this->assertNotContains( 'nukeworld', $rights );
71 public function testRevokePermissions() {
72 $rights = User
::getGroupPermissions( array( 'unittesters', 'formertesters' ) );
73 $this->assertNotContains( 'runtest', $rights );
74 $this->assertNotContains( 'writetest', $rights );
75 $this->assertNotContains( 'modifytest', $rights );
76 $this->assertNotContains( 'nukeworld', $rights );
79 public function testUserPermissions() {
80 $rights = $this->user
->getRights();
81 $this->assertContains( 'runtest', $rights );
82 $this->assertNotContains( 'writetest', $rights );
83 $this->assertNotContains( 'modifytest', $rights );
84 $this->assertNotContains( 'nukeworld', $rights );
88 * @dataProvider provideGetGroupsWithPermission
90 public function testGetGroupsWithPermission( $expected, $right ) {
91 $result = User
::getGroupsWithPermission( $right );
95 $this->assertEquals( $expected, $result, "Groups with permission $right" );
98 public function provideGetGroupsWithPermission() {
101 array( 'unittesters', 'testwriters' ),
105 array( 'unittesters' ),
109 array( 'testwriters' ),
113 array( 'testwriters' ),
120 * @dataProvider provideUserNames
122 public function testIsValidUserName( $username, $result, $message ) {
123 $this->assertEquals( $this->user
->isValidUserName( $username ), $result, $message );
126 public function provideUserNames() {
128 array( '', false, 'Empty string' ),
129 array( ' ', false, 'Blank space' ),
130 array( 'abcd', false, 'Starts with small letter' ),
131 array( 'Ab/cd', false, 'Contains slash' ),
132 array( 'Ab cd' , true, 'Whitespace' ),
133 array( '192.168.1.1', false, 'IP' ),
134 array( 'User:Abcd', false, 'Reserved Namespace' ),
135 array( '12abcd232' , true , 'Starts with Numbers' ),
136 array( '?abcd' , true, 'Start with ? mark' ),
137 array( '#abcd', false, 'Start with #' ),
138 array( 'Abcdകഖഗഘ', true, ' Mixed scripts' ),
139 array( 'ജോസ്തോമസ്', false, 'ZWNJ- Format control character' ),
140 array( 'Ab cd', false, ' Ideographic space' ),