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\external;
|
|
|
20 |
|
|
|
21 |
use advanced_testcase;
|
|
|
22 |
use core\context\system;
|
|
|
23 |
use core_reportbuilder_generator;
|
|
|
24 |
use core_reportbuilder\system_report_factory;
|
|
|
25 |
use core_reportbuilder\local\systemreports\reports_list;
|
|
|
26 |
use core_user\reportbuilder\datasource\users;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Unit tests for system report data exporter
|
|
|
30 |
*
|
|
|
31 |
* @package core_reportbuilder
|
|
|
32 |
* @covers \core_reportbuilder\external\system_report_data_exporter
|
|
|
33 |
* @copyright 2023 Paul Holden <paulh@moodle.com>
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class system_report_data_exporter_test extends advanced_testcase {
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Test exported data structure
|
|
|
40 |
*/
|
|
|
41 |
public function test_export(): void {
|
|
|
42 |
global $PAGE;
|
|
|
43 |
|
|
|
44 |
$this->resetAfterTest();
|
|
|
45 |
$this->setAdminUser();
|
|
|
46 |
|
|
|
47 |
/** @var core_reportbuilder_generator $generator */
|
|
|
48 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
|
|
|
49 |
|
|
|
50 |
// Two reports, created one second apart to ensure consistent ordering by time created.
|
|
|
51 |
$generator->create_report(['name' => 'My first report', 'source' => users::class]);
|
|
|
52 |
$this->waitForSecond();
|
|
|
53 |
$generator->create_report(['name' => 'My second report', 'source' => users::class, 'tags' => ['cat', 'dog']]);
|
|
|
54 |
|
|
|
55 |
$reportinstance = system_report_factory::create(reports_list::class, system::instance());
|
|
|
56 |
|
|
|
57 |
$exporter = new system_report_data_exporter(null, ['report' => $reportinstance, 'page' => 0, 'perpage' => 1]);
|
|
|
58 |
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
|
|
|
59 |
|
|
|
60 |
$this->assertEquals([
|
|
|
61 |
'Name',
|
|
|
62 |
'Report source',
|
|
|
63 |
'Tags',
|
|
|
64 |
'Time created',
|
|
|
65 |
'Time modified',
|
|
|
66 |
'Modified by',
|
|
|
67 |
], $export->headers);
|
|
|
68 |
|
|
|
69 |
$this->assertCount(1, $export->rows);
|
|
|
70 |
[$name, $source, $tags, $timecreated, $timemodified, $modifiedby] = $export->rows[0]['columns'];
|
|
|
71 |
|
|
|
72 |
$this->assertStringContainsString('My second report', $name);
|
|
|
73 |
$this->assertEquals(users::get_name(), $source);
|
|
|
74 |
$this->assertEquals('cat, dog', $tags);
|
|
|
75 |
$this->assertNotEmpty($timecreated);
|
|
|
76 |
$this->assertNotEmpty($timemodified);
|
|
|
77 |
$this->assertEquals('Admin User', $modifiedby);
|
|
|
78 |
|
|
|
79 |
$this->assertEquals(2, $export->totalrowcount);
|
|
|
80 |
}
|
|
|
81 |
}
|