1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Unit tests for activities completed by classification.
|
|
|
19 |
*
|
|
|
20 |
* @package core_analytics
|
|
|
21 |
* @copyright 2017 David Monllaó {@link http://www.davidmonllao.com}
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Unit tests for activities completed by classification.
|
|
|
29 |
*
|
|
|
30 |
* @package core_analytics
|
|
|
31 |
* @copyright 2017 David Monllaó {@link http://www.davidmonllao.com}
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class community_of_inquiry_activities_completed_by_testcase extends advanced_testcase {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* availability_levels
|
|
|
38 |
*
|
|
|
39 |
* @return array
|
|
|
40 |
*/
|
|
|
41 |
public function availability_levels() {
|
|
|
42 |
return array(
|
|
|
43 |
'activity' => array('activity'),
|
|
|
44 |
'section' => array('section'),
|
|
|
45 |
);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* test_get_activities_with_availability
|
|
|
50 |
*
|
|
|
51 |
* @dataProvider availability_levels
|
|
|
52 |
* @param string $availabilitylevel
|
|
|
53 |
* @return void
|
|
|
54 |
*/
|
|
|
55 |
public function test_get_activities_with_availability($availabilitylevel) {
|
|
|
56 |
|
|
|
57 |
list($course, $stu1) = $this->setup_course();
|
|
|
58 |
|
|
|
59 |
// Forum1 is ignored as section 0 does not count.
|
|
|
60 |
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
|
|
|
61 |
|
|
|
62 |
$modinfo = get_fast_modinfo($course, $stu1->id);
|
|
|
63 |
$cm = $modinfo->get_cm($forum->cmid);
|
|
|
64 |
|
|
|
65 |
if ($availabilitylevel === 'activity') {
|
|
|
66 |
$availabilityinfo = new \core_availability\info_module($cm);
|
|
|
67 |
} else if ($availabilitylevel === 'section') {
|
|
|
68 |
$availabilityinfo = new \core_availability\info_section($cm->get_modinfo()->get_section_info($cm->sectionnum));
|
|
|
69 |
} else {
|
|
|
70 |
$this->fail('Unsupported availability level');
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
$fromtime = strtotime('2015-10-22 00:00:00 GMT');
|
|
|
74 |
$untiltime = strtotime('2015-10-24 00:00:00 GMT');
|
|
|
75 |
$structure = (object)array('op' => '|', 'show' => true, 'c' => array(
|
|
|
76 |
(object)array('type' => 'date', 'd' => '<', 't' => $untiltime),
|
|
|
77 |
(object)array('type' => 'date', 'd' => '>=', 't' => $fromtime)
|
|
|
78 |
));
|
|
|
79 |
|
|
|
80 |
$method = new ReflectionMethod($availabilityinfo, 'set_in_database');
|
|
|
81 |
$method->invoke($availabilityinfo, json_encode($structure));
|
|
|
82 |
|
|
|
83 |
$this->setUser($stu1);
|
|
|
84 |
|
|
|
85 |
// Reset modinfo we also want coursemodinfo cache definition to be cleared.
|
|
|
86 |
get_fast_modinfo($course, $stu1->id, true);
|
|
|
87 |
rebuild_course_cache($course->id, true);
|
|
|
88 |
|
|
|
89 |
$modinfo = get_fast_modinfo($course, $stu1->id);
|
|
|
90 |
|
|
|
91 |
$cm = $modinfo->get_cm($forum->cmid);
|
|
|
92 |
|
|
|
93 |
$course = new \core_analytics\course($course);
|
|
|
94 |
list($indicator, $method) = $this->instantiate_indicator('mod_forum', $course);
|
|
|
95 |
|
|
|
96 |
// Condition from after provided end time.
|
|
|
97 |
$this->assertCount(0, $method->invoke($indicator, strtotime('2015-10-20 00:00:00 GMT'),
|
|
|
98 |
strtotime('2015-10-21 00:00:00 GMT'), $stu1));
|
|
|
99 |
|
|
|
100 |
// Condition until before provided start time
|
|
|
101 |
$this->assertCount(0, $method->invoke($indicator, strtotime('2015-10-25 00:00:00 GMT'),
|
|
|
102 |
strtotime('2015-10-26 00:00:00 GMT'), $stu1));
|
|
|
103 |
|
|
|
104 |
// Condition until after provided end time.
|
|
|
105 |
$this->assertCount(0, $method->invoke($indicator, strtotime('2015-10-22 00:00:00 GMT'),
|
|
|
106 |
strtotime('2015-10-23 00:00:00 GMT'), $stu1));
|
|
|
107 |
|
|
|
108 |
// Condition until after provided start time and before provided end time.
|
|
|
109 |
$this->assertCount(1, $method->invoke($indicator, strtotime('2015-10-22 00:00:00 GMT'),
|
|
|
110 |
strtotime('2015-10-25 00:00:00 GMT'), $stu1));
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* test_get_activities_with_weeks
|
|
|
115 |
*
|
|
|
116 |
* @return void
|
|
|
117 |
*/
|
|
|
118 |
public function test_get_activities_with_weeks() {
|
|
|
119 |
|
|
|
120 |
$startdate = gmmktime('0', '0', '0', 10, 24, 2015);
|
|
|
121 |
$record = array(
|
|
|
122 |
'format' => 'weeks',
|
|
|
123 |
'numsections' => 4,
|
|
|
124 |
'startdate' => $startdate,
|
|
|
125 |
);
|
|
|
126 |
|
|
|
127 |
list($course, $stu1) = $this->setup_course($record);
|
|
|
128 |
|
|
|
129 |
// Forum1 is ignored as section 0 does not count.
|
|
|
130 |
$forum1 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
131 |
array('section' => 0));
|
|
|
132 |
$forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
133 |
array('section' => 1));
|
|
|
134 |
$forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
135 |
array('section' => 2));
|
|
|
136 |
$forum4 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
137 |
array('section' => 4));
|
|
|
138 |
$forum5 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
139 |
array('section' => 4));
|
|
|
140 |
|
|
|
141 |
$course = new \core_analytics\course($course);
|
|
|
142 |
list($indicator, $method) = $this->instantiate_indicator('mod_forum', $course);
|
|
|
143 |
|
|
|
144 |
$this->setUser($stu1);
|
|
|
145 |
|
|
|
146 |
$first = $startdate;
|
|
|
147 |
$second = $startdate + WEEKSECS;
|
|
|
148 |
$third = $startdate + (WEEKSECS * 2);
|
|
|
149 |
$forth = $startdate + (WEEKSECS * 3);
|
|
|
150 |
$this->assertCount(1, $method->invoke($indicator, $first, $first + WEEKSECS, $stu1));
|
|
|
151 |
$this->assertCount(1, $method->invoke($indicator, $second, $second + WEEKSECS, $stu1));
|
|
|
152 |
$this->assertCount(0, $method->invoke($indicator, $third, $third + WEEKSECS, $stu1));
|
|
|
153 |
$this->assertCount(2, $method->invoke($indicator, $forth, $forth + WEEKSECS, $stu1));
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
/**
|
|
|
157 |
* test_get_activities_by_section
|
|
|
158 |
*
|
|
|
159 |
* @return void
|
|
|
160 |
*/
|
|
|
161 |
public function test_get_activities_by_section() {
|
|
|
162 |
|
|
|
163 |
// This makes debugging easier, sorry WA's +8 :).
|
|
|
164 |
$this->setTimezone('UTC');
|
|
|
165 |
|
|
|
166 |
// 1 year.
|
|
|
167 |
$startdate = gmmktime('0', '0', '0', 10, 24, 2015);
|
|
|
168 |
$enddate = gmmktime('0', '0', '0', 10, 24, 2016);
|
|
|
169 |
$numsections = 12;
|
|
|
170 |
$record = array(
|
|
|
171 |
'format' => 'topics',
|
|
|
172 |
'numsections' => $numsections,
|
|
|
173 |
'startdate' => $startdate,
|
|
|
174 |
'enddate' => $enddate
|
|
|
175 |
);
|
|
|
176 |
|
|
|
177 |
list($course, $stu1) = $this->setup_course($record);
|
|
|
178 |
|
|
|
179 |
// Forum1 is ignored as section 0 does not count.
|
|
|
180 |
$forum1 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
181 |
array('section' => 0));
|
|
|
182 |
$forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
183 |
array('section' => 1));
|
|
|
184 |
$forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
185 |
array('section' => 4));
|
|
|
186 |
$forum4 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
187 |
array('section' => 8));
|
|
|
188 |
$forum5 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
189 |
array('section' => 10));
|
|
|
190 |
$forum6 = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
|
|
191 |
array('section' => 12));
|
|
|
192 |
|
|
|
193 |
$course = new \core_analytics\course($course);
|
|
|
194 |
list($indicator, $method) = $this->instantiate_indicator('mod_forum', $course);
|
|
|
195 |
|
|
|
196 |
$this->setUser($stu1);
|
|
|
197 |
|
|
|
198 |
// Split the course in quarters.
|
|
|
199 |
$duration = ($enddate - $startdate) / 4;
|
|
|
200 |
$first = $startdate;
|
|
|
201 |
$second = $startdate + $duration;
|
|
|
202 |
$third = $startdate + ($duration * 2);
|
|
|
203 |
$forth = $startdate + ($duration * 3);
|
|
|
204 |
$this->assertCount(1, $method->invoke($indicator, $first, $first + $duration, $stu1));
|
|
|
205 |
$this->assertCount(1, $method->invoke($indicator, $second, $second + $duration, $stu1));
|
|
|
206 |
$this->assertCount(1, $method->invoke($indicator, $third, $third + $duration, $stu1));
|
|
|
207 |
$this->assertCount(2, $method->invoke($indicator, $forth, $forth + $duration, $stu1));
|
|
|
208 |
|
|
|
209 |
// Split the course in as many parts as sections.
|
|
|
210 |
$duration = ($enddate - $startdate) / $numsections;
|
|
|
211 |
for ($i = 1; $i <= $numsections; $i++) {
|
|
|
212 |
// The -1 because section 1 start represents the course start.
|
|
|
213 |
$timeranges[$i] = $startdate + ($duration * ($i - 1));
|
|
|
214 |
}
|
|
|
215 |
$this->assertCount(1, $method->invoke($indicator, $timeranges[1], $timeranges[1] + $duration, $stu1));
|
|
|
216 |
$this->assertCount(1, $method->invoke($indicator, $timeranges[4], $timeranges[4] + $duration, $stu1));
|
|
|
217 |
$this->assertCount(1, $method->invoke($indicator, $timeranges[8], $timeranges[8] + $duration, $stu1));
|
|
|
218 |
$this->assertCount(1, $method->invoke($indicator, $timeranges[10], $timeranges[10] + $duration, $stu1));
|
|
|
219 |
$this->assertCount(1, $method->invoke($indicator, $timeranges[12], $timeranges[12] + $duration, $stu1));
|
|
|
220 |
|
|
|
221 |
// Nothing here.
|
|
|
222 |
$this->assertCount(0, $method->invoke($indicator, $timeranges[2], $timeranges[2] + $duration, $stu1));
|
|
|
223 |
$this->assertCount(0, $method->invoke($indicator, $timeranges[3], $timeranges[3] + $duration, $stu1));
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
/**
|
|
|
227 |
* test_get_activities_with_specific_restrictions
|
|
|
228 |
*
|
|
|
229 |
* @return void
|
|
|
230 |
*/
|
|
|
231 |
public function test_get_activities_with_specific_restrictions() {
|
|
|
232 |
|
|
|
233 |
list($course, $stu1) = $this->setup_course();
|
|
|
234 |
|
|
|
235 |
$end = strtotime('2015-10-24 00:00:00 GMT');
|
|
|
236 |
|
|
|
237 |
// 1 with time close, one without.
|
|
|
238 |
$params = array('course' => $course->id);
|
|
|
239 |
$assign1 = $this->getDataGenerator()->create_module('assign', $params);
|
|
|
240 |
$params['duedate'] = $end;
|
|
|
241 |
$assign2 = $this->getDataGenerator()->create_module('assign', $params);
|
|
|
242 |
|
|
|
243 |
// 1 with time close, one without.
|
|
|
244 |
$params = array('course' => $course->id);
|
|
|
245 |
$choice1 = $this->getDataGenerator()->create_module('choice', $params);
|
|
|
246 |
$params['timeclose'] = $end;
|
|
|
247 |
$choice1 = $this->getDataGenerator()->create_module('choice', $params);
|
|
|
248 |
|
|
|
249 |
// 1 with time close, one without.
|
|
|
250 |
$params = array('course' => $course->id);
|
|
|
251 |
$data1 = $this->getDataGenerator()->create_module('data', $params);
|
|
|
252 |
$params['timeavailableto'] = $end;
|
|
|
253 |
$data1 = $this->getDataGenerator()->create_module('data', $params);
|
|
|
254 |
|
|
|
255 |
// 1 with time close, one without.
|
|
|
256 |
$params = array('course' => $course->id);
|
|
|
257 |
$feedback1 = $this->getDataGenerator()->create_module('feedback', $params);
|
|
|
258 |
$params['timeclose'] = $end;
|
|
|
259 |
$feedback1 = $this->getDataGenerator()->create_module('feedback', $params);
|
|
|
260 |
|
|
|
261 |
// 1 with time close, one without.
|
|
|
262 |
$params = array('course' => $course->id);
|
|
|
263 |
$lesson1 = $this->getDataGenerator()->create_module('lesson', $params);
|
|
|
264 |
$params['deadline'] = $end;
|
|
|
265 |
$lesson1 = $this->getDataGenerator()->create_module('lesson', $params);
|
|
|
266 |
|
|
|
267 |
// 1 with time close, one without.
|
|
|
268 |
$params = array('course' => $course->id);
|
|
|
269 |
$quiz1 = $this->getDataGenerator()->create_module('quiz', $params);
|
|
|
270 |
$params['timeclose'] = $end;
|
|
|
271 |
$quiz1 = $this->getDataGenerator()->create_module('quiz', $params);
|
|
|
272 |
|
|
|
273 |
// 1 with time close, one without.
|
|
|
274 |
$params = array('course' => $course->id);
|
|
|
275 |
$scorm1 = $this->getDataGenerator()->create_module('scorm', $params);
|
|
|
276 |
$params['timeclose'] = $end;
|
|
|
277 |
$scorm1 = $this->getDataGenerator()->create_module('scorm', $params);
|
|
|
278 |
|
|
|
279 |
// 1 with time close, one without.
|
|
|
280 |
$params = array('course' => $course->id);
|
|
|
281 |
$workshop1 = $this->getDataGenerator()->create_module('workshop', $params);
|
|
|
282 |
$params['submissionend'] = $end;
|
|
|
283 |
$workshop1 = $this->getDataGenerator()->create_module('workshop', $params);
|
|
|
284 |
|
|
|
285 |
$course = new \core_analytics\course($course);
|
|
|
286 |
|
|
|
287 |
$activitytypes = array('mod_assign', 'mod_choice', 'mod_data', 'mod_feedback', 'mod_lesson',
|
|
|
288 |
'mod_quiz', 'mod_scorm', 'mod_workshop');
|
|
|
289 |
foreach ($activitytypes as $activitytype) {
|
|
|
290 |
|
|
|
291 |
list($indicator, $method) = $this->instantiate_indicator($activitytype, $course);
|
|
|
292 |
|
|
|
293 |
$message = $activitytype . ' activity type returned activities do not match expected size';
|
|
|
294 |
$this->assertCount(0, $method->invoke($indicator, strtotime('2015-10-20 00:00:00 GMT'),
|
|
|
295 |
strtotime('2015-10-21 00:00:00 GMT'), $stu1), $message);
|
|
|
296 |
|
|
|
297 |
$this->assertCount(0, $method->invoke($indicator, strtotime('2015-10-25 00:00:00 GMT'),
|
|
|
298 |
strtotime('2015-10-26 00:00:00 GMT'), $stu1), $message);
|
|
|
299 |
|
|
|
300 |
$this->assertCount(1, $method->invoke($indicator, strtotime('2015-10-22 00:00:00 GMT'),
|
|
|
301 |
strtotime('2015-10-25 00:00:00 GMT'), $stu1), $message);
|
|
|
302 |
}
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
/**
|
|
|
306 |
* setup_course
|
|
|
307 |
*
|
|
|
308 |
* @param stdClass $courserecord
|
|
|
309 |
* @return array
|
|
|
310 |
*/
|
|
|
311 |
protected function setup_course($courserecord = null) {
|
|
|
312 |
global $CFG;
|
|
|
313 |
|
|
|
314 |
$this->resetAfterTest(true);
|
|
|
315 |
|
|
|
316 |
$this->setAdminUser();
|
|
|
317 |
|
|
|
318 |
$CFG->enableavailability = true;
|
|
|
319 |
|
|
|
320 |
$course = $this->getDataGenerator()->create_course($courserecord);
|
|
|
321 |
$stu1 = $this->getDataGenerator()->create_user();
|
|
|
322 |
$this->getDataGenerator()->enrol_user($stu1->id, $course->id, 'student');
|
|
|
323 |
|
|
|
324 |
return array($course, $stu1);
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
/**
|
|
|
328 |
* Returns the module cognitive depth indicator and the reflection method.
|
|
|
329 |
*
|
|
|
330 |
* @param string $modulename
|
|
|
331 |
* @param \core_analytics\course $course
|
|
|
332 |
* @return array
|
|
|
333 |
*/
|
|
|
334 |
private function instantiate_indicator($modulename, \core_analytics\course $course) {
|
|
|
335 |
|
|
|
336 |
$classname = '\\' . $modulename . '\analytics\indicator\cognitive_depth';
|
|
|
337 |
$indicator = new $classname();
|
|
|
338 |
$class = new ReflectionClass($indicator);
|
|
|
339 |
|
|
|
340 |
$property = $class->getProperty('course');
|
|
|
341 |
$property->setValue($indicator, $course);
|
|
|
342 |
|
|
|
343 |
$method = new ReflectionMethod($indicator, 'get_activities');
|
|
|
344 |
|
|
|
345 |
return array($indicator, $method);
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
}
|