|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Xtools; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
|
6
|
|
|
|
|
7
|
|
|
class UserTest extends PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* A username should be given an initial capital letter in all cases. |
|
12
|
|
|
*/ |
|
13
|
|
|
public function testUsernameHasInitialCapital() |
|
14
|
|
|
{ |
|
15
|
|
|
$user = new User('lowercasename'); |
|
16
|
|
|
$this->assertEquals('Lowercasename', $user->getUsername()); |
|
17
|
|
|
$user2 = new User('UPPERCASENAME'); |
|
18
|
|
|
$this->assertEquals('UPPERCASENAME', $user2->getUsername()); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* A user has an integer identifier on a project (and this can differ from project |
|
23
|
|
|
* to project). |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testUserHasIdOnProject() |
|
26
|
|
|
{ |
|
27
|
|
|
// Set up stub user and project repositories. |
|
28
|
|
|
$userRepo = $this->getMock(UserRepository::class); |
|
29
|
|
|
$userRepo->expects($this->once()) |
|
30
|
|
|
->method('getId') |
|
31
|
|
|
->willReturn(12); |
|
32
|
|
|
$projectRepo = $this->getMock(ProjectRepository::class); |
|
33
|
|
|
$projectRepo->expects($this->once()) |
|
34
|
|
|
->method('getOne') |
|
35
|
|
|
->willReturn(['dbname' => 'testWiki']); |
|
36
|
|
|
|
|
37
|
|
|
// Make sure the user has the correct ID. |
|
38
|
|
|
$user = new User('TestUser'); |
|
39
|
|
|
$user->setRepository($userRepo); |
|
40
|
|
|
$project = new Project('wiki.example.org'); |
|
41
|
|
|
$project->setRepository($projectRepo); |
|
42
|
|
|
$this->assertEquals(12, $user->getId($project)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Is a user an admin on a given project? |
|
47
|
|
|
* @dataProvider isAdminProvider |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testIsAdmin($username, $groups, $isAdmin) |
|
50
|
|
|
{ |
|
51
|
|
|
$userRepo = $this->getMock(UserRepository::class); |
|
52
|
|
|
$userRepo->expects($this->once()) |
|
53
|
|
|
->method('getGroups') |
|
54
|
|
|
->willReturn($groups); |
|
55
|
|
|
$user = new User($username); |
|
56
|
|
|
$user->setRepository($userRepo); |
|
57
|
|
|
$this->assertEquals($isAdmin, $user->isAdmin(new Project('testWiki'))); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function isAdminProvider() |
|
61
|
|
|
{ |
|
62
|
|
|
return [ |
|
63
|
|
|
['AdminUser', ['sysop', 'autopatrolled'], true], |
|
64
|
|
|
['NormalUser', ['autopatrolled'], false], |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|