From 49d1ce3ac28e8281e8ef5feba03a138dde7c667e Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Wed, 27 Nov 2019 10:51:16 +0100 Subject: [PATCH] MDL-67118 auth_ldap: add pagesize/subcontexts test provider With that provider we'll be explicitly covering that any pagesize and subcontexts search is returning results consistently so the internal paging/servercontrols work as expected. --- auth/ldap/tests/plugin_test.php | 35 ++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/auth/ldap/tests/plugin_test.php b/auth/ldap/tests/plugin_test.php index f746583e6b1..17ee9dd9b26 100644 --- a/auth/ldap/tests/plugin_test.php +++ b/auth/ldap/tests/plugin_test.php @@ -36,7 +36,36 @@ defined('MOODLE_INTERNAL') || die(); class auth_ldap_plugin_testcase extends advanced_testcase { - public function test_auth_ldap() { + /** + * Data provider for auth_ldap tests + * + * Used to ensure that all the paged stuff works properly, irrespectively + * of the pagesize configured (that implies all the chunking and paging + * built in the plugis is doing its work consistently). Both searching and + * not searching within subcontexts. + * + * @return array[] + */ + public function auth_ldap_provider() { + $pagesizes = [1, 3, 5, 1000]; + $subcontexts = [0, 1]; + $combinations = []; + foreach ($pagesizes as $pagesize) { + foreach ($subcontexts as $subcontext) { + $combinations["pagesize {$pagesize}, subcontexts {$subcontext}"] = [$pagesize, $subcontext]; + } + } + return $combinations; + } + + /** + * General auth_ldap testcase + * + * @dataProvider auth_ldap_provider + * @param int $pagesize Value to be configured in settings controlling page size. + * @param int $subcontext Value to be configured in settings controlling searching in subcontexts. + */ + public function test_auth_ldap(int $pagesize, int $subcontext) { global $CFG, $DB; if (!extension_loaded('ldap')) { @@ -100,12 +129,12 @@ class auth_ldap_plugin_testcase extends advanced_testcase { set_config('start_tls', 0, 'auth_ldap'); set_config('ldap_version', 3, 'auth_ldap'); set_config('ldapencoding', 'utf-8', 'auth_ldap'); - set_config('pagesize', '2', 'auth_ldap'); + set_config('pagesize', $pagesize, 'auth_ldap'); set_config('bind_dn', TEST_AUTH_LDAP_BIND_DN, 'auth_ldap'); set_config('bind_pw', TEST_AUTH_LDAP_BIND_PW, 'auth_ldap'); set_config('user_type', 'rfc2307', 'auth_ldap'); set_config('contexts', 'ou=users,'.$topdn, 'auth_ldap'); - set_config('search_sub', 0, 'auth_ldap'); + set_config('search_sub', $subcontext, 'auth_ldap'); set_config('opt_deref', LDAP_DEREF_NEVER, 'auth_ldap'); set_config('user_attribute', 'cn', 'auth_ldap'); set_config('memberattribute', 'memberuid', 'auth_ldap');