MDL-61995 tool_assignmentupgrade: Implemented privacy providers
[moodle.git] / admin / tool / assignmentupgrade / tests / privacy_test.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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.
13 //
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/>.
17 /**
18  * Privacy tests for tool_assignmentupgrade.
19  *
20  * @package    tool_assignmentupgrade
21  * @category   test
22  * @copyright  2018 Zig Tan <zig@moodle.com>
23  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24  */
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;
32 /**
33  * Unit tests for tool_assignmentupgrade/classes/privacy/policy
34  *
35  * @copyright  2018 Zig Tan <zig@moodle.com>
36  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37  */
38 class tool_assignmentupgrade_privacy_testcase extends provider_testcase {
40     /**
41      * Overriding setUp() function to always reset after tests.
42      */
43     public function setUp() {
44         $this->resetAfterTest(true);
45     }
47     /**
48      * Test for provider::test_export_user_preferences().
49      */
50     public function test_export_user_preferences() {
51         // Test setup.
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.
59         $params = [
60             'userid' => $user->id,
61             'name' => 'tool_assignmentupgrade_perpage'
62         ];
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);
73     }
75 }