See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]
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 * Unit tests for the privacy legacy polyfill for quiz access rules. 19 * 20 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 namespace mod_quiz; 25 26 use quiz; 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 global $CFG; 31 require_once($CFG->dirroot . '/mod/quiz/attemptlib.php'); 32 33 /** 34 * Unit tests for the privacy legacy polyfill for quiz access rules. 35 * 36 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class privacy_legacy_quizaccess_polyfill_test extends \advanced_testcase { 40 /** 41 * Test that the core_quizaccess\privacy\legacy_polyfill works and that the static _export_quizaccess_user_data can 42 * be called. 43 */ 44 public function test_export_quizaccess_user_data() { 45 $quiz = $this->createMock(quiz::class); 46 $user = (object) []; 47 $returnvalue = (object) []; 48 49 $mock = $this->createMock(test_privacy_legacy_quizaccess_polyfill_mock_wrapper::class); 50 $mock->expects($this->once()) 51 ->method('get_return_value') 52 ->with('_export_quizaccess_user_data', [$quiz, $user]) 53 ->willReturn($returnvalue); 54 55 test_privacy_legacy_quizaccess_polyfill_provider::$mock = $mock; 56 $result = test_privacy_legacy_quizaccess_polyfill_provider::export_quizaccess_user_data($quiz, $user); 57 $this->assertSame($returnvalue, $result); 58 } 59 60 /** 61 * Test the _delete_quizaccess_for_context shim. 62 */ 63 public function test_delete_quizaccess_for_context() { 64 $context = \context_system::instance(); 65 66 $quiz = $this->createMock(quiz::class); 67 68 $mock = $this->createMock(test_privacy_legacy_quizaccess_polyfill_mock_wrapper::class); 69 $mock->expects($this->once()) 70 ->method('get_return_value') 71 ->with('_delete_quizaccess_data_for_all_users_in_context', [$quiz]); 72 73 test_privacy_legacy_quizaccess_polyfill_provider::$mock = $mock; 74 test_privacy_legacy_quizaccess_polyfill_provider::delete_quizaccess_data_for_all_users_in_context($quiz); 75 } 76 77 /** 78 * Test the _delete_quizaccess_for_user shim. 79 */ 80 public function test_delete_quizaccess_for_user() { 81 $context = \context_system::instance(); 82 83 $quiz = $this->createMock(quiz::class); 84 $user = (object) []; 85 86 $mock = $this->createMock(test_privacy_legacy_quizaccess_polyfill_mock_wrapper::class); 87 $mock->expects($this->once()) 88 ->method('get_return_value') 89 ->with('_delete_quizaccess_data_for_user', [$quiz, $user]); 90 91 test_privacy_legacy_quizaccess_polyfill_provider::$mock = $mock; 92 test_privacy_legacy_quizaccess_polyfill_provider::delete_quizaccess_data_for_user($quiz, $user); 93 } 94 95 /** 96 * Test the _delete_quizaccess_for_users shim. 97 */ 98 public function test_delete_quizaccess_for_users() { 99 $context = $this->createMock(\context_module::class); 100 $user = (object) []; 101 $approveduserlist = new \core_privacy\local\request\approved_userlist($context, 'mod_quiz', [$user]); 102 103 $mock = $this->createMock(test_privacy_legacy_quizaccess_polyfill_mock_wrapper::class); 104 $mock->expects($this->once()) 105 ->method('get_return_value') 106 ->with('_delete_quizaccess_data_for_users', [$approveduserlist]); 107 108 test_privacy_legacy_quizaccess_polyfill_provider::$mock = $mock; 109 test_privacy_legacy_quizaccess_polyfill_provider::delete_quizaccess_data_for_users($approveduserlist); 110 } 111 } 112 113 /** 114 * Legacy polyfill test class for the quizaccess_provider. 115 * 116 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 117 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 118 */ 119 class test_privacy_legacy_quizaccess_polyfill_provider implements 120 \core_privacy\local\metadata\provider, 121 \mod_quiz\privacy\quizaccess_provider, 122 \mod_quiz\privacy\quizaccess_user_provider { 123 124 use \mod_quiz\privacy\legacy_quizaccess_polyfill; 125 use \core_privacy\local\legacy_polyfill; 126 127 /** 128 * @var test_privacy_legacy_quizaccess_polyfill_provider $mock. 129 */ 130 public static $mock = null; 131 132 /** 133 * Export all user data for the quizaccess plugin. 134 * 135 * @param \quiz $quiz 136 * @param \stdClass $user 137 */ 138 protected static function _export_quizaccess_user_data($quiz, $user) { 139 return static::$mock->get_return_value(__FUNCTION__, func_get_args()); 140 } 141 142 /** 143 * Deletes all user data for the given context. 144 * 145 * @param \quiz $quiz 146 */ 147 protected static function _delete_quizaccess_data_for_all_users_in_context($quiz) { 148 static::$mock->get_return_value(__FUNCTION__, func_get_args()); 149 } 150 151 /** 152 * Delete personal data for the given user and context. 153 * 154 * @param \quiz $quiz The quiz being deleted 155 * @param \stdClass $user The user to export data for 156 */ 157 protected static function _delete_quizaccess_data_for_user($quiz, $user) { 158 static::$mock->get_return_value(__FUNCTION__, func_get_args()); 159 } 160 161 /** 162 * Delete all user data for the specified users, in the specified context. 163 * 164 * @param \core_privacy\local\request\approved_userlist $userlist 165 */ 166 protected static function _delete_quizaccess_data_for_users($userlist) { 167 static::$mock->get_return_value(__FUNCTION__, func_get_args()); 168 } 169 170 /** 171 * Returns metadata about this plugin. 172 * 173 * @param \core_privacy\local\metadata\collection $collection The initialised collection to add items to. 174 * @return \core_privacy\local\metadata\collection A listing of user data stored through this system. 175 */ 176 protected static function _get_metadata(\core_privacy\local\metadata\collection $collection) { 177 return $collection; 178 } 179 } 180 181 /** 182 * Called inside the polyfill methods in the test polyfill provider, allowing us to ensure these are called with correct params. 183 * 184 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 185 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 186 */ 187 class test_privacy_legacy_quizaccess_polyfill_mock_wrapper { 188 /** 189 * Get the return value for the specified item. 190 */ 191 public function get_return_value() { 192 } 193 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body