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]); 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(['Name', 'Report source', 'Time created', 'Time modified', 'Modified by'], $export->headers); 61 62 $this->assertCount(1, $export->rows); 63 [$name, $source, $timecreated, $timemodified, $modifiedby] = $export->rows[0]['columns']; 64 65 $this->assertStringContainsString('My second report', $name); 66 $this->assertEquals(users::get_name(), $source); 67 $this->assertNotEmpty($timecreated); 68 $this->assertNotEmpty($timemodified); 69 $this->assertEquals('Admin User', $modifiedby); 70 71 $this->assertEquals(2, $export->totalrowcount); 72 } 73 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body