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 |
* Tests for the progress report sorting.
|
|
|
19 |
*
|
|
|
20 |
* @package report_progress
|
|
|
21 |
* @copyright 2021 The Open University
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Class for testing report progress helper.
|
|
|
29 |
*
|
|
|
30 |
* @copyright 2021 The Open University
|
|
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
|
|
32 |
*/
|
|
|
33 |
class report_progress_helper_testcase extends advanced_testcase {
|
|
|
34 |
|
|
|
35 |
/** @var testing_data_generator data generator.*/
|
|
|
36 |
protected $generator;
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Set up testcase.
|
|
|
40 |
*/
|
|
|
41 |
public function setUp(): void {
|
|
|
42 |
global $CFG;
|
|
|
43 |
|
|
|
44 |
$CFG->enablecompletion = true;
|
|
|
45 |
$this->setAdminUser();
|
|
|
46 |
$this->resetAfterTest();
|
|
|
47 |
$this->generator = $this->getDataGenerator();
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Test process_activities_by_filter_options function.
|
|
|
52 |
*/
|
|
|
53 |
public function test_sort_activities() {
|
|
|
54 |
$expectedactivitytypes = ['all' => 'All activities and resources', 'assign' => 'Assignments', 'quiz' => 'Quizzes'];
|
|
|
55 |
|
|
|
56 |
// Generate test data.
|
|
|
57 |
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
|
|
58 |
$quiz2 = $this->generator->create_module('quiz', ['course' => $course->id, 'name' => 'Quiz 2'],
|
|
|
59 |
['completion' => 1]);
|
|
|
60 |
$quiz1 = $this->generator->create_module('quiz', ['course' => $course->id, 'name' => 'Quiz 1'],
|
|
|
61 |
['completion' => 1]);
|
|
|
62 |
$assign1 = $this->generator->create_module('assign', ['course' => $course->id, 'name' => 'Assignment'],
|
|
|
63 |
['completion' => 1]);
|
|
|
64 |
$completion = new completion_info($course);
|
|
|
65 |
// Sort the activities by name.
|
|
|
66 |
list($activitytypes, $activities) = \report_progress\local\helper::get_activities_to_show($completion, 'quiz',
|
|
|
67 |
'alphabetical');
|
|
|
68 |
|
|
|
69 |
// Check weather the result is filtered and sorted.
|
|
|
70 |
$this->assertEquals(2, count($activities));
|
|
|
71 |
$this->assertEquals('Quiz 1', $activities[0]->name);
|
|
|
72 |
$this->assertEquals('Quiz 2', $activities[1]->name);
|
|
|
73 |
$this->assertEquals($activitytypes, $expectedactivitytypes);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Test filtering by section.
|
|
|
78 |
*/
|
|
|
79 |
public function test_filter_activities_by_section() {
|
|
|
80 |
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
|
|
81 |
$this->generator->create_module('quiz', ['course' => $course->id, 'name' => 'Quiz 2', 'section' => 1],
|
|
|
82 |
['completion' => 1]);
|
|
|
83 |
$this->generator->create_module('quiz', ['course' => $course->id, 'name' => 'Quiz 1', 'section' => 2],
|
|
|
84 |
['completion' => 1]);
|
|
|
85 |
$this->generator->create_module('assign', ['course' => $course->id, 'name' => 'Assignment', 'section' => 2],
|
|
|
86 |
['completion' => 1]);
|
|
|
87 |
$completion = new completion_info($course);
|
|
|
88 |
|
|
|
89 |
// Get activities of section 0.
|
|
|
90 |
list($activitytypes, $activities) = \report_progress\local\helper::get_activities_to_show($completion, '', '', 0);
|
|
|
91 |
$this->assertEquals(0, count($activities));
|
|
|
92 |
$this->assertEquals($activitytypes, ['all' => 'All activities and resources']);
|
|
|
93 |
|
|
|
94 |
// Get activities of section 1.
|
|
|
95 |
list($activitytypes, $activities) = \report_progress\local\helper::get_activities_to_show($completion, '', '', 1);
|
|
|
96 |
$this->assertEquals(1, count($activities));
|
|
|
97 |
$this->assertEquals('Quiz 2', array_shift($activities)->name);
|
|
|
98 |
$this->assertEquals($activitytypes, ['all' => 'All activities and resources', 'quiz' => 'Quizzes']);
|
|
|
99 |
|
|
|
100 |
// Get activities of section 2.
|
|
|
101 |
list($activitytypes, $activities) = \report_progress\local\helper::get_activities_to_show($completion, '', '', 2);
|
|
|
102 |
$this->assertEquals(2, count($activities));
|
|
|
103 |
$this->assertEquals('Quiz 1', array_shift($activities)->name);
|
|
|
104 |
$this->assertEquals('Assignment', array_shift($activities)->name);
|
|
|
105 |
$this->assertEquals(
|
|
|
106 |
$activitytypes,
|
|
|
107 |
['all' => 'All activities and resources', 'assign' => 'Assignments', 'quiz' => 'Quizzes']
|
|
|
108 |
);
|
|
|
109 |
|
|
|
110 |
// Get assignments of section 2.
|
|
|
111 |
list($activitytypes, $activities) = \report_progress\local\helper::get_activities_to_show($completion, 'assign', '', 2);
|
|
|
112 |
$this->assertEquals(1, count($activities));
|
|
|
113 |
$this->assertEquals('Assignment', array_shift($activities)->name);
|
|
|
114 |
$this->assertEquals(
|
|
|
115 |
$activitytypes,
|
|
|
116 |
['all' => 'All activities and resources', 'assign' => 'Assignments', 'quiz' => 'Quizzes']
|
|
|
117 |
);
|
|
|
118 |
|
|
|
119 |
// Get assignments of section 1.
|
|
|
120 |
list($activitytypes, $activities) = \report_progress\local\helper::get_activities_to_show($completion, 'assign', '', 1);
|
|
|
121 |
$this->assertEquals(0, count($activities));
|
|
|
122 |
$this->assertEquals(
|
|
|
123 |
$activitytypes,
|
|
|
124 |
['all' => 'All activities and resources', 'assign' => 'Assignments', 'quiz' => 'Quizzes']
|
|
|
125 |
);
|
|
|
126 |
}
|
|
|
127 |
}
|