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 userlist 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_userlist
;
31 use \core_privacy\local\request\userlist
;
34 * Tests for the \core_privacy API's approved userlist functionality.
36 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class approved_userlist_test
extends advanced_testcase
{
41 * The approved userlist should not be modifiable once set.
43 public function test_default_values_set() {
44 $this->resetAfterTest();
46 $u1 = $this->getDataGenerator()->create_user();
47 $u2 = $this->getDataGenerator()->create_user();
48 $u3 = $this->getDataGenerator()->create_user();
49 $u4 = $this->getDataGenerator()->create_user();
51 $context = \context_system
::instance();
52 $component = 'core_privacy';
54 $uut = new approved_userlist($context, $component, [$u1->id
, $u2->id
]);
56 $this->assertEquals($context, $uut->get_context());
57 $this->assertEquals($component, $uut->get_component());
65 $result = $uut->get_userids();
68 $this->assertEquals($expected, $result);
71 public function test_create_from_userlist() {
72 $this->resetAfterTest();
74 $u1 = $this->getDataGenerator()->create_user();
75 $u2 = $this->getDataGenerator()->create_user();
76 $u3 = $this->getDataGenerator()->create_user();
77 $u4 = $this->getDataGenerator()->create_user();
79 $context = \context_system
::instance();
80 $component = 'core_privacy';
82 $sourcelist = new userlist($context, $component);
83 $sourcelist->add_users([$u1->id
, $u3->id
]);
91 $approvedlist = approved_userlist
::create_from_userlist($sourcelist);
93 $this->assertEquals($component, $approvedlist->get_component());
94 $this->assertEquals($context, $approvedlist->get_context());
96 $result = $approvedlist->get_userids();
98 $this->assertEquals($expected, $result);