diff --git a/admin/tool/usertours/classes/privacy/provider.php b/admin/tool/usertours/classes/privacy/provider.php
index 3713d071236..21b70deaf3b 100644
--- a/admin/tool/usertours/classes/privacy/provider.php
+++ b/admin/tool/usertours/classes/privacy/provider.php
@@ -47,7 +47,7 @@ class provider implements
/**
* Returns meta data about this system.
*
- * @param collection $itemcollection The initialised item collection to add items to.
+ * @param collection $items The initialised item collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $items) : collection {
@@ -64,7 +64,7 @@ class provider implements
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
- $preferences = get_user_preferences();
+ $preferences = get_user_preferences(null, null, $userid);
foreach ($preferences as $name => $value) {
$descriptionidentifier = null;
$tourid = null;
diff --git a/admin/tool/usertours/tests/privacy_provider_test.php b/admin/tool/usertours/tests/privacy_provider_test.php
index 17138da2f95..8e552e14e77 100644
--- a/admin/tool/usertours/tests/privacy_provider_test.php
+++ b/admin/tool/usertours/tests/privacy_provider_test.php
@@ -15,9 +15,9 @@
// along with Moodle. If not, see .
/**
- * Unit tests for the block_html implementation of the privacy API.
+ * Unit tests for the tool_usertours implementation of the privacy API.
*
- * @package block_html
+ * @package tool_usertours
* @category test
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -27,19 +27,22 @@ defined('MOODLE_INTERNAL') || die();
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\writer;
-use \core_privacy\local\request\approved_contextlist;
-use \core_privacy\local\request\deletion_criteria;
use \tool_usertours\tour;
use \tool_usertours\privacy\provider;
/**
- * Unit tests for the block_html implementation of the privacy API.
+ * Unit tests for the tool_usertours implementation of the privacy API.
*
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class tool_usertours_privacy_testcase extends \core_privacy\tests\provider_testcase {
+class tool_usertours_privacy_provider_testcase extends \core_privacy\tests\provider_testcase {
+ /**
+ * Helper method for creating a tour
+ *
+ * @return tour
+ */
protected function create_test_tour(): tour {
return (new tour())
->set_name('test_tour')
@@ -118,6 +121,37 @@ class tool_usertours_privacy_testcase extends \core_privacy\tests\provider_testc
$this->assertCount(2, (array) $prefs);
}
+ /**
+ * Make sure we are exporting preferences for the correct user
+ */
+ public function test_export_user_preferences_correct_user(): void {
+ $this->resetAfterTest();
+
+ $tour = $this->create_test_tour();
+
+ // Create test user, mark them as having completed the tour.
+ $user = $this->getDataGenerator()->create_user();
+ $this->setUser($user);
+ $tour->mark_user_completed();
+
+ // Switch to admin user, mark them as having reset the tour.
+ $this->setAdminUser();
+ $tour->request_user_reset();
+
+ // Export test users preferences.
+ provider::export_user_preferences($user->id);
+
+ $writer = writer::with_context(\context_system::instance());
+ $this->assertTrue($writer->has_any_data());
+
+ $prefs = $writer->get_user_preferences('tool_usertours');
+ $this->assertCount(1, (array) $prefs);
+
+ // We should have received back the "completed tour" preference of the test user.
+ $this->assertStringStartsWith('You last marked the "' . $tour->get_name() . '" user tour as completed on',
+ reset($prefs)->description);
+ }
+
/**
* Ensure that export_user_preferences excludes deleted tours.
*/