From 279c5eaf38800a5ededd549056cf239845185caf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Mudr=C3=A1k?= <david@moodle.com>
Date: Tue, 8 May 2018 10:52:58 +0200
Subject: [PATCH 2/2] alloc

---
 .../allocation/manual/classes/privacy/provider.php |  1 +
 .../manual/tests/privacy_provider_test.php         | 69 ++++++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100644 mod/workshop/allocation/manual/tests/privacy_provider_test.php

diff --git a/mod/workshop/allocation/manual/classes/privacy/provider.php b/mod/workshop/allocation/manual/classes/privacy/provider.php
index 781f93a139..d732ba5b7a 100644
--- a/mod/workshop/allocation/manual/classes/privacy/provider.php
+++ b/mod/workshop/allocation/manual/classes/privacy/provider.php
@@ -26,6 +26,7 @@
 namespace workshopallocation_manual\privacy;
 
 use core_privacy\local\metadata\collection;
+use core_privacy\local\request\writer;
 
 defined('MOODLE_INTERNAL') || die();
 
diff --git a/mod/workshop/allocation/manual/tests/privacy_provider_test.php b/mod/workshop/allocation/manual/tests/privacy_provider_test.php
new file mode 100644
index 0000000000..39faa4c970
--- /dev/null
+++ b/mod/workshop/allocation/manual/tests/privacy_provider_test.php
@@ -0,0 +1,69 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Provides the {@link workshopallocation_manual_privacy_provider_testcase} class.
+ *
+ * @package     workshopallocation_manual
+ * @category    test
+ * @copyright   2018 David Mudrák <david@moodle.com>
+ * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+use core_privacy\local\request\writer;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Unit tests for the privacy API implementation.
+ *
+ * @copyright 2018 David Mudrák <david@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class workshopallocation_manual_privacy_provider_testcase extends \core_privacy\tests\provider_testcase {
+
+    /**
+     * When no preference exists, there should be no export.
+     */
+    public function test_no_preference() {
+        global $USER;
+        $this->resetAfterTest();
+        $this->setAdminUser();
+
+        \workshopallocation_manual\privacy\provider::export_user_preferences($USER->id);
+        $this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
+    }
+
+    /**
+     * Test that the recently selected perpage is exported.
+     */
+    public function test_export_preferences() {
+        global $USER;
+        $this->resetAfterTest();
+        $this->setAdminUser();
+
+        set_user_preference('workshopallocation_manual_perpage', 81);
+
+        \workshopallocation_manual\privacy\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('workshopallocation_manual');
+        $this->assertNotEmpty($prefs->workshopallocation_manual_perpage);
+        $this->assertEquals(81, $prefs->workshopallocation_manual_perpage->value);
+        $this->assertContains(get_string('privacy:metadata:preference:perpage', 'workshopallocation_manual'),
+            $prefs->workshopallocation_manual_perpage->description);
+    }
+}
-- 
2.16.1

