MDL-66075 mod_forum: add more coverage of get_from_discussion_ids
Specifically, this is now testing the $canseeprivatereplies param for different users and over a more complete range of cases.
This commit is contained in:
committed by
Simey Lameze
parent
babc6bf707
commit
24ddc6dc64
@@ -227,38 +227,85 @@ class mod_forum_vaults_post_testcase extends advanced_testcase {
|
||||
|
||||
[$student, $otherstudent] = $this->helper_create_users($course, 2, 'student');
|
||||
[$teacher, $otherteacher] = $this->helper_create_users($course, 2, 'teacher');
|
||||
[$discussion, $post] = $this->helper_post_to_forum($forum, $teacher);
|
||||
$reply = $this->helper_post_to_discussion($forum, $discussion, $teacher, [
|
||||
'privatereplyto' => $student->id,
|
||||
]);
|
||||
|
||||
// Create the posts structure below.
|
||||
// Forum:
|
||||
// -> Post (student 1)
|
||||
// -> Post private reply (teacher 1)
|
||||
// -> Otherpost (teacher 1)
|
||||
// -> Otherpost private reply (teacher 2)
|
||||
// -> Otherpost reply (student 1)
|
||||
// -> Otherpost reply private reply (teacher 1).
|
||||
[$discussion, $post] = $this->helper_post_to_forum($forum, $student);
|
||||
$postprivatereply = $this->helper_reply_to_post($post, $teacher, [
|
||||
'privatereplyto' => $student->id
|
||||
]);
|
||||
[$otherdiscussion, $otherpost] = $this->helper_post_to_forum($forum, $teacher);
|
||||
$otherpostprivatereply = $this->helper_reply_to_post($otherpost, $otherteacher, [
|
||||
'privatereplyto' => $teacher->id,
|
||||
]);
|
||||
$otherpostreply = $this->helper_reply_to_post($otherpost, $student);
|
||||
$otherpostreplyprivatereply = $this->helper_reply_to_post($otherpostreply, $teacher, [
|
||||
'privatereplyto' => $student->id
|
||||
]);
|
||||
|
||||
// The user is the author.
|
||||
// Teacher 1. Request all posts from the vault, telling the vault that the teacher CAN see private replies made by anyone.
|
||||
$entities = $this->vault->get_from_discussion_ids($teacher, [$discussion->id, $otherdiscussion->id], true);
|
||||
$this->assertCount(3, $entities);
|
||||
$this->assertCount(6, $entities);
|
||||
$this->assertArrayHasKey($post->id, $entities); // Order is not guaranteed, so just verify element existence.
|
||||
$this->assertArrayHasKey($reply->id, $entities);
|
||||
$this->assertArrayHasKey($postprivatereply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpost->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostprivatereply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreplyprivatereply->id, $entities);
|
||||
|
||||
// The user is the intended recipient.
|
||||
// Student 1. Request all posts from the vault, telling the vault that the student CAN'T see private replies made by anyone.
|
||||
// Teacher2's private reply to otherpost is omitted.
|
||||
$entities = $this->vault->get_from_discussion_ids($student, [$discussion->id, $otherdiscussion->id], false);
|
||||
$this->assertCount(3, $entities);
|
||||
$this->assertCount(5, $entities);
|
||||
$this->assertArrayHasKey($post->id, $entities); // Order is not guaranteed, so just verify element existence.
|
||||
$this->assertArrayHasKey($reply->id, $entities);
|
||||
$this->assertArrayHasKey($postprivatereply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpost->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreplyprivatereply->id, $entities);
|
||||
|
||||
// The user is another teacher..
|
||||
// Student 1. Request all posts from the vault, telling the vault that student CAN see all private replies made.
|
||||
// The private reply made by teacher 2 to otherpost is now included.
|
||||
$entities = $this->vault->get_from_discussion_ids($student, [$discussion->id, $otherdiscussion->id], true);
|
||||
$this->assertCount(6, $entities);
|
||||
$this->assertArrayHasKey($post->id, $entities); // Order is not guaranteed, so just verify element existence.
|
||||
$this->assertArrayHasKey($postprivatereply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpost->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostprivatereply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreplyprivatereply->id, $entities);
|
||||
|
||||
// Teacher 2. Request all posts from the vault, telling the vault that teacher2 CAN see all private replies made.
|
||||
$entities = $this->vault->get_from_discussion_ids($otherteacher, [$discussion->id, $otherdiscussion->id], true);
|
||||
$this->assertCount(6, $entities);
|
||||
$this->assertArrayHasKey($post->id, $entities); // Order is not guaranteed, so just verify element existence.
|
||||
$this->assertArrayHasKey($postprivatereply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpost->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostprivatereply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreplyprivatereply->id, $entities);
|
||||
|
||||
// Teacher 2. Request all posts from the vault, telling the vault that teacher2 CANNOT see all private replies made.
|
||||
// The private replies not relating to teacher 2 directly are omitted.
|
||||
$entities = $this->vault->get_from_discussion_ids($otherteacher, [$discussion->id, $otherdiscussion->id], false);
|
||||
$this->assertCount(4, $entities);
|
||||
$this->assertArrayHasKey($post->id, $entities); // Order is not guaranteed, so just verify element existence.
|
||||
$this->assertArrayHasKey($otherpost->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostprivatereply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreply->id, $entities);
|
||||
|
||||
// Student 2. Request all posts from the vault, telling the vault that student2 CAN'T see all private replies made.
|
||||
// All private replies are omitted, as none relate to student2.
|
||||
$entities = $this->vault->get_from_discussion_ids($otherstudent, [$discussion->id, $otherdiscussion->id], false);
|
||||
$this->assertCount(3, $entities);
|
||||
$this->assertArrayHasKey($post->id, $entities); // Order is not guaranteed, so just verify element existence.
|
||||
$this->assertArrayHasKey($reply->id, $entities);
|
||||
$this->assertArrayHasKey($otherpost->id, $entities);
|
||||
|
||||
// The user is a different student.
|
||||
$entities = $this->vault->get_from_discussion_ids($otherstudent, [$discussion->id, $otherdiscussion->id], false);
|
||||
$this->assertCount(2, $entities);
|
||||
$this->assertArrayHasKey($post->id, $entities); // Order is not guaranteed, so just verify element existence.
|
||||
$this->assertArrayHasKey($otherpost->id, $entities);
|
||||
$this->assertArrayHasKey($otherpostreply->id, $entities);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user