From c3f53e4e3939429401d7a3527beb8faebbee8167 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 30 Aug 2023 00:04:58 +0100 Subject: [PATCH] MDL-79202 tool_mobile: correctly interpolate minutes in exception. --- admin/tool/mobile/classes/external.php | 2 +- admin/tool/mobile/tests/externallib_test.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/admin/tool/mobile/classes/external.php b/admin/tool/mobile/classes/external.php index b8d821328e3..ec79cd91220 100644 --- a/admin/tool/mobile/classes/external.php +++ b/admin/tool/mobile/classes/external.php @@ -318,7 +318,7 @@ class external extends external_api { $timenow = time(); if ($timenow - $last < $mintimereq) { $minutes = $mintimereq / MINSECS; - throw new moodle_exception('autologinkeygenerationlockout', 'tool_mobile', $minutes); + throw new moodle_exception('autologinkeygenerationlockout', 'tool_mobile', '', $minutes); } set_user_preference('tool_mobile_autologin_request_last', $timenow, $USER); diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php index b722042f9ba..4ba382fae33 100644 --- a/admin/tool/mobile/tests/externallib_test.php +++ b/admin/tool/mobile/tests/externallib_test.php @@ -406,18 +406,18 @@ class externallib_test extends externallib_advanced_testcase { $result = external::get_autologin_key($token->privatetoken); $result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result); - // Change min time between requests to 30 seconds. - set_config('autologinmintimebetweenreq', 30, 'tool_mobile'); + // Change min time between requests to 3 minutes. + set_config('autologinmintimebetweenreq', 3 * MINSECS, 'tool_mobile'); - // Mock a previous request, 60 seconds ago. - $mocktime = time() - MINSECS; + // Mock a previous request, 4 minutes ago. + $mocktime = time() - (4 * MINSECS); set_user_preference('tool_mobile_autologin_request_last', $mocktime, $USER); - $result = external::get_autologin_key($token->privatetoken); // All good, we were expecint 30 seconds or more. + $result = external::get_autologin_key($token->privatetoken); $result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result); // We just requested one token, we must wait. $this->expectException('moodle_exception'); - $this->expectExceptionMessage(get_string('autologinkeygenerationlockout', 'tool_mobile')); + $this->expectExceptionMessage(get_string('autologinkeygenerationlockout', 'tool_mobile', 3)); $result = external::get_autologin_key($token->privatetoken); }