Merge branch 'wip-MDL-62755-master' of git://github.com/abgreeve/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 27 Jun 2018 23:55:53 +0000 (01:55 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 27 Jun 2018 23:55:53 +0000 (01:55 +0200)
mod/assign/classes/privacy/provider.php
mod/assign/tests/privacy_test.php

index 7f7841d..8150d63 100644 (file)
@@ -141,8 +141,6 @@ class provider implements metadataprovider, pluginprovider, preference_provider
                   JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                   JOIN {assign_grades} ag ON a.id = ag.assignment AND (ag.userid = :userid OR ag.grader = :graderid)";
 
-                  global $DB;
-
         $contextlist = new contextlist();
         $contextlist->add_from_sql($sql, $params);
 
@@ -475,10 +473,10 @@ class provider implements metadataprovider, pluginprovider, preference_provider
                 $data->duedate = transform::datetime($overrides->duedate);
             }
             if (!empty($overrides->cutoffdate)) {
-                $overrides->cutoffdate = transform::datetime($overrides->cutoffdate);
+                $data->cutoffdate = transform::datetime($overrides->cutoffdate);
             }
             if (!empty($overrides->allowsubmissionsfromdate)) {
-                $overrides->allowsubmissionsfromdate = transform::datetime($overrides->allowsubmissionsfromdate);
+                $data->allowsubmissionsfromdate = transform::datetime($overrides->allowsubmissionsfromdate);
             }
             if (!empty($data)) {
                 writer::with_context($context)->export_data([get_string('overrides', 'mod_assign')], $data);
index ac2ee02..bcae99d 100644 (file)
@@ -152,6 +152,7 @@ class mod_assign_privacy_testcase extends provider_testcase {
      * Test that a student with multiple submissions and grades is returned with the correct data.
      */
     public function test_export_user_data_student() {
+        global $DB;
         $this->resetAfterTest();
         $course = $this->getDataGenerator()->create_course();
         $coursecontext = \context_course::instance($course->id);
@@ -176,6 +177,14 @@ class mod_assign_privacy_testcase extends provider_testcase {
 
         $this->setUser($teacher);
 
+        $overridedata = new \stdClass();
+        $overridedata->assignid = $assign->get_instance()->id;
+        $overridedata->userid = $user->id;
+        $overridedata->duedate = time();
+        $overridedata->allowsubmissionsfromdate = time();
+        $overridedata->cutoffdate = time();
+        $DB->insert_record('assign_overrides', $overridedata);
+
         $grade1 = '67.00';
         $teachercommenttext = 'Please try again.';
         $data = new \stdClass();
@@ -222,6 +231,15 @@ class mod_assign_privacy_testcase extends provider_testcase {
         // Check feedback.
         $this->assertContains($teachercommenttext, $writer->get_data(['attempt 1', 'Feedback comments'])->commenttext);
         $this->assertContains($teachercommenttext2, $writer->get_data(['attempt 2', 'Feedback comments'])->commenttext);
+
+        // Check override data was exported correctly.
+        $overrideexport = $writer->get_data(['Overrides']);
+        $this->assertEquals(\core_privacy\local\request\transform::datetime($overridedata->duedate),
+                $overrideexport->duedate);
+        $this->assertEquals(\core_privacy\local\request\transform::datetime($overridedata->cutoffdate),
+                $overrideexport->cutoffdate);
+        $this->assertEquals(\core_privacy\local\request\transform::datetime($overridedata->allowsubmissionsfromdate),
+                $overrideexport->allowsubmissionsfromdate);
     }
 
     /**