From f3c9599e1fbf3e730c229ce93909000d5e6304cd Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 11 Apr 2019 09:02:31 +0100 Subject: [PATCH] MDL-65335 auth: Make oauth2 enabled check more efficient --- auth/oauth2/classes/api.php | 3 +-- auth/oauth2/tests/api_test.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/auth/oauth2/classes/api.php b/auth/oauth2/classes/api.php index 1b152b58bb7..e5b0789b576 100644 --- a/auth/oauth2/classes/api.php +++ b/auth/oauth2/classes/api.php @@ -402,7 +402,6 @@ class api { * @return bool */ public static function is_enabled() { - $plugininfo = \core_plugin_manager::instance()->get_plugin_info('auth_oauth2'); - return $plugininfo->is_enabled(); + return is_enabled_auth('oauth2'); } } diff --git a/auth/oauth2/tests/api_test.php b/auth/oauth2/tests/api_test.php index 83bf1a6c71a..d2fc8e1fac0 100644 --- a/auth/oauth2/tests/api_test.php +++ b/auth/oauth2/tests/api_test.php @@ -140,4 +140,23 @@ class auth_oauth2_external_testcase extends advanced_testcase { $this->assertEquals($newuser->id, $match->get('userid')); } + /** + * Test that is_enabled correctly identifies when the plugin is enabled. + */ + public function test_is_enabled() { + $this->resetAfterTest(); + + set_config('auth', 'manual,oauth2'); + $this->assertTrue(\auth_oauth2\api::is_enabled()); + } + + /** + * Test that is_enabled correctly identifies when the plugin is disabled. + */ + public function test_is_enabled_disabled() { + $this->resetAfterTest(); + + set_config('auth', 'manual'); + $this->assertFalse(\auth_oauth2\api::is_enabled()); + } }