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. 13 // 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/>. 16 17 /** 18 * Provides the {@see \core_form\privacy\provider_test} class. 19 * 20 * @package core_form 21 * @category test 22 * @copyright 2018 David Mudrák <david@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 namespace core_form\privacy; 26 27 use core_form\privacy\provider; 28 use core_privacy\local\request\writer; 29 30 defined('MOODLE_INTERNAL') || die(); 31 32 /** 33 * Unit tests for the privacy API implementation. 34 * 35 * @copyright 2018 David Mudrák <david@moodle.com> 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class provider_test extends \core_privacy\tests\provider_testcase { 39 40 /** 41 * When no preference exists, there should be no export. 42 */ 43 public function test_no_preference() { 44 global $USER; 45 $this->resetAfterTest(); 46 $this->setAdminUser(); 47 48 provider::export_user_preferences($USER->id); 49 $this->assertFalse(writer::with_context(\context_system::instance())->has_any_data()); 50 } 51 52 /** 53 * Test that the recently selected filepicker view mode is exported. 54 * 55 * @dataProvider data_filemanager_recentviewmode 56 * @param string $val Value of the preference filemanager_recentviewmode 57 * @param string $desc Text describing the preference 58 */ 59 public function test_filemanager_recentviewmode(string $val, string $desc) { 60 $this->resetAfterTest(); 61 62 // Create test user, add some preferences. 63 $user = $this->getDataGenerator()->create_user(); 64 $this->setUser($user); 65 66 set_user_preference('filemanager_recentviewmode', $val, $user); 67 68 // Switch to admin user (so we can validate preferences of the correct user are being exported). 69 $this->setAdminUser(); 70 71 // Export test users preferences. 72 provider::export_user_preferences($user->id); 73 $this->assertTrue(writer::with_context(\context_system::instance())->has_any_data()); 74 75 $prefs = writer::with_context(\context_system::instance())->get_user_preferences('core_form'); 76 $this->assertNotEmpty($prefs->filemanager_recentviewmode); 77 $this->assertNotEmpty($prefs->filemanager_recentviewmode->value); 78 $this->assertNotEmpty($prefs->filemanager_recentviewmode->description); 79 $this->assertEquals($val, $prefs->filemanager_recentviewmode->value); 80 $this->assertStringContainsString($desc, $prefs->filemanager_recentviewmode->description); 81 } 82 83 /** 84 * Provides data for the {@link self::test_filemanager_recentviewmode()} method. 85 * 86 * @return array 87 */ 88 public function data_filemanager_recentviewmode() { 89 return [ 90 'icons' => [ 91 'val' => '1', 92 'desc' => get_string('displayasicons', 'core_repository'), 93 ], 94 'tree' => [ 95 'val' => '2', 96 'desc' => get_string('displayastree', 'core_repository'), 97 ], 98 'details' => [ 99 'val' => '3', 100 'desc' => get_string('displaydetails', 'core_repository'), 101 ], 102 'unknown' => [ 103 'val' => 'unexpectedvalue_foo_bar', 104 'desc' => 'unexpectedvalue_foo_bar', 105 ], 106 ]; 107 } 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body