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 |
* Data provider tests.
|
|
|
19 |
*
|
|
|
20 |
* @package core_competency
|
|
|
21 |
* @category test
|
|
|
22 |
* @copyright 2018 Frédéric Massart
|
|
|
23 |
* @author Frédéric Massart <fred@branchup.tech>
|
|
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
25 |
*/
|
|
|
26 |
namespace core_competency\privacy;
|
|
|
27 |
|
|
|
28 |
defined('MOODLE_INTERNAL') || die();
|
|
|
29 |
global $CFG, $DB;
|
|
|
30 |
|
|
|
31 |
use core_privacy\tests\provider_testcase;
|
|
|
32 |
use core_privacy\local\request\contextlist;
|
|
|
33 |
use core_privacy\local\request\approved_contextlist;
|
|
|
34 |
use core_privacy\local\request\approved_userlist;
|
|
|
35 |
use core_privacy\local\request\transform;
|
|
|
36 |
use core_privacy\local\request\userlist;
|
|
|
37 |
use core_privacy\local\request\writer;
|
|
|
38 |
use core_competency\api;
|
|
|
39 |
use core_competency\privacy\provider;
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Data provider testcase class.
|
|
|
43 |
*
|
|
|
44 |
* @package core_competency
|
|
|
45 |
* @category test
|
|
|
46 |
* @copyright 2018 Frédéric Massart
|
|
|
47 |
* @author Frédéric Massart <fred@branchup.tech>
|
|
|
48 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
49 |
* @covers \core_competency\privacy\provider
|
|
|
50 |
*/
|
|
|
51 |
class provider_test extends provider_testcase {
|
|
|
52 |
|
|
|
53 |
public function setUp(): void {
|
|
|
54 |
global $PAGE;
|
|
|
55 |
$this->resetAfterTest();
|
|
|
56 |
|
|
|
57 |
// We need this or exporters (core\external\exporter) do not receive the right renderer.
|
|
|
58 |
$PAGE->get_renderer('core');
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public function test_get_contexts_for_userid_with_usermodified_for_framework() {
|
|
|
62 |
$dg = $this->getDataGenerator();
|
|
|
63 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
64 |
|
|
|
65 |
$cat1 = $dg->create_category();
|
|
|
66 |
$cat2 = $dg->create_category();
|
|
|
67 |
$u1 = $dg->create_user();
|
|
|
68 |
$u2 = $dg->create_user();
|
|
|
69 |
$u3 = $dg->create_user();
|
|
|
70 |
$u4 = $dg->create_user();
|
|
|
71 |
|
|
|
72 |
$sysctx = \context_system::instance();
|
|
|
73 |
$cat1ctx = \context_coursecat::instance($cat1->id);
|
|
|
74 |
$cat2ctx = \context_coursecat::instance($cat2->id);
|
|
|
75 |
|
|
|
76 |
// Test recovery through framework context.
|
|
|
77 |
$this->setUser($u1);
|
|
|
78 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), []);
|
|
|
79 |
$f1 = $ccg->create_framework();
|
|
|
80 |
$contextlist = provider::get_contexts_for_userid($u1->id);
|
|
|
81 |
$this->assert_contextlist($contextlist, [$sysctx]);
|
|
|
82 |
$f2 = $ccg->create_framework(['contextid' => $cat1ctx->id]);
|
|
|
83 |
$contextlist = provider::get_contexts_for_userid($u1->id);
|
|
|
84 |
$this->assert_contextlist($contextlist, [$sysctx, $cat1ctx]);
|
|
|
85 |
|
|
|
86 |
// Test recovery of category context alone.
|
|
|
87 |
$this->setUser($u2);
|
|
|
88 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
89 |
$ccg->create_framework(['contextid' => $cat2ctx->id]);
|
|
|
90 |
$contextlist = provider::get_contexts_for_userid($u2->id);
|
|
|
91 |
$this->assert_contextlist($contextlist, [$cat2ctx]);
|
|
|
92 |
|
|
|
93 |
// Test recovery through competency.
|
|
|
94 |
$this->setUser($u3);
|
|
|
95 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
96 |
$c1 = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
|
|
|
97 |
$c2 = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
|
|
|
98 |
$c3 = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
|
|
|
99 |
$contextlist = provider::get_contexts_for_userid($u3->id);
|
|
|
100 |
$this->assert_contextlist($contextlist, [$sysctx]);
|
|
|
101 |
$c4 = $ccg->create_competency(['competencyframeworkid' => $f2->get('id')]);
|
|
|
102 |
$c5 = $ccg->create_competency(['competencyframeworkid' => $f2->get('id')]);
|
|
|
103 |
$c6 = $ccg->create_competency(['competencyframeworkid' => $f2->get('id')]);
|
|
|
104 |
$contextlist = provider::get_contexts_for_userid($u3->id);
|
|
|
105 |
$this->assert_contextlist($contextlist, [$sysctx, $cat1ctx]);
|
|
|
106 |
|
|
|
107 |
// Test recovery through related competency.
|
|
|
108 |
$this->setUser($u4);
|
|
|
109 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
110 |
$cr = $ccg->create_related_competency(['competencyid' => $c1->get('id'), 'relatedcompetencyid' => $c2->get('id')]);
|
|
|
111 |
$contextlist = provider::get_contexts_for_userid($u4->id);
|
|
|
112 |
$this->assert_contextlist($contextlist, [$sysctx]);
|
|
|
113 |
$cr = $ccg->create_related_competency(['competencyid' => $c4->get('id'), 'relatedcompetencyid' => $c5->get('id')]);
|
|
|
114 |
$contextlist = provider::get_contexts_for_userid($u4->id);
|
|
|
115 |
$this->assert_contextlist($contextlist, [$sysctx, $cat1ctx]);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
public function test_get_users_in_context_with_usermodified_for_framework() {
|
|
|
119 |
$dg = $this->getDataGenerator();
|
|
|
120 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
121 |
|
|
|
122 |
$cat1 = $dg->create_category();
|
|
|
123 |
$cat2 = $dg->create_category();
|
|
|
124 |
$u1 = $dg->create_user();
|
|
|
125 |
$u2 = $dg->create_user();
|
|
|
126 |
$u3 = $dg->create_user();
|
|
|
127 |
$u4 = $dg->create_user();
|
|
|
128 |
|
|
|
129 |
$sysctx = \context_system::instance();
|
|
|
130 |
$cat1ctx = \context_coursecat::instance($cat1->id);
|
|
|
131 |
$cat2ctx = \context_coursecat::instance($cat2->id);
|
|
|
132 |
|
|
|
133 |
// Add frameworks.
|
|
|
134 |
$this->setUser($u1);
|
|
|
135 |
$f1 = $ccg->create_framework();
|
|
|
136 |
$f2 = $ccg->create_framework(['contextid' => $cat1ctx->id]);
|
|
|
137 |
|
|
|
138 |
$this->setUser($u2);
|
|
|
139 |
$ccg->create_framework(['contextid' => $cat2ctx->id]);
|
|
|
140 |
|
|
|
141 |
// Add competencies.
|
|
|
142 |
$this->setUser($u3);
|
|
|
143 |
$c1 = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
|
|
|
144 |
$c2 = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
|
|
|
145 |
$c3 = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
|
|
|
146 |
$c4 = $ccg->create_competency(['competencyframeworkid' => $f2->get('id')]);
|
|
|
147 |
$c5 = $ccg->create_competency(['competencyframeworkid' => $f2->get('id')]);
|
|
|
148 |
$c6 = $ccg->create_competency(['competencyframeworkid' => $f2->get('id')]);
|
|
|
149 |
|
|
|
150 |
// Add related competencies.
|
|
|
151 |
$this->setUser($u4);
|
|
|
152 |
$cr = $ccg->create_related_competency(['competencyid' => $c1->get('id'), 'relatedcompetencyid' => $c2->get('id')]);
|
|
|
153 |
$cr = $ccg->create_related_competency(['competencyid' => $c4->get('id'), 'relatedcompetencyid' => $c5->get('id')]);
|
|
|
154 |
|
|
|
155 |
// Test correct users appear in each context.
|
|
|
156 |
$component = 'core_competency';
|
|
|
157 |
|
|
|
158 |
$userlist = new userlist($sysctx, $component);
|
|
|
159 |
provider::get_users_in_context($userlist);
|
|
|
160 |
$expected = [$u1->id, $u3->id, $u4->id];
|
|
|
161 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
162 |
|
|
|
163 |
$userlist = new userlist($cat1ctx, $component);
|
|
|
164 |
provider::get_users_in_context($userlist);
|
|
|
165 |
$expected = [$u1->id, $u3->id, $u4->id];
|
|
|
166 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
167 |
|
|
|
168 |
$userlist = new userlist($cat2ctx, $component);
|
|
|
169 |
provider::get_users_in_context($userlist);
|
|
|
170 |
$expected = [$u2->id];
|
|
|
171 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
public function test_get_contexts_for_userid_with_usermodified_for_template() {
|
|
|
175 |
$dg = $this->getDataGenerator();
|
|
|
176 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
177 |
|
|
|
178 |
$cat1 = $dg->create_category();
|
|
|
179 |
$cat2 = $dg->create_category();
|
|
|
180 |
$u1 = $dg->create_user();
|
|
|
181 |
$u2 = $dg->create_user();
|
|
|
182 |
$u3 = $dg->create_user();
|
|
|
183 |
$u4 = $dg->create_user();
|
|
|
184 |
$cohort = $dg->create_cohort();
|
|
|
185 |
|
|
|
186 |
$sysctx = \context_system::instance();
|
|
|
187 |
$cat1ctx = \context_coursecat::instance($cat1->id);
|
|
|
188 |
$cat2ctx = \context_coursecat::instance($cat2->id);
|
|
|
189 |
|
|
|
190 |
$f1 = $ccg->create_framework();
|
|
|
191 |
$f2 = $ccg->create_framework(['contextid' => $cat1ctx->id]);
|
|
|
192 |
$f3 = $ccg->create_framework(['contextid' => $cat2ctx->id]);
|
|
|
193 |
$cs = [];
|
|
|
194 |
|
|
|
195 |
foreach ([$f1, $f2, $f3] as $f) {
|
|
|
196 |
$cs[$f->get('id')] = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
// Test recovery through template context.
|
|
|
200 |
$this->setUser($u1);
|
|
|
201 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), []);
|
|
|
202 |
$t1 = $ccg->create_template();
|
|
|
203 |
$contextlist = provider::get_contexts_for_userid($u1->id);
|
|
|
204 |
$this->assert_contextlist($contextlist, [$sysctx]);
|
|
|
205 |
$t2 = $ccg->create_template(['contextid' => $cat1ctx->id]);
|
|
|
206 |
$contextlist = provider::get_contexts_for_userid($u1->id);
|
|
|
207 |
$this->assert_contextlist($contextlist, [$sysctx, $cat1ctx]);
|
|
|
208 |
|
|
|
209 |
// Test recovery of category context alone.
|
|
|
210 |
$this->setUser($u2);
|
|
|
211 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
212 |
$ccg->create_template(['contextid' => $cat2ctx->id]);
|
|
|
213 |
$contextlist = provider::get_contexts_for_userid($u2->id);
|
|
|
214 |
$this->assert_contextlist($contextlist, [$cat2ctx]);
|
|
|
215 |
|
|
|
216 |
// Test recovery through template competency.
|
|
|
217 |
$this->setUser($u3);
|
|
|
218 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
219 |
$c1 = $ccg->create_template_competency(['competencyid' => $cs[$f1->get('id')]->get('id'), 'templateid' => $t1->get('id')]);
|
|
|
220 |
$contextlist = provider::get_contexts_for_userid($u3->id);
|
|
|
221 |
$this->assert_contextlist($contextlist, [$sysctx]);
|
|
|
222 |
$c4 = $ccg->create_template_competency(['competencyid' => $cs[$f2->get('id')]->get('id'), 'templateid' => $t2->get('id')]);
|
|
|
223 |
$contextlist = provider::get_contexts_for_userid($u3->id);
|
|
|
224 |
$this->assert_contextlist($contextlist, [$sysctx, $cat1ctx]);
|
|
|
225 |
|
|
|
226 |
// Test recovery through template cohort.
|
|
|
227 |
$this->setUser($u4);
|
|
|
228 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
229 |
$c1 = $ccg->create_template_cohort(['cohortid' => $cohort->id, 'templateid' => $t1->get('id')]);
|
|
|
230 |
$contextlist = provider::get_contexts_for_userid($u4->id);
|
|
|
231 |
$this->assert_contextlist($contextlist, [$sysctx]);
|
|
|
232 |
$c4 = $ccg->create_template_cohort(['cohortid' => $cohort->id, 'templateid' => $t2->get('id')]);
|
|
|
233 |
$contextlist = provider::get_contexts_for_userid($u4->id);
|
|
|
234 |
$this->assert_contextlist($contextlist, [$sysctx, $cat1ctx]);
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
public function test_get_users_in_context_with_usermodified_for_template() {
|
|
|
238 |
$dg = $this->getDataGenerator();
|
|
|
239 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
240 |
|
|
|
241 |
$cat1 = $dg->create_category();
|
|
|
242 |
$cat2 = $dg->create_category();
|
|
|
243 |
$u1 = $dg->create_user();
|
|
|
244 |
$u2 = $dg->create_user();
|
|
|
245 |
$u3 = $dg->create_user();
|
|
|
246 |
$u4 = $dg->create_user();
|
|
|
247 |
$cohort = $dg->create_cohort();
|
|
|
248 |
|
|
|
249 |
$sysctx = \context_system::instance();
|
|
|
250 |
$cat1ctx = \context_coursecat::instance($cat1->id);
|
|
|
251 |
$cat2ctx = \context_coursecat::instance($cat2->id);
|
|
|
252 |
|
|
|
253 |
$f1 = $ccg->create_framework();
|
|
|
254 |
$f2 = $ccg->create_framework(['contextid' => $cat1ctx->id]);
|
|
|
255 |
$f3 = $ccg->create_framework(['contextid' => $cat2ctx->id]);
|
|
|
256 |
$cs = [];
|
|
|
257 |
|
|
|
258 |
foreach ([$f1, $f2, $f3] as $f) {
|
|
|
259 |
$cs[$f->get('id')] = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
// Create template context.
|
|
|
263 |
$this->setUser($u1);
|
|
|
264 |
$t1 = $ccg->create_template();
|
|
|
265 |
$t2 = $ccg->create_template(['contextid' => $cat1ctx->id]);
|
|
|
266 |
|
|
|
267 |
// Add to category context.
|
|
|
268 |
$this->setUser($u2);
|
|
|
269 |
$ccg->create_template(['contextid' => $cat2ctx->id]);
|
|
|
270 |
|
|
|
271 |
// Create template competencies.
|
|
|
272 |
$this->setUser($u3);
|
|
|
273 |
$c1 = $ccg->create_template_competency(['competencyid' => $cs[$f1->get('id')]->get('id'), 'templateid' => $t1->get('id')]);
|
|
|
274 |
$c4 = $ccg->create_template_competency(['competencyid' => $cs[$f2->get('id')]->get('id'), 'templateid' => $t2->get('id')]);
|
|
|
275 |
|
|
|
276 |
// Create template cohorts.
|
|
|
277 |
$this->setUser($u4);
|
|
|
278 |
$c1 = $ccg->create_template_cohort(['cohortid' => $cohort->id, 'templateid' => $t1->get('id')]);
|
|
|
279 |
$c4 = $ccg->create_template_cohort(['cohortid' => $cohort->id, 'templateid' => $t2->get('id')]);
|
|
|
280 |
|
|
|
281 |
// Test correct users appear in each context.
|
|
|
282 |
$component = 'core_competency';
|
|
|
283 |
|
|
|
284 |
$userlist = new userlist($sysctx, $component);
|
|
|
285 |
provider::get_users_in_context($userlist);
|
|
|
286 |
$expected = [$u1->id, $u3->id, $u4->id];
|
|
|
287 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
288 |
|
|
|
289 |
$userlist = new userlist($cat1ctx, $component);
|
|
|
290 |
provider::get_users_in_context($userlist);
|
|
|
291 |
$expected = [$u1->id, $u3->id, $u4->id];
|
|
|
292 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
293 |
|
|
|
294 |
$userlist = new userlist($cat2ctx, $component);
|
|
|
295 |
provider::get_users_in_context($userlist);
|
|
|
296 |
$expected = [$u2->id];
|
|
|
297 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
public function test_get_contexts_for_userid_with_usermodified_for_course() {
|
|
|
301 |
$dg = $this->getDataGenerator();
|
|
|
302 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
303 |
$c1 = $dg->create_course();
|
|
|
304 |
$c2 = $dg->create_course();
|
|
|
305 |
$u0 = $dg->create_user();
|
|
|
306 |
$u1 = $dg->create_user();
|
|
|
307 |
$u2 = $dg->create_user();
|
|
|
308 |
$u3 = $dg->create_user();
|
|
|
309 |
$u4 = $dg->create_user();
|
|
|
310 |
$c1ctx = \context_course::instance($c1->id);
|
|
|
311 |
$c2ctx = \context_course::instance($c2->id);
|
|
|
312 |
|
|
|
313 |
$f = $ccg->create_framework();
|
|
|
314 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
315 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
316 |
|
|
|
317 |
$this->setUser($u1);
|
|
|
318 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), []);
|
|
|
319 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
320 |
$ccg->create_course_competency(['courseid' => $c1->id, 'competencyid' => $comp1->get('id')]);
|
|
|
321 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$c1ctx]);
|
|
|
322 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
323 |
|
|
|
324 |
$this->setUser($u2);
|
|
|
325 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$c1ctx]);
|
|
|
326 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
327 |
$ccg->create_course_competency(['courseid' => $c2->id, 'competencyid' => $comp2->get('id')]);
|
|
|
328 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$c1ctx]);
|
|
|
329 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$c2ctx]);
|
|
|
330 |
$ccg->create_course_competency(['courseid' => $c1->id, 'competencyid' => $comp2->get('id')]);
|
|
|
331 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$c1ctx]);
|
|
|
332 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$c1ctx, $c2ctx]);
|
|
|
333 |
|
|
|
334 |
$this->setUser($u3);
|
|
|
335 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
336 |
$ccs = new \core_competency\course_competency_settings(null, (object) ['courseid' => $c1->id]);
|
|
|
337 |
$ccs->create();
|
|
|
338 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$c1ctx]);
|
|
|
339 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$c1ctx, $c2ctx]);
|
|
|
340 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), [$c1ctx]);
|
|
|
341 |
|
|
|
342 |
$this->setUser($u4);
|
|
|
343 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
344 |
$ccg->create_user_competency_course(['courseid' => $c2->id, 'userid' => $u0->id, 'competencyid' => $comp1->get('id')]);
|
|
|
345 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$c1ctx]);
|
|
|
346 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$c1ctx, $c2ctx]);
|
|
|
347 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), [$c1ctx]);
|
|
|
348 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), [$c2ctx]);
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
public function test_get_users_in_context_with_usermodified_for_course() {
|
|
|
352 |
$dg = $this->getDataGenerator();
|
|
|
353 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
354 |
$c1 = $dg->create_course();
|
|
|
355 |
$c2 = $dg->create_course();
|
|
|
356 |
$u0 = $dg->create_user();
|
|
|
357 |
$u1 = $dg->create_user();
|
|
|
358 |
$u2 = $dg->create_user();
|
|
|
359 |
$u3 = $dg->create_user();
|
|
|
360 |
$u4 = $dg->create_user();
|
|
|
361 |
$c1ctx = \context_course::instance($c1->id);
|
|
|
362 |
$c2ctx = \context_course::instance($c2->id);
|
|
|
363 |
|
|
|
364 |
$f = $ccg->create_framework();
|
|
|
365 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
366 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
367 |
|
|
|
368 |
$this->setUser($u1);
|
|
|
369 |
$ccg->create_course_competency(['courseid' => $c1->id, 'competencyid' => $comp1->get('id')]);
|
|
|
370 |
|
|
|
371 |
$this->setUser($u2);
|
|
|
372 |
$ccg->create_course_competency(['courseid' => $c2->id, 'competencyid' => $comp2->get('id')]);
|
|
|
373 |
$ccg->create_course_competency(['courseid' => $c1->id, 'competencyid' => $comp2->get('id')]);
|
|
|
374 |
|
|
|
375 |
$this->setUser($u3);
|
|
|
376 |
$ccs = new \core_competency\course_competency_settings(null, (object) ['courseid' => $c1->id]);
|
|
|
377 |
$ccs->create();
|
|
|
378 |
|
|
|
379 |
$this->setUser($u4);
|
|
|
380 |
$ccg->create_user_competency_course(['courseid' => $c2->id, 'userid' => $u0->id, 'competencyid' => $comp1->get('id')]);
|
|
|
381 |
|
|
|
382 |
// Test correct users appear in each context.
|
|
|
383 |
$component = 'core_competency';
|
|
|
384 |
|
|
|
385 |
$userlist = new userlist($c1ctx, $component);
|
|
|
386 |
provider::get_users_in_context($userlist);
|
|
|
387 |
$expected = [$u1->id, $u2->id, $u3->id];
|
|
|
388 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
389 |
|
|
|
390 |
$userlist = new userlist($c2ctx, $component);
|
|
|
391 |
provider::get_users_in_context($userlist);
|
|
|
392 |
$expected = [$u0->id, $u2->id, $u4->id];
|
|
|
393 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
394 |
}
|
|
|
395 |
|
|
|
396 |
public function test_get_contexts_for_userid_with_usermodified_for_module() {
|
|
|
397 |
$dg = $this->getDataGenerator();
|
|
|
398 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
399 |
$c1 = $dg->create_course();
|
|
|
400 |
$m1 = $dg->create_module('choice', ['course' => $c1]);
|
|
|
401 |
$m2 = $dg->create_module('choice', ['course' => $c1]);
|
|
|
402 |
$u1 = $dg->create_user();
|
|
|
403 |
$u2 = $dg->create_user();
|
|
|
404 |
$m1ctx = \context_module::instance($m1->cmid);
|
|
|
405 |
$m2ctx = \context_module::instance($m2->cmid);
|
|
|
406 |
|
|
|
407 |
$f = $ccg->create_framework();
|
|
|
408 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
409 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
410 |
|
|
|
411 |
$this->setUser($u1);
|
|
|
412 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), []);
|
|
|
413 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
414 |
$ccg->create_course_module_competency(['cmid' => $m1->cmid, 'competencyid' => $comp1->get('id')]);
|
|
|
415 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$m1ctx]);
|
|
|
416 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
417 |
|
|
|
418 |
$this->setUser($u2);
|
|
|
419 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$m1ctx]);
|
|
|
420 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
421 |
$ccg->create_course_module_competency(['cmid' => $m2->cmid, 'competencyid' => $comp2->get('id')]);
|
|
|
422 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$m1ctx]);
|
|
|
423 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$m2ctx]);
|
|
|
424 |
$ccg->create_course_module_competency(['cmid' => $m1->cmid, 'competencyid' => $comp2->get('id')]);
|
|
|
425 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$m1ctx]);
|
|
|
426 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$m1ctx, $m2ctx]);
|
|
|
427 |
}
|
|
|
428 |
|
|
|
429 |
public function test_get_users_in_context_with_usermodified_for_module() {
|
|
|
430 |
$dg = $this->getDataGenerator();
|
|
|
431 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
432 |
$c1 = $dg->create_course();
|
|
|
433 |
$m1 = $dg->create_module('choice', ['course' => $c1]);
|
|
|
434 |
$m2 = $dg->create_module('choice', ['course' => $c1]);
|
|
|
435 |
$u1 = $dg->create_user();
|
|
|
436 |
$u2 = $dg->create_user();
|
|
|
437 |
$m1ctx = \context_module::instance($m1->cmid);
|
|
|
438 |
$m2ctx = \context_module::instance($m2->cmid);
|
|
|
439 |
|
|
|
440 |
$f = $ccg->create_framework();
|
|
|
441 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
442 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
443 |
|
|
|
444 |
$this->setUser($u1);
|
|
|
445 |
$ccg->create_course_module_competency(['cmid' => $m1->cmid, 'competencyid' => $comp1->get('id')]);
|
|
|
446 |
|
|
|
447 |
$this->setUser($u2);
|
|
|
448 |
$ccg->create_course_module_competency(['cmid' => $m2->cmid, 'competencyid' => $comp2->get('id')]);
|
|
|
449 |
$ccg->create_course_module_competency(['cmid' => $m1->cmid, 'competencyid' => $comp2->get('id')]);
|
|
|
450 |
|
|
|
451 |
// Test correct users appear in each context.
|
|
|
452 |
$component = 'core_competency';
|
|
|
453 |
|
|
|
454 |
$userlist = new userlist($m1ctx, $component);
|
|
|
455 |
provider::get_users_in_context($userlist);
|
|
|
456 |
$expected = [$u1->id, $u2->id];
|
|
|
457 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
458 |
|
|
|
459 |
$userlist = new userlist($m2ctx, $component);
|
|
|
460 |
provider::get_users_in_context($userlist);
|
|
|
461 |
$expected = [$u2->id];
|
|
|
462 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
public function test_get_contexts_for_userid_with_usermodified_for_plan() {
|
|
|
466 |
$dg = $this->getDataGenerator();
|
|
|
467 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
468 |
$u0 = $dg->create_user();
|
|
|
469 |
$u1 = $dg->create_user();
|
|
|
470 |
$u2 = $dg->create_user();
|
|
|
471 |
$u3 = $dg->create_user();
|
|
|
472 |
$u0ctx = \context_user::instance($u0->id);
|
|
|
473 |
|
|
|
474 |
$f = $ccg->create_framework();
|
|
|
475 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
476 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
477 |
|
|
|
478 |
$this->setUser($u1);
|
|
|
479 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), []);
|
|
|
480 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
481 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
482 |
$plan = $ccg->create_plan(['userid' => $u0->id]);
|
|
|
483 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u0ctx]);
|
|
|
484 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
485 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
486 |
|
|
|
487 |
$this->setUser($u2);
|
|
|
488 |
$ccg->create_plan_competency(['planid' => $plan->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
489 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u0ctx]);
|
|
|
490 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$u0ctx]);
|
|
|
491 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
492 |
|
|
|
493 |
$this->setUser($u3);
|
|
|
494 |
$ccg->create_user_competency_plan(['planid' => $plan->get('id'), 'competencyid' => $comp1->get('id'),
|
|
|
495 |
'userid' => $u0->id]);
|
|
|
496 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u0ctx]);
|
|
|
497 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$u0ctx]);
|
|
|
498 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), [$u0ctx]);
|
|
|
499 |
}
|
|
|
500 |
|
|
|
501 |
public function test_get_users_in_context_with_usermodified_for_plan() {
|
|
|
502 |
$dg = $this->getDataGenerator();
|
|
|
503 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
504 |
$u0 = $dg->create_user();
|
|
|
505 |
$u1 = $dg->create_user();
|
|
|
506 |
$u2 = $dg->create_user();
|
|
|
507 |
$u3 = $dg->create_user();
|
|
|
508 |
$u0ctx = \context_user::instance($u0->id);
|
|
|
509 |
|
|
|
510 |
$f = $ccg->create_framework();
|
|
|
511 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
512 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
513 |
|
|
|
514 |
$this->setUser($u1);
|
|
|
515 |
$plan = $ccg->create_plan(['userid' => $u0->id]);
|
|
|
516 |
|
|
|
517 |
$this->setUser($u2);
|
|
|
518 |
$ccg->create_plan_competency(['planid' => $plan->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
519 |
|
|
|
520 |
$this->setUser($u3);
|
|
|
521 |
$ccg->create_user_competency_plan(['planid' => $plan->get('id'), 'competencyid' => $comp1->get('id'),
|
|
|
522 |
'userid' => $u0->id]);
|
|
|
523 |
|
|
|
524 |
// Test correct users appear in the context.
|
|
|
525 |
$component = 'core_competency';
|
|
|
526 |
|
|
|
527 |
$userlist = new userlist($u0ctx, $component);
|
|
|
528 |
provider::get_users_in_context($userlist);
|
|
|
529 |
$expected = [$u0->id, $u1->id, $u2->id, $u3->id];
|
|
|
530 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
531 |
}
|
|
|
532 |
|
|
|
533 |
public function test_get_contexts_for_userid_with_usermodified_for_competency_data() {
|
|
|
534 |
$dg = $this->getDataGenerator();
|
|
|
535 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
536 |
$u0 = $dg->create_user();
|
|
|
537 |
$u1 = $dg->create_user();
|
|
|
538 |
$u2 = $dg->create_user();
|
|
|
539 |
$u3 = $dg->create_user();
|
|
|
540 |
$u4 = $dg->create_user();
|
|
|
541 |
$u5 = $dg->create_user();
|
|
|
542 |
$u6 = $dg->create_user();
|
|
|
543 |
$u7 = $dg->create_user();
|
|
|
544 |
$u8 = $dg->create_user();
|
|
|
545 |
$u0ctx = \context_user::instance($u0->id);
|
|
|
546 |
|
|
|
547 |
$f = $ccg->create_framework();
|
|
|
548 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
549 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
550 |
|
|
|
551 |
$this->setUser($u1);
|
|
|
552 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), []);
|
|
|
553 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
554 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
555 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
556 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), []);
|
|
|
557 |
$this->assert_contextlist(provider::get_contexts_for_userid($u6->id), []);
|
|
|
558 |
$uc = $ccg->create_user_competency(['userid' => $u0->id, 'competencyid' => $comp1->get('id'),
|
|
|
559 |
'reviewerid' => $u6->id]);
|
|
|
560 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u0ctx]);
|
|
|
561 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
562 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
563 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
564 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), []);
|
|
|
565 |
$this->assert_contextlist(provider::get_contexts_for_userid($u6->id), [$u0ctx]);
|
|
|
566 |
|
|
|
567 |
$this->setUser($u2);
|
|
|
568 |
$e = $ccg->create_evidence(['usercompetencyid' => $uc->get('id'), 'actionuserid' => $u5->id]);
|
|
|
569 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u0ctx]);
|
|
|
570 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$u0ctx]);
|
|
|
571 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
572 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
573 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), [$u0ctx]);
|
|
|
574 |
$this->assert_contextlist(provider::get_contexts_for_userid($u6->id), [$u0ctx]);
|
|
|
575 |
|
|
|
576 |
$this->setUser($u3);
|
|
|
577 |
$ccg->create_user_evidence(['userid' => $u0->id]);
|
|
|
578 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u0ctx]);
|
|
|
579 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$u0ctx]);
|
|
|
580 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), [$u0ctx]);
|
|
|
581 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
582 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), [$u0ctx]);
|
|
|
583 |
$this->assert_contextlist(provider::get_contexts_for_userid($u6->id), [$u0ctx]);
|
|
|
584 |
|
|
|
585 |
$this->setUser($u4);
|
|
|
586 |
$ccg->create_user_evidence(['userid' => $u0->id]);
|
|
|
587 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u0ctx]);
|
|
|
588 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$u0ctx]);
|
|
|
589 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), [$u0ctx]);
|
|
|
590 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), [$u0ctx]);
|
|
|
591 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), [$u0ctx]);
|
|
|
592 |
$this->assert_contextlist(provider::get_contexts_for_userid($u6->id), [$u0ctx]);
|
|
|
593 |
|
|
|
594 |
// Comment on competency.
|
|
|
595 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
596 |
$this->assert_contextlist(provider::get_contexts_for_userid($u7->id), []);
|
|
|
597 |
$this->setUser($u7);
|
|
|
598 |
$comments = $uc->get_comment_object();
|
|
|
599 |
$comments->add('Hello there!');
|
|
|
600 |
$this->assert_contextlist(provider::get_contexts_for_userid($u7->id), [$u0ctx]);
|
|
|
601 |
|
|
|
602 |
// Comment on plan.
|
|
|
603 |
$this->assert_contextlist(provider::get_contexts_for_userid($u8->id), []);
|
|
|
604 |
$this->setUser($u8);
|
|
|
605 |
$plan = $ccg->create_plan(['userid' => $u0->id]);
|
|
|
606 |
$comments = $plan->get_comment_object();
|
|
|
607 |
$comments->add('Hi, planet!');
|
|
|
608 |
$this->assert_contextlist(provider::get_contexts_for_userid($u8->id), [$u0ctx]);
|
|
|
609 |
}
|
|
|
610 |
|
|
|
611 |
public function test_get_users_in_context_with_usermodified_for_competency_data() {
|
|
|
612 |
$dg = $this->getDataGenerator();
|
|
|
613 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
614 |
$u0 = $dg->create_user();
|
|
|
615 |
$u1 = $dg->create_user();
|
|
|
616 |
$u2 = $dg->create_user();
|
|
|
617 |
$u3 = $dg->create_user();
|
|
|
618 |
$u4 = $dg->create_user();
|
|
|
619 |
$u5 = $dg->create_user();
|
|
|
620 |
$u6 = $dg->create_user();
|
|
|
621 |
$u7 = $dg->create_user();
|
|
|
622 |
$u8 = $dg->create_user();
|
|
|
623 |
$u0ctx = \context_user::instance($u0->id);
|
|
|
624 |
|
|
|
625 |
$f = $ccg->create_framework();
|
|
|
626 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
627 |
|
|
|
628 |
$this->setUser($u1);
|
|
|
629 |
$uc = $ccg->create_user_competency(['userid' => $u0->id, 'competencyid' => $comp1->get('id'),
|
|
|
630 |
'reviewerid' => $u6->id]);
|
|
|
631 |
|
|
|
632 |
$this->setUser($u2);
|
|
|
633 |
$e = $ccg->create_evidence(['usercompetencyid' => $uc->get('id'), 'actionuserid' => $u5->id]);
|
|
|
634 |
|
|
|
635 |
$this->setUser($u3);
|
|
|
636 |
$ccg->create_user_evidence(['userid' => $u0->id]);
|
|
|
637 |
|
|
|
638 |
$this->setUser($u4);
|
|
|
639 |
$ccg->create_user_evidence(['userid' => $u0->id]);
|
|
|
640 |
|
|
|
641 |
// Comment on competency.
|
|
|
642 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
643 |
$this->setUser($u7);
|
|
|
644 |
$comments = $uc->get_comment_object();
|
|
|
645 |
$comments->add('Hello there!');
|
|
|
646 |
|
|
|
647 |
// Comment on plan.
|
|
|
648 |
$this->setUser($u8);
|
|
|
649 |
$plan = $ccg->create_plan(['userid' => $u0->id]);
|
|
|
650 |
$comments = $plan->get_comment_object();
|
|
|
651 |
$comments->add('Hi, planet!');
|
|
|
652 |
|
|
|
653 |
// Test correct users appear in the context.
|
|
|
654 |
$component = 'core_competency';
|
|
|
655 |
|
|
|
656 |
$userlist = new userlist($u0ctx, $component);
|
|
|
657 |
provider::get_users_in_context($userlist);
|
|
|
658 |
$expected = [$u0->id, $u1->id, $u2->id, $u3->id, $u4->id, $u5->id, $u6->id, $u7->id, $u8->id];
|
|
|
659 |
$this->assert_array_match($expected, $userlist->get_userids());
|
|
|
660 |
}
|
|
|
661 |
|
|
|
662 |
public function test_get_contexts_for_userid_with_actual_data_and_actual_data_is_goooood() {
|
|
|
663 |
$dg = $this->getDataGenerator();
|
|
|
664 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
665 |
$c1 = $dg->create_course();
|
|
|
666 |
$u1 = $dg->create_user();
|
|
|
667 |
$u2 = $dg->create_user();
|
|
|
668 |
$u3 = $dg->create_user();
|
|
|
669 |
$u4 = $dg->create_user();
|
|
|
670 |
$u5 = $dg->create_user();
|
|
|
671 |
|
|
|
672 |
$c1ctx = \context_course::instance($c1->id);
|
|
|
673 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
674 |
$u2ctx = \context_user::instance($u2->id);
|
|
|
675 |
$u3ctx = \context_user::instance($u3->id);
|
|
|
676 |
$u4ctx = \context_user::instance($u4->id);
|
|
|
677 |
|
|
|
678 |
$f = $ccg->create_framework();
|
|
|
679 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
680 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
681 |
|
|
|
682 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), []);
|
|
|
683 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
684 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
685 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
686 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), []);
|
|
|
687 |
|
|
|
688 |
$ccg->create_plan(['userid' => $u1->id]);
|
|
|
689 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u1ctx]);
|
|
|
690 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), []);
|
|
|
691 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
692 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
693 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), []);
|
|
|
694 |
|
|
|
695 |
$ccg->create_user_competency(['userid' => $u2->id, 'competencyid' => $comp1->get('id')]);
|
|
|
696 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u1ctx]);
|
|
|
697 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$u2ctx]);
|
|
|
698 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), []);
|
|
|
699 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
700 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), []);
|
|
|
701 |
|
|
|
702 |
$ccg->create_user_competency_course(['userid' => $u3->id, 'competencyid' => $comp1->get('id'), 'courseid' => $c1->id]);
|
|
|
703 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u1ctx]);
|
|
|
704 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$u2ctx]);
|
|
|
705 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), [$c1ctx]);
|
|
|
706 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), []);
|
|
|
707 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), []);
|
|
|
708 |
|
|
|
709 |
$ue = $ccg->create_user_evidence(['userid' => $u4->id]);
|
|
|
710 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u1ctx]);
|
|
|
711 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$u2ctx]);
|
|
|
712 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), [$c1ctx]);
|
|
|
713 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), [$u4ctx]);
|
|
|
714 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), []);
|
|
|
715 |
|
|
|
716 |
// A user editing a context relationship.
|
|
|
717 |
$this->setUser($u5);
|
|
|
718 |
$ccg->create_user_evidence_competency(['userevidenceid' => $ue->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
719 |
$this->setAdminUser();
|
|
|
720 |
$this->assert_contextlist(provider::get_contexts_for_userid($u1->id), [$u1ctx]);
|
|
|
721 |
$this->assert_contextlist(provider::get_contexts_for_userid($u2->id), [$u2ctx]);
|
|
|
722 |
$this->assert_contextlist(provider::get_contexts_for_userid($u3->id), [$c1ctx]);
|
|
|
723 |
$this->assert_contextlist(provider::get_contexts_for_userid($u4->id), [$u4ctx]);
|
|
|
724 |
$this->assert_contextlist(provider::get_contexts_for_userid($u5->id), [$u4ctx]);
|
|
|
725 |
}
|
|
|
726 |
|
|
|
727 |
public function test_get_users_in_context_with_actual_data_and_actual_data_is_goooood() {
|
|
|
728 |
$dg = $this->getDataGenerator();
|
|
|
729 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
730 |
$c1 = $dg->create_course();
|
|
|
731 |
$u1 = $dg->create_user();
|
|
|
732 |
$u2 = $dg->create_user();
|
|
|
733 |
$u3 = $dg->create_user();
|
|
|
734 |
$u4 = $dg->create_user();
|
|
|
735 |
|
|
|
736 |
$c1ctx = \context_course::instance($c1->id);
|
|
|
737 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
738 |
$u2ctx = \context_user::instance($u2->id);
|
|
|
739 |
$u3ctx = \context_user::instance($u3->id);
|
|
|
740 |
$u4ctx = \context_user::instance($u4->id);
|
|
|
741 |
|
|
|
742 |
$f = $ccg->create_framework();
|
|
|
743 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
744 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
745 |
|
|
|
746 |
$ccg->create_plan(['userid' => $u1->id]);
|
|
|
747 |
|
|
|
748 |
$ccg->create_user_competency(['userid' => $u2->id, 'competencyid' => $comp1->get('id')]);
|
|
|
749 |
|
|
|
750 |
$ccg->create_user_competency_course(['userid' => $u3->id, 'competencyid' => $comp1->get('id'), 'courseid' => $c1->id]);
|
|
|
751 |
|
|
|
752 |
$ccg->create_user_evidence(['userid' => $u4->id]);
|
|
|
753 |
|
|
|
754 |
// Test correct users appear in each context.
|
|
|
755 |
$component = 'core_competency';
|
|
|
756 |
|
|
|
757 |
$userlist = new userlist($u1ctx, $component);
|
|
|
758 |
provider::get_users_in_context($userlist);
|
|
|
759 |
$this->assert_array_match([$u1->id], $userlist->get_userids());
|
|
|
760 |
|
|
|
761 |
$userlist = new userlist($u2ctx, $component);
|
|
|
762 |
provider::get_users_in_context($userlist);
|
|
|
763 |
$this->assert_array_match([$u2->id], $userlist->get_userids());
|
|
|
764 |
|
|
|
765 |
$userlist = new userlist($c1ctx, $component);
|
|
|
766 |
provider::get_users_in_context($userlist);
|
|
|
767 |
$this->assert_array_match([$u3->id], $userlist->get_userids());
|
|
|
768 |
|
|
|
769 |
$userlist = new userlist($u4ctx, $component);
|
|
|
770 |
provider::get_users_in_context($userlist);
|
|
|
771 |
$this->assert_array_match([$u4->id], $userlist->get_userids());
|
|
|
772 |
}
|
|
|
773 |
|
|
|
774 |
public function test_delete_data_for_user() {
|
|
|
775 |
$dg = $this->getDataGenerator();
|
|
|
776 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
777 |
|
|
|
778 |
$c1 = $dg->create_course();
|
|
|
779 |
$c2 = $dg->create_course();
|
|
|
780 |
$u1 = $dg->create_user();
|
|
|
781 |
$u2 = $dg->create_user();
|
|
|
782 |
|
|
|
783 |
$c1ctx = \context_course::instance($c1->id);
|
|
|
784 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
785 |
$u2ctx = \context_user::instance($u2->id);
|
|
|
786 |
|
|
|
787 |
$f = $ccg->create_framework();
|
|
|
788 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
789 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
790 |
|
|
|
791 |
$ue1a = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
792 |
$ue1b = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
793 |
$ue2 = $ccg->create_user_evidence(['userid' => $u2->id]);
|
|
|
794 |
$uec1a = $ccg->create_user_evidence_competency(['userevidenceid' => $ue1a->get('id'),
|
|
|
795 |
'competencyid' => $comp1->get('id')]);
|
|
|
796 |
$uec1b = $ccg->create_user_evidence_competency(['userevidenceid' => $ue1b->get('id'),
|
|
|
797 |
'competencyid' => $comp2->get('id')]);
|
|
|
798 |
$uec2 = $ccg->create_user_evidence_competency(['userevidenceid' => $ue2->get('id'),
|
|
|
799 |
'competencyid' => $comp1->get('id')]);
|
|
|
800 |
|
|
|
801 |
$p1a = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
802 |
$p1b = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
803 |
$p2 = $ccg->create_plan(['userid' => $u2->id]);
|
|
|
804 |
$pc1a = $ccg->create_plan_competency(['planid' => $p1a->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
805 |
$pc1b = $ccg->create_plan_competency(['planid' => $p1b->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
806 |
$pc2 = $ccg->create_plan_competency(['planid' => $p2->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
807 |
$ucp1a = $ccg->create_user_competency_plan(['userid' => $u1->id, 'planid' => $p1a->get('id'),
|
|
|
808 |
'competencyid' => $comp1->get('id')]);
|
|
|
809 |
$ucp1b = $ccg->create_user_competency_plan(['userid' => $u1->id, 'planid' => $p1b->get('id'),
|
|
|
810 |
'competencyid' => $comp2->get('id')]);
|
|
|
811 |
$ucp2 = $ccg->create_user_competency_plan(['userid' => $u2->id, 'planid' => $p2->get('id'),
|
|
|
812 |
'competencyid' => $comp1->get('id')]);
|
|
|
813 |
|
|
|
814 |
$uc1a = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp1->get('id')]);
|
|
|
815 |
$uc1b = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp2->get('id')]);
|
|
|
816 |
$uc2 = $ccg->create_user_competency(['userid' => $u2->id, 'competencyid' => $comp2->get('id')]);
|
|
|
817 |
$e1a = $ccg->create_evidence(['usercompetencyid' => $uc1a->get('id')]);
|
|
|
818 |
$e1b = $ccg->create_evidence(['usercompetencyid' => $uc1b->get('id')]);
|
|
|
819 |
$e2 = $ccg->create_evidence(['usercompetencyid' => $uc2->get('id')]);
|
|
|
820 |
|
|
|
821 |
$ucc1a = $ccg->create_user_competency_course(['userid' => $u1->id, 'courseid' => $c1->id,
|
|
|
822 |
'competencyid' => $comp1->get('id')]);
|
|
|
823 |
$ucc1b = $ccg->create_user_competency_course(['userid' => $u1->id, 'courseid' => $c2->id,
|
|
|
824 |
'competencyid' => $comp1->get('id')]);
|
|
|
825 |
$ucc2 = $ccg->create_user_competency_course(['userid' => $u2->id, 'courseid' => $c1->id,
|
|
|
826 |
'competencyid' => $comp1->get('id')]);
|
|
|
827 |
|
|
|
828 |
// User 1 comments on both plans.
|
|
|
829 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
830 |
$this->setUser($u1);
|
|
|
831 |
$p1a->get_comment_object()->add('Hi...');
|
|
|
832 |
$p1a->get_comment_object()->add('mister');
|
|
|
833 |
$p2->get_comment_object()->add('Ahoy!');
|
|
|
834 |
|
|
|
835 |
// User 2 comments on both competencies.
|
|
|
836 |
$this->setUser($u2);
|
|
|
837 |
$uc1a->get_comment_object()->add('Hi, too!');
|
|
|
838 |
$uc1a->get_comment_object()->add('How are you?');
|
|
|
839 |
$uc2->get_comment_object()->add('Ahoy, too!');
|
|
|
840 |
|
|
|
841 |
$p1acommentobj = $p1a->get_comment_object();
|
|
|
842 |
$p2commentobj = $p2->get_comment_object();
|
|
|
843 |
$uc1acommentobj = $uc1a->get_comment_object();
|
|
|
844 |
$uc2commentobj = $uc2->get_comment_object();
|
|
|
845 |
|
|
|
846 |
$this->setAdminUser();
|
|
|
847 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
848 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1b->get('id')));
|
|
|
849 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue2->get('id')));
|
|
|
850 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
851 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1b->get('id')));
|
|
|
852 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec2->get('id')));
|
|
|
853 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
854 |
$this->assertTrue(\core_competency\plan::record_exists($p1b->get('id')));
|
|
|
855 |
$this->assertTrue(\core_competency\plan::record_exists($p2->get('id')));
|
|
|
856 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
857 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1b->get('id')));
|
|
|
858 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc2->get('id')));
|
|
|
859 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
860 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1b->get('id')));
|
|
|
861 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp2->get('id')));
|
|
|
862 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
863 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1b->get('id')));
|
|
|
864 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc2->get('id')));
|
|
|
865 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
866 |
$this->assertTrue(\core_competency\evidence::record_exists($e1b->get('id')));
|
|
|
867 |
$this->assertTrue(\core_competency\evidence::record_exists($e2->get('id')));
|
|
|
868 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1a->get('id')));
|
|
|
869 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1b->get('id')));
|
|
|
870 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc2->get('id')));
|
|
|
871 |
$this->assert_has_comments($p1acommentobj);
|
|
|
872 |
$this->assertEquals(2, $this->get_comments_count($p1acommentobj, $u1->id));
|
|
|
873 |
$this->assertEquals(0, $this->get_comments_count($p1acommentobj, $u2->id));
|
|
|
874 |
$this->assert_has_comments($p2commentobj);
|
|
|
875 |
$this->assertEquals(1, $this->get_comments_count($p2commentobj, $u1->id));
|
|
|
876 |
$this->assertEquals(0, $this->get_comments_count($p2commentobj, $u2->id));
|
|
|
877 |
$this->assert_has_comments($uc1acommentobj);
|
|
|
878 |
$this->assertEquals(0, $this->get_comments_count($uc1acommentobj, $u1->id));
|
|
|
879 |
$this->assertEquals(2, $this->get_comments_count($uc1acommentobj, $u2->id));
|
|
|
880 |
$this->assert_has_comments($uc2commentobj);
|
|
|
881 |
$this->assertEquals(0, $this->get_comments_count($uc2commentobj, $u1->id));
|
|
|
882 |
$this->assertEquals(1, $this->get_comments_count($uc2commentobj, $u2->id));
|
|
|
883 |
|
|
|
884 |
// Deleting user context only.
|
|
|
885 |
$appctx = new approved_contextlist($u1, 'core_competency', [$u1ctx->id]);
|
|
|
886 |
provider::delete_data_for_user($appctx);
|
|
|
887 |
|
|
|
888 |
$this->assertFalse(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
889 |
$this->assertFalse(\core_competency\user_evidence::record_exists($ue1b->get('id')));
|
|
|
890 |
$this->assertFalse(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
891 |
$this->assertFalse(\core_competency\user_evidence_competency::record_exists($uec1b->get('id')));
|
|
|
892 |
$this->assertFalse(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
893 |
$this->assertFalse(\core_competency\plan::record_exists($p1b->get('id')));
|
|
|
894 |
$this->assertFalse(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
895 |
$this->assertFalse(\core_competency\plan_competency::record_exists($pc1b->get('id')));
|
|
|
896 |
$this->assertFalse(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
897 |
$this->assertFalse(\core_competency\user_competency_plan::record_exists($ucp1b->get('id')));
|
|
|
898 |
$this->assertFalse(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
899 |
$this->assertFalse(\core_competency\user_competency::record_exists($uc1b->get('id')));
|
|
|
900 |
$this->assertFalse(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
901 |
$this->assertFalse(\core_competency\evidence::record_exists($e1b->get('id')));
|
|
|
902 |
|
|
|
903 |
$this->assert_has_no_comments($p1acommentobj);
|
|
|
904 |
$this->assertEquals(0, $this->get_comments_count($p1acommentobj, $u1->id));
|
|
|
905 |
$this->assertEquals(0, $this->get_comments_count($p1acommentobj, $u2->id));
|
|
|
906 |
$this->assert_has_no_comments($uc1acommentobj);
|
|
|
907 |
$this->assertEquals(0, $this->get_comments_count($uc1acommentobj, $u1->id));
|
|
|
908 |
$this->assertEquals(0, $this->get_comments_count($uc1acommentobj, $u2->id));
|
|
|
909 |
|
|
|
910 |
// This should not have been affected.
|
|
|
911 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1a->get('id')));
|
|
|
912 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1b->get('id')));
|
|
|
913 |
|
|
|
914 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue2->get('id')));
|
|
|
915 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec2->get('id')));
|
|
|
916 |
$this->assertTrue(\core_competency\plan::record_exists($p2->get('id')));
|
|
|
917 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc2->get('id')));
|
|
|
918 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp2->get('id')));
|
|
|
919 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc2->get('id')));
|
|
|
920 |
$this->assertTrue(\core_competency\evidence::record_exists($e2->get('id')));
|
|
|
921 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc2->get('id')));
|
|
|
922 |
$this->assert_has_comments($p2commentobj);
|
|
|
923 |
$this->assertEquals(1, $this->get_comments_count($p2commentobj, $u1->id));
|
|
|
924 |
$this->assertEquals(0, $this->get_comments_count($p2commentobj, $u2->id));
|
|
|
925 |
$this->assert_has_comments($uc2commentobj);
|
|
|
926 |
$this->assertEquals(0, $this->get_comments_count($uc2commentobj, $u1->id));
|
|
|
927 |
$this->assertEquals(1, $this->get_comments_count($uc2commentobj, $u2->id));
|
|
|
928 |
|
|
|
929 |
// Deleting course context as well.
|
|
|
930 |
$appctx = new approved_contextlist($u1, 'core_competency', [$u1ctx->id, $c1ctx->id]);
|
|
|
931 |
provider::delete_data_for_user($appctx);
|
|
|
932 |
|
|
|
933 |
$this->assertFalse(\core_competency\user_competency_course::record_exists($ucc1a->get('id')));
|
|
|
934 |
|
|
|
935 |
// The rest belongs to another course, or the other user.
|
|
|
936 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1b->get('id')));
|
|
|
937 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue2->get('id')));
|
|
|
938 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec2->get('id')));
|
|
|
939 |
$this->assertTrue(\core_competency\plan::record_exists($p2->get('id')));
|
|
|
940 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc2->get('id')));
|
|
|
941 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp2->get('id')));
|
|
|
942 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc2->get('id')));
|
|
|
943 |
$this->assertTrue(\core_competency\evidence::record_exists($e2->get('id')));
|
|
|
944 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc2->get('id')));
|
|
|
945 |
}
|
|
|
946 |
|
|
|
947 |
public function test_delete_data_for_user_with_other_user_context() {
|
|
|
948 |
$dg = $this->getDataGenerator();
|
|
|
949 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
950 |
|
|
|
951 |
$u1 = $dg->create_user();
|
|
|
952 |
$u2 = $dg->create_user();
|
|
|
953 |
|
|
|
954 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
955 |
$u2ctx = \context_user::instance($u2->id);
|
|
|
956 |
|
|
|
957 |
$f = $ccg->create_framework();
|
|
|
958 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
959 |
|
|
|
960 |
// Create a bunch of data for user 1.
|
|
|
961 |
$ue1a = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
962 |
$uec1a = $ccg->create_user_evidence_competency(['userevidenceid' => $ue1a->get('id'),
|
|
|
963 |
'competencyid' => $comp1->get('id')]);
|
|
|
964 |
$p1a = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
965 |
$pc1a = $ccg->create_plan_competency(['planid' => $p1a->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
966 |
$ucp1a = $ccg->create_user_competency_plan(['userid' => $u1->id, 'planid' => $p1a->get('id'),
|
|
|
967 |
'competencyid' => $comp1->get('id')]);
|
|
|
968 |
$uc1a = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp1->get('id')]);
|
|
|
969 |
$e1a = $ccg->create_evidence(['usercompetencyid' => $uc1a->get('id')]);
|
|
|
970 |
|
|
|
971 |
$p2a = $ccg->create_plan(['userid' => $u2->id]);
|
|
|
972 |
|
|
|
973 |
// User 2 comments.
|
|
|
974 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
975 |
$this->setUser($u2);
|
|
|
976 |
$p1a->get_comment_object()->add('Hi...');
|
|
|
977 |
$p2a->get_comment_object()->add('Hi, hi!');
|
|
|
978 |
$uc1a->get_comment_object()->add('Hi, too!');
|
|
|
979 |
|
|
|
980 |
// Confirm state.
|
|
|
981 |
$this->setAdminUser();
|
|
|
982 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
983 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
984 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
985 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
986 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
987 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
988 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
989 |
$this->assert_has_comments($p1a->get_comment_object());
|
|
|
990 |
$this->assertEquals(1, $this->get_comments_count($p1a->get_comment_object(), $u2->id));
|
|
|
991 |
$this->assert_has_comments($p2a->get_comment_object());
|
|
|
992 |
$this->assertEquals(1, $this->get_comments_count($p2a->get_comment_object(), $u2->id));
|
|
|
993 |
$this->assert_has_comments($uc1a->get_comment_object());
|
|
|
994 |
$this->assertEquals(1, $this->get_comments_count($uc1a->get_comment_object(), $u2->id));
|
|
|
995 |
|
|
|
996 |
$this->assertTrue(\core_competency\plan::record_exists($p2a->get('id')));
|
|
|
997 |
|
|
|
998 |
// Delete for user 2, but we pass u1 context.
|
|
|
999 |
provider::delete_data_for_user(new approved_contextlist($u2, 'core_competency', [$u1ctx->id]));
|
|
|
1000 |
|
|
|
1001 |
// Nothing should have happened.
|
|
|
1002 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1003 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1004 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1005 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1006 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1007 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1008 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1009 |
$this->assert_has_comments($p1a->get_comment_object());
|
|
|
1010 |
$this->assertEquals(1, $this->get_comments_count($p1a->get_comment_object(), $u2->id));
|
|
|
1011 |
$this->assert_has_comments($p2a->get_comment_object());
|
|
|
1012 |
$this->assertEquals(1, $this->get_comments_count($p2a->get_comment_object(), $u2->id));
|
|
|
1013 |
$this->assert_has_comments($uc1a->get_comment_object());
|
|
|
1014 |
$this->assertEquals(1, $this->get_comments_count($uc1a->get_comment_object(), $u2->id));
|
|
|
1015 |
|
|
|
1016 |
$this->assertTrue(\core_competency\plan::record_exists($p2a->get('id')));
|
|
|
1017 |
|
|
|
1018 |
// Delete for user 2, but we pass u1 and u2 context.
|
|
|
1019 |
$p2acommentobj = $p2a->get_comment_object();
|
|
|
1020 |
provider::delete_data_for_user(new approved_contextlist($u2, 'core_competency', [$u1ctx->id, $u2ctx->id]));
|
|
|
1021 |
|
|
|
1022 |
// The plan got deleted.
|
|
|
1023 |
$this->assertFalse(\core_competency\plan::record_exists($p2a->get('id')));
|
|
|
1024 |
$this->assert_has_no_comments($p2acommentobj);
|
|
|
1025 |
|
|
|
1026 |
// Nothing should have happened for u1.
|
|
|
1027 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1028 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1029 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1030 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1031 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1032 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1033 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1034 |
$this->assert_has_comments($p1a->get_comment_object());
|
|
|
1035 |
$this->assertEquals(1, $this->get_comments_count($p1a->get_comment_object(), $u2->id));
|
|
|
1036 |
$this->assert_has_comments($uc1a->get_comment_object());
|
|
|
1037 |
$this->assertEquals(1, $this->get_comments_count($uc1a->get_comment_object(), $u2->id));
|
|
|
1038 |
}
|
|
|
1039 |
|
|
|
1040 |
public function test_delete_data_for_users() {
|
|
|
1041 |
$dg = $this->getDataGenerator();
|
|
|
1042 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
1043 |
|
|
|
1044 |
$c1 = $dg->create_course();
|
|
|
1045 |
$c2 = $dg->create_course();
|
|
|
1046 |
$u1 = $dg->create_user();
|
|
|
1047 |
$u2 = $dg->create_user();
|
|
|
1048 |
|
|
|
1049 |
$c1ctx = \context_course::instance($c1->id);
|
|
|
1050 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
1051 |
|
|
|
1052 |
$f = $ccg->create_framework();
|
|
|
1053 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1054 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1055 |
|
|
|
1056 |
$ue1a = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
1057 |
$ue1b = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
1058 |
$ue2 = $ccg->create_user_evidence(['userid' => $u2->id]);
|
|
|
1059 |
$uec1a = $ccg->create_user_evidence_competency(['userevidenceid' => $ue1a->get('id'),
|
|
|
1060 |
'competencyid' => $comp1->get('id')]);
|
|
|
1061 |
$uec1b = $ccg->create_user_evidence_competency(['userevidenceid' => $ue1b->get('id'),
|
|
|
1062 |
'competencyid' => $comp2->get('id')]);
|
|
|
1063 |
$uec2 = $ccg->create_user_evidence_competency(['userevidenceid' => $ue2->get('id'),
|
|
|
1064 |
'competencyid' => $comp1->get('id')]);
|
|
|
1065 |
|
|
|
1066 |
$p1a = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
1067 |
$p1b = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
1068 |
$p2 = $ccg->create_plan(['userid' => $u2->id]);
|
|
|
1069 |
$pc1a = $ccg->create_plan_competency(['planid' => $p1a->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
1070 |
$pc1b = $ccg->create_plan_competency(['planid' => $p1b->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
1071 |
$pc2 = $ccg->create_plan_competency(['planid' => $p2->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
1072 |
$ucp1a = $ccg->create_user_competency_plan(['userid' => $u1->id, 'planid' => $p1a->get('id'),
|
|
|
1073 |
'competencyid' => $comp1->get('id')]);
|
|
|
1074 |
$ucp1b = $ccg->create_user_competency_plan(['userid' => $u1->id, 'planid' => $p1b->get('id'),
|
|
|
1075 |
'competencyid' => $comp2->get('id')]);
|
|
|
1076 |
$ucp2 = $ccg->create_user_competency_plan(['userid' => $u2->id, 'planid' => $p2->get('id'),
|
|
|
1077 |
'competencyid' => $comp1->get('id')]);
|
|
|
1078 |
|
|
|
1079 |
$uc1a = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp1->get('id')]);
|
|
|
1080 |
$uc1b = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp2->get('id')]);
|
|
|
1081 |
$uc2 = $ccg->create_user_competency(['userid' => $u2->id, 'competencyid' => $comp2->get('id')]);
|
|
|
1082 |
$e1a = $ccg->create_evidence(['usercompetencyid' => $uc1a->get('id')]);
|
|
|
1083 |
$e1b = $ccg->create_evidence(['usercompetencyid' => $uc1b->get('id')]);
|
|
|
1084 |
$e2 = $ccg->create_evidence(['usercompetencyid' => $uc2->get('id')]);
|
|
|
1085 |
|
|
|
1086 |
$ucc1a = $ccg->create_user_competency_course(['userid' => $u1->id, 'courseid' => $c1->id,
|
|
|
1087 |
'competencyid' => $comp1->get('id')]);
|
|
|
1088 |
$ucc1b = $ccg->create_user_competency_course(['userid' => $u1->id, 'courseid' => $c2->id,
|
|
|
1089 |
'competencyid' => $comp1->get('id')]);
|
|
|
1090 |
$ucc2 = $ccg->create_user_competency_course(['userid' => $u2->id, 'courseid' => $c1->id,
|
|
|
1091 |
'competencyid' => $comp1->get('id')]);
|
|
|
1092 |
|
|
|
1093 |
// User 1 comments on both plans.
|
|
|
1094 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
1095 |
$this->setUser($u1);
|
|
|
1096 |
$p1a->get_comment_object()->add('Hi...');
|
|
|
1097 |
$p1a->get_comment_object()->add('mister');
|
|
|
1098 |
$p2->get_comment_object()->add('Ahoy!');
|
|
|
1099 |
|
|
|
1100 |
// User 2 comments on both competencies.
|
|
|
1101 |
$this->setUser($u2);
|
|
|
1102 |
$uc1a->get_comment_object()->add('Hi, too!');
|
|
|
1103 |
$uc1a->get_comment_object()->add('How are you?');
|
|
|
1104 |
$uc2->get_comment_object()->add('Ahoy, too!');
|
|
|
1105 |
|
|
|
1106 |
$p1acommentobj = $p1a->get_comment_object();
|
|
|
1107 |
$p2commentobj = $p2->get_comment_object();
|
|
|
1108 |
$uc1acommentobj = $uc1a->get_comment_object();
|
|
|
1109 |
$uc2commentobj = $uc2->get_comment_object();
|
|
|
1110 |
|
|
|
1111 |
$this->setAdminUser();
|
|
|
1112 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1113 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1b->get('id')));
|
|
|
1114 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue2->get('id')));
|
|
|
1115 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1116 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1b->get('id')));
|
|
|
1117 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec2->get('id')));
|
|
|
1118 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1119 |
$this->assertTrue(\core_competency\plan::record_exists($p1b->get('id')));
|
|
|
1120 |
$this->assertTrue(\core_competency\plan::record_exists($p2->get('id')));
|
|
|
1121 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1122 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1b->get('id')));
|
|
|
1123 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc2->get('id')));
|
|
|
1124 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1125 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1b->get('id')));
|
|
|
1126 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp2->get('id')));
|
|
|
1127 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1128 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1b->get('id')));
|
|
|
1129 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc2->get('id')));
|
|
|
1130 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1131 |
$this->assertTrue(\core_competency\evidence::record_exists($e1b->get('id')));
|
|
|
1132 |
$this->assertTrue(\core_competency\evidence::record_exists($e2->get('id')));
|
|
|
1133 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1a->get('id')));
|
|
|
1134 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1b->get('id')));
|
|
|
1135 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc2->get('id')));
|
|
|
1136 |
$this->assert_has_comments($p1acommentobj);
|
|
|
1137 |
$this->assertEquals(2, $this->get_comments_count($p1acommentobj, $u1->id));
|
|
|
1138 |
$this->assertEquals(0, $this->get_comments_count($p1acommentobj, $u2->id));
|
|
|
1139 |
$this->assert_has_comments($p2commentobj);
|
|
|
1140 |
$this->assertEquals(1, $this->get_comments_count($p2commentobj, $u1->id));
|
|
|
1141 |
$this->assertEquals(0, $this->get_comments_count($p2commentobj, $u2->id));
|
|
|
1142 |
$this->assert_has_comments($uc1acommentobj);
|
|
|
1143 |
$this->assertEquals(0, $this->get_comments_count($uc1acommentobj, $u1->id));
|
|
|
1144 |
$this->assertEquals(2, $this->get_comments_count($uc1acommentobj, $u2->id));
|
|
|
1145 |
$this->assert_has_comments($uc2commentobj);
|
|
|
1146 |
$this->assertEquals(0, $this->get_comments_count($uc2commentobj, $u1->id));
|
|
|
1147 |
$this->assertEquals(1, $this->get_comments_count($uc2commentobj, $u2->id));
|
|
|
1148 |
|
|
|
1149 |
// Deleting user context.
|
|
|
1150 |
$userlist = new approved_userlist($u1ctx, 'core_competency', [$u1->id, $u2->id]);
|
|
|
1151 |
provider::delete_data_for_users($userlist);
|
|
|
1152 |
|
|
|
1153 |
$this->assertFalse(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1154 |
$this->assertFalse(\core_competency\user_evidence::record_exists($ue1b->get('id')));
|
|
|
1155 |
$this->assertFalse(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1156 |
$this->assertFalse(\core_competency\user_evidence_competency::record_exists($uec1b->get('id')));
|
|
|
1157 |
$this->assertFalse(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1158 |
$this->assertFalse(\core_competency\plan::record_exists($p1b->get('id')));
|
|
|
1159 |
$this->assertFalse(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1160 |
$this->assertFalse(\core_competency\plan_competency::record_exists($pc1b->get('id')));
|
|
|
1161 |
$this->assertFalse(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1162 |
$this->assertFalse(\core_competency\user_competency_plan::record_exists($ucp1b->get('id')));
|
|
|
1163 |
$this->assertFalse(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1164 |
$this->assertFalse(\core_competency\user_competency::record_exists($uc1b->get('id')));
|
|
|
1165 |
$this->assertFalse(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1166 |
$this->assertFalse(\core_competency\evidence::record_exists($e1b->get('id')));
|
|
|
1167 |
|
|
|
1168 |
$this->assert_has_no_comments($p1acommentobj);
|
|
|
1169 |
$this->assertEquals(0, $this->get_comments_count($p1acommentobj, $u1->id));
|
|
|
1170 |
$this->assertEquals(0, $this->get_comments_count($p1acommentobj, $u2->id));
|
|
|
1171 |
$this->assert_has_no_comments($uc1acommentobj);
|
|
|
1172 |
$this->assertEquals(0, $this->get_comments_count($uc1acommentobj, $u1->id));
|
|
|
1173 |
$this->assertEquals(0, $this->get_comments_count($uc1acommentobj, $u2->id));
|
|
|
1174 |
|
|
|
1175 |
// This should not have been affected.
|
|
|
1176 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1a->get('id')));
|
|
|
1177 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1b->get('id')));
|
|
|
1178 |
|
|
|
1179 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue2->get('id')));
|
|
|
1180 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec2->get('id')));
|
|
|
1181 |
$this->assertTrue(\core_competency\plan::record_exists($p2->get('id')));
|
|
|
1182 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc2->get('id')));
|
|
|
1183 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp2->get('id')));
|
|
|
1184 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc2->get('id')));
|
|
|
1185 |
$this->assertTrue(\core_competency\evidence::record_exists($e2->get('id')));
|
|
|
1186 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc2->get('id')));
|
|
|
1187 |
$this->assert_has_comments($p2commentobj);
|
|
|
1188 |
$this->assertEquals(1, $this->get_comments_count($p2commentobj, $u1->id));
|
|
|
1189 |
$this->assertEquals(0, $this->get_comments_count($p2commentobj, $u2->id));
|
|
|
1190 |
$this->assert_has_comments($uc2commentobj);
|
|
|
1191 |
$this->assertEquals(0, $this->get_comments_count($uc2commentobj, $u1->id));
|
|
|
1192 |
$this->assertEquals(1, $this->get_comments_count($uc2commentobj, $u2->id));
|
|
|
1193 |
|
|
|
1194 |
// Deleting course context as well.
|
|
|
1195 |
$userlist = new approved_userlist($c1ctx, 'core_competency', [$u1->id]);
|
|
|
1196 |
provider::delete_data_for_users($userlist);
|
|
|
1197 |
|
|
|
1198 |
$this->assertFalse(\core_competency\user_competency_course::record_exists($ucc1a->get('id')));
|
|
|
1199 |
|
|
|
1200 |
// The rest belongs to another course, or the other user.
|
|
|
1201 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1b->get('id')));
|
|
|
1202 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue2->get('id')));
|
|
|
1203 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec2->get('id')));
|
|
|
1204 |
$this->assertTrue(\core_competency\plan::record_exists($p2->get('id')));
|
|
|
1205 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc2->get('id')));
|
|
|
1206 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp2->get('id')));
|
|
|
1207 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc2->get('id')));
|
|
|
1208 |
$this->assertTrue(\core_competency\evidence::record_exists($e2->get('id')));
|
|
|
1209 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc2->get('id')));
|
|
|
1210 |
}
|
|
|
1211 |
|
|
|
1212 |
public function test_delete_data_for_users_with_other_user_context() {
|
|
|
1213 |
$dg = $this->getDataGenerator();
|
|
|
1214 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
1215 |
|
|
|
1216 |
$u1 = $dg->create_user();
|
|
|
1217 |
$u2 = $dg->create_user();
|
|
|
1218 |
|
|
|
1219 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
1220 |
$u2ctx = \context_user::instance($u2->id);
|
|
|
1221 |
|
|
|
1222 |
$f = $ccg->create_framework();
|
|
|
1223 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1224 |
|
|
|
1225 |
// Create a bunch of data for user 1.
|
|
|
1226 |
$ue1a = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
1227 |
$uec1a = $ccg->create_user_evidence_competency(['userevidenceid' => $ue1a->get('id'),
|
|
|
1228 |
'competencyid' => $comp1->get('id')]);
|
|
|
1229 |
$p1a = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
1230 |
$pc1a = $ccg->create_plan_competency(['planid' => $p1a->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
1231 |
$ucp1a = $ccg->create_user_competency_plan(['userid' => $u1->id, 'planid' => $p1a->get('id'),
|
|
|
1232 |
'competencyid' => $comp1->get('id')]);
|
|
|
1233 |
$uc1a = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp1->get('id')]);
|
|
|
1234 |
$e1a = $ccg->create_evidence(['usercompetencyid' => $uc1a->get('id')]);
|
|
|
1235 |
|
|
|
1236 |
$p2a = $ccg->create_plan(['userid' => $u2->id]);
|
|
|
1237 |
|
|
|
1238 |
// User 2 comments.
|
|
|
1239 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
1240 |
$this->setUser($u2);
|
|
|
1241 |
$p1a->get_comment_object()->add('Hi...');
|
|
|
1242 |
$p2a->get_comment_object()->add('Hi, hi!');
|
|
|
1243 |
$uc1a->get_comment_object()->add('Hi, too!');
|
|
|
1244 |
|
|
|
1245 |
// Confirm state.
|
|
|
1246 |
$this->setAdminUser();
|
|
|
1247 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1248 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1249 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1250 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1251 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1252 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1253 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1254 |
$this->assert_has_comments($p1a->get_comment_object());
|
|
|
1255 |
$this->assertEquals(1, $this->get_comments_count($p1a->get_comment_object(), $u2->id));
|
|
|
1256 |
$this->assert_has_comments($p2a->get_comment_object());
|
|
|
1257 |
$this->assertEquals(1, $this->get_comments_count($p2a->get_comment_object(), $u2->id));
|
|
|
1258 |
$this->assert_has_comments($uc1a->get_comment_object());
|
|
|
1259 |
$this->assertEquals(1, $this->get_comments_count($uc1a->get_comment_object(), $u2->id));
|
|
|
1260 |
|
|
|
1261 |
$this->assertTrue(\core_competency\plan::record_exists($p2a->get('id')));
|
|
|
1262 |
|
|
|
1263 |
// Delete for user 2, but we pass u1 context.
|
|
|
1264 |
$userlist = new approved_userlist($u1ctx, 'core_competency', [$u2->id]);
|
|
|
1265 |
provider::delete_data_for_users($userlist);
|
|
|
1266 |
|
|
|
1267 |
// Nothing should have happened.
|
|
|
1268 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1269 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1270 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1271 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1272 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1273 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1274 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1275 |
$this->assert_has_comments($p1a->get_comment_object());
|
|
|
1276 |
$this->assertEquals(1, $this->get_comments_count($p1a->get_comment_object(), $u2->id));
|
|
|
1277 |
$this->assert_has_comments($p2a->get_comment_object());
|
|
|
1278 |
$this->assertEquals(1, $this->get_comments_count($p2a->get_comment_object(), $u2->id));
|
|
|
1279 |
$this->assert_has_comments($uc1a->get_comment_object());
|
|
|
1280 |
$this->assertEquals(1, $this->get_comments_count($uc1a->get_comment_object(), $u2->id));
|
|
|
1281 |
|
|
|
1282 |
$this->assertTrue(\core_competency\plan::record_exists($p2a->get('id')));
|
|
|
1283 |
|
|
|
1284 |
// Delete for user 2, in user 2 context.
|
|
|
1285 |
$p2acommentobj = $p2a->get_comment_object();
|
|
|
1286 |
$userlist = new approved_userlist($u2ctx, 'core_competency', [$u2->id]);
|
|
|
1287 |
provider::delete_data_for_users($userlist);
|
|
|
1288 |
|
|
|
1289 |
// The plan got deleted.
|
|
|
1290 |
$this->assertFalse(\core_competency\plan::record_exists($p2a->get('id')));
|
|
|
1291 |
$this->assert_has_no_comments($p2acommentobj);
|
|
|
1292 |
|
|
|
1293 |
// Nothing should have happened for u1.
|
|
|
1294 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1295 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1296 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1297 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1298 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1299 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1300 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1301 |
$this->assert_has_comments($p1a->get_comment_object());
|
|
|
1302 |
$this->assertEquals(1, $this->get_comments_count($p1a->get_comment_object(), $u2->id));
|
|
|
1303 |
$this->assert_has_comments($uc1a->get_comment_object());
|
|
|
1304 |
$this->assertEquals(1, $this->get_comments_count($uc1a->get_comment_object(), $u2->id));
|
|
|
1305 |
}
|
|
|
1306 |
|
|
|
1307 |
public function test_delete_data_for_all_users_in_context() {
|
|
|
1308 |
$dg = $this->getDataGenerator();
|
|
|
1309 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
1310 |
|
|
|
1311 |
$c1 = $dg->create_course();
|
|
|
1312 |
$c2 = $dg->create_course();
|
|
|
1313 |
$u1 = $dg->create_user();
|
|
|
1314 |
$u2 = $dg->create_user();
|
|
|
1315 |
|
|
|
1316 |
$c1ctx = \context_course::instance($c1->id);
|
|
|
1317 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
1318 |
$u2ctx = \context_user::instance($u2->id);
|
|
|
1319 |
|
|
|
1320 |
$f = $ccg->create_framework();
|
|
|
1321 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1322 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1323 |
|
|
|
1324 |
$ue1a = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
1325 |
$ue1b = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
1326 |
$ue2 = $ccg->create_user_evidence(['userid' => $u2->id]);
|
|
|
1327 |
$uec1a = $ccg->create_user_evidence_competency(['userevidenceid' => $ue1a->get('id'),
|
|
|
1328 |
'competencyid' => $comp1->get('id')]);
|
|
|
1329 |
$uec1b = $ccg->create_user_evidence_competency(['userevidenceid' => $ue1b->get('id'),
|
|
|
1330 |
'competencyid' => $comp2->get('id')]);
|
|
|
1331 |
$uec2 = $ccg->create_user_evidence_competency(['userevidenceid' => $ue2->get('id'),
|
|
|
1332 |
'competencyid' => $comp1->get('id')]);
|
|
|
1333 |
|
|
|
1334 |
$p1a = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
1335 |
$p1b = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
1336 |
$p2 = $ccg->create_plan(['userid' => $u2->id]);
|
|
|
1337 |
$pc1a = $ccg->create_plan_competency(['planid' => $p1a->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
1338 |
$pc1b = $ccg->create_plan_competency(['planid' => $p1b->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
1339 |
$pc2 = $ccg->create_plan_competency(['planid' => $p2->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
1340 |
$ucp1a = $ccg->create_user_competency_plan(['userid' => $u1->id, 'planid' => $p1a->get('id'),
|
|
|
1341 |
'competencyid' => $comp1->get('id')]);
|
|
|
1342 |
$ucp1b = $ccg->create_user_competency_plan(['userid' => $u1->id, 'planid' => $p1b->get('id'),
|
|
|
1343 |
'competencyid' => $comp2->get('id')]);
|
|
|
1344 |
$ucp2 = $ccg->create_user_competency_plan(['userid' => $u2->id, 'planid' => $p2->get('id'),
|
|
|
1345 |
'competencyid' => $comp1->get('id')]);
|
|
|
1346 |
|
|
|
1347 |
$uc1a = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp1->get('id')]);
|
|
|
1348 |
$uc1b = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp2->get('id')]);
|
|
|
1349 |
$uc2 = $ccg->create_user_competency(['userid' => $u2->id, 'competencyid' => $comp2->get('id')]);
|
|
|
1350 |
$e1a = $ccg->create_evidence(['usercompetencyid' => $uc1a->get('id')]);
|
|
|
1351 |
$e1b = $ccg->create_evidence(['usercompetencyid' => $uc1b->get('id')]);
|
|
|
1352 |
$e2 = $ccg->create_evidence(['usercompetencyid' => $uc2->get('id')]);
|
|
|
1353 |
|
|
|
1354 |
$ucc1a = $ccg->create_user_competency_course(['userid' => $u1->id, 'courseid' => $c1->id,
|
|
|
1355 |
'competencyid' => $comp1->get('id')]);
|
|
|
1356 |
$ucc1b = $ccg->create_user_competency_course(['userid' => $u1->id, 'courseid' => $c2->id,
|
|
|
1357 |
'competencyid' => $comp1->get('id')]);
|
|
|
1358 |
$ucc2 = $ccg->create_user_competency_course(['userid' => $u2->id, 'courseid' => $c1->id,
|
|
|
1359 |
'competencyid' => $comp1->get('id')]);
|
|
|
1360 |
|
|
|
1361 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1362 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1b->get('id')));
|
|
|
1363 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue2->get('id')));
|
|
|
1364 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1365 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1b->get('id')));
|
|
|
1366 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec2->get('id')));
|
|
|
1367 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1368 |
$this->assertTrue(\core_competency\plan::record_exists($p1b->get('id')));
|
|
|
1369 |
$this->assertTrue(\core_competency\plan::record_exists($p2->get('id')));
|
|
|
1370 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1371 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1b->get('id')));
|
|
|
1372 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc2->get('id')));
|
|
|
1373 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1374 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1b->get('id')));
|
|
|
1375 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp2->get('id')));
|
|
|
1376 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1377 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1b->get('id')));
|
|
|
1378 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc2->get('id')));
|
|
|
1379 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1380 |
$this->assertTrue(\core_competency\evidence::record_exists($e1b->get('id')));
|
|
|
1381 |
$this->assertTrue(\core_competency\evidence::record_exists($e2->get('id')));
|
|
|
1382 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1a->get('id')));
|
|
|
1383 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1b->get('id')));
|
|
|
1384 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc2->get('id')));
|
|
|
1385 |
|
|
|
1386 |
// Deleting the course 1 context.
|
|
|
1387 |
provider::delete_data_for_all_users_in_context($c1ctx);
|
|
|
1388 |
$this->assertFalse(\core_competency\user_competency_course::record_exists($ucc1a->get('id')));
|
|
|
1389 |
$this->assertFalse(\core_competency\user_competency_course::record_exists($ucc2->get('id')));
|
|
|
1390 |
|
|
|
1391 |
// Not affected.
|
|
|
1392 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1393 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue1b->get('id')));
|
|
|
1394 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue2->get('id')));
|
|
|
1395 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1396 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec1b->get('id')));
|
|
|
1397 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec2->get('id')));
|
|
|
1398 |
$this->assertTrue(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1399 |
$this->assertTrue(\core_competency\plan::record_exists($p1b->get('id')));
|
|
|
1400 |
$this->assertTrue(\core_competency\plan::record_exists($p2->get('id')));
|
|
|
1401 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1402 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc1b->get('id')));
|
|
|
1403 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc2->get('id')));
|
|
|
1404 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1405 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp1b->get('id')));
|
|
|
1406 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp2->get('id')));
|
|
|
1407 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1408 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc1b->get('id')));
|
|
|
1409 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc2->get('id')));
|
|
|
1410 |
$this->assertTrue(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1411 |
$this->assertTrue(\core_competency\evidence::record_exists($e1b->get('id')));
|
|
|
1412 |
$this->assertTrue(\core_competency\evidence::record_exists($e2->get('id')));
|
|
|
1413 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1b->get('id')));
|
|
|
1414 |
|
|
|
1415 |
// Deleting the user 1 context.
|
|
|
1416 |
provider::delete_data_for_all_users_in_context($u1ctx);
|
|
|
1417 |
$this->assertFalse(\core_competency\user_evidence::record_exists($ue1a->get('id')));
|
|
|
1418 |
$this->assertFalse(\core_competency\user_evidence::record_exists($ue1b->get('id')));
|
|
|
1419 |
$this->assertFalse(\core_competency\user_evidence_competency::record_exists($uec1a->get('id')));
|
|
|
1420 |
$this->assertFalse(\core_competency\user_evidence_competency::record_exists($uec1b->get('id')));
|
|
|
1421 |
$this->assertFalse(\core_competency\plan::record_exists($p1a->get('id')));
|
|
|
1422 |
$this->assertFalse(\core_competency\plan::record_exists($p1b->get('id')));
|
|
|
1423 |
$this->assertFalse(\core_competency\plan_competency::record_exists($pc1a->get('id')));
|
|
|
1424 |
$this->assertFalse(\core_competency\plan_competency::record_exists($pc1b->get('id')));
|
|
|
1425 |
$this->assertFalse(\core_competency\user_competency_plan::record_exists($ucp1a->get('id')));
|
|
|
1426 |
$this->assertFalse(\core_competency\user_competency_plan::record_exists($ucp1b->get('id')));
|
|
|
1427 |
$this->assertFalse(\core_competency\user_competency::record_exists($uc1a->get('id')));
|
|
|
1428 |
$this->assertFalse(\core_competency\user_competency::record_exists($uc1b->get('id')));
|
|
|
1429 |
$this->assertFalse(\core_competency\evidence::record_exists($e1a->get('id')));
|
|
|
1430 |
$this->assertFalse(\core_competency\evidence::record_exists($e1b->get('id')));
|
|
|
1431 |
|
|
|
1432 |
// Not affected.
|
|
|
1433 |
$this->assertTrue(\core_competency\user_evidence::record_exists($ue2->get('id')));
|
|
|
1434 |
$this->assertTrue(\core_competency\user_evidence_competency::record_exists($uec2->get('id')));
|
|
|
1435 |
$this->assertTrue(\core_competency\plan::record_exists($p2->get('id')));
|
|
|
1436 |
$this->assertTrue(\core_competency\plan_competency::record_exists($pc2->get('id')));
|
|
|
1437 |
$this->assertTrue(\core_competency\user_competency_plan::record_exists($ucp2->get('id')));
|
|
|
1438 |
$this->assertTrue(\core_competency\user_competency::record_exists($uc2->get('id')));
|
|
|
1439 |
$this->assertTrue(\core_competency\evidence::record_exists($e2->get('id')));
|
|
|
1440 |
$this->assertTrue(\core_competency\user_competency_course::record_exists($ucc1b->get('id')));
|
|
|
1441 |
}
|
|
|
1442 |
|
|
|
1443 |
public function test_export_data_for_user_in_module_context_where_usermodified_matches() {
|
|
|
1444 |
$dg = $this->getDataGenerator();
|
|
|
1445 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
1446 |
|
|
|
1447 |
$c1 = $dg->create_course();
|
|
|
1448 |
$u1 = $dg->create_user();
|
|
|
1449 |
$u2 = $dg->create_user();
|
|
|
1450 |
$m1 = $dg->create_module('page', ['course' => $c1]);
|
|
|
1451 |
$m2 = $dg->create_module('page', ['course' => $c1]);
|
|
|
1452 |
|
|
|
1453 |
$m1ctx = \context_module::instance($m1->cmid);
|
|
|
1454 |
$m2ctx = \context_module::instance($m2->cmid);
|
|
|
1455 |
|
|
|
1456 |
$f = $ccg->create_framework();
|
|
|
1457 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1458 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1459 |
$comp3 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1460 |
$ccg->create_course_module_competency(['competencyid' => $comp3->get('id'), 'cmid' => $m1->cmid]);
|
|
|
1461 |
|
|
|
1462 |
$this->setUser($u1);
|
|
|
1463 |
$ccg->create_course_module_competency(['competencyid' => $comp1->get('id'), 'cmid' => $m1->cmid]);
|
|
|
1464 |
$ccg->create_course_module_competency(['competencyid' => $comp2->get('id'), 'cmid' => $m2->cmid]);
|
|
|
1465 |
|
|
|
1466 |
$this->setUser($u2);
|
|
|
1467 |
$ccg->create_course_module_competency(['competencyid' => $comp3->get('id'), 'cmid' => $m2->cmid]);
|
|
|
1468 |
|
|
|
1469 |
// Export.
|
|
|
1470 |
$this->setAdminUser();
|
|
|
1471 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$m1ctx->id]));
|
|
|
1472 |
|
|
|
1473 |
// Check exported context 1.
|
|
|
1474 |
$data = writer::with_context($m1ctx)->get_data([get_string('competencies', 'core_competency')]);
|
|
|
1475 |
$this->assertCount(1, $data->associations);
|
|
|
1476 |
$this->assertEquals(transform::yesno(true), $data->associations[0]['created_or_modified_by_you']);
|
|
|
1477 |
|
|
|
1478 |
// Check exported context 2.
|
|
|
1479 |
$data = writer::with_context($m2ctx)->get_data([get_string('competencies', 'core_competency')]);
|
|
|
1480 |
$this->assertEmpty($data);
|
|
|
1481 |
|
|
|
1482 |
// Export both contexts.
|
|
|
1483 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$m1ctx->id, $m2ctx->id]));
|
|
|
1484 |
|
|
|
1485 |
// Check exported context 1.
|
|
|
1486 |
$data = writer::with_context($m1ctx)->get_data([get_string('competencies', 'core_competency')]);
|
|
|
1487 |
$this->assertCount(1, $data->associations);
|
|
|
1488 |
$this->assertEquals($comp1->get('shortname'), $data->associations[0]['name']);
|
|
|
1489 |
$this->assertEquals(transform::yesno(true), $data->associations[0]['created_or_modified_by_you']);
|
|
|
1490 |
|
|
|
1491 |
// Check exported context 2.
|
|
|
1492 |
$data = writer::with_context($m2ctx)->get_data([get_string('competencies', 'core_competency')]);
|
|
|
1493 |
$this->assertCount(1, $data->associations);
|
|
|
1494 |
$this->assertEquals($comp2->get('shortname'), $data->associations[0]['name']);
|
|
|
1495 |
$this->assertEquals(transform::yesno(true), $data->associations[0]['created_or_modified_by_you']);
|
|
|
1496 |
}
|
|
|
1497 |
|
|
|
1498 |
public function test_export_data_for_user_in_course_context_where_usermodified_matches() {
|
|
|
1499 |
$dg = $this->getDataGenerator();
|
|
|
1500 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
1501 |
|
|
|
1502 |
$c1 = $dg->create_course();
|
|
|
1503 |
$c2 = $dg->create_course();
|
|
|
1504 |
$u0 = $dg->create_user();
|
|
|
1505 |
$u1 = $dg->create_user();
|
|
|
1506 |
$u2 = $dg->create_user();
|
|
|
1507 |
$u3 = $dg->create_user();
|
|
|
1508 |
$u4 = $dg->create_user();
|
|
|
1509 |
|
|
|
1510 |
$c1ctx = \context_course::instance($c1->id);
|
|
|
1511 |
$c2ctx = \context_course::instance($c2->id);
|
|
|
1512 |
|
|
|
1513 |
$f = $ccg->create_framework();
|
|
|
1514 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1515 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1516 |
$comp3 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1517 |
$comp4 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1518 |
$ccg->create_course_competency(['competencyid' => $comp3->get('id'), 'courseid' => $c1->id]);
|
|
|
1519 |
$ccg->create_user_competency_course(['competencyid' => $comp3->get('id'), 'courseid' => $c1->id, 'userid' => $u0->id]);
|
|
|
1520 |
|
|
|
1521 |
$this->setUser($u1);
|
|
|
1522 |
$ccg->create_course_competency(['competencyid' => $comp1->get('id'), 'courseid' => $c1->id]);
|
|
|
1523 |
$ccg->create_course_competency(['competencyid' => $comp4->get('id'), 'courseid' => $c1->id]);
|
|
|
1524 |
$ccg->create_course_competency(['competencyid' => $comp2->get('id'), 'courseid' => $c2->id]);
|
|
|
1525 |
$ccg->create_user_competency_course(['competencyid' => $comp1->get('id'), 'courseid' => $c1->id, 'userid' => $u0->id]);
|
|
|
1526 |
$ccg->create_user_competency_course(['competencyid' => $comp4->get('id'), 'courseid' => $c1->id, 'userid' => $u0->id]);
|
|
|
1527 |
$ccg->create_user_competency_course(['competencyid' => $comp2->get('id'), 'courseid' => $c2->id, 'userid' => $u0->id]);
|
|
|
1528 |
$ccs = new \core_competency\course_competency_settings(null, (object) ['courseid' => $c1->id]);
|
|
|
1529 |
$ccs->create();
|
|
|
1530 |
|
|
|
1531 |
$this->setUser($u2);
|
|
|
1532 |
$ccg->create_course_competency(['competencyid' => $comp3->get('id'), 'courseid' => $c2->id]);
|
|
|
1533 |
$ccg->create_user_competency_course(['competencyid' => $comp3->get('id'), 'courseid' => $c2->id, 'userid' => $u0->id]);
|
|
|
1534 |
$ccs = new \core_competency\course_competency_settings(null, (object) ['courseid' => $c2->id]);
|
|
|
1535 |
$ccs->create();
|
|
|
1536 |
|
|
|
1537 |
// Export.
|
|
|
1538 |
$this->setAdminUser();
|
|
|
1539 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$c1ctx->id]));
|
|
|
1540 |
|
|
|
1541 |
// Check exported context 1.
|
|
|
1542 |
$data = writer::with_context($c1ctx)->get_related_data([get_string('competencies', 'core_competency')], 'associations');
|
|
|
1543 |
$this->assertCount(2, $data->competencies);
|
|
|
1544 |
$this->assertEquals($comp1->get('shortname'), $data->competencies[0]['name']);
|
|
|
1545 |
$this->assertEquals(transform::yesno(true), $data->competencies[0]['created_or_modified_by_you']);
|
|
|
1546 |
$this->assertEquals($comp4->get('shortname'), $data->competencies[1]['name']);
|
|
|
1547 |
$this->assertEquals(transform::yesno(true), $data->competencies[1]['created_or_modified_by_you']);
|
|
|
1548 |
$data = writer::with_context($c1ctx)->get_related_data([get_string('competencies', 'core_competency')], 'settings');
|
|
|
1549 |
$this->assertEquals(transform::yesno(true), $data->created_or_modified_by_you);
|
|
|
1550 |
$data = writer::with_context($c1ctx)->get_related_data([get_string('competencies', 'core_competency')], 'rated_by_me');
|
|
|
1551 |
$this->assertCount(2, $data->ratings);
|
|
|
1552 |
$this->assertEquals($comp1->get('shortname'), $data->ratings[0]['name']);
|
|
|
1553 |
$this->assertEquals($comp4->get('shortname'), $data->ratings[1]['name']);
|
|
|
1554 |
|
|
|
1555 |
// Check exported context 2.
|
|
|
1556 |
$data = writer::with_context($c2ctx)->get_related_data([get_string('competencies', 'core_competency')], 'associations');
|
|
|
1557 |
$this->assertEmpty($data);
|
|
|
1558 |
$data = writer::with_context($c2ctx)->get_related_data([get_string('competencies', 'core_competency')], 'settings');
|
|
|
1559 |
$this->assertEmpty($data);
|
|
|
1560 |
$data = writer::with_context($c2ctx)->get_related_data([get_string('competencies', 'core_competency')], 'rated_by_me');
|
|
|
1561 |
$this->assertEmpty($data);
|
|
|
1562 |
|
|
|
1563 |
// Export both contexts.
|
|
|
1564 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$c1ctx->id, $c2ctx->id]));
|
|
|
1565 |
|
|
|
1566 |
// Check exported context 1.
|
|
|
1567 |
$data = writer::with_context($c1ctx)->get_related_data([get_string('competencies', 'core_competency')], 'associations');
|
|
|
1568 |
$this->assertCount(2, $data->competencies);
|
|
|
1569 |
$this->assertEquals($comp1->get('shortname'), $data->competencies[0]['name']);
|
|
|
1570 |
$this->assertEquals(transform::yesno(true), $data->competencies[0]['created_or_modified_by_you']);
|
|
|
1571 |
$this->assertEquals($comp4->get('shortname'), $data->competencies[1]['name']);
|
|
|
1572 |
$this->assertEquals(transform::yesno(true), $data->competencies[1]['created_or_modified_by_you']);
|
|
|
1573 |
$data = writer::with_context($c1ctx)->get_related_data([get_string('competencies', 'core_competency')], 'settings');
|
|
|
1574 |
$this->assertEquals(transform::yesno(true), $data->created_or_modified_by_you);
|
|
|
1575 |
$data = writer::with_context($c1ctx)->get_related_data([get_string('competencies', 'core_competency')], 'rated_by_me');
|
|
|
1576 |
$this->assertCount(2, $data->ratings);
|
|
|
1577 |
$this->assertEquals($comp1->get('shortname'), $data->ratings[0]['name']);
|
|
|
1578 |
$this->assertEquals($comp4->get('shortname'), $data->ratings[1]['name']);
|
|
|
1579 |
|
|
|
1580 |
// Check exported context 2.
|
|
|
1581 |
$data = writer::with_context($c2ctx)->get_related_data([get_string('competencies', 'core_competency')], 'associations');
|
|
|
1582 |
$this->assertCount(1, $data->competencies);
|
|
|
1583 |
$this->assertEquals($comp2->get('shortname'), $data->competencies[0]['name']);
|
|
|
1584 |
$this->assertEquals(transform::yesno(true), $data->competencies[0]['created_or_modified_by_you']);
|
|
|
1585 |
$data = writer::with_context($c2ctx)->get_related_data([get_string('competencies', 'core_competency')], 'settings');
|
|
|
1586 |
$this->assertEmpty($data);
|
|
|
1587 |
$data = writer::with_context($c2ctx)->get_related_data([get_string('competencies', 'core_competency')], 'rated_by_me');
|
|
|
1588 |
$this->assertCount(1, $data->ratings);
|
|
|
1589 |
$this->assertEquals($comp2->get('shortname'), $data->ratings[0]['name']);
|
|
|
1590 |
}
|
|
|
1591 |
|
|
|
1592 |
public function test_export_data_for_user_in_course_context_with_real_data() {
|
|
|
1593 |
$dg = $this->getDataGenerator();
|
|
|
1594 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
1595 |
|
|
|
1596 |
$c1 = $dg->create_course();
|
|
|
1597 |
$c2 = $dg->create_course();
|
|
|
1598 |
$u1 = $dg->create_user();
|
|
|
1599 |
$u2 = $dg->create_user();
|
|
|
1600 |
|
|
|
1601 |
$c1ctx = \context_course::instance($c1->id);
|
|
|
1602 |
$c2ctx = \context_course::instance($c2->id);
|
|
|
1603 |
|
|
|
1604 |
$f = $ccg->create_framework();
|
|
|
1605 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1606 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1607 |
$comp3 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1608 |
|
|
|
1609 |
$ccg->create_user_competency_course(['competencyid' => $comp1->get('id'), 'courseid' => $c1->id,
|
|
|
1610 |
'userid' => $u1->id, 'grade' => 1, 'proficiency' => true]);
|
|
|
1611 |
$ccg->create_user_competency_course(['competencyid' => $comp2->get('id'), 'courseid' => $c1->id,
|
|
|
1612 |
'userid' => $u1->id, 'grade' => 2, 'proficiency' => false]);
|
|
|
1613 |
$ccg->create_user_competency_course(['competencyid' => $comp2->get('id'), 'courseid' => $c2->id,
|
|
|
1614 |
'userid' => $u1->id, 'grade' => 3, 'proficiency' => false]);
|
|
|
1615 |
$ccg->create_user_competency_course(['competencyid' => $comp3->get('id'), 'courseid' => $c2->id,
|
|
|
1616 |
'userid' => $u1->id]);
|
|
|
1617 |
|
|
|
1618 |
$ccg->create_user_competency_course(['competencyid' => $comp3->get('id'), 'courseid' => $c1->id, 'userid' => $u2->id]);
|
|
|
1619 |
$ccg->create_user_competency_course(['competencyid' => $comp3->get('id'), 'courseid' => $c2->id, 'userid' => $u2->id]);
|
|
|
1620 |
|
|
|
1621 |
// Export user 1, in course 1.
|
|
|
1622 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$c1ctx->id]));
|
|
|
1623 |
|
|
|
1624 |
// Check course 1.
|
|
|
1625 |
$data = writer::with_context($c1ctx)->get_data([get_string('competencies', 'core_competency')]);
|
|
|
1626 |
$this->assertCount(2, $data->ratings);
|
|
|
1627 |
$this->assertEquals($comp1->get('shortname'), $data->ratings[0]['name']);
|
|
|
1628 |
$this->assertEquals('A', $data->ratings[0]['rating']['rating']);
|
|
|
1629 |
$this->assertEquals(transform::yesno(true), $data->ratings[0]['rating']['proficient']);
|
|
|
1630 |
$this->assertEquals($comp2->get('shortname'), $data->ratings[1]['name']);
|
|
|
1631 |
$this->assertEquals('B', $data->ratings[1]['rating']['rating']);
|
|
|
1632 |
$this->assertEquals(transform::yesno(false), $data->ratings[1]['rating']['proficient']);
|
|
|
1633 |
|
|
|
1634 |
// Check course 2.
|
|
|
1635 |
$data = writer::with_context($c2ctx)->get_data([get_string('competencies', 'core_competency')]);
|
|
|
1636 |
$this->assertEmpty($data);
|
|
|
1637 |
|
|
|
1638 |
// Export user 1, in course 2.
|
|
|
1639 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$c2ctx->id]));
|
|
|
1640 |
$data = writer::with_context($c2ctx)->get_data([get_string('competencies', 'core_competency')]);
|
|
|
1641 |
$this->assertCount(2, $data->ratings);
|
|
|
1642 |
$this->assertEquals($comp2->get('shortname'), $data->ratings[0]['name']);
|
|
|
1643 |
$this->assertEquals('C', $data->ratings[0]['rating']['rating']);
|
|
|
1644 |
$this->assertEquals(transform::yesno(false), $data->ratings[0]['rating']['proficient']);
|
|
|
1645 |
$this->assertEquals($comp3->get('shortname'), $data->ratings[1]['name']);
|
|
|
1646 |
$this->assertEquals('-', $data->ratings[1]['rating']['rating']);
|
|
|
1647 |
$this->assertEquals('-', $data->ratings[1]['rating']['proficient']);
|
|
|
1648 |
}
|
|
|
1649 |
|
|
|
1650 |
public function test_export_data_for_user_in_system_and_category_contexts() {
|
|
|
1651 |
$dg = $this->getDataGenerator();
|
|
|
1652 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
1653 |
|
|
|
1654 |
$c1 = $dg->create_cohort();
|
|
|
1655 |
$c2 = $dg->create_cohort();
|
|
|
1656 |
$cat1 = $dg->create_category();
|
|
|
1657 |
$cat2 = $dg->create_category();
|
|
|
1658 |
|
|
|
1659 |
$cat1ctx = \context_coursecat::instance($cat1->id);
|
|
|
1660 |
$cat2ctx = \context_coursecat::instance($cat2->id);
|
|
|
1661 |
$sysctx = \context_system::instance();
|
|
|
1662 |
|
|
|
1663 |
$u1 = $dg->create_user();
|
|
|
1664 |
$u2 = $dg->create_user();
|
|
|
1665 |
$u3 = $dg->create_user();
|
|
|
1666 |
$u4 = $dg->create_user();
|
|
|
1667 |
$u2 = $dg->create_user();
|
|
|
1668 |
|
|
|
1669 |
$this->setUser($u1);
|
|
|
1670 |
$f1 = $ccg->create_framework();
|
|
|
1671 |
$f1bis = $ccg->create_framework();
|
|
|
1672 |
$f2 = $ccg->create_framework(['contextid' => $cat1ctx->id]);
|
|
|
1673 |
$c2a = $ccg->create_competency(['competencyframeworkid' => $f2->get('id')]);
|
|
|
1674 |
$c2b = $ccg->create_competency(['competencyframeworkid' => $f2->get('id')]);
|
|
|
1675 |
|
|
|
1676 |
$t1 = $ccg->create_template();
|
|
|
1677 |
$t2 = $ccg->create_template(['contextid' => $cat1ctx->id]);
|
|
|
1678 |
$tc2a = $ccg->create_template_competency(['templateid' => $t2->get('id'), 'competencyid' => $c2a->get('id')]);
|
|
|
1679 |
$tch2 = $ccg->create_template_cohort(['templateid' => $t2->get('id'), 'cohortid' => $c1->id]);
|
|
|
1680 |
|
|
|
1681 |
$this->setUser($u2);
|
|
|
1682 |
$f3 = $ccg->create_framework(['contextid' => $cat2ctx->id]);
|
|
|
1683 |
$c1a = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
|
|
|
1684 |
$c1b = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
|
|
|
1685 |
$c3a = $ccg->create_competency(['competencyframeworkid' => $f3->get('id')]);
|
|
|
1686 |
$c3b = $ccg->create_competency(['competencyframeworkid' => $f3->get('id')]);
|
|
|
1687 |
$c3c = $ccg->create_competency(['competencyframeworkid' => $f3->get('id')]);
|
|
|
1688 |
$c3d = $ccg->create_competency(['competencyframeworkid' => $f3->get('id')]);
|
|
|
1689 |
$rc1 = $ccg->create_related_competency(['competencyid' => $c2a->get('id'), 'relatedcompetencyid' => $c2b->get('id')]);
|
|
|
1690 |
|
|
|
1691 |
$t3 = $ccg->create_template(['contextid' => $cat2ctx->id]);
|
|
|
1692 |
$tch1 = $ccg->create_template_cohort(['templateid' => $t1->get('id'), 'cohortid' => $c2->id]);
|
|
|
1693 |
$tc1a = $ccg->create_template_competency(['templateid' => $t1->get('id'), 'competencyid' => $c1a->get('id')]);
|
|
|
1694 |
$tc1b = $ccg->create_template_competency(['templateid' => $t1->get('id'), 'competencyid' => $c2a->get('id')]);
|
|
|
1695 |
$tc3a = $ccg->create_template_competency(['templateid' => $t3->get('id'), 'competencyid' => $c3a->get('id')]);
|
|
|
1696 |
|
|
|
1697 |
$this->setUser($u1);
|
|
|
1698 |
$rc2 = $ccg->create_related_competency(['competencyid' => $c3a->get('id'), 'relatedcompetencyid' => $c3b->get('id')]);
|
|
|
1699 |
$rc3 = $ccg->create_related_competency(['competencyid' => $c3a->get('id'), 'relatedcompetencyid' => $c3c->get('id')]);
|
|
|
1700 |
|
|
|
1701 |
$this->setAdminUser();
|
|
|
1702 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$sysctx->id, $cat1ctx->id, $cat2ctx->id]));
|
|
|
1703 |
|
|
|
1704 |
// Check frameworks for u1 in system.
|
|
|
1705 |
$data = writer::with_context($sysctx)->get_related_data([get_string('competencies', 'core_competency')], 'frameworks');
|
|
|
1706 |
$this->assertCount(2, $data->frameworks);
|
|
|
1707 |
$this->assertEquals($f1->get('shortname'), $data->frameworks[0]['name']);
|
|
|
1708 |
$this->assertEquals(transform::yesno(true), $data->frameworks[0]['created_or_modified_by_you']);
|
|
|
1709 |
$this->assertEquals($f1bis->get('shortname'), $data->frameworks[1]['name']);
|
|
|
1710 |
$this->assertEquals(transform::yesno(true), $data->frameworks[1]['created_or_modified_by_you']);
|
|
|
1711 |
$this->assertEmpty($data->frameworks[0]['competencies']);
|
|
|
1712 |
$this->assertEmpty($data->frameworks[1]['competencies']);
|
|
|
1713 |
|
|
|
1714 |
// Check templates for u1 in system.
|
|
|
1715 |
$data = writer::with_context($sysctx)->get_related_data([get_string('competencies', 'core_competency')], 'templates');
|
|
|
1716 |
$this->assertCount(1, $data->templates);
|
|
|
1717 |
$this->assertEquals($t1->get('shortname'), $data->templates[0]['name']);
|
|
|
1718 |
$this->assertEquals(transform::yesno(true), $data->templates[0]['created_or_modified_by_you']);
|
|
|
1719 |
$this->assertEmpty($data->templates[0]['competencies']);
|
|
|
1720 |
$this->assertEmpty($data->templates[0]['cohorts']);
|
|
|
1721 |
|
|
|
1722 |
// Check frameworks for u1 in cat1.
|
|
|
1723 |
$data = writer::with_context($cat1ctx)->get_related_data([get_string('competencies', 'core_competency')], 'frameworks');
|
|
|
1724 |
$this->assertCount(1, $data->frameworks);
|
|
|
1725 |
$this->assertEquals($f2->get('shortname'), $data->frameworks[0]['name']);
|
|
|
1726 |
$this->assertEquals(transform::yesno(true), $data->frameworks[0]['created_or_modified_by_you']);
|
|
|
1727 |
$this->assertCount(2, $data->frameworks[0]['competencies']);
|
|
|
1728 |
$this->assertEquals($c2a->get('shortname'), $data->frameworks[0]['competencies'][0]['name']);
|
|
|
1729 |
$this->assertEquals(transform::yesno(true), $data->frameworks[0]['competencies'][0]['created_or_modified_by_you']);
|
|
|
1730 |
$this->assertEquals($c2b->get('shortname'), $data->frameworks[0]['competencies'][1]['name']);
|
|
|
1731 |
$this->assertEquals(transform::yesno(true), $data->frameworks[0]['competencies'][1]['created_or_modified_by_you']);
|
|
|
1732 |
|
|
|
1733 |
// Check templates for u1 in cat1.
|
|
|
1734 |
$data = writer::with_context($cat1ctx)->get_related_data([get_string('competencies', 'core_competency')], 'templates');
|
|
|
1735 |
$this->assertCount(1, $data->templates);
|
|
|
1736 |
$this->assertEquals($t2->get('shortname'), $data->templates[0]['name']);
|
|
|
1737 |
$this->assertEquals(transform::yesno(true), $data->templates[0]['created_or_modified_by_you']);
|
|
|
1738 |
$this->assertCount(1, $data->templates[0]['competencies']);
|
|
|
1739 |
$this->assertEquals($c2a->get('shortname'), $data->templates[0]['competencies'][0]['name']);
|
|
|
1740 |
$this->assertEquals(transform::yesno(true), $data->templates[0]['competencies'][0]['created_or_modified_by_you']);
|
|
|
1741 |
$this->assertCount(1, $data->templates[0]['cohorts']);
|
|
|
1742 |
$this->assertEquals($c1->name, $data->templates[0]['cohorts'][0]['name']);
|
|
|
1743 |
$this->assertEquals(transform::yesno(true), $data->templates[0]['cohorts'][0]['created_or_modified_by_you']);
|
|
|
1744 |
|
|
|
1745 |
// Check frameworks for u1 in cat2.
|
|
|
1746 |
$data = writer::with_context($cat2ctx)->get_related_data([get_string('competencies', 'core_competency')], 'frameworks');
|
|
|
1747 |
$this->assertCount(1, $data->frameworks);
|
|
|
1748 |
$this->assertEquals($f3->get('shortname'), $data->frameworks[0]['name']);
|
|
|
1749 |
$this->assertEquals(transform::yesno(false), $data->frameworks[0]['created_or_modified_by_you']);
|
|
|
1750 |
$this->assertCount(3, $data->frameworks[0]['competencies']);
|
|
|
1751 |
$competency = $data->frameworks[0]['competencies'][0];
|
|
|
1752 |
$this->assertEquals($c3a->get('shortname'), $competency['name']);
|
|
|
1753 |
$this->assertEquals(transform::yesno(false), $competency['created_or_modified_by_you']);
|
|
|
1754 |
$this->assertCount(2, $competency['related_competencies']);
|
|
|
1755 |
$this->assertEquals($c3b->get('shortname'), $competency['related_competencies'][0]['name']);
|
|
|
1756 |
$this->assertEquals(transform::yesno(true), $competency['related_competencies'][0]['created_or_modified_by_you']);
|
|
|
1757 |
$this->assertEquals($c3c->get('shortname'), $competency['related_competencies'][1]['name']);
|
|
|
1758 |
$this->assertEquals(transform::yesno(true), $competency['related_competencies'][1]['created_or_modified_by_you']);
|
|
|
1759 |
$competency = $data->frameworks[0]['competencies'][1];
|
|
|
1760 |
$this->assertEquals($c3b->get('shortname'), $competency['name']);
|
|
|
1761 |
$this->assertCount(1, $competency['related_competencies']);
|
|
|
1762 |
$competency = $data->frameworks[0]['competencies'][2];
|
|
|
1763 |
$this->assertEquals($c3c->get('shortname'), $competency['name']);
|
|
|
1764 |
$this->assertCount(1, $competency['related_competencies']);
|
|
|
1765 |
|
|
|
1766 |
// Check templates for u1 in cat2.
|
|
|
1767 |
$data = writer::with_context($cat2ctx)->get_related_data([get_string('competencies', 'core_competency')], 'templates');
|
|
|
1768 |
$this->assertEmpty($data->templates);
|
|
|
1769 |
|
|
|
1770 |
provider::export_user_data(new approved_contextlist($u2, 'core_competency', [$sysctx->id, $cat1ctx->id, $cat2ctx->id]));
|
|
|
1771 |
|
|
|
1772 |
// Check frameworks for u2 in system.
|
|
|
1773 |
$data = writer::with_context($sysctx)->get_related_data([get_string('competencies', 'core_competency')], 'frameworks');
|
|
|
1774 |
$this->assertCount(1, $data->frameworks);
|
|
|
1775 |
$this->assertEquals($f1->get('shortname'), $data->frameworks[0]['name']);
|
|
|
1776 |
$this->assertEquals(transform::yesno(false), $data->frameworks[0]['created_or_modified_by_you']);
|
|
|
1777 |
$this->assertCount(2, $data->frameworks[0]['competencies']);
|
|
|
1778 |
$competency = $data->frameworks[0]['competencies'][0];
|
|
|
1779 |
$this->assertEquals($c1a->get('shortname'), $competency['name']);
|
|
|
1780 |
$this->assertEquals(transform::yesno(true), $competency['created_or_modified_by_you']);
|
|
|
1781 |
$competency = $data->frameworks[0]['competencies'][1];
|
|
|
1782 |
$this->assertEquals($c1b->get('shortname'), $competency['name']);
|
|
|
1783 |
$this->assertEquals(transform::yesno(true), $competency['created_or_modified_by_you']);
|
|
|
1784 |
|
|
|
1785 |
// Check templates for u2 in system.
|
|
|
1786 |
$data = writer::with_context($sysctx)->get_related_data([get_string('competencies', 'core_competency')], 'templates');
|
|
|
1787 |
$this->assertCount(1, $data->templates);
|
|
|
1788 |
$this->assertEquals($t1->get('shortname'), $data->templates[0]['name']);
|
|
|
1789 |
$this->assertEquals(transform::yesno(false), $data->templates[0]['created_or_modified_by_you']);
|
|
|
1790 |
$this->assertCount(2, $data->templates[0]['competencies']);
|
|
|
1791 |
$competency = $data->templates[0]['competencies'][0];
|
|
|
1792 |
$this->assertEquals($c1a->get('shortname'), $competency['name']);
|
|
|
1793 |
$this->assertEquals(transform::yesno(true), $competency['created_or_modified_by_you']);
|
|
|
1794 |
$competency = $data->templates[0]['competencies'][1];
|
|
|
1795 |
$this->assertEquals($c2a->get('shortname'), $competency['name']);
|
|
|
1796 |
$this->assertEquals(transform::yesno(true), $competency['created_or_modified_by_you']);
|
|
|
1797 |
$this->assertCount(1, $data->templates[0]['cohorts']);
|
|
|
1798 |
$this->assertEquals($c2->name, $data->templates[0]['cohorts'][0]['name']);
|
|
|
1799 |
$this->assertEquals(transform::yesno(true), $data->templates[0]['cohorts'][0]['created_or_modified_by_you']);
|
|
|
1800 |
|
|
|
1801 |
// Check frameworks for u2 in cat1.
|
|
|
1802 |
$data = writer::with_context($cat1ctx)->get_related_data([get_string('competencies', 'core_competency')], 'frameworks');
|
|
|
1803 |
$this->assertCount(1, $data->frameworks);
|
|
|
1804 |
$this->assertEquals(transform::yesno(false), $data->frameworks[0]['created_or_modified_by_you']);
|
|
|
1805 |
$this->assertCount(2, $data->frameworks[0]['competencies']);
|
|
|
1806 |
$competency = $data->frameworks[0]['competencies'][0];
|
|
|
1807 |
$this->assertEquals($c2a->get('shortname'), $competency['name']);
|
|
|
1808 |
$this->assertEquals(transform::yesno(false), $competency['created_or_modified_by_you']);
|
|
|
1809 |
$this->assertCount(1, $competency['related_competencies']);
|
|
|
1810 |
$this->assertEquals($c2b->get('shortname'), $competency['related_competencies'][0]['name']);
|
|
|
1811 |
$this->assertEquals(transform::yesno(true), $competency['related_competencies'][0]['created_or_modified_by_you']);
|
|
|
1812 |
|
|
|
1813 |
// Check templates for u2 in system.
|
|
|
1814 |
$data = writer::with_context($cat2ctx)->get_related_data([get_string('competencies', 'core_competency')], 'templates');
|
|
|
1815 |
$this->assertCount(1, $data->templates);
|
|
|
1816 |
$this->assertEquals($t3->get('shortname'), $data->templates[0]['name']);
|
|
|
1817 |
$this->assertEquals(transform::yesno(true), $data->templates[0]['created_or_modified_by_you']);
|
|
|
1818 |
$this->assertCount(1, $data->templates[0]['competencies']);
|
|
|
1819 |
$competency = $data->templates[0]['competencies'][0];
|
|
|
1820 |
$this->assertEquals($c3a->get('shortname'), $competency['name']);
|
|
|
1821 |
$this->assertEquals(transform::yesno(true), $competency['created_or_modified_by_you']);
|
|
|
1822 |
}
|
|
|
1823 |
|
|
|
1824 |
public function test_export_data_for_user_with_related_learning_plans() {
|
|
|
1825 |
global $DB;
|
|
|
1826 |
|
|
|
1827 |
$path = [
|
|
|
1828 |
get_string('competencies', 'core_competency'),
|
|
|
1829 |
get_string('privacy:path:relatedtome', 'core_competency'),
|
|
|
1830 |
get_string('privacy:path:plans', 'core_competency'),
|
|
|
1831 |
];
|
|
|
1832 |
$yes = transform::yesno(true);
|
|
|
1833 |
$no = transform::yesno(false);
|
|
|
1834 |
|
|
|
1835 |
$dg = $this->getDataGenerator();
|
|
|
1836 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
1837 |
|
|
|
1838 |
$u0 = $dg->create_user();
|
|
|
1839 |
$u1 = $dg->create_user();
|
|
|
1840 |
$u2 = $dg->create_user();
|
|
|
1841 |
$u3 = $dg->create_user();
|
|
|
1842 |
$u4 = $dg->create_user();
|
|
|
1843 |
$u5 = $dg->create_user();
|
|
|
1844 |
$u6 = $dg->create_user();
|
|
|
1845 |
$u7 = $dg->create_user();
|
|
|
1846 |
$u8 = $dg->create_user();
|
|
|
1847 |
|
|
|
1848 |
$dg->role_assign($DB->get_field('role', 'id', ['archetype' => 'manager'], IGNORE_MULTIPLE), $u6->id);
|
|
|
1849 |
$u0ctx = \context_user::instance($u0->id);
|
|
|
1850 |
|
|
|
1851 |
$f = $ccg->create_framework();
|
|
|
1852 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1853 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1854 |
$comp3 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1855 |
$comp4 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
1856 |
|
|
|
1857 |
$t = $ccg->create_template();
|
|
|
1858 |
$tc1 = $ccg->create_template_competency(['competencyid' => $comp1->get('id'), 'templateid' => $t->get('id')]);
|
|
|
1859 |
$tc2 = $ccg->create_template_competency(['competencyid' => $comp2->get('id'), 'templateid' => $t->get('id')]);
|
|
|
1860 |
$tc3 = $ccg->create_template_competency(['competencyid' => $comp3->get('id'), 'templateid' => $t->get('id')]);
|
|
|
1861 |
$tc4 = $ccg->create_template_competency(['competencyid' => $comp4->get('id'), 'templateid' => $t->get('id')]);
|
|
|
1862 |
|
|
|
1863 |
$this->setUser($u1);
|
|
|
1864 |
$p1 = $ccg->create_plan(['templateid' => $t->get('id'), 'userid' => $u0->id]);
|
|
|
1865 |
|
|
|
1866 |
$this->setUser($u2);
|
|
|
1867 |
$p2 = $ccg->create_plan(['userid' => $u0->id, 'reviewerid' => $u7->id]);
|
|
|
1868 |
|
|
|
1869 |
$this->setUser($u3);
|
|
|
1870 |
$p1c1 = $ccg->create_plan_competency(['planid' => $p1->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
1871 |
$p2c2 = $ccg->create_plan_competency(['planid' => $p2->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
1872 |
$p2c3 = $ccg->create_plan_competency(['planid' => $p2->get('id'), 'competencyid' => $comp3->get('id')]);
|
|
|
1873 |
|
|
|
1874 |
$this->setUser($u4);
|
|
|
1875 |
$uc1 = $ccg->create_user_competency(['competencyid' => $comp1->get('id'), 'userid' => $u0->id, 'grade' => 1,
|
|
|
1876 |
'proficiency' => true]);
|
|
|
1877 |
$uc2 = $ccg->create_user_competency(['competencyid' => $comp2->get('id'), 'userid' => $u0->id, 'grade' => 2,
|
|
|
1878 |
'proficiency' => false]);
|
|
|
1879 |
$uc3 = $ccg->create_user_competency(['competencyid' => $comp3->get('id'), 'userid' => $u0->id]);
|
|
|
1880 |
$uc4 = $ccg->create_user_competency(['competencyid' => $comp4->get('id'), 'userid' => $u0->id, 'reviewerid' => $u5->id]);
|
|
|
1881 |
|
|
|
1882 |
$this->setUser($u5);
|
|
|
1883 |
$p3 = $ccg->create_plan(['userid' => $u0->id]);
|
|
|
1884 |
$p3c1 = $ccg->create_plan_competency(['planid' => $p3->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
1885 |
$p3c3 = $ccg->create_plan_competency(['planid' => $p3->get('id'), 'competencyid' => $comp3->get('id')]);
|
|
|
1886 |
|
|
|
1887 |
// Add comments on plan.
|
|
|
1888 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
1889 |
$this->setUser($u0);
|
|
|
1890 |
$p1->get_comment_object()->add('Hello.');
|
|
|
1891 |
$this->setUser($u8);
|
|
|
1892 |
$p1->get_comment_object()->add('Hi.');
|
|
|
1893 |
|
|
|
1894 |
// Export data for user 1.
|
|
|
1895 |
writer::reset();
|
|
|
1896 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$u0ctx->id]));
|
|
|
1897 |
$planpath = array_merge($path, ["{$p1->get('name')} ({$p1->get('id')})"]);
|
|
|
1898 |
$data = writer::with_context($u0ctx)->get_data($planpath);
|
|
|
1899 |
$this->assertEquals($p1->get('name'), $data->name);
|
|
|
1900 |
$this->assertEquals($yes, $data->created_or_modified_by_you);
|
|
|
1901 |
|
|
|
1902 |
// Export data for user 2.
|
|
|
1903 |
writer::reset();
|
|
|
1904 |
provider::export_user_data(new approved_contextlist($u2, 'core_competency', [$u0ctx->id]));
|
|
|
1905 |
$planpath = array_merge($path, ["{$p2->get('name')} ({$p2->get('id')})"]);
|
|
|
1906 |
$data = writer::with_context($u0ctx)->get_data($planpath);
|
|
|
1907 |
$this->assertEquals($p2->get('name'), $data->name);
|
|
|
1908 |
$this->assertEquals($yes, $data->created_or_modified_by_you);
|
|
|
1909 |
|
|
|
1910 |
// Export data for user 3.
|
|
|
1911 |
writer::reset();
|
|
|
1912 |
provider::export_user_data(new approved_contextlist($u3, 'core_competency', [$u0ctx->id]));
|
|
|
1913 |
$planpath = array_merge($path, ["{$p1->get('name')} ({$p1->get('id')})"]);
|
|
|
1914 |
$data = writer::with_context($u0ctx)->get_data($planpath);
|
|
|
1915 |
$this->assertEquals($p1->get('name'), $data->name);
|
|
|
1916 |
$this->assertEquals($no, $data->created_or_modified_by_you);
|
|
|
1917 |
$this->assertCount(1, $data->competencies);
|
|
|
1918 |
$this->assertEquals($comp1->get('shortname'), $data->competencies[0]['name']);
|
|
|
1919 |
$this->assertEquals($yes, $data->competencies[0]['created_or_modified_by_you']);
|
|
|
1920 |
|
|
|
1921 |
$planpath = array_merge($path, ["{$p2->get('name')} ({$p2->get('id')})"]);
|
|
|
1922 |
$data = writer::with_context($u0ctx)->get_data($planpath);
|
|
|
1923 |
$this->assertEquals($p2->get('name'), $data->name);
|
|
|
1924 |
$this->assertEquals($no, $data->created_or_modified_by_you);
|
|
|
1925 |
$competencies = $data->competencies;
|
|
|
1926 |
$this->assertCount(2, $competencies);
|
|
|
1927 |
$this->assertEquals($comp2->get('shortname'), $competencies[0]['name']);
|
|
|
1928 |
$this->assertEquals($yes, $competencies[0]['created_or_modified_by_you']);
|
|
|
1929 |
$this->assertEquals($comp3->get('shortname'), $competencies[1]['name']);
|
|
|
1930 |
$this->assertEquals($yes, $competencies[1]['created_or_modified_by_you']);
|
|
|
1931 |
|
|
|
1932 |
// Export data for user 4.
|
|
|
1933 |
writer::reset();
|
|
|
1934 |
provider::export_user_data(new approved_contextlist($u4, 'core_competency', [$u0ctx->id]));
|
|
|
1935 |
foreach ([$p1, $p2, $p3] as $plan) {
|
|
|
1936 |
$planpath = array_merge($path, ["{$p2->get('name')} ({$p2->get('id')})"]);
|
|
|
1937 |
$data = writer::with_context($u0ctx)->get_data($planpath);
|
|
|
1938 |
$this->assertEmpty($data);
|
|
|
1939 |
}
|
|
|
1940 |
|
|
|
1941 |
// Export data for user 5.
|
|
|
1942 |
writer::reset();
|
|
|
1943 |
provider::export_user_data(new approved_contextlist($u5, 'core_competency', [$u0ctx->id]));
|
|
|
1944 |
$planpath = array_merge($path, ["{$p3->get('name')} ({$p3->get('id')})"]);
|
|
|
1945 |
$data = writer::with_context($u0ctx)->get_data($planpath);
|
|
|
1946 |
$this->assertEquals($p3->get('name'), $data->name);
|
|
|
1947 |
$this->assertEquals($yes, $data->created_or_modified_by_you);
|
|
|
1948 |
$this->assertCount(2, $data->competencies);
|
|
|
1949 |
$competency = $data->competencies[0];
|
|
|
1950 |
$this->assertEquals($comp1->get('shortname'), $competency['name']);
|
|
|
1951 |
$this->assertEquals($yes, $competency['created_or_modified_by_you']);
|
|
|
1952 |
$competency = $data->competencies[1];
|
|
|
1953 |
$this->assertEquals($comp3->get('shortname'), $competency['name']);
|
|
|
1954 |
$this->assertEquals($yes, $competency['created_or_modified_by_you']);
|
|
|
1955 |
|
|
|
1956 |
// Do some stuff.
|
|
|
1957 |
$this->setUser($u6);
|
|
|
1958 |
api::complete_plan($p3);
|
|
|
1959 |
|
|
|
1960 |
// Export data for user 6.
|
|
|
1961 |
writer::reset();
|
|
|
1962 |
provider::export_user_data(new approved_contextlist($u6, 'core_competency', [$u0ctx->id]));
|
|
|
1963 |
$planpath = array_merge($path, ["{$p3->get('name')} ({$p3->get('id')})"]);
|
|
|
1964 |
$data = writer::with_context($u0ctx)->get_data($planpath);
|
|
|
1965 |
$this->assertEquals($p3->get('name'), $data->name);
|
|
|
1966 |
$this->assertEquals($yes, $data->created_or_modified_by_you);
|
|
|
1967 |
$this->assertCount(2, $data->competencies);
|
|
|
1968 |
$competency = $data->competencies[0];
|
|
|
1969 |
$this->assertEquals($comp1->get('shortname'), $competency['name']);
|
|
|
1970 |
$this->assertArrayNotHasKey('created_or_modified_by_you', $competency);
|
|
|
1971 |
$this->assertEquals('A', $competency['rating']['rating']);
|
|
|
1972 |
$this->assertEquals($yes, $competency['rating']['created_or_modified_by_you']);
|
|
|
1973 |
$competency = $data->competencies[1];
|
|
|
1974 |
$this->assertEquals($comp3->get('shortname'), $competency['name']);
|
|
|
1975 |
$this->assertArrayNotHasKey('created_or_modified_by_you', $competency);
|
|
|
1976 |
$this->assertEquals('-', $competency['rating']['rating']);
|
|
|
1977 |
$this->assertEquals($yes, $competency['rating']['created_or_modified_by_you']);
|
|
|
1978 |
|
|
|
1979 |
// Export data for user 7.
|
|
|
1980 |
writer::reset();
|
|
|
1981 |
provider::export_user_data(new approved_contextlist($u7, 'core_competency', [$u0ctx->id]));
|
|
|
1982 |
$planpath = array_merge($path, ["{$p2->get('name')} ({$p2->get('id')})"]);
|
|
|
1983 |
$data = writer::with_context($u0ctx)->get_data($planpath);
|
|
|
1984 |
$this->assertEquals($p2->get('name'), $data->name);
|
|
|
1985 |
$this->assertEquals($no, $data->created_or_modified_by_you);
|
|
|
1986 |
$this->assertEquals($yes, $data->reviewer_is_you);
|
|
|
1987 |
|
|
|
1988 |
// Export data for user 8.
|
|
|
1989 |
writer::reset();
|
|
|
1990 |
$this->setUser($u8);
|
|
|
1991 |
provider::export_user_data(new approved_contextlist($u8, 'core_competency', [$u0ctx->id]));
|
|
|
1992 |
$planpath = array_merge($path, ["{$p1->get('name')} ({$p1->get('id')})"]);
|
|
|
1993 |
$data = writer::with_context($u0ctx)->get_data($planpath);
|
|
|
1994 |
$this->assertEquals($p1->get('name'), $data->name);
|
|
|
1995 |
$this->assertEquals($no, $data->created_or_modified_by_you);
|
|
|
1996 |
$this->assertEquals($no, $data->reviewer_is_you);
|
|
|
1997 |
$commentspath = array_merge($planpath, [get_string('commentsubcontext', 'core_comment')]);
|
|
|
1998 |
$data = writer::with_context($u0ctx)->get_data($commentspath);
|
|
|
1999 |
$this->assert_exported_comments(['Hi.'], $data->comments);
|
|
|
2000 |
}
|
|
|
2001 |
|
|
|
2002 |
public function test_export_data_for_user_with_related_competencies() {
|
|
|
2003 |
$path = [
|
|
|
2004 |
get_string('competencies', 'core_competency'),
|
|
|
2005 |
get_string('privacy:path:relatedtome', 'core_competency'),
|
|
|
2006 |
get_string('competencies', 'core_competency'),
|
|
|
2007 |
];
|
|
|
2008 |
$yes = transform::yesno(true);
|
|
|
2009 |
$no = transform::yesno(false);
|
|
|
2010 |
$makecomppath = function($comp) use ($path) {
|
|
|
2011 |
return array_merge($path, ["{$comp->get('shortname')} ({$comp->get('id')})"]);
|
|
|
2012 |
};
|
|
|
2013 |
|
|
|
2014 |
$dg = $this->getDataGenerator();
|
|
|
2015 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
2016 |
|
|
|
2017 |
$u0 = $dg->create_user();
|
|
|
2018 |
$u1 = $dg->create_user();
|
|
|
2019 |
$u2 = $dg->create_user();
|
|
|
2020 |
$u3 = $dg->create_user();
|
|
|
2021 |
$u4 = $dg->create_user();
|
|
|
2022 |
$u5 = $dg->create_user();
|
|
|
2023 |
|
|
|
2024 |
$u0ctx = \context_user::instance($u0->id);
|
|
|
2025 |
|
|
|
2026 |
$f = $ccg->create_framework();
|
|
|
2027 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2028 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2029 |
$comp3 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2030 |
$comp4 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2031 |
|
|
|
2032 |
$this->setUser($u1);
|
|
|
2033 |
api::add_evidence($u0->id, $comp1->get('id'), $u0ctx, \core_competency\evidence::ACTION_LOG,
|
|
|
2034 |
'privacy:metadata:competency_evidence', 'core_competency');
|
|
|
2035 |
api::add_evidence($u0->id, $comp1->get('id'), $u0ctx, \core_competency\evidence::ACTION_LOG,
|
|
|
2036 |
'privacy:metadata:competency_evidence', 'core_competency');
|
|
|
2037 |
api::add_evidence($u0->id, $comp2->get('id'), $u0ctx, \core_competency\evidence::ACTION_LOG,
|
|
|
2038 |
'privacy:metadata:competency_evidence', 'core_competency');
|
|
|
2039 |
|
|
|
2040 |
$this->setUser($u2);
|
|
|
2041 |
api::add_evidence($u0->id, $comp1->get('id'), $u0ctx, \core_competency\evidence::ACTION_COMPLETE,
|
|
|
2042 |
'privacy:metadata:competency_evidence', 'core_competency', null, false, null, null, $u3->id);
|
|
|
2043 |
|
|
|
2044 |
$this->setUser($u3);
|
|
|
2045 |
api::add_evidence($u0->id, $comp2->get('id'), $u0ctx, \core_competency\evidence::ACTION_OVERRIDE,
|
|
|
2046 |
'privacy:metadata:competency_evidence', 'core_competency', null, false, null, 1, $u4->id, 'Ze note');
|
|
|
2047 |
|
|
|
2048 |
$this->setUser($u4);
|
|
|
2049 |
$uc3 = $ccg->create_user_competency(['userid' => $u0->id, 'competencyid' => $comp3->get('id')]);
|
|
|
2050 |
$uc4 = $ccg->create_user_competency(['userid' => $u0->id, 'competencyid' => $comp4->get('id'), 'reviewerid' => $u2->id]);
|
|
|
2051 |
|
|
|
2052 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
2053 |
$this->setUser($u0);
|
|
|
2054 |
$uc3->get_comment_object()->add('...');
|
|
|
2055 |
$this->setUser($u5);
|
|
|
2056 |
$uc3->get_comment_object()->add('Hello!');
|
|
|
2057 |
$uc3->get_comment_object()->add('It\'s me...');
|
|
|
2058 |
|
|
|
2059 |
// Export data for user 1.
|
|
|
2060 |
writer::reset();
|
|
|
2061 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$u0ctx->id]));
|
|
|
2062 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp1));
|
|
|
2063 |
$competency = (array) $data;
|
|
|
2064 |
$this->assertEquals($comp1->get('shortname'), $competency['name']);
|
|
|
2065 |
$evidence = $competency['evidence'];
|
|
|
2066 |
$this->assertCount(2, $evidence);
|
|
|
2067 |
$this->assertEquals(get_string('privacy:evidence:action:log', 'core_competency'), $evidence[0]['action']);
|
|
|
2068 |
$this->assertEquals('-', $evidence[0]['actionuserid']);
|
|
|
2069 |
$this->assertEquals($no, $evidence[0]['acting_user_is_you']);
|
|
|
2070 |
$this->assertEquals($yes, $evidence[0]['created_or_modified_by_you']);
|
|
|
2071 |
$this->assertEquals(get_string('privacy:evidence:action:log', 'core_competency'), $evidence[1]['action']);
|
|
|
2072 |
$this->assertEquals('-', $evidence[1]['actionuserid']);
|
|
|
2073 |
$this->assertEquals($no, $evidence[1]['acting_user_is_you']);
|
|
|
2074 |
$this->assertEquals($yes, $evidence[1]['created_or_modified_by_you']);
|
|
|
2075 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp2));
|
|
|
2076 |
$competency = (array) $data;
|
|
|
2077 |
$this->assertEquals($comp2->get('shortname'), $competency['name']);
|
|
|
2078 |
$evidence = $competency['evidence'];
|
|
|
2079 |
$this->assertCount(1, $evidence);
|
|
|
2080 |
$this->assertEquals(get_string('privacy:evidence:action:log', 'core_competency'), $evidence[0]['action']);
|
|
|
2081 |
$this->assertEquals('-', $evidence[0]['actionuserid']);
|
|
|
2082 |
$this->assertEquals($no, $evidence[0]['acting_user_is_you']);
|
|
|
2083 |
$this->assertEquals($yes, $evidence[0]['created_or_modified_by_you']);
|
|
|
2084 |
|
|
|
2085 |
// Export data for user 2.
|
|
|
2086 |
writer::reset();
|
|
|
2087 |
provider::export_user_data(new approved_contextlist($u2, 'core_competency', [$u0ctx->id]));
|
|
|
2088 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp1));
|
|
|
2089 |
$competency = (array) $data;
|
|
|
2090 |
$this->assertEquals($comp1->get('shortname'), $competency['name']);
|
|
|
2091 |
$evidence = $competency['evidence'];
|
|
|
2092 |
$this->assertCount(1, $evidence);
|
|
|
2093 |
$this->assertEquals(get_string('privacy:evidence:action:complete', 'core_competency'), $evidence[0]['action']);
|
|
|
2094 |
$this->assertEquals($u3->id, $evidence[0]['actionuserid']);
|
|
|
2095 |
$this->assertEquals($no, $evidence[0]['acting_user_is_you']);
|
|
|
2096 |
$this->assertEquals($yes, $evidence[0]['created_or_modified_by_you']);
|
|
|
2097 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp4));
|
|
|
2098 |
$competency = (array) $data;
|
|
|
2099 |
$this->assertEquals($comp4->get('shortname'), $competency['name']);
|
|
|
2100 |
$this->assertCount(0, $competency['evidence']);
|
|
|
2101 |
$this->assertEquals($yes, $competency['rating']['reviewer_is_you']);
|
|
|
2102 |
$this->assertEquals($no, $competency['rating']['created_or_modified_by_you']);
|
|
|
2103 |
|
|
|
2104 |
// Export data for user 3.
|
|
|
2105 |
writer::reset();
|
|
|
2106 |
provider::export_user_data(new approved_contextlist($u3, 'core_competency', [$u0ctx->id]));
|
|
|
2107 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp1));
|
|
|
2108 |
$competency = (array) $data;
|
|
|
2109 |
$this->assertEquals($comp1->get('shortname'), $competency['name']);
|
|
|
2110 |
$evidence = $competency['evidence'];
|
|
|
2111 |
$this->assertCount(1, $evidence);
|
|
|
2112 |
$this->assertEquals($u3->id, $evidence[0]['actionuserid']);
|
|
|
2113 |
$this->assertEquals($yes, $evidence[0]['acting_user_is_you']);
|
|
|
2114 |
$this->assertEquals($no, $evidence[0]['created_or_modified_by_you']);
|
|
|
2115 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp2));
|
|
|
2116 |
$competency = (array) $data;
|
|
|
2117 |
$this->assertEquals($comp2->get('shortname'), $competency['name']);
|
|
|
2118 |
$evidence = $competency['evidence'];
|
|
|
2119 |
$this->assertCount(1, $evidence);
|
|
|
2120 |
$this->assertEquals(get_string('privacy:evidence:action:override', 'core_competency'), $evidence[0]['action']);
|
|
|
2121 |
$this->assertEquals($u4->id, $evidence[0]['actionuserid']);
|
|
|
2122 |
$this->assertEquals($no, $evidence[0]['acting_user_is_you']);
|
|
|
2123 |
$this->assertEquals($yes, $evidence[0]['created_or_modified_by_you']);
|
|
|
2124 |
|
|
|
2125 |
// Export data for user 4.
|
|
|
2126 |
writer::reset();
|
|
|
2127 |
provider::export_user_data(new approved_contextlist($u4, 'core_competency', [$u0ctx->id]));
|
|
|
2128 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp2));
|
|
|
2129 |
$competency = (array) $data;
|
|
|
2130 |
$this->assertEquals($comp2->get('shortname'), $competency['name']);
|
|
|
2131 |
$this->assertNull($competency['rating']);
|
|
|
2132 |
$this->assertCount(1, $competency['evidence']);
|
|
|
2133 |
$evidence = $competency['evidence'][0];
|
|
|
2134 |
$this->assertEquals($u4->id, $evidence['actionuserid']);
|
|
|
2135 |
$this->assertEquals($yes, $evidence['acting_user_is_you']);
|
|
|
2136 |
$this->assertEquals($no, $evidence['created_or_modified_by_you']);
|
|
|
2137 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp3));
|
|
|
2138 |
$competency = (array) $data;
|
|
|
2139 |
$this->assertEquals($comp3->get('shortname'), $competency['name']);
|
|
|
2140 |
$this->assertEquals($no, $competency['rating']['reviewer_is_you']);
|
|
|
2141 |
$this->assertEquals($yes, $competency['rating']['created_or_modified_by_you']);
|
|
|
2142 |
$this->assertEmpty($competency['evidence']);
|
|
|
2143 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp4));
|
|
|
2144 |
$competency = (array) $data;
|
|
|
2145 |
$this->assertEquals($comp4->get('shortname'), $competency['name']);
|
|
|
2146 |
$this->assertEquals($no, $competency['rating']['reviewer_is_you']);
|
|
|
2147 |
$this->assertEquals($yes, $competency['rating']['created_or_modified_by_you']);
|
|
|
2148 |
$this->assertEmpty($competency['evidence']);
|
|
|
2149 |
|
|
|
2150 |
// Export data for user 5.
|
|
|
2151 |
$this->setUser($u5);
|
|
|
2152 |
writer::reset();
|
|
|
2153 |
provider::export_user_data(new approved_contextlist($u5, 'core_competency', [$u0ctx->id]));
|
|
|
2154 |
$data = writer::with_context($u0ctx)->get_data($makecomppath($comp3));
|
|
|
2155 |
$competency = (array) $data;
|
|
|
2156 |
$this->assertEquals($comp3->get('shortname'), $competency['name']);
|
|
|
2157 |
$data = writer::with_context($u0ctx)->get_data(array_merge($makecomppath($comp3),
|
|
|
2158 |
[get_string('commentsubcontext', 'core_comment')]));
|
|
|
2159 |
$this->assert_exported_comments(['Hello!', 'It\'s me...'], $data->comments);
|
|
|
2160 |
}
|
|
|
2161 |
|
|
|
2162 |
public function test_export_data_for_user_with_related_user_evidence() {
|
|
|
2163 |
$path = [
|
|
|
2164 |
get_string('competencies', 'core_competency'),
|
|
|
2165 |
get_string('privacy:path:relatedtome', 'core_competency'),
|
|
|
2166 |
get_string('privacy:path:userevidence', 'core_competency')
|
|
|
2167 |
];
|
|
|
2168 |
$yes = transform::yesno(true);
|
|
|
2169 |
$no = transform::yesno(false);
|
|
|
2170 |
|
|
|
2171 |
$dg = $this->getDataGenerator();
|
|
|
2172 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
2173 |
|
|
|
2174 |
$u0 = $dg->create_user();
|
|
|
2175 |
$u0b = $dg->create_user();
|
|
|
2176 |
$u1 = $dg->create_user();
|
|
|
2177 |
$u2 = $dg->create_user();
|
|
|
2178 |
$u3 = $dg->create_user();
|
|
|
2179 |
$u4 = $dg->create_user();
|
|
|
2180 |
|
|
|
2181 |
$u0ctx = \context_user::instance($u0->id);
|
|
|
2182 |
|
|
|
2183 |
$f = $ccg->create_framework();
|
|
|
2184 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2185 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2186 |
$comp3 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2187 |
|
|
|
2188 |
$this->setUser($u0);
|
|
|
2189 |
$ue0 = $ccg->create_user_evidence(['userid' => $u0->id]);
|
|
|
2190 |
|
|
|
2191 |
$this->setUser($u1);
|
|
|
2192 |
$ue1 = $ccg->create_user_evidence(['userid' => $u0->id]);
|
|
|
2193 |
$ue1b = $ccg->create_user_evidence(['userid' => $u0b->id]);
|
|
|
2194 |
|
|
|
2195 |
$this->setUser($u2);
|
|
|
2196 |
$ccg->create_user_evidence_competency(['userevidenceid' => $ue1->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
2197 |
$ccg->create_user_evidence_competency(['userevidenceid' => $ue1b->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
2198 |
$ue2 = $ccg->create_user_evidence(['userid' => $u0->id]);
|
|
|
2199 |
$ue2b = $ccg->create_user_evidence(['userid' => $u0b->id]);
|
|
|
2200 |
|
|
|
2201 |
$this->setUser($u3);
|
|
|
2202 |
$ccg->create_user_evidence_competency(['userevidenceid' => $ue2->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
2203 |
$ccg->create_user_evidence_competency(['userevidenceid' => $ue2->get('id'), 'competencyid' => $comp3->get('id')]);
|
|
|
2204 |
|
|
|
2205 |
// Export for user 1.
|
|
|
2206 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$u0ctx->id]));
|
|
|
2207 |
$uepath = array_merge($path, ["{$ue1->get('name')} ({$ue1->get('id')})"]);
|
|
|
2208 |
$data = writer::with_context($u0ctx)->get_data($uepath);
|
|
|
2209 |
$this->assertEquals($ue1->get('name'), $data->name);
|
|
|
2210 |
$this->assertEquals($yes, $data->created_or_modified_by_you);
|
|
|
2211 |
$this->assertEmpty($data->competencies);
|
|
|
2212 |
|
|
|
2213 |
// Export for user 2.
|
|
|
2214 |
provider::export_user_data(new approved_contextlist($u2, 'core_competency', [$u0ctx->id]));
|
|
|
2215 |
$uepath = array_merge($path, ["{$ue1->get('name')} ({$ue1->get('id')})"]);
|
|
|
2216 |
$data = writer::with_context($u0ctx)->get_data($uepath);
|
|
|
2217 |
$this->assertEquals($ue1->get('name'), $data->name);
|
|
|
2218 |
$this->assertEquals($no, $data->created_or_modified_by_you);
|
|
|
2219 |
$this->assertCount(1, $data->competencies);
|
|
|
2220 |
$competency = $data->competencies[0];
|
|
|
2221 |
$this->assertEquals($comp1->get('shortname'), $competency['name']);
|
|
|
2222 |
$this->assertEquals($yes, $competency['created_or_modified_by_you']);
|
|
|
2223 |
|
|
|
2224 |
$uepath = array_merge($path, ["{$ue2->get('name')} ({$ue2->get('id')})"]);
|
|
|
2225 |
$data = writer::with_context($u0ctx)->get_data($uepath);
|
|
|
2226 |
$this->assertEquals($ue2->get('name'), $data->name);
|
|
|
2227 |
$this->assertEquals($yes, $data->created_or_modified_by_you);
|
|
|
2228 |
$this->assertEmpty($data->competencies);
|
|
|
2229 |
|
|
|
2230 |
// Export for user 3.
|
|
|
2231 |
provider::export_user_data(new approved_contextlist($u3, 'core_competency', [$u0ctx->id]));
|
|
|
2232 |
$uepath = array_merge($path, ["{$ue2->get('name')} ({$ue2->get('id')})"]);
|
|
|
2233 |
$evidence = writer::with_context($u0ctx)->get_data($uepath);
|
|
|
2234 |
$this->assertEquals($ue2->get('name'), $evidence->name);
|
|
|
2235 |
$this->assertEquals($no, $evidence->created_or_modified_by_you);
|
|
|
2236 |
$this->assertCount(2, $evidence->competencies);
|
|
|
2237 |
$competency = $evidence->competencies[0];
|
|
|
2238 |
$this->assertEquals($comp2->get('shortname'), $competency['name']);
|
|
|
2239 |
$this->assertEquals($yes, $competency['created_or_modified_by_you']);
|
|
|
2240 |
$competency = $evidence->competencies[1];
|
|
|
2241 |
$this->assertEquals($comp3->get('shortname'), $competency['name']);
|
|
|
2242 |
$this->assertEquals($yes, $competency['created_or_modified_by_you']);
|
|
|
2243 |
}
|
|
|
2244 |
|
|
|
2245 |
public function test_export_data_for_user_about_their_learning_plans() {
|
|
|
2246 |
$this->setAdminUser();
|
|
|
2247 |
$dg = $this->getDataGenerator();
|
|
|
2248 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
2249 |
$path = [get_string('competencies', 'core_competency'), get_string('privacy:path:plans', 'core_competency')];
|
|
|
2250 |
$yes = transform::yesno(true);
|
|
|
2251 |
$no = transform::yesno(false);
|
|
|
2252 |
|
|
|
2253 |
$u1 = $dg->create_user();
|
|
|
2254 |
$u2 = $dg->create_user();
|
|
|
2255 |
$u3 = $dg->create_user();
|
|
|
2256 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
2257 |
$u2ctx = \context_user::instance($u2->id);
|
|
|
2258 |
|
|
|
2259 |
$f = $ccg->create_framework();
|
|
|
2260 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2261 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2262 |
$comp3 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2263 |
$comp4 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2264 |
|
|
|
2265 |
$t = $ccg->create_template();
|
|
|
2266 |
$tc2 = $ccg->create_template_competency(['competencyid' => $comp2->get('id'), 'templateid' => $t->get('id')]);
|
|
|
2267 |
$tc3 = $ccg->create_template_competency(['competencyid' => $comp3->get('id'), 'templateid' => $t->get('id')]);
|
|
|
2268 |
$tc4 = $ccg->create_template_competency(['competencyid' => $comp4->get('id'), 'templateid' => $t->get('id')]);
|
|
|
2269 |
|
|
|
2270 |
$p1a = $ccg->create_plan(['userid' => $u1->id, 'templateid' => $t->get('id'),
|
|
|
2271 |
'status' => \core_competency\plan::STATUS_WAITING_FOR_REVIEW]);
|
|
|
2272 |
$p1b = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
2273 |
$ccg->create_plan_competency(['planid' => $p1b->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
2274 |
$ccg->create_plan_competency(['planid' => $p1b->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
2275 |
$ccg->create_plan_competency(['planid' => $p1b->get('id'), 'competencyid' => $comp4->get('id')]);
|
|
|
2276 |
$p1c = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
2277 |
$ccg->create_plan_competency(['planid' => $p1c->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
2278 |
$ccg->create_plan_competency(['planid' => $p1c->get('id'), 'competencyid' => $comp3->get('id')]);
|
|
|
2279 |
$ccg->create_plan_competency(['planid' => $p1c->get('id'), 'competencyid' => $comp4->get('id')]);
|
|
|
2280 |
$p1d = $ccg->create_plan(['userid' => $u1->id]);
|
|
|
2281 |
|
|
|
2282 |
$p2a = $ccg->create_plan(['userid' => $u2->id]);
|
|
|
2283 |
$ccg->create_plan_competency(['planid' => $p2a->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
2284 |
$ccg->create_plan_competency(['planid' => $p2a->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
2285 |
|
|
|
2286 |
$uc1a = $ccg->create_user_competency(['competencyid' => $comp1->get('id'), 'userid' => $u1->id,
|
|
|
2287 |
'grade' => 2, 'proficiency' => false]);
|
|
|
2288 |
$uc1b = $ccg->create_user_competency(['competencyid' => $comp2->get('id'), 'userid' => $u1->id,
|
|
|
2289 |
'grade' => 3, 'proficiency' => false]);
|
|
|
2290 |
$uc1c = $ccg->create_user_competency(['competencyid' => $comp3->get('id'), 'userid' => $u1->id]);
|
|
|
2291 |
|
|
|
2292 |
// Add comments on plan.
|
|
|
2293 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
2294 |
$this->setUser($u1);
|
|
|
2295 |
$p1a->get_comment_object()->add('Hello.');
|
|
|
2296 |
$p1a->get_comment_object()->add('It\'s me.');
|
|
|
2297 |
$this->setUser($u3);
|
|
|
2298 |
$p1a->get_comment_object()->add('After all these years...');
|
|
|
2299 |
|
|
|
2300 |
// Complete the plan to create archiving, and modify the user competency again.
|
|
|
2301 |
api::complete_plan($p1c);
|
|
|
2302 |
$uc1a->set('grade', 1);
|
|
|
2303 |
$uc1a->set('proficiency', true);
|
|
|
2304 |
$uc1a->update();
|
|
|
2305 |
|
|
|
2306 |
// Export user data in both contexts.
|
|
|
2307 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$u1ctx->id, $u2ctx->id]));
|
|
|
2308 |
|
|
|
2309 |
// This plan is based off a template.
|
|
|
2310 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$p1a->get('name')} ({$p1a->get('id')})"]));
|
|
|
2311 |
$this->assertNotEmpty($data);
|
|
|
2312 |
$this->assertEquals($p1a->get('name'), $data->name);
|
|
|
2313 |
$this->assertEquals($p1a->get_statusname(), $data->status);
|
|
|
2314 |
$this->assertCount(3, $data->competencies);
|
|
|
2315 |
$comp = $data->competencies[0];
|
|
|
2316 |
$this->assertEquals($comp2->get('shortname'), $comp['name']);
|
|
|
2317 |
$this->assertEquals('C', $comp['rating']['rating']);
|
|
|
2318 |
$comp = $data->competencies[1];
|
|
|
2319 |
$this->assertEquals($comp3->get('shortname'), $comp['name']);
|
|
|
2320 |
$this->assertEquals('-', $comp['rating']['rating']);
|
|
|
2321 |
$comp = $data->competencies[2];
|
|
|
2322 |
$this->assertEquals($comp4->get('shortname'), $comp['name']);
|
|
|
2323 |
$this->assertNull($comp['rating']);
|
|
|
2324 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$p1a->get('name')} ({$p1a->get('id')})",
|
|
|
2325 |
get_string('commentsubcontext', 'core_comment')]));
|
|
|
2326 |
$this->assert_exported_comments(['Hello.', 'It\'s me.', 'After all these years...'], $data->comments);
|
|
|
2327 |
|
|
|
2328 |
// This plan is manually created.
|
|
|
2329 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$p1b->get('name')} ({$p1b->get('id')})"]));
|
|
|
2330 |
$this->assertNotEmpty($data);
|
|
|
2331 |
$this->assertEquals($p1b->get('name'), $data->name);
|
|
|
2332 |
$this->assertCount(3, $data->competencies);
|
|
|
2333 |
$comp = $data->competencies[0];
|
|
|
2334 |
$this->assertEquals($comp1->get('shortname'), $comp['name']);
|
|
|
2335 |
$this->assertEquals('A', $comp['rating']['rating']);
|
|
|
2336 |
$comp = $data->competencies[1];
|
|
|
2337 |
$this->assertEquals($comp2->get('shortname'), $comp['name']);
|
|
|
2338 |
$this->assertEquals('C', $comp['rating']['rating']);
|
|
|
2339 |
$comp = $data->competencies[2];
|
|
|
2340 |
$this->assertEquals($comp4->get('shortname'), $comp['name']);
|
|
|
2341 |
$this->assertNull($comp['rating']);
|
|
|
2342 |
|
|
|
2343 |
// This plan is complete.
|
|
|
2344 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$p1c->get('name')} ({$p1c->get('id')})"]));
|
|
|
2345 |
$this->assertNotEmpty($data);
|
|
|
2346 |
$this->assertEquals($p1c->get('name'), $data->name);
|
|
|
2347 |
$this->assertCount(3, $data->competencies);
|
|
|
2348 |
$comp = $data->competencies[0];
|
|
|
2349 |
$this->assertEquals($comp1->get('shortname'), $comp['name']);
|
|
|
2350 |
$this->assertEquals('B', $comp['rating']['rating']);
|
|
|
2351 |
$comp = $data->competencies[1];
|
|
|
2352 |
$this->assertEquals($comp3->get('shortname'), $comp['name']);
|
|
|
2353 |
$this->assertEquals('-', $comp['rating']['rating']);
|
|
|
2354 |
$comp = $data->competencies[2];
|
|
|
2355 |
$this->assertEquals($comp4->get('shortname'), $comp['name']);
|
|
|
2356 |
$this->assertEquals('-', $comp['rating']['rating']);
|
|
|
2357 |
|
|
|
2358 |
// This plan is empty.
|
|
|
2359 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$p1d->get('name')} ({$p1d->get('id')})"]));
|
|
|
2360 |
$this->assertNotEmpty($data);
|
|
|
2361 |
$this->assertEquals($p1d->get('name'), $data->name);
|
|
|
2362 |
$this->assertEquals($p1d->get_statusname(), $data->status);
|
|
|
2363 |
$this->assertEmpty($data->competencies);
|
|
|
2364 |
|
|
|
2365 |
// Confirm that we do not get export what we shouldn't.
|
|
|
2366 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$p2a->get('name')} ({$p2a->get('id')})"]));
|
|
|
2367 |
$this->assertEmpty($data);
|
|
|
2368 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$p1a->get('name')} ({$p1a->get('id')})"]));
|
|
|
2369 |
$this->assertEmpty($data);
|
|
|
2370 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$p1b->get('name')} ({$p1b->get('id')})"]));
|
|
|
2371 |
$this->assertEmpty($data);
|
|
|
2372 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$p1c->get('name')} ({$p1c->get('id')})"]));
|
|
|
2373 |
$this->assertEmpty($data);
|
|
|
2374 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$p2a->get('name')} ({$p2a->get('id')})"]));
|
|
|
2375 |
$this->assertEmpty($data);
|
|
|
2376 |
|
|
|
2377 |
// Export for user 2.
|
|
|
2378 |
writer::reset();
|
|
|
2379 |
provider::export_user_data(new approved_contextlist($u2, 'core_competency', [$u1ctx->id, $u2ctx->id]));
|
|
|
2380 |
|
|
|
2381 |
// Validate the basic plan.
|
|
|
2382 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$p2a->get('name')} ({$p2a->get('id')})"]));
|
|
|
2383 |
$this->assertNotEmpty($data);
|
|
|
2384 |
$this->assertEquals($p2a->get('name'), $data->name);
|
|
|
2385 |
$this->assertCount(2, $data->competencies);
|
|
|
2386 |
$comp = $data->competencies[0];
|
|
|
2387 |
$this->assertEquals($comp1->get('shortname'), $comp['name']);
|
|
|
2388 |
$this->assertNull($comp['rating']);
|
|
|
2389 |
$comp = $data->competencies[1];
|
|
|
2390 |
$this->assertEquals($comp2->get('shortname'), $comp['name']);
|
|
|
2391 |
$this->assertNull($comp['rating']);
|
|
|
2392 |
|
|
|
2393 |
// Confirm that we do not get export what we shouldn't.
|
|
|
2394 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$p1a->get('name')} ({$p1a->get('id')})"]));
|
|
|
2395 |
$this->assertEmpty($data);
|
|
|
2396 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$p1b->get('name')} ({$p1b->get('id')})"]));
|
|
|
2397 |
$this->assertEmpty($data);
|
|
|
2398 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$p1c->get('name')} ({$p1c->get('id')})"]));
|
|
|
2399 |
$this->assertEmpty($data);
|
|
|
2400 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$p1a->get('name')} ({$p1a->get('id')})"]));
|
|
|
2401 |
$this->assertEmpty($data);
|
|
|
2402 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$p1b->get('name')} ({$p1b->get('id')})"]));
|
|
|
2403 |
$this->assertEmpty($data);
|
|
|
2404 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$p1c->get('name')} ({$p1c->get('id')})"]));
|
|
|
2405 |
$this->assertEmpty($data);
|
|
|
2406 |
}
|
|
|
2407 |
|
|
|
2408 |
public function test_export_data_for_user_about_their_competencies() {
|
|
|
2409 |
$dg = $this->getDataGenerator();
|
|
|
2410 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
2411 |
$path = [get_string('competencies', 'core_competency'), get_string('competencies', 'core_competency')];
|
|
|
2412 |
$no = transform::yesno(false);
|
|
|
2413 |
|
|
|
2414 |
$u1 = $dg->create_user();
|
|
|
2415 |
$u2 = $dg->create_user();
|
|
|
2416 |
$u3 = $dg->create_user();
|
|
|
2417 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
2418 |
$u2ctx = \context_user::instance($u2->id);
|
|
|
2419 |
|
|
|
2420 |
$f = $ccg->create_framework();
|
|
|
2421 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2422 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2423 |
$comp3 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2424 |
|
|
|
2425 |
$uc1a = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp1->get('id')]);
|
|
|
2426 |
$uc1b = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp2->get('id'),
|
|
|
2427 |
'grade' => 2, 'proficiency' => false]);
|
|
|
2428 |
$uc1c = $ccg->create_user_competency(['userid' => $u1->id, 'competencyid' => $comp3->get('id')]);
|
|
|
2429 |
$e1a1 = $ccg->create_evidence(['usercompetencyid' => $uc1a->get('id'),
|
|
|
2430 |
'action' => \core_competency\evidence::ACTION_COMPLETE, 'grade' => 1]);
|
|
|
2431 |
$e1a2 = $ccg->create_evidence(['usercompetencyid' => $uc1a->get('id'), 'note' => 'Not too bad']);
|
|
|
2432 |
$e1b1 = $ccg->create_evidence(['usercompetencyid' => $uc1b->get('id'), 'url' => 'https://example.com']);
|
|
|
2433 |
|
|
|
2434 |
$uc2a = $ccg->create_user_competency(['userid' => $u2->id, 'competencyid' => $comp1->get('id')]);
|
|
|
2435 |
$uc2b = $ccg->create_user_competency(['userid' => $u2->id, 'competencyid' => $comp2->get('id')]);
|
|
|
2436 |
$e2a1 = $ccg->create_evidence(['usercompetencyid' => $uc2b->get('id'), 'note' => 'A']);
|
|
|
2437 |
$e2a2 = $ccg->create_evidence(['usercompetencyid' => $uc2b->get('id'), 'note' => 'B']);
|
|
|
2438 |
$e2a3 = $ccg->create_evidence(['usercompetencyid' => $uc2b->get('id'), 'note' => 'C']);
|
|
|
2439 |
|
|
|
2440 |
// Add comments on competency.
|
|
|
2441 |
$this->allow_anyone_to_comment_anywhere();
|
|
|
2442 |
$this->setUser($u1);
|
|
|
2443 |
$uc1a->get_comment_object()->add('Hello.');
|
|
|
2444 |
$uc1a->get_comment_object()->add('It\'s me.');
|
|
|
2445 |
$this->setUser($u3);
|
|
|
2446 |
$uc1a->get_comment_object()->add('After all these years...');
|
|
|
2447 |
|
|
|
2448 |
// Export for user 1 in both contexts.
|
|
|
2449 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$u1ctx->id, $u2ctx->id]));
|
|
|
2450 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$comp1->get('shortname')} ({$comp1->get('id')})"]));
|
|
|
2451 |
$this->assertNotEmpty($data);
|
|
|
2452 |
$this->assertEquals($comp1->get('shortname'), $data->name);
|
|
|
2453 |
$this->assertEquals('-', $data->rating['rating']);
|
|
|
2454 |
$this->assertCount(2, $data->evidence);
|
|
|
2455 |
$this->assertEquals(get_string('privacy:evidence:action:complete', 'core_competency'), $data->evidence[1]['action']);
|
|
|
2456 |
$this->assertEquals('Not too bad', $data->evidence[0]['note']);
|
|
|
2457 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$comp1->get('shortname')} ({$comp1->get('id')})",
|
|
|
2458 |
get_string('commentsubcontext', 'core_comment')]));
|
|
|
2459 |
$this->assert_exported_comments(['Hello.', 'It\'s me.', 'After all these years...'], $data->comments);
|
|
|
2460 |
|
|
|
2461 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$comp2->get('shortname')} ({$comp2->get('id')})"]));
|
|
|
2462 |
$this->assertNotEmpty($data);
|
|
|
2463 |
$this->assertEquals($comp2->get('shortname'), $data->name);
|
|
|
2464 |
$this->assertEquals('B', $data->rating['rating']);
|
|
|
2465 |
$this->assertEquals($no, $data->rating['proficient']);
|
|
|
2466 |
$this->assertCount(1, $data->evidence);
|
|
|
2467 |
$this->assertEquals('https://example.com', $data->evidence[0]['url']);
|
|
|
2468 |
|
|
|
2469 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$comp3->get('shortname')} ({$comp3->get('id')})"]));
|
|
|
2470 |
$this->assertNotEmpty($data);
|
|
|
2471 |
$this->assertEquals($comp3->get('shortname'), $data->name);
|
|
|
2472 |
$this->assertEquals('-', $data->rating['rating']);
|
|
|
2473 |
$this->assertEquals('-', $data->rating['proficient']);
|
|
|
2474 |
$this->assertEmpty($data->evidence);
|
|
|
2475 |
|
|
|
2476 |
// We don't know anything about user 2.
|
|
|
2477 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$comp1->get('shortname')} ({$comp1->get('id')})"]));
|
|
|
2478 |
$this->assertEmpty($data);
|
|
|
2479 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$comp2->get('shortname')} ({$comp2->get('id')})"]));
|
|
|
2480 |
$this->assertEmpty($data);
|
|
|
2481 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$comp3->get('shortname')} ({$comp3->get('id')})"]));
|
|
|
2482 |
$this->assertEmpty($data);
|
|
|
2483 |
|
|
|
2484 |
// Export for user 2 in both contexts.
|
|
|
2485 |
writer::reset();
|
|
|
2486 |
provider::export_user_data(new approved_contextlist($u2, 'core_competency', [$u1ctx->id, $u2ctx->id]));
|
|
|
2487 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$comp1->get('shortname')} ({$comp1->get('id')})"]));
|
|
|
2488 |
$this->assertNotEmpty($data);
|
|
|
2489 |
$this->assertEquals($comp1->get('shortname'), $data->name);
|
|
|
2490 |
$this->assertEquals('-', $data->rating['rating']);
|
|
|
2491 |
$this->assertCount(0, $data->evidence);
|
|
|
2492 |
|
|
|
2493 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$comp2->get('shortname')} ({$comp2->get('id')})"]));
|
|
|
2494 |
$this->assertNotEmpty($data);
|
|
|
2495 |
$this->assertEquals($comp2->get('shortname'), $data->name);
|
|
|
2496 |
$this->assertEquals('-', $data->rating['rating']);
|
|
|
2497 |
$this->assertCount(3, $data->evidence);
|
|
|
2498 |
$this->assertEquals('C', $data->evidence[0]['note']);
|
|
|
2499 |
$this->assertEquals('B', $data->evidence[1]['note']);
|
|
|
2500 |
$this->assertEquals('A', $data->evidence[2]['note']);
|
|
|
2501 |
|
|
|
2502 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$comp3->get('shortname')} ({$comp3->get('id')})"]));
|
|
|
2503 |
$this->assertEmpty($data);
|
|
|
2504 |
|
|
|
2505 |
// We don't know anything about user 1.
|
|
|
2506 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$comp1->get('shortname')} ({$comp1->get('id')})"]));
|
|
|
2507 |
$this->assertEmpty($data);
|
|
|
2508 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$comp2->get('shortname')} ({$comp2->get('id')})"]));
|
|
|
2509 |
$this->assertEmpty($data);
|
|
|
2510 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$comp3->get('shortname')} ({$comp3->get('id')})"]));
|
|
|
2511 |
$this->assertEmpty($data);
|
|
|
2512 |
}
|
|
|
2513 |
|
|
|
2514 |
public function test_export_data_for_user_about_their_user_evidence() {
|
|
|
2515 |
$dg = $this->getDataGenerator();
|
|
|
2516 |
$ccg = $dg->get_plugin_generator('core_competency');
|
|
|
2517 |
$path = [get_string('competencies', 'core_competency'), get_string('privacy:path:userevidence', 'core_competency')];
|
|
|
2518 |
|
|
|
2519 |
$u1 = $dg->create_user();
|
|
|
2520 |
$u2 = $dg->create_user();
|
|
|
2521 |
$u3 = $dg->create_user();
|
|
|
2522 |
|
|
|
2523 |
$u1ctx = \context_user::instance($u1->id);
|
|
|
2524 |
$u2ctx = \context_user::instance($u2->id);
|
|
|
2525 |
$u3ctx = \context_user::instance($u3->id);
|
|
|
2526 |
|
|
|
2527 |
$f = $ccg->create_framework();
|
|
|
2528 |
$comp1 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2529 |
$comp2 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2530 |
$comp3 = $ccg->create_competency(['competencyframeworkid' => $f->get('id')]);
|
|
|
2531 |
|
|
|
2532 |
$ue1a = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
2533 |
$ue1b = $ccg->create_user_evidence(['userid' => $u1->id]);
|
|
|
2534 |
$ue2a = $ccg->create_user_evidence(['userid' => $u2->id]);
|
|
|
2535 |
$ue3a = $ccg->create_user_evidence(['userid' => $u3->id]);
|
|
|
2536 |
$ccg->create_user_evidence_competency(['userevidenceid' => $ue1a->get('id'), 'competencyid' => $comp1->get('id')]);
|
|
|
2537 |
$ccg->create_user_evidence_competency(['userevidenceid' => $ue1a->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
2538 |
$ccg->create_user_evidence_competency(['userevidenceid' => $ue1b->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
2539 |
$ccg->create_user_evidence_competency(['userevidenceid' => $ue2a->get('id'), 'competencyid' => $comp2->get('id')]);
|
|
|
2540 |
|
|
|
2541 |
// Export for user 1 in two contexts to make sure.
|
|
|
2542 |
provider::export_user_data(new approved_contextlist($u1, 'core_competency', [$u1ctx->id, $u2ctx->id]));
|
|
|
2543 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$ue1a->get('name')} ({$ue1a->get('id')})"]));
|
|
|
2544 |
$this->assertNotEmpty($data);
|
|
|
2545 |
$this->assertEquals($ue1a->get('name'), $data->name);
|
|
|
2546 |
$this->assertCount(2, $data->competencies);
|
|
|
2547 |
$this->assertEquals($comp1->get('shortname'), $data->competencies[0]['name']);
|
|
|
2548 |
$this->assertEquals($comp2->get('shortname'), $data->competencies[1]['name']);
|
|
|
2549 |
|
|
|
2550 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$ue1b->get('name')} ({$ue1b->get('id')})"]));
|
|
|
2551 |
$this->assertNotEmpty($data);
|
|
|
2552 |
$this->assertEquals($ue1b->get('name'), $data->name);
|
|
|
2553 |
$this->assertCount(1, $data->competencies);
|
|
|
2554 |
$this->assertEquals($comp2->get('shortname'), $data->competencies[0]['name']);
|
|
|
2555 |
|
|
|
2556 |
// We should not have access to other's info.
|
|
|
2557 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$ue2a->get('name')} ({$ue2a->get('id')})"]));
|
|
|
2558 |
$this->assertEmpty($data);
|
|
|
2559 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$ue2a->get('name')} ({$ue2a->get('id')})"]));
|
|
|
2560 |
$this->assertEmpty($data);
|
|
|
2561 |
|
|
|
2562 |
// Export for user 2 in two contexts to make sure.
|
|
|
2563 |
writer::reset();
|
|
|
2564 |
provider::export_user_data(new approved_contextlist($u2, 'core_competency', [$u2ctx->id, $u1ctx->id]));
|
|
|
2565 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$ue2a->get('name')} ({$ue2a->get('id')})"]));
|
|
|
2566 |
$this->assertNotEmpty($data);
|
|
|
2567 |
$this->assertEquals($ue2a->get('name'), $data->name);
|
|
|
2568 |
$this->assertCount(1, $data->competencies);
|
|
|
2569 |
$this->assertEquals($comp2->get('shortname'), $data->competencies[0]['name']);
|
|
|
2570 |
|
|
|
2571 |
// We should not have access to other's info.
|
|
|
2572 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$ue1a->get('name')} ({$ue1a->get('id')})"]));
|
|
|
2573 |
$this->assertEmpty($data);
|
|
|
2574 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$ue1a->get('name')} ({$ue1a->get('id')})"]));
|
|
|
2575 |
$this->assertEmpty($data);
|
|
|
2576 |
$data = writer::with_context($u1ctx)->get_data(array_merge($path, ["{$ue1b->get('name')} ({$ue1b->get('id')})"]));
|
|
|
2577 |
$this->assertEmpty($data);
|
|
|
2578 |
$data = writer::with_context($u2ctx)->get_data(array_merge($path, ["{$ue1b->get('name')} ({$ue1b->get('id')})"]));
|
|
|
2579 |
$this->assertEmpty($data);
|
|
|
2580 |
|
|
|
2581 |
// Export for user 3.
|
|
|
2582 |
writer::reset();
|
|
|
2583 |
provider::export_user_data(new approved_contextlist($u3, 'core_competency', [$u3ctx->id]));
|
|
|
2584 |
$data = writer::with_context($u3ctx)->get_data(array_merge($path, ["{$ue3a->get('name')} ({$ue3a->get('id')})"]));
|
|
|
2585 |
$this->assertNotEmpty($data);
|
|
|
2586 |
$this->assertEquals($ue3a->get('name'), $data->name);
|
|
|
2587 |
$this->assertCount(0, $data->competencies);
|
|
|
2588 |
}
|
|
|
2589 |
|
|
|
2590 |
/**
|
|
|
2591 |
* Helps testing comments on plans.
|
|
|
2592 |
*
|
|
|
2593 |
* @return void
|
|
|
2594 |
*/
|
|
|
2595 |
protected function allow_anyone_to_comment_anywhere() {
|
|
|
2596 |
global $DB;
|
|
|
2597 |
$roleid = $DB->get_field('role', 'id', ['shortname' => 'user'], MUST_EXIST);
|
|
|
2598 |
assign_capability('moodle/competency:plancomment', CAP_ALLOW, $roleid, SYSCONTEXTID, true);
|
|
|
2599 |
assign_capability('moodle/competency:planmanage', CAP_ALLOW, $roleid, SYSCONTEXTID, true);
|
|
|
2600 |
assign_capability('moodle/competency:planmanagedraft', CAP_ALLOW, $roleid, SYSCONTEXTID, true);
|
|
|
2601 |
assign_capability('moodle/competency:usercompetencycomment', CAP_ALLOW, $roleid, SYSCONTEXTID, true);
|
|
|
2602 |
assign_capability('moodle/competency:usercompetencyview', CAP_ALLOW, $roleid, SYSCONTEXTID, true);
|
|
|
2603 |
accesslib_clear_all_caches_for_unit_testing();
|
|
|
2604 |
}
|
|
|
2605 |
|
|
|
2606 |
/**
|
|
|
2607 |
* Assert the content of a contextlist.
|
|
|
2608 |
*
|
|
|
2609 |
* @param contextlist $contextlist The list.
|
|
|
2610 |
* @param array $expectedcontextsorids The expected content.
|
|
|
2611 |
* @return void
|
|
|
2612 |
*/
|
|
|
2613 |
protected function assert_contextlist(contextlist $contextlist, $expectedcontextsorids) {
|
|
|
2614 |
$contextids = array_unique($contextlist->get_contextids());
|
|
|
2615 |
$expectedids = array_unique(array_map(function($item) {
|
|
|
2616 |
return $item instanceof \context ? $item->id : $id;
|
|
|
2617 |
}, $expectedcontextsorids));
|
|
|
2618 |
$this->assert_array_match($expectedids, $contextids);
|
|
|
2619 |
}
|
|
|
2620 |
|
|
|
2621 |
/**
|
|
|
2622 |
* Assert that array match.
|
|
|
2623 |
*
|
|
|
2624 |
* @param array $array1 The first one.
|
|
|
2625 |
* @param array $array2 The second one.
|
|
|
2626 |
* @return void
|
|
|
2627 |
*/
|
|
|
2628 |
protected function assert_array_match($array1, $array2) {
|
|
|
2629 |
$array1 = (array) (object) $array1;
|
|
|
2630 |
$array2 = (array) (object) $array2;
|
|
|
2631 |
sort($array1);
|
|
|
2632 |
sort($array2);
|
|
|
2633 |
$this->assertEquals($array1, $array2);
|
|
|
2634 |
}
|
|
|
2635 |
|
|
|
2636 |
/**
|
|
|
2637 |
* Assert the content of exported comments.
|
|
|
2638 |
*
|
|
|
2639 |
* @param array $expected The content of the comments.
|
|
|
2640 |
* @param array $comments The exported comments.
|
|
|
2641 |
* @return void
|
|
|
2642 |
*/
|
|
|
2643 |
protected function assert_exported_comments($expected, $comments) {
|
|
|
2644 |
$this->assertCount(count($expected), $comments);
|
|
|
2645 |
$contents = array_map(function($comment) {
|
|
|
2646 |
return strip_tags($comment->content);
|
|
|
2647 |
}, $comments);
|
|
|
2648 |
$this->assert_array_match($expected, $contents);
|
|
|
2649 |
}
|
|
|
2650 |
|
|
|
2651 |
/**
|
|
|
2652 |
* Assert that a comment object has comments.
|
|
|
2653 |
*
|
|
|
2654 |
* @param \comment $comment The comment object.
|
|
|
2655 |
* @return void
|
|
|
2656 |
*/
|
|
|
2657 |
protected function assert_has_comments(\comment $comment) {
|
|
|
2658 |
global $DB;
|
|
|
2659 |
$this->assertTrue($DB->record_exists('comments', [
|
|
|
2660 |
'contextid' => $comment->get_context()->id,
|
|
|
2661 |
'component' => $comment->get_component(),
|
|
|
2662 |
'commentarea' => $comment->get_commentarea(),
|
|
|
2663 |
'itemid' => $comment->get_itemid()
|
|
|
2664 |
]));
|
|
|
2665 |
}
|
|
|
2666 |
|
|
|
2667 |
/**
|
|
|
2668 |
* Assert that a comment object does not have any comments.
|
|
|
2669 |
*
|
|
|
2670 |
* @param \comment $comment The comment object.
|
|
|
2671 |
* @return void
|
|
|
2672 |
*/
|
|
|
2673 |
protected function assert_has_no_comments(\comment $comment) {
|
|
|
2674 |
global $DB;
|
|
|
2675 |
$this->assertFalse($DB->record_exists('comments', [
|
|
|
2676 |
'contextid' => $comment->get_context()->id,
|
|
|
2677 |
'component' => $comment->get_component(),
|
|
|
2678 |
'commentarea' => $comment->get_commentarea(),
|
|
|
2679 |
'itemid' => $comment->get_itemid()
|
|
|
2680 |
]));
|
|
|
2681 |
}
|
|
|
2682 |
|
|
|
2683 |
/**
|
|
|
2684 |
* Get the count of comments.
|
|
|
2685 |
*
|
|
|
2686 |
* @param \comment $comment The comment object.
|
|
|
2687 |
* @param int $userid The user ID.
|
|
|
2688 |
* @return int
|
|
|
2689 |
*/
|
|
|
2690 |
protected function get_comments_count(\comment $comment, $userid = null) {
|
|
|
2691 |
global $DB;
|
|
|
2692 |
$params = [
|
|
|
2693 |
'contextid' => $comment->get_context()->id,
|
|
|
2694 |
'component' => $comment->get_component(),
|
|
|
2695 |
'commentarea' => $comment->get_commentarea(),
|
|
|
2696 |
'itemid' => $comment->get_itemid(),
|
|
|
2697 |
];
|
|
|
2698 |
if ($userid) {
|
|
|
2699 |
$params['userid'] = $userid;
|
|
|
2700 |
}
|
|
|
2701 |
return $DB->count_records('comments', $params);
|
|
|
2702 |
}
|
|
|
2703 |
}
|