Skip to content

Commit

Permalink
MDL-62169 mod_assignment: Improved phpunit test reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
zig-moodle committed May 7, 2018
1 parent 0fed66a commit 966dd82
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions mod/assignment/tests/privacy_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class mod_assignment_privacy_testcase extends advanced_testcase {
*/
private $course2students = [];

/**
* @var int array Array of test assignments associated for Course 1.
*/
private $course1assignments = [];

/**
* @var int array Array of test assignments associated for Course 2.
*/
private $course2assignments = [];

/**
* Test for provider::get_contexts_for_userid().
*
Expand Down Expand Up @@ -116,7 +126,10 @@ public function test_export_user_data_teacher() {
$contexts = $contextlist->get_contexts();

// Context 1 - Course 1's Assignment 1 -- (onlinetext).
$writer = writer::with_context($contexts[0]);
$context = context_module::instance($this->course1assignments['ass1']->cmid);
$this->assertContains($context, $contexts);

$writer = writer::with_context($context);
$subcontexts = [
get_string('privacy:markedsubmissionspath', 'mod_assignment'),
transform::user($teacher1->id)
Expand All @@ -136,7 +149,10 @@ public function test_export_user_data_teacher() {
}

// Context 2 - Course 1's Assignment 2 -- (single file upload).
$writer = writer::with_context($contexts[1]);
$context = context_module::instance($this->course1assignments['ass2']->cmid);
$this->assertContains($context, $contexts);

$writer = writer::with_context($context);
foreach ($this->course1students as $student) {
$subcontexts = [
get_string('privacy:markedsubmissionspath', 'mod_assignment'),
Expand All @@ -152,7 +168,10 @@ public function test_export_user_data_teacher() {
}

// Context 3 - Course 2's Assignment 1 -- (offline).
$writer = writer::with_context($contexts[2]);
$context = context_module::instance($this->course2assignments['ass1']->cmid);
$this->assertContains($context, $contexts);

$writer = writer::with_context($context);
foreach ($this->course2students as $student) {
$subcontexts = [
get_string('privacy:markedsubmissionspath', 'mod_assignment'),
Expand All @@ -164,7 +183,10 @@ public function test_export_user_data_teacher() {
}

// Context 4 - Course 2's Assignment 2 -- (multiple file upload).
$writer = writer::with_context($contexts[3]);
$context = context_module::instance($this->course2assignments['ass2']->cmid);
$this->assertContains($context, $contexts);

$writer = writer::with_context($context);
foreach ($this->course2students as $student) {
$subcontexts = [
get_string('privacy:markedsubmissionspath', 'mod_assignment'),
Expand Down Expand Up @@ -203,7 +225,10 @@ public function test_export_user_data_student() {
$contexts = $contextlist->get_contexts();

// Context 1 - Course 1's Assignment 1 -- (onlinetext).
$writer = writer::with_context($contexts[0]);
$context = context_module::instance($this->course1assignments['ass1']->cmid);
$this->assertContains($context, $contexts);

$writer = writer::with_context($context);
$subcontexts = [
get_string('privacy:submissionpath', 'mod_assignment')
];
Expand All @@ -213,7 +238,10 @@ public function test_export_user_data_student() {
$this->assertEquals("<p>Course 1 - Ass 1: " . $student1->id . "</p>", $submission->data1);

// Context 2 - Course 1's Assignment 2 -- (single file upload).
$writer = writer::with_context($contexts[1]);
$context = context_module::instance($this->course1assignments['ass2']->cmid);
$this->assertContains($context, $contexts);

$writer = writer::with_context($context);
$subcontexts = [
get_string('privacy:submissionpath', 'mod_assignment')
];
Expand All @@ -237,7 +265,10 @@ public function test_export_user_data_student() {
$contexts = $contextlist->get_contexts();

// Context 1 - Course 2's Assignment 1 -- (offline).
$writer = writer::with_context($contexts[0]);
$context = context_module::instance($this->course2assignments['ass1']->cmid);
$this->assertContains($context, $contexts);

$writer = writer::with_context($context);
$subcontexts = [
get_string('privacy:submissionpath', 'mod_assignment')
];
Expand All @@ -247,7 +278,10 @@ public function test_export_user_data_student() {
$this->assertEquals("<p>Course 2 - Ass 1: " . $student2->id . "</p>", $submission->data1);

// Context 2 - Course 2's Assignment 2 -- (multiple file upload).
$writer = writer::with_context($contexts[1]);
$context = context_module::instance($this->course2assignments['ass2']->cmid);
$this->assertContains($context, $contexts);

$writer = writer::with_context($context);
$subcontexts = [
get_string('privacy:submissionpath', 'mod_assignment')
];
Expand Down Expand Up @@ -367,6 +401,12 @@ protected function create_courses_and_assignments() {
'assignmenttype' => 'uploadsingle',
]
);

$this->course1assignments = [
'ass1' => $course1assignment1,
'ass2' => $course1assignment2
];

$course2assignment1 = $this->getDataGenerator()->create_module('assignment',
[
'course' => $course2->id,
Expand All @@ -382,6 +422,11 @@ protected function create_courses_and_assignments() {
]
);

$this->course2assignments = [
'ass1' => $course2assignment1,
'ass2' => $course2assignment2
];

// Teacher 1 add test assignment submission for Course 1 - Assignment 1.
$this->add_assignment_submission(
$course1assignment1,
Expand Down

0 comments on commit 966dd82

Please sign in to comment.