See Release Notes
Long Term Support Release
Differences Between: [Versions 401 and 402] [Versions 401 and 403]
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 context_system; 23 use moodle_url; 24 use core_reportbuilder\system_report_available; 25 use core_reportbuilder\system_report_factory; 26 27 /** 28 * Unit tests for system report exporter 29 * 30 * @package core_reportbuilder 31 * @covers \core_reportbuilder\external\system_report_exporter 32 * @copyright 2021 Paul Holden <paulh@moodle.com> 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class system_report_exporter_test extends advanced_testcase { 36 37 /** 38 * Load test fixture 39 */ 40 public static function setUpBeforeClass(): void { 41 global $CFG; 42 43 require_once("{$CFG->dirroot}/reportbuilder/tests/fixtures/system_report_available.php"); 44 } 45 46 /** 47 * Data provider for {@see test_export} 48 * 49 * @return array[] 50 */ 51 public function export_provider(): array { 52 return [ 53 ['With filters' => true], 54 ['Without filters' => false], 55 ]; 56 } 57 58 /** 59 * Text execute method 60 * 61 * @param bool $withfilters 62 * 63 * @dataProvider export_provider 64 */ 65 public function test_export(bool $withfilters): void { 66 global $PAGE; 67 68 $this->resetAfterTest(); 69 70 // Prevent debug warnings from flexible_table. 71 $PAGE->set_url(new moodle_url('/')); 72 73 $systemreport = system_report_factory::create(system_report_available::class, context_system::instance(), '', '', 0, 74 ['withfilters' => $withfilters]); 75 76 $exporter = new system_report_exporter($systemreport->get_report_persistent(), [ 77 'source' => $systemreport, 78 'parameters' => json_encode($systemreport->get_parameters()), 79 ]); 80 81 $data = $exporter->export($PAGE->get_renderer('core_reportbuilder')); 82 $this->assertNotEmpty($data->table); 83 84 if ($withfilters) { 85 $this->assertEquals('{"withfilters":true}', $data->parameters); 86 $this->assertTrue($data->filterspresent); 87 $this->assertNotEmpty($data->filtersform); 88 } else { 89 $this->assertEquals('{"withfilters":false}', $data->parameters); 90 $this->assertFalse($data->filterspresent); 91 $this->assertEmpty($data->filtersform); 92 } 93 } 94 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body