MDL-70763 quiz_overview: export preferences for correct user.

This commit is contained in:
Paul Holden
2021-04-04 23:15:43 +01:00
parent e89432fb19
commit e44ae4df58
2 changed files with 20 additions and 10 deletions
@@ -59,7 +59,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) {
$preference = get_user_preferences('quiz_overview_slotmarks', null);
$preference = get_user_preferences('quiz_overview_slotmarks', null, $userid);
if (null !== $preference) {
if (empty($preference)) {
$description = get_string('privacy:preference:slotmarks:no', 'quiz_overview');
@@ -55,14 +55,19 @@ class quiz_overview_privacy_provider_testcase extends \core_privacy\tests\provid
* Preference does exist.
*/
public function test_preference_yes() {
global $USER;
$this->resetAfterTest();
// Create test user, add some preferences.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
set_user_preference('quiz_overview_slotmarks', 1, $user);
// Switch to admin user (so we can validate preferences of the correct user are being exported).
$this->setAdminUser();
set_user_preference('quiz_overview_slotmarks', 1);
provider::export_user_preferences($USER->id);
// Export test users preferences.
provider::export_user_preferences($user->id);
$writer = writer::with_context(\context_system::instance());
$this->assertTrue($writer->has_any_data());
@@ -78,14 +83,19 @@ class quiz_overview_privacy_provider_testcase extends \core_privacy\tests\provid
* Preference does exist and is no.
*/
public function test_preference_no() {
global $USER;
$this->resetAfterTest();
$this->setAdminUser();
// Create test user, add some preferences.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
set_user_preference('quiz_overview_slotmarks', 0);
provider::export_user_preferences($USER->id);
// Switch to admin user (so we can validate preferences of the correct user are being exported).
$this->setAdminUser();
// Export test users preferences.
provider::export_user_preferences($user->id);
$writer = writer::with_context(\context_system::instance());
$this->assertTrue($writer->has_any_data());