This commit is contained in:
Sara Arjona
2025-03-24 17:44:15 +01:00
3 changed files with 61 additions and 3 deletions
@@ -67,6 +67,7 @@ class report_action_exporter extends exporter {
'optional' => true,
],
],
'multiple' => true,
],
];
}
@@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
declare(strict_types=1);
namespace core_reportbuilder\external;
use advanced_testcase;
use core_reportbuilder\output\report_action;
/**
* Unit tests for report action exporter
*
* @package core_reportbuilder
* @covers \core_reportbuilder\external\report_action_exporter
* @copyright 2025 Paul Holden <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class report_action_exporter_test extends advanced_testcase {
/**
* Test exported data/structure
*/
public function test_export(): void {
global $PAGE;
$reportaction = new report_action('Add', ['class' => 'btn', 'data-action' => 'action']);
$exporter = new report_action_exporter(null, ['reportaction' => $reportaction]);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertEquals((object) [
'tag' => 'button',
'title' => 'Add',
'attributes' => [
['name' => 'class', 'value' => 'btn'],
['name' => 'data-action', 'value' => 'action'],
],
], $export);
}
}
+6 -3
View File
@@ -54,7 +54,7 @@ final class get_test extends externallib_advanced_testcase {
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
$instance = manager::get_report_from_persistent($report);
$instance->set_report_action(new report_action('Add', []));
$instance->set_report_action(new report_action('Add', ['class' => 'btn', 'data-action' => 'action']));
$instance->set_report_info_container('Hello');
// Add two filters.
@@ -100,7 +100,7 @@ final class get_test extends externallib_advanced_testcase {
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
$instance = manager::get_report_from_persistent($report);
$instance->set_report_action(new report_action('Add', []));
$instance->set_report_action(new report_action('Add', ['class' => 'btn', 'data-action' => 'action']));
$instance->set_report_info_container('Hello');
// Add two filters.
@@ -118,7 +118,10 @@ final class get_test extends externallib_advanced_testcase {
$this->assertEquals([
'tag' => 'button',
'title' => 'Add',
'attributes' => [],
'attributes' => [
['name' => 'class', 'value' => 'btn'],
['name' => 'data-action', 'value' => 'action'],
],
], $result['button']);
$this->assertEquals('Hello', $result['infocontainer']);
$this->assertTrue($result['filterspresent']);