1 |
efrain |
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/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Provides the {@see workshopallocation_manual\privacy\provider_test} class.
|
|
|
19 |
*
|
|
|
20 |
* @package workshopallocation_manual
|
|
|
21 |
* @category test
|
|
|
22 |
* @copyright 2018 David Mudrák <david@moodle.com>
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
namespace workshopallocation_manual\privacy;
|
|
|
26 |
|
|
|
27 |
use core_privacy\local\request\writer;
|
|
|
28 |
|
|
|
29 |
defined('MOODLE_INTERNAL') || die();
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Unit tests for the privacy API implementation.
|
|
|
33 |
*
|
|
|
34 |
* @copyright 2018 David Mudrák <david@moodle.com>
|
|
|
35 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
36 |
*/
|
|
|
37 |
class provider_test extends \core_privacy\tests\provider_testcase {
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* When no preference exists, there should be no export.
|
|
|
41 |
*/
|
|
|
42 |
public function test_no_preference() {
|
|
|
43 |
global $USER;
|
|
|
44 |
$this->resetAfterTest();
|
|
|
45 |
$this->setAdminUser();
|
|
|
46 |
|
|
|
47 |
\workshopallocation_manual\privacy\provider::export_user_preferences($USER->id);
|
|
|
48 |
$this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Test that the recently selected perpage is exported.
|
|
|
53 |
*/
|
|
|
54 |
public function test_export_preferences() {
|
|
|
55 |
global $USER;
|
|
|
56 |
$this->resetAfterTest();
|
|
|
57 |
$this->setAdminUser();
|
|
|
58 |
|
|
|
59 |
set_user_preference('workshopallocation_manual_perpage', 81);
|
|
|
60 |
|
|
|
61 |
\workshopallocation_manual\privacy\provider::export_user_preferences($USER->id);
|
|
|
62 |
$this->assertTrue(writer::with_context(\context_system::instance())->has_any_data());
|
|
|
63 |
|
|
|
64 |
$prefs = writer::with_context(\context_system::instance())->get_user_preferences('workshopallocation_manual');
|
|
|
65 |
$this->assertNotEmpty($prefs->workshopallocation_manual_perpage);
|
|
|
66 |
$this->assertEquals(81, $prefs->workshopallocation_manual_perpage->value);
|
|
|
67 |
$this->assertStringContainsString(get_string('privacy:metadata:preference:perpage', 'workshopallocation_manual'),
|
|
|
68 |
$prefs->workshopallocation_manual_perpage->description);
|
|
|
69 |
}
|
|
|
70 |
}
|