Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
authplain: Add tests for group retrieval
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# users.auth.php | ||
# <?php exit()?> | ||
# Don't modify the lines above | ||
# | ||
# Userfile | ||
# | ||
# Format: | ||
# | ||
# login:passwordhash:Real Name:email:groups,comma,separated | ||
|
||
|
||
user_1:$1$tGu7CW5z$VpsMjRIx5tbyOJaQ2SP23.:Admin:admin@example.com:user,first_group | ||
user_2:$1$2uJ5C3ib$edo0EDEb/yLAFHme7RK851:User 2:user2@example.com:user,second_group,third_group | ||
user_3:$1$yqnlDqgZ$Sste968uKhuxH6wIQt6/D/:User 3:user3@example.com:user,fourth_group,first_group,third_group | ||
user_4:$1$tXjajS9s$peoGPBQep.P245H1Lfloj0:User 4:user4@example.com:user,third_group | ||
user_5:$1$IWrqdhol$xXOmufjZ2hW1aAVp7zDP.1:User 5:user5@example.com:user,second_group,fifth_group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* Class userdata_test | ||
* | ||
* Test group retrieval | ||
* | ||
* @group plugins | ||
*/ | ||
class userdata_test extends DokuWikiTest | ||
{ | ||
/** @var auth_plugin_authplain */ | ||
protected $auth; | ||
|
||
/** | ||
* Load auth with test conf | ||
* @throws Exception | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
global $config_cascade; | ||
$config_cascade['plainauth.users']['default'] = __DIR__ . '/conf/auth.users.php'; | ||
$this->auth = new auth_plugin_authplain(); | ||
} | ||
|
||
/** | ||
* Test that all groups are retrieved in the correct order, without duplicates | ||
*/ | ||
public function test_retrieve_groups() | ||
{ | ||
$expected = ['user', 'first_group', 'second_group', 'third_group', 'fourth_group', 'fifth_group']; | ||
$actual = $this->auth->retrieveGroups(); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* Test with small and large limits | ||
*/ | ||
public function test_retrieve_groups_limit() | ||
{ | ||
$expected = ['user', 'first_group']; | ||
$actual = $this->auth->retrieveGroups(0, 2); | ||
$this->assertEquals($expected, $actual); | ||
|
||
$expected = ['user', 'first_group', 'second_group', 'third_group', 'fourth_group', 'fifth_group']; | ||
$actual = $this->auth->retrieveGroups(0, 20); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* Test with small and large offsets | ||
*/ | ||
public function test_retrieve_groups_offset() | ||
{ | ||
$expected = ['third_group', 'fourth_group', 'fifth_group']; | ||
$actual = $this->auth->retrieveGroups(3,10); | ||
$this->assertEquals($expected, $actual); | ||
|
||
$expected = []; | ||
$actual = $this->auth->retrieveGroups(10,3); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
} |