on-demand release 4.2dev+
[moodle.git] / privacy / tests / types_user_preference_test.php
blob3e2dd30e45248481984f483eb49e7ec9674052f7
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.
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;
21 /**
22 * Tests for the \core_privacy API's types\user_preference functionality.
24 * @package core_privacy
25 * @category test
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 {
32 /**
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();
45 /**
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) {
54 global $CFG;
55 $this->resetAfterTest();
57 $CFG->debug = DEBUG_NORMAL;
58 $record = new user_preference($name, $summary);
59 $this->assertDebuggingNotCalled();
62 /**
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();
75 /**
76 * Data provider with a list of invalid string identifiers.
78 * @return array
80 public function invalid_string_provider() {
81 return [
82 'Space in summary' => [
83 'example',
84 'This table is used for purposes.',
86 'Comma in summary' => [
87 'example',
88 'privacy,foo',
93 /**
94 * Data provider with a list of valid string identifiers.
96 * @return array
98 public function valid_string_provider() {
99 return [
100 'Valid combination' => [
101 'example',
102 'privacy:example:valid',