Merge branch 'MDL-66230' of https://github.com/paulholden/moodle
[moodle.git] / admin / tool / usertours / tests / privacy_provider_test.php
index 8cfc81a..db0139d 100644 (file)
@@ -112,4 +112,37 @@ class tool_usertours_privacy_testcase extends \core_privacy\tests\provider_testc
 
         $this->assertCount(2, (array) $prefs);
     }
+
+    /**
+     * Ensure that export_user_preferences excludes deleted tours.
+     */
+    public function test_export_user_preferences_deleted_tour() {
+        global $DB;
+
+        $this->resetAfterTest();
+        $this->setAdminUser();
+
+        $user = \core_user::get_user_by_username('admin');
+
+        $alltours = $DB->get_records('tool_usertours_tours');
+
+        $tour1 = tour::instance(array_shift($alltours)->id);
+        $tour1->mark_user_completed();
+
+        $tour2 = tour::instance(array_shift($alltours)->id);
+        $tour2->mark_user_completed();
+        $tour2->remove();
+
+        $writer = writer::with_context(\context_system::instance());
+
+        provider::export_user_preferences($user->id);
+        $this->assertTrue($writer->has_any_data());
+
+        // We should have one preference.
+        $prefs = $writer->get_user_preferences('tool_usertours');
+        $this->assertCount(1, (array) $prefs);
+
+        // The preference should be related to the first tour.
+        $this->assertContains($tour1->get_name(), reset($prefs)->description);
+    }
 }