Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-35190 random failures in course externallib test

  • Loading branch information...
commit 7d6c58bc24bd12b3bedd9970b10f49fc4699d8ea 1 parent 569f1ad
Jérôme Mouneyrac mouneyrac authored

Showing 1 changed file with 46 additions and 32 deletions. Show diff stats Hide diff stats

  1. +46 32 course/tests/externallib_test.php
78 course/tests/externallib_test.php
@@ -165,20 +165,28 @@ public function test_get_categories() {
165 165 global $DB;
166 166
167 167 $this->resetAfterTest(true);
  168 +
  169 + $generatedcats = array();
168 170 $category1data['idnumber'] = 'idnumbercat1';
169 171 $category1data['name'] = 'Category 1 for PHPunit test';
170 172 $category1data['description'] = 'Category 1 description';
171 173 $category1data['descriptionformat'] = FORMAT_MOODLE;
172 174 $category1 = self::getDataGenerator()->create_category($category1data);
  175 + $generatedcats[$category1->id] = $category1;
173 176 $category2 = self::getDataGenerator()->create_category(
174 177 array('parent' => $category1->id));
  178 + $generatedcats[$category2->id] = $category2;
175 179 $category6 = self::getDataGenerator()->create_category(
176 180 array('parent' => $category1->id, 'visible' => 0));
  181 + $generatedcats[$category6->id] = $category6;
177 182 $category3 = self::getDataGenerator()->create_category();
  183 + $generatedcats[$category3->id] = $category3;
178 184 $category4 = self::getDataGenerator()->create_category(
179 185 array('parent' => $category3->id));
  186 + $generatedcats[$category4->id] = $category4;
180 187 $category5 = self::getDataGenerator()->create_category(
181 188 array('parent' => $category4->id));
  189 + $generatedcats[$category5->id] = $category5;
182 190
183 191 // Set the required capabilities by the external function.
184 192 $context = context_system::instance();
@@ -193,11 +201,13 @@ public function test_get_categories() {
193 201 $this->assertEquals(2, count($categories));
194 202
195 203 // Check the return values
196   - $this->assertEquals($categories[0]['id'], $category1->id);
197   - $this->assertEquals($categories[0]['idnumber'], $category1->idnumber);
198   - $this->assertEquals($categories[0]['name'], $category1->name);
199   - $this->assertEquals($categories[0]['description'], $category1->description);
200   - $this->assertEquals($categories[0]['descriptionformat'], FORMAT_HTML);
  204 + foreach ($categories as $category) {
  205 + $generatedcat = $generatedcats[$category['id']];
  206 + $this->assertEquals($category['idnumber'], $generatedcat->idnumber);
  207 + $this->assertEquals($category['name'], $generatedcat->name);
  208 + $this->assertEquals($category['description'], $generatedcat->description);
  209 + $this->assertEquals($category['descriptionformat'], FORMAT_HTML);
  210 + }
201 211
202 212 // Check different params.
203 213 $categories = core_course_external::get_categories(array(
@@ -440,13 +450,17 @@ public function test_get_courses () {
440 450
441 451 $this->resetAfterTest(true);
442 452
  453 + $generatedcourses = array();
443 454 $coursedata['idnumber'] = 'idnumbercourse1';
444 455 $coursedata['fullname'] = 'Course 1 for PHPunit test';
445 456 $coursedata['summary'] = 'Course 1 description';
446 457 $coursedata['summaryformat'] = FORMAT_MOODLE;
447 458 $course1 = self::getDataGenerator()->create_course($coursedata);
  459 + $generatedcourses[$course1->id] = $course1;
448 460 $course2 = self::getDataGenerator()->create_course();
  461 + $generatedcourses[$course2->id] = $course2;
449 462 $course3 = self::getDataGenerator()->create_course();
  463 + $generatedcourses[$course3->id] = $course3;
450 464
451 465 // Set the required capabilities by the external function.
452 466 $context = context_system::instance();
@@ -464,33 +478,33 @@ public function test_get_courses () {
464 478 // Check we retrieve the good total number of categories.
465 479 $this->assertEquals(2, count($courses));
466 480
467   - // Check the return values for course 1
468   - $dbcourse = $DB->get_record('course', array('id' => $course1->id));
469   - $this->assertEquals($courses[0]['id'], $dbcourse->id);
470   - $this->assertEquals($courses[0]['idnumber'], $coursedata['idnumber']);
471   - $this->assertEquals($courses[0]['fullname'], $coursedata['fullname']);
472   - $this->assertEquals($courses[0]['summary'], $coursedata['summary']);
473   - $this->assertEquals($courses[0]['summaryformat'], FORMAT_HTML);
474   - $this->assertEquals($courses[0]['shortname'], $dbcourse->shortname);
475   - $this->assertEquals($courses[0]['categoryid'], $dbcourse->category);
476   - $this->assertEquals($courses[0]['format'], $dbcourse->format);
477   - $this->assertEquals($courses[0]['showgrades'], $dbcourse->showgrades);
478   - $this->assertEquals($courses[0]['newsitems'], $dbcourse->newsitems);
479   - $this->assertEquals($courses[0]['startdate'], $dbcourse->startdate);
480   - $this->assertEquals($courses[0]['numsections'], $dbcourse->numsections);
481   - $this->assertEquals($courses[0]['maxbytes'], $dbcourse->maxbytes);
482   - $this->assertEquals($courses[0]['showreports'], $dbcourse->showreports);
483   - $this->assertEquals($courses[0]['visible'], $dbcourse->visible);
484   - $this->assertEquals($courses[0]['hiddensections'], $dbcourse->hiddensections);
485   - $this->assertEquals($courses[0]['groupmode'], $dbcourse->groupmode);
486   - $this->assertEquals($courses[0]['groupmodeforce'], $dbcourse->groupmodeforce);
487   - $this->assertEquals($courses[0]['defaultgroupingid'], $dbcourse->defaultgroupingid);
488   - $this->assertEquals($courses[0]['completionnotify'], $dbcourse->completionnotify);
489   - $this->assertEquals($courses[0]['lang'], $dbcourse->lang);
490   - $this->assertEquals($courses[0]['forcetheme'], $dbcourse->theme);
491   - $this->assertEquals($courses[0]['completionstartonenrol'], $dbcourse->completionstartonenrol);
492   - $this->assertEquals($courses[0]['enablecompletion'], $dbcourse->enablecompletion);
493   - $this->assertEquals($courses[0]['completionstartonenrol'], $dbcourse->completionstartonenrol);
  481 + foreach ($courses as $course) {
  482 + $dbcourse = $generatedcourses[$course['id']];
  483 + $this->assertEquals($course['idnumber'], $dbcourse->idnumber);
  484 + $this->assertEquals($course['fullname'], $dbcourse->fullname);
  485 + $this->assertEquals($course['summary'], $dbcourse->summary);
  486 + $this->assertEquals($course['summaryformat'], FORMAT_HTML);
  487 + $this->assertEquals($course['shortname'], $dbcourse->shortname);
  488 + $this->assertEquals($course['categoryid'], $dbcourse->category);
  489 + $this->assertEquals($course['format'], $dbcourse->format);
  490 + $this->assertEquals($course['showgrades'], $dbcourse->showgrades);
  491 + $this->assertEquals($course['newsitems'], $dbcourse->newsitems);
  492 + $this->assertEquals($course['startdate'], $dbcourse->startdate);
  493 + $this->assertEquals($course['numsections'], $dbcourse->numsections);
  494 + $this->assertEquals($course['maxbytes'], $dbcourse->maxbytes);
  495 + $this->assertEquals($course['showreports'], $dbcourse->showreports);
  496 + $this->assertEquals($course['visible'], $dbcourse->visible);
  497 + $this->assertEquals($course['hiddensections'], $dbcourse->hiddensections);
  498 + $this->assertEquals($course['groupmode'], $dbcourse->groupmode);
  499 + $this->assertEquals($course['groupmodeforce'], $dbcourse->groupmodeforce);
  500 + $this->assertEquals($course['defaultgroupingid'], $dbcourse->defaultgroupingid);
  501 + $this->assertEquals($course['completionnotify'], $dbcourse->completionnotify);
  502 + $this->assertEquals($course['lang'], $dbcourse->lang);
  503 + $this->assertEquals($course['forcetheme'], $dbcourse->theme);
  504 + $this->assertEquals($course['completionstartonenrol'], $dbcourse->completionstartonenrol);
  505 + $this->assertEquals($course['enablecompletion'], $dbcourse->enablecompletion);
  506 + $this->assertEquals($course['completionstartonenrol'], $dbcourse->completionstartonenrol);
  507 + }
494 508
495 509 // Get all courses in the DB
496 510 $courses = core_course_external::get_courses(array());

0 comments on commit 7d6c58b

Please sign in to comment.
Something went wrong with that request. Please try again.