2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Tests for report_helper.
22 * @copyright 2021 Sujith Haridasan
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 use core\report_helper
;
32 * Tests the functions for report_helper class.
34 class report_helper_test
extends \advanced_testcase
{
36 * Data provider for testing selected report for same and different courses
40 public function data_selected_report(): array {
43 ['url' => '/test', 'id' => 1],
44 ['url' => '/foo', 'id' => 1]]
47 ['url' => '/test', 'id' => 1],
48 ['url' => '/foo/bar', 'id' => 2]]
54 * Testing selected report saved in $USER session.
56 * @dataProvider data_selected_report
57 * @param array $courseurlid The array has both course url and course id
59 public function test_save_selected_report(array $courseurlid): void
{
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');
68 $this->assertEquals($USER->course_last_report
[$courseid1], $url1);
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');
76 $this->assertEquals($USER->course_last_report
[$courseid2], $url2);