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