250
250
$this->assertTrue(enrol_user_sees_own_courses());
251
251
$this->assertEquals($reads, $DB->perf_get_reads());
254
public function test_enrol_get_shared_courses() {
255
$this->resetAfterTest();
257
$user1 = $this->getDataGenerator()->create_user();
258
$user2 = $this->getDataGenerator()->create_user();
259
$user3 = $this->getDataGenerator()->create_user();
261
$course1 = $this->getDataGenerator()->create_course();
262
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
263
$this->getDataGenerator()->enrol_user($user2->id, $course1->id);
265
$course2 = $this->getDataGenerator()->create_course();
266
$this->getDataGenerator()->enrol_user($user1->id, $course2->id);
268
// Test that user1 and user2 have courses in common.
269
$this->assertTrue(enrol_get_shared_courses($user1, $user2, false, true));
270
// Test that user1 and user3 have no courses in common.
271
$this->assertFalse(enrol_get_shared_courses($user1, $user3, false, true));
273
// Test retrieving the courses in common.
274
$sharedcourses = enrol_get_shared_courses($user1, $user2, true);
276
// Only should be one shared course.
277
$this->assertCount(1, $sharedcourses);
278
$sharedcourse = array_shift($sharedcourses);
279
// It should be course 1.
280
$this->assertEquals($sharedcourse->id, $course1->id);