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 request transform helper.
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\transform
;
33 * Tests for the \core_privacy API's request transform helper 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 request_transform_test
extends advanced_testcase
{
40 * Test that user translation currently does nothing.
42 * We have not determined if we will do this or not, but we provide the functionality and encourgae people to use
43 * it so that it can be retrospectively fitted if required.
45 public function test_user() {
46 // Note: This test currently sucks, but there's no point creating users just to test this.
47 for ($i = 0; $i < 10; $i++
) {
48 $this->assertEquals($i, transform
::user($i));
53 * Test that the datetime is translated into a string.
55 public function test_datetime() {
58 $datestr = transform
::datetime($time);
60 // Assert it is a string.
61 $this->assertInternalType('string', $datestr);
63 // To prevent failures on MAC where we are returned with a lower-case 'am' we want to convert this to 'AM'.
64 $datestr = str_replace('am', 'AM', $datestr);
66 // Assert the formatted date is correct.
67 $dateobj = new DateTime();
68 $dateobj->setTimestamp($time);
69 $this->assertEquals($dateobj->format('l, j F Y, g:i A'), $datestr);
73 * Test that the date is translated into a string.
75 public function test_date() {
78 $datestr = transform
::date($time);
80 // Assert it is a string.
81 $this->assertInternalType('string', $datestr);
83 // Assert the formatted date is correct.
84 $dateobj = new DateTime();
85 $dateobj->setTimestamp($time);
86 $this->assertEquals($dateobj->format('j F Y'), $datestr);
90 * Ensure that the yesno function translates correctly.
92 * @dataProvider yesno_provider
93 * @param mixed $input The input to test
94 * @param string $expected The expected value
96 public function test_yesno($input, $expected) {
97 $this->assertEquals($expected, transform
::yesno($input));
101 * Data provider for tests of the yesno transformation.
105 public function yesno_provider() {