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 |
* Completion unit tests common base for Completion Progress block.
|
|
|
19 |
*
|
|
|
20 |
* @package block_completion_progress
|
|
|
21 |
* @copyright 2020 Jonathon Fowler <fowlerj@usq.edu.au>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace block_completion_progress\tests;
|
|
|
26 |
|
|
|
27 |
defined('MOODLE_INTERNAL') || die();
|
|
|
28 |
|
|
|
29 |
global $CFG;
|
|
|
30 |
|
|
|
31 |
use block_completion_progress\completion_progress;
|
|
|
32 |
use block_completion_progress\defaults;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Completion unit tests common base for Completion Progress block.
|
|
|
36 |
*
|
|
|
37 |
* @package block_completion_progress
|
|
|
38 |
* @copyright 2020 Jonathon Fowler <fowlerj@usq.edu.au>
|
|
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
40 |
*/
|
|
|
41 |
abstract class completion_testcase extends \advanced_testcase {
|
|
|
42 |
/**
|
|
|
43 |
* The test course.
|
|
|
44 |
* @var object
|
|
|
45 |
*/
|
|
|
46 |
protected $course;
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* A completion_progress block instance in the test course.
|
|
|
50 |
* @var object
|
|
|
51 |
*/
|
|
|
52 |
protected $blockinstance;
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* Setup function - we will create a course and add an assign instance to it.
|
|
|
57 |
*/
|
|
|
58 |
protected function setUp(): void {
|
|
|
59 |
$this->resetAfterTest(true);
|
|
|
60 |
|
|
|
61 |
set_config('enablecompletion', 1);
|
|
|
62 |
|
|
|
63 |
$generator = $this->getDataGenerator();
|
|
|
64 |
|
|
|
65 |
$this->course = $generator->create_course([
|
|
|
66 |
'enablecompletion' => 1,
|
|
|
67 |
]);
|
|
|
68 |
|
|
|
69 |
// Add a block.
|
|
|
70 |
$context = \context_course::instance($this->course->id);
|
|
|
71 |
$blockinfo = [
|
|
|
72 |
'parentcontextid' => $context->id,
|
|
|
73 |
'pagetypepattern' => 'course-view-*',
|
|
|
74 |
'showinsubcontexts' => 0,
|
|
|
75 |
'defaultweight' => 5,
|
|
|
76 |
'timecreated' => time(),
|
|
|
77 |
'timemodified' => time(),
|
|
|
78 |
'defaultregion' => 'side-post',
|
|
|
79 |
'configdata' => base64_encode(serialize((object)[
|
|
|
80 |
'orderby' => defaults::ORDERBY,
|
|
|
81 |
'longbars' => defaults::LONGBARS,
|
|
|
82 |
'progressBarIcons' => defaults::PROGRESSBARICONS,
|
|
|
83 |
'showpercentage' => defaults::SHOWPERCENTAGE,
|
|
|
84 |
'progressTitle' => "",
|
|
|
85 |
'activitiesincluded' => defaults::ACTIVITIESINCLUDED,
|
|
|
86 |
])),
|
|
|
87 |
];
|
|
|
88 |
$this->blockinstance = $this->getDataGenerator()->create_block('completion_progress', $blockinfo);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Assert a user's completion status for a course module.
|
|
|
93 |
* @param object $student
|
|
|
94 |
* @param object $cm
|
|
|
95 |
* @param integer|string $status
|
|
|
96 |
*/
|
|
|
97 |
protected function assert_progress_completion($student, $cm, $status) {
|
|
|
98 |
$progress = (new completion_progress($this->course))
|
|
|
99 |
->for_user($student)
|
|
|
100 |
->for_block_instance($this->blockinstance);
|
|
|
101 |
$completions = $progress->get_completions();
|
|
|
102 |
$this->assertEquals(
|
|
|
103 |
[$cm->id => $status],
|
|
|
104 |
$completions
|
|
|
105 |
);
|
|
|
106 |
}
|
|
|
107 |
}
|