$return = array_pop($return);
$this->assertEquals($return['warningcode'], 'contactnotcreated');
$this->assertEquals($return['itemid'], 99999);
+
+ // Try to add a contact to another user, should throw an exception.
+ // All assertions must be added before this point.
+ $this->expectException('required_capability_exception');
+ core_message_external::create_contacts(array($user2->id), $user3->id);
}
/**
// Removing mixed valid and invalid data.
$return = core_message_external::delete_contacts(array($user6->id, 99999));
$this->assertNull($return);
+
+ // Try to delete a contact of another user contact list, should throw an exception.
+ // All assertions must be added before this point.
+ $this->expectException('required_capability_exception');
+ core_message_external::delete_contacts(array($user2->id), $user3->id);
}
/**
$return = array_pop($return);
$this->assertEquals($return['warningcode'], 'contactnotblocked');
$this->assertEquals($return['itemid'], 99999);
+
+ // Try to block a contact of another user contact list, should throw an exception.
+ // All assertions must be added before this point.
+ $this->expectException('required_capability_exception');
+ core_message_external::block_contacts(array($user2->id), $user3->id);
}
/**
$return = core_message_external::unblock_contacts(array($user6->id, 99999));
$this->assertNull($return);
+ // Try to unblock a contact of another user contact list, should throw an exception.
+ // All assertions must be added before this point.
+ $this->expectException('required_capability_exception');
+ core_message_external::unblock_contacts(array($user2->id), $user3->id);
}
/**
$course3->shortname = 'Three search';
$course3 = $this->getDataGenerator()->create_course($course3);
+ $course4 = new stdClass();
+ $course4->fullname = 'Course Four';
+ $course4->shortname = 'CF100';
+ $course4 = $this->getDataGenerator()->create_course($course4);
+
+ $this->getDataGenerator()->enrol_user($user1->id, $course1->id, 'student');
+ $this->getDataGenerator()->enrol_user($user1->id, $course2->id, 'student');
+ $this->getDataGenerator()->enrol_user($user1->id, $course3->id, 'student');
+
// Add some users as contacts.
message_add_contact($user2->id, 0, $user1->id);
message_add_contact($user3->id, 0, $user1->id);
$this->assertEquals($user2->id, $contacts[1]['userid']);
// Check that we retrieved the correct courses.
- $this->assertCount(2, $courses);
- $this->assertEquals($course3->id, $courses[0]['id']);
- $this->assertEquals($course1->id, $courses[1]['id']);
+ $this->assertCount(0, $courses);
// Check that we retrieved the correct non-contacts.
$this->assertCount(1, $noncontacts);