Skip to content

Commit

Permalink
authplain: Add tests for group retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
annda committed Apr 30, 2019
1 parent b2fcc74 commit 503e913
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/plugins/authplain/_test/conf/auth.users.php
@@ -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
64 changes: 64 additions & 0 deletions lib/plugins/authplain/_test/userdata.test.php
@@ -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);
}
}

0 comments on commit 503e913

Please sign in to comment.