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 * Unit Tests for the approved contextlist Class
20 * @package core_privacy
22 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die();
30 use \core_privacy\local\request\approved_contextlist
;
33 * Tests for the \core_privacy API's approved contextlist functionality.
35 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class approved_contextlist_test
extends advanced_testcase
{
40 * The approved contextlist should not be modifiable once set.
42 public function test_default_values_set() {
43 $testuser = \core_user
::get_user_by_username('admin');
44 $contextids = [3, 2, 1];
45 $component = 'core_privacy';
47 $uit = new approved_contextlist($testuser, $component, $contextids);
49 $this->assertEquals($testuser, $uit->get_user());
50 $this->assertEquals($component, $uit->get_component());
51 $result = $uit->get_contextids();
53 // Note: Array order is not guaranteed and should not matter.
54 foreach ($contextids as $contextid) {
55 $this->assertNotFalse(array_search($contextid, $result));