See Release Notes
Long Term Support Release
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 namespace core_courseformat\privacy; 18 19 use context_course; 20 use core_privacy\local\request\writer; 21 22 /** 23 * Privacy tests for core_courseformat. 24 * 25 * @package core_courseformat 26 * @category test 27 * @copyright 2021 Ferran Recio <ferran@moodle.com> 28 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 29 */ 30 class provider_test extends \core_privacy\tests\provider_testcase { 31 32 /** 33 * Test for provider::test_export_user_preferences(). 34 */ 35 public function test_export_user_preferences() { 36 $this->resetAfterTest(); 37 38 // Test setup. 39 $generator = $this->getDataGenerator(); 40 $course = $generator->create_course(); 41 course_create_sections_if_missing($course, [0, 1, 2]); 42 $user = $generator->create_and_enrol($course, 'student'); 43 44 $prefix = provider::SECTION_PREFERENCES_PREFIX; 45 $preference = "{$prefix}_{$course->id}"; 46 $value = "Something"; 47 $preferencestring = get_string("preference:$prefix", 'courseformat', $course->fullname); 48 49 // Add a user home page preference for the User. 50 set_user_preference($preference , $value, $user); 51 52 // Test the user preferences export contains 1 user preference record for the User. 53 provider::export_user_preferences($user->id); 54 $coursecontext = context_course::instance($course->id); 55 $writer = writer::with_context($coursecontext); 56 $this->assertTrue($writer->has_any_data()); 57 58 $exportedpreferences = $writer->get_user_preferences('core_courseformat'); 59 $this->assertCount(1, (array) $exportedpreferences); 60 $this->assertEquals( 61 $value, 62 $exportedpreferences->$preference->value 63 ); 64 $this->assertEquals( 65 $preferencestring, 66 $exportedpreferences->{$preference}->description 67 ); 68 } 69 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body