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