From 38cb434ba65b52ac0c6c955d4d73e0d0dd413a44 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 27 Mar 2019 12:01:42 +0000 Subject: [PATCH] MDL-65197 editor: handle empty user preference in privacy export. --- lib/editor/classes/privacy/provider.php | 2 +- lib/editor/tests/privacy_provider_test.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/editor/classes/privacy/provider.php b/lib/editor/classes/privacy/provider.php index 40c0786bfe1..9d807a6dbcc 100644 --- a/lib/editor/classes/privacy/provider.php +++ b/lib/editor/classes/privacy/provider.php @@ -62,7 +62,7 @@ class provider implements */ public static function export_user_preferences(int $userid) { $preference = get_user_preferences('htmleditor'); - if (null !== $preference) { + if (!empty($preference)) { $desc = get_string('privacy:preference:htmleditor', 'core_editor', get_string('pluginname', "editor_{$preference}")); writer::export_user_preference('core_editor', 'htmleditor', $preference, $desc); diff --git a/lib/editor/tests/privacy_provider_test.php b/lib/editor/tests/privacy_provider_test.php index d33e0071d17..6d1dcf912c8 100644 --- a/lib/editor/tests/privacy_provider_test.php +++ b/lib/editor/tests/privacy_provider_test.php @@ -36,6 +36,7 @@ defined('MOODLE_INTERNAL') || die(); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class core_editor_privacy_provider_testcase extends \core_privacy\tests\provider_testcase { + /** * When no preference exists, there should be no export. */ @@ -48,6 +49,21 @@ class core_editor_privacy_provider_testcase extends \core_privacy\tests\provider $this->assertFalse(writer::with_context(\context_system::instance())->has_any_data()); } + /** + * When preference exists but is empty, there should be no export. + */ + public function test_empty_preference() { + global $USER; + + $this->resetAfterTest(); + $this->setAdminUser(); + + set_user_preference('htmleditor', ''); + + provider::export_user_preferences($USER->id); + $this->assertFalse(writer::with_context(\context_system::instance())->has_any_data()); + } + /** * When an editor is set, the name of that editor will be reported. */