mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-39723 prevent update_courses() bad habits.
All the external functions end calling require_login() that is always in charge of setting the $COURSE global. This is not a problem, but in the case of core_course_external::update_courses() testing, where we are, in the same "request", both setting and getting the $COURSE information and it's clearly outdated, so the test fails. Alternative solution would be to modify the external function to ensure that, after updating a course, $COURSE is also updated with the changes but it does not seem to be necessary for "normal" usage (both UI/WS POVs).
This commit is contained in:
parent
79452da1c8
commit
a182f88f7f
1 changed files with 10 additions and 1 deletions
|
@ -671,7 +671,15 @@ class core_course_external_testcase extends externallib_advanced_testcase {
|
|||
* Test update_courses
|
||||
*/
|
||||
public function test_update_courses() {
|
||||
global $DB, $CFG, $USER;
|
||||
global $DB, $CFG, $USER, $COURSE;
|
||||
|
||||
// Get current $COURSE to be able to restore it later (defaults to $SITE). We need this
|
||||
// trick because we are both updating and getting (for testing) course information
|
||||
// in the same request and core_course_external::update_courses()
|
||||
// is overwriting $COURSE all over the time with OLD values, so later
|
||||
// use of get_course() fetches those OLD values instead of the updated ones.
|
||||
// See MDL-39723 for more info.
|
||||
$origcourse = clone($COURSE);
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
|
@ -724,6 +732,7 @@ class core_course_external_testcase extends externallib_advanced_testcase {
|
|||
$courses = array($course1, $course2);
|
||||
|
||||
$updatedcoursewarnings = core_course_external::update_courses($courses);
|
||||
$COURSE = $origcourse; // Restore $COURSE. Instead of using the OLD one set by the previous line.
|
||||
|
||||
// Check that right number of courses were created.
|
||||
$this->assertEquals(0, count($updatedcoursewarnings['warnings']));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue