From a20d6752506f00a4dc8e07f8432ba77fce319fcb Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 14 Oct 2014 11:37:27 +0100 Subject: [PATCH] MDL-47666 DB auth & enrol: unit tests fail with custom DB drivers Changed to used $DB->get_db_family, rather than hard-coding the list of class names. --- auth/db/tests/db_test.php | 23 +++++++++++------------ enrol/database/tests/sync_test.php | 21 ++++++++++----------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/auth/db/tests/db_test.php b/auth/db/tests/db_test.php index 64f34f30de17f..3931ea998016e 100644 --- a/auth/db/tests/db_test.php +++ b/auth/db/tests/db_test.php @@ -52,14 +52,9 @@ protected function init_auth_database() { set_config('host', $CFG->dbhost.':'.$CFG->dboptions['dbport'], 'auth/db'); } - switch (get_class($DB)) { - case 'mssql_native_moodle_database': - set_config('type', 'mssql_n', 'auth/db'); - set_config('sybasequoting', '1', 'auth/db'); - break; + switch ($DB->get_dbfamily()) { - case 'mariadb_native_moodle_database': - case 'mysqli_native_moodle_database': + case 'mysql': set_config('type', 'mysqli', 'auth/db'); set_config('setupsql', "SET NAMES 'UTF-8'", 'auth/db'); set_config('sybasequoting', '0', 'auth/db'); @@ -72,12 +67,12 @@ protected function init_auth_database() { } break; - case 'oci_native_moodle_database': + case 'oracle': set_config('type', 'oci8po', 'auth/db'); set_config('sybasequoting', '1', 'auth/db'); break; - case 'pgsql_native_moodle_database': + case 'postgres': set_config('type', 'postgres7', 'auth/db'); $setupsql = "SET NAMES 'UTF-8'"; if (!empty($CFG->dboptions['dbschema'])) { @@ -98,13 +93,17 @@ protected function init_auth_database() { } break; - case 'sqlsrv_native_moodle_database': - set_config('type', 'mssqlnative', 'auth/db'); + case 'mssql': + if (get_class($DB) == 'mssql_native_moodle_database') { + set_config('type', 'mssql_n', 'auth/db'); + } else { + set_config('type', 'mssqlnative', 'auth/db'); + } set_config('sybasequoting', '1', 'auth/db'); break; default: - throw new exception('Unknown database driver '.get_class($DB)); + throw new exception('Unknown database family ' . $DB->get_dbfamily()); } $table = new xmldb_table('auth_db_users'); diff --git a/enrol/database/tests/sync_test.php b/enrol/database/tests/sync_test.php index 39f8078229a43..782983315778b 100644 --- a/enrol/database/tests/sync_test.php +++ b/enrol/database/tests/sync_test.php @@ -54,14 +54,9 @@ protected function init_enrol_database() { set_config('dbhost', $CFG->dbhost.':'.$CFG->dboptions['dbport'], 'enrol_database'); } - switch (get_class($DB)) { - case 'mssql_native_moodle_database': - set_config('dbtype', 'mssql_n', 'enrol_database'); - set_config('dbsybasequoting', '1', 'enrol_database'); - break; + switch ($DB->get_dbfamily()) { - case 'mariadb_native_moodle_database': - case 'mysqli_native_moodle_database': + case 'mysql': set_config('dbtype', 'mysqli', 'enrol_database'); set_config('dbsetupsql', "SET NAMES 'UTF-8'", 'enrol_database'); set_config('dbsybasequoting', '0', 'enrol_database'); @@ -74,12 +69,12 @@ protected function init_enrol_database() { } break; - case 'oci_native_moodle_database': + case 'oracle': set_config('dbtype', 'oci8po', 'enrol_database'); set_config('dbsybasequoting', '1', 'enrol_database'); break; - case 'pgsql_native_moodle_database': + case 'postgres': set_config('dbtype', 'postgres7', 'enrol_database'); $setupsql = "SET NAMES 'UTF-8'"; if (!empty($CFG->dboptions['dbschema'])) { @@ -100,8 +95,12 @@ protected function init_enrol_database() { } break; - case 'sqlsrv_native_moodle_database': - set_config('dbtype', 'mssqlnative', 'enrol_database'); + case 'mssql': + if (get_class($DB) == 'mssql_native_moodle_database') { + set_config('dbtype', 'mssql_n', 'enrol_database'); + } else { + set_config('dbtype', 'mssqlnative', 'enrol_database'); + } set_config('dbsybasequoting', '1', 'enrol_database'); break;