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/>.
17 namespace core_privacy
;
19 use core_privacy\local\metadata\types\user_preference
;
22 * Tests for the \core_privacy API's types\user_preference functionality.
24 * @package core_privacy
26 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * @coversDefaultClass \core_privacy\local\metadata\types\user_preference
30 class types_user_preference_test
extends \advanced_testcase
{
33 * Ensure that warnings are thrown if string identifiers contain invalid characters.
35 * @dataProvider invalid_string_provider
36 * @param string $name Name
37 * @param string $summary Summary
38 * @covers ::__construct
40 public function test_invalid_configs($name, $summary) {
41 $record = new user_preference($name, $summary);
42 $this->assertDebuggingCalled();
46 * Ensure that warnings are not thrown if debugging is not enabled, even if string identifiers contain invalid characters.
48 * @dataProvider invalid_string_provider
49 * @param string $name Name
50 * @param string $summary Summary
51 * @covers ::__construct
53 public function test_invalid_configs_debug_normal($name, $summary) {
55 $this->resetAfterTest();
57 $CFG->debug
= DEBUG_NORMAL
;
58 $record = new user_preference($name, $summary);
59 $this->assertDebuggingNotCalled();
63 * Ensure that no warnings are shown for valid combinations.
65 * @dataProvider valid_string_provider
66 * @param string $name Name
67 * @param string $summary Summary
68 * @covers ::__construct
70 public function test_valid_configs($name, $summary) {
71 $record = new user_preference($name, $summary);
72 $this->assertDebuggingNotCalled();
76 * Data provider with a list of invalid string identifiers.
80 public function invalid_string_provider() {
82 'Space in summary' => [
84 'This table is used for purposes.',
86 'Comma in summary' => [
94 * Data provider with a list of valid string identifiers.
98 public function valid_string_provider() {
100 'Valid combination' => [
102 'privacy:example:valid',