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 |
declare(strict_types=1);
|
|
|
18 |
|
|
|
19 |
namespace core_reportbuilder;
|
|
|
20 |
|
|
|
21 |
use advanced_testcase;
|
|
|
22 |
use context_system;
|
|
|
23 |
use core_reportbuilder\local\report\action;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Unit tests for the system report class
|
|
|
27 |
*
|
|
|
28 |
* @package core_reportbuilder
|
|
|
29 |
* @covers \core_reportbuilder\system_report
|
|
|
30 |
* @copyright 2021 David Matamoros <davidmc@moodle.com>
|
|
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
32 |
*/
|
|
|
33 |
class system_report_test extends advanced_testcase {
|
|
|
34 |
/**
|
|
|
35 |
* Test for actions
|
|
|
36 |
*/
|
|
|
37 |
public function test_actions(): void {
|
|
|
38 |
global $CFG;
|
|
|
39 |
require_once("{$CFG->dirroot}/reportbuilder/tests/fixtures/system_report_available.php");
|
|
|
40 |
|
|
|
41 |
$this->resetAfterTest();
|
|
|
42 |
|
|
|
43 |
$systemreport = system_report_factory::create(system_report_available::class, context_system::instance(),
|
|
|
44 |
'', '', 0, ['withactions' => true]);
|
|
|
45 |
$actions = $systemreport->get_actions();
|
|
|
46 |
$this->assertCount(1, $actions);
|
|
|
47 |
$action = reset($actions);
|
|
|
48 |
$this->assertInstanceOf(action::class, $action);
|
|
|
49 |
|
|
|
50 |
$systemreport->add_action($action);
|
|
|
51 |
$actions = $systemreport->get_actions();
|
|
|
52 |
$this->assertCount(2, $actions);
|
|
|
53 |
$this->assertTrue($systemreport->has_actions());
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Test for parameters
|
|
|
58 |
*/
|
|
|
59 |
public function test_parameters(): void {
|
|
|
60 |
global $CFG;
|
|
|
61 |
require_once("{$CFG->dirroot}/reportbuilder/tests/fixtures/system_report_available.php");
|
|
|
62 |
|
|
|
63 |
$this->resetAfterTest();
|
|
|
64 |
|
|
|
65 |
$systemreport = system_report_factory::create(system_report_available::class, context_system::instance(),
|
|
|
66 |
'', '', 0, ['withactions' => true]);
|
|
|
67 |
|
|
|
68 |
$this->assertEquals(['withactions' => true], $systemreport->get_parameters());
|
|
|
69 |
|
|
|
70 |
$systemreport->set_parameters(['withfilters' => true, 'secondparameter' => false]);
|
|
|
71 |
$this->assertEquals(['withfilters' => true, 'secondparameter' => false], $systemreport->get_parameters());
|
|
|
72 |
|
|
|
73 |
$this->assertFalse((bool)$systemreport->get_parameter('secondparameter', true, PARAM_BOOL));
|
|
|
74 |
// Get a param that does not exist.
|
|
|
75 |
$this->assertEquals('3', $systemreport->get_parameter('thirdparameter', '3', PARAM_INT));
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Test for column sorting
|
|
|
80 |
*/
|
|
|
81 |
public function test_initial_sort_column(): void {
|
|
|
82 |
global $CFG;
|
|
|
83 |
require_once("{$CFG->dirroot}/reportbuilder/tests/fixtures/system_report_available.php");
|
|
|
84 |
|
|
|
85 |
$this->resetAfterTest();
|
|
|
86 |
|
|
|
87 |
$systemreport = system_report_factory::create(system_report_available::class, context_system::instance());
|
|
|
88 |
$systemreport->set_initial_sort_column('user:username', SORT_DESC);
|
|
|
89 |
$column = $systemreport->get_column('user:username');
|
|
|
90 |
|
|
|
91 |
$this->assertEquals($column, $systemreport->get_initial_sort_column());
|
|
|
92 |
$this->assertEquals(SORT_DESC, $systemreport->get_initial_sort_direction());
|
|
|
93 |
}
|
|
|
94 |
}
|