Merge branch 'MDL-70763-311' of git://github.com/paulholden/moodle into MOODLE_311_STABLE
This commit is contained in:
@@ -87,7 +87,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) {
|
||||
$prefname = null;
|
||||
$prefdescription = null;
|
||||
|
||||
@@ -63,14 +63,18 @@ class gradereport_grader_privacy_testcase extends \core_privacy\tests\provider_t
|
||||
* These preferences can be set on each course, but the value is shared in the whole site.
|
||||
*/
|
||||
public function test_export_user_preferences_single() {
|
||||
// Add some user preferences.
|
||||
// Create test user, add some preferences.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
set_user_preference('grade_report_showcalculations', 1, $user);
|
||||
set_user_preference('grade_report_meanselection', GRADE_REPORT_MEAN_GRADED, $user);
|
||||
set_user_preference('grade_report_studentsperpage', 50, $user);
|
||||
|
||||
// Validate exported data.
|
||||
// Switch to admin user (so we can validate preferences of our test user are still exported).
|
||||
$this->setAdminUser();
|
||||
|
||||
// Validate exported data for our test user.
|
||||
provider::export_user_preferences($user->id);
|
||||
$context = context_user::instance($user->id);
|
||||
$writer = writer::with_context($context);
|
||||
|
||||
@@ -61,7 +61,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('htmleditor');
|
||||
$preference = get_user_preferences('htmleditor', null, $userid);
|
||||
if (!empty($preference)) {
|
||||
$desc = get_string('privacy:preference:htmleditor', 'core_editor',
|
||||
get_string('pluginname', "editor_{$preference}"));
|
||||
|
||||
@@ -53,14 +53,19 @@ class core_editor_privacy_provider_testcase extends \core_privacy\tests\provider
|
||||
* When preference exists but is empty, there should be no export.
|
||||
*/
|
||||
public function test_empty_preference() {
|
||||
global $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create test user, add some preferences.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
set_user_preference('htmleditor', '', $user);
|
||||
|
||||
// Switch to admin user (so we can validate preferences of the correct user are being exported).
|
||||
$this->setAdminUser();
|
||||
|
||||
set_user_preference('htmleditor', '');
|
||||
|
||||
provider::export_user_preferences($USER->id);
|
||||
// Export test users preferences.
|
||||
provider::export_user_preferences($user->id);
|
||||
$this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
|
||||
}
|
||||
|
||||
@@ -68,13 +73,19 @@ class core_editor_privacy_provider_testcase extends \core_privacy\tests\provider
|
||||
* When an editor is set, the name of that editor will be reported.
|
||||
*/
|
||||
public function test_editor_atto() {
|
||||
global $USER;
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create test user, add some preferences.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
set_user_preference('htmleditor', 'atto');
|
||||
|
||||
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);
|
||||
$this->assertTrue(writer::with_context(\context_system::instance())->has_any_data());
|
||||
|
||||
$prefs = writer::with_context(\context_system::instance())->get_user_preferences('core_editor');
|
||||
|
||||
@@ -63,9 +63,7 @@ class provider implements
|
||||
* @param int $userid The ID of the user whose data is to be exported.
|
||||
*/
|
||||
public static function export_user_preferences(int $userid) {
|
||||
|
||||
$preference = get_user_preferences('filemanager_recentviewmode');
|
||||
|
||||
$preference = get_user_preferences('filemanager_recentviewmode', null, $userid);
|
||||
if ($preference !== null) {
|
||||
switch ($preference) {
|
||||
case 1:
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core_form\privacy\provider;
|
||||
use core_privacy\local\request\writer;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@@ -43,7 +44,7 @@ class core_form_privacy_provider_testcase extends \core_privacy\tests\provider_t
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
\core_form\privacy\provider::export_user_preferences($USER->id);
|
||||
provider::export_user_preferences($USER->id);
|
||||
$this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
|
||||
}
|
||||
|
||||
@@ -55,13 +56,19 @@ class core_form_privacy_provider_testcase extends \core_privacy\tests\provider_t
|
||||
* @param string $desc Text describing the preference
|
||||
*/
|
||||
public function test_filemanager_recentviewmode(string $val, string $desc) {
|
||||
global $USER;
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create test user, add some preferences.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
set_user_preference('filemanager_recentviewmode', $val, $user);
|
||||
|
||||
// Switch to admin user (so we can validate preferences of the correct user are being exported).
|
||||
$this->setAdminUser();
|
||||
|
||||
set_user_preference('filemanager_recentviewmode', $val);
|
||||
|
||||
core_form\privacy\provider::export_user_preferences($USER->id);
|
||||
// Export test users preferences.
|
||||
provider::export_user_preferences($user->id);
|
||||
$this->assertTrue(writer::with_context(\context_system::instance())->has_any_data());
|
||||
|
||||
$prefs = writer::with_context(\context_system::instance())->get_user_preferences('core_form');
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user