Skip to content

Commit

Permalink
MDL-77989 core: Fix uses of legacy external API
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Apr 21, 2023
1 parent 1a53cbb commit fcba0cb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion course/format/tests/external/file_handlers_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

namespace core_courseformat\external;

use core_external\external_api;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');

use external_api;
use dndupload_handler;

/**
Expand Down
3 changes: 2 additions & 1 deletion question/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace core_question;

use core_external\restricted_context_exception;
use core_question_external;
use externallib_advanced_testcase;

Expand Down Expand Up @@ -322,7 +323,7 @@ public function test_get_random_question_summaries_restricted_context() {
// to be reset afterwards.
core_question_external::get_random_question_summaries(1, false, [], $systemcontext->id);
} catch (\Exception $e) {
$this->assertInstanceOf('restricted_context_exception', $e);
$this->assertInstanceOf(restricted_context_exception::class, $e);
}
// Reset the restriction so that other tests don't fail aftwards.
core_question_external::set_context_restriction($systemcontext);
Expand Down
9 changes: 7 additions & 2 deletions webservice/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function test_init_service_class() {
* Tests update_token_lastaccess() function.
*/
public function test_update_token_lastaccess() {
global $DB;
global $DB, $USER;

$this->resetAfterTest(true);

Expand All @@ -167,7 +167,12 @@ public function test_update_token_lastaccess() {
$DB->insert_record('external_services', $webservice);

// Add token.
$tokenstr = external_create_service_token($webservice->name, \context_system::instance()->id);
$tokenstr = \core_external\util::generate_token(
EXTERNAL_TOKEN_EMBEDDED,
\core_external\util::get_service_by_name($webservice->name),
$USER->id,
\core\context\system::instance()
);
$token = $DB->get_record('external_tokens', ['token' => $tokenstr]);

// Trigger last access once (at current time).
Expand Down

0 comments on commit fcba0cb

Please sign in to comment.