2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Privacy tests for tool_assignmentupgrade.
20 * @package tool_assignmentupgrade
22 * @copyright 2018 Zig Tan <zig@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 use \core_privacy\tests\provider_testcase;
29 use \core_privacy\local\request\writer;
30 use \tool_assignmentupgrade\privacy\provider;
33 * Unit tests for tool_assignmentupgrade/classes/privacy/policy
35 * @copyright 2018 Zig Tan <zig@moodle.com>
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class tool_assignmentupgrade_privacy_testcase extends provider_testcase {
41 * Overriding setUp() function to always reset after tests.
43 public function setUp() {
44 $this->resetAfterTest(true);
48 * Test for provider::test_export_user_preferences().
50 public function test_export_user_preferences() {
52 $user = $this->getDataGenerator()->create_user();
53 $this->setUser($user);
55 // Add a user home page preference for the User.
56 set_user_preference('tool_assignmentupgrade_perpage', '100', $user);
58 // Test the user preference exists.
60 'userid' => $user->id,
61 'name' => 'tool_assignmentupgrade_perpage'
64 // Test the user preferences export contains 1 user preference record for the User.
65 provider::export_user_preferences($user->id);
66 $contextuser = context_user::instance($user->id);
67 $writer = writer::with_context($contextuser);
68 $this->assertTrue($writer->has_any_data());
70 $exportedpreferences = $writer->get_user_preferences('tool_assignmentupgrade');
71 $this->assertCount(1, (array) $exportedpreferences);
72 $this->assertEquals('100', $exportedpreferences->perpage->value);