weekly release 4.5dev
[moodle.git] / lib / tests / report_helper_test.php
blobf6cab8c765506132bd804bf33ef00b646caec3b6
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.
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/>.
17 /**
18 * Tests for report_helper.
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
26 namespace core;
28 use moodle_url;
29 use core\report_helper;
31 /**
32 * Tests the functions for report_helper class.
34 class report_helper_test extends \advanced_testcase {
35 /**
36 * Data provider for testing selected report for same and different courses
38 * @return array
40 public function data_selected_report(): array {
41 return [
42 ['course_url_id' => [
43 ['url' => '/test', 'id' => 1],
44 ['url' => '/foo', 'id' => 1]]
46 ['course_url_id' => [
47 ['url' => '/test', 'id' => 1],
48 ['url' => '/foo/bar', 'id' => 2]]
53 /**
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 {
60 global $USER;
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);