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 report_helper.
|
|
|
19 |
*
|
|
|
20 |
* @package core
|
|
|
21 |
* @category test
|
|
|
22 |
* @copyright 2021 Sujith Haridasan
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace core;
|
|
|
27 |
|
|
|
28 |
use moodle_url;
|
|
|
29 |
use core\report_helper;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Tests the functions for report_helper class.
|
|
|
33 |
*/
|
|
|
34 |
class report_helper_test extends \advanced_testcase {
|
|
|
35 |
/**
|
|
|
36 |
* Data provider for testing selected report for same and different courses
|
|
|
37 |
*
|
|
|
38 |
* @return array
|
|
|
39 |
*/
|
|
|
40 |
public function data_selected_report(): array {
|
|
|
41 |
return [
|
|
|
42 |
['course_url_id' => [
|
|
|
43 |
['url' => '/test', 'id' => 1],
|
|
|
44 |
['url' => '/foo', 'id' => 1]]
|
|
|
45 |
],
|
|
|
46 |
['course_url_id' => [
|
|
|
47 |
['url' => '/test', 'id' => 1],
|
|
|
48 |
['url' => '/foo/bar', 'id' => 2]]
|
|
|
49 |
]
|
|
|
50 |
];
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Testing selected report saved in $USER session.
|
|
|
55 |
*
|
|
|
56 |
* @dataProvider data_selected_report
|
|
|
57 |
* @param array $courseurlid The array has both course url and course id
|
|
|
58 |
*/
|
|
|
59 |
public function test_save_selected_report(array $courseurlid): void {
|
|
|
60 |
global $USER;
|
|
|
61 |
|
|
|
62 |
$url1 = new moodle_url($courseurlid[0]['url']);
|
|
|
63 |
$courseid1 = $courseurlid[0]['id'];
|
|
|
64 |
report_helper::save_selected_report($courseid1, $url1);
|
|
|
65 |
$this->assertDebuggingCalled('save_selected_report() has been deprecated because it is no ' .
|
|
|
66 |
'longer used and will be removed in future versions of Moodle');
|
|
|
67 |
|
|
|
68 |
$this->assertEquals($USER->course_last_report[$courseid1], $url1);
|
|
|
69 |
|
|
|
70 |
$url2 = new moodle_url($courseurlid[1]['url']);
|
|
|
71 |
$courseid2 = $courseurlid[1]['id'];
|
|
|
72 |
report_helper::save_selected_report($courseid2, $url2);
|
|
|
73 |
$this->assertDebuggingCalled('save_selected_report() has been deprecated because it is no ' .
|
|
|
74 |
'longer used and will be removed in future versions of Moodle');
|
|
|
75 |
|
|
|
76 |
$this->assertEquals($USER->course_last_report[$courseid2], $url2);
|
|
|
77 |
}
|
|
|
78 |
}
|