Skip to content
Browse files

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).
  • Loading branch information...
stronk7 committed Jun 4, 2013
1 parent 79452da commit a182f88f7f34e31c279459f50a29ffd8d8575708
Showing with 10 additions and 1 deletion.
  1. +10 −1 course/tests/externallib_test.php
@@ -671,7 +671,15 @@ public function test_duplicate_course() {
* 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);
@@ -724,6 +732,7 @@ public function test_update_courses() {
$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']));

0 comments on commit a182f88

Please sign in to comment.
You can’t perform that action at this time.