This commit is contained in:
Ilya Tregubov 2022-06-17 15:07:04 +04:00
commit 70fb867346
13 changed files with 595 additions and 17 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -129,7 +129,7 @@ export const init = (initialized) => {
const pendingPromise = new Pending('core_reportbuilder/sorting:direction');
const reportElement = toggleSortDirection.closest(reportSelectors.regions.report);
const listElement = toggleSortDirection.closest('li');
const sortenabled = listElement.dataset.columnSortEnabled;
const toggleSorting = listElement.querySelector(reportSelectors.actions.reportToggleColumnSort);
let sortdirection = parseInt(listElement.dataset.columnSortDirection);
if (sortdirection === SORTORDER.ASCENDING) {
@ -138,7 +138,7 @@ export const init = (initialized) => {
sortdirection = SORTORDER.ASCENDING;
}
updateSorting(reportElement, toggleSortDirection, sortenabled, sortdirection)
updateSorting(reportElement, toggleSortDirection, toggleSorting.checked, sortdirection)
.then(() => {
// Re-focus the toggle sort direction element after reloading the region.
const toggleSortDirectionElement = document.getElementById(toggleSortDirection.id);

View file

@ -61,7 +61,7 @@ class custom_report_columns_sorting_exporter extends exporter {
'title' => ['type' => PARAM_TEXT],
'heading' => ['type' => PARAM_TEXT],
'sortdirection' => ['type' => PARAM_INT],
'sortenabled' => ['type' => PARAM_INT],
'sortenabled' => ['type' => PARAM_BOOL],
'sortorder' => ['type' => PARAM_INT],
'sorticon' => [
'type' => [
@ -120,7 +120,7 @@ class custom_report_columns_sorting_exporter extends exporter {
'title' => $columntitle,
'heading' => $columnheading !== '' ? $columnheading : $columntitle,
'sortdirection' => $persistent->get('sortdirection'),
'sortenabled' => (int)$persistent->get('sortenabled'),
'sortenabled' => $persistent->get('sortenabled'),
'sortorder' => $persistent->get('sortorder'),
'sorticon' => $sorticon->export_for_pix(),
'movetitle' => get_string('movesorting', 'core_reportbuilder', $columntitle),

View file

@ -97,11 +97,8 @@ class custom_report_exporter extends persistent_exporter {
'cardview' => ['type' => custom_report_card_view_exporter::read_properties_definition()],
'filtersapplied' => ['type' => PARAM_INT],
'filterspresent' => ['type' => PARAM_BOOL],
'filtersform' => [
'type' => PARAM_RAW,
'optional' => true,
],
'editmode' => ['type' => PARAM_INT],
'filtersform' => ['type' => PARAM_RAW],
'editmode' => ['type' => PARAM_BOOL],
'javascript' => ['type' => PARAM_RAW],
];
}
@ -164,7 +161,7 @@ class custom_report_exporter extends persistent_exporter {
'filtersapplied' => $report->get_applied_filter_count(),
'filterspresent' => $filterspresent,
'filtersform' => $filtersform,
'editmode' => (int)$this->editmode,
'editmode' => $this->editmode,
'javascript' => '',
];
}

View file

@ -104,8 +104,14 @@
<div class="{{#editmode}}p-2 border{{/editmode}}">
<div data-region="core_reportbuilder/report-header" class="dropdown d-flex justify-content-end">
{{! Preview/Edit button }}
<button data-action="toggle-edit-preview" data-edit-mode="{{editmode}}" class="btn btn-outline-secondary"
title="{{#editmode}}{{#str}} switchpreview, core_reportbuilder {{/str}}{{/editmode}}{{^editmode}}{{#str}} switchedit, core_reportbuilder {{/str}}{{/editmode}}">
<button data-action="toggle-edit-preview" class="btn btn-outline-secondary"
{{#editmode}}
data-edit-mode="1" title="{{#str}} switchpreview, core_reportbuilder {{/str}}"
{{/editmode}}
{{^editmode}}
data-edit-mode="0" title="{{#str}} switchedit, core_reportbuilder {{/str}}"
{{/editmode}}
>
{{#editmode}}
{{#pix}} i/preview, core {{/pix}}
{{#str}} preview, core {{/str}}

View file

@ -49,7 +49,6 @@
data-column-sort-id="{{id}}"
data-column-sort-name="{{title}}"
data-column-sort-direction="{{sortdirection}}"
data-column-sort-enabled="{{sortenabled}}"
data-column-sort-position="{{sortorder}}">
{{>core/drag_handle}}
{{#sorticon}}

View file

@ -0,0 +1,58 @@
<?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_generator;
use core_reportbuilder\manager;
use core_user\reportbuilder\datasource\users;
/**
* Unit tests for custom report card view exporter
*
* @package core_reportbuilder
* @covers \core_reportbuilder\external\custom_report_card_view_exporter
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_card_view_exporter_test extends advanced_testcase {
/**
* Test exported data structure
*/
public function test_export(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => users::class]);
$reportinstance = manager::get_report_from_persistent($report);
$exporter = new custom_report_card_view_exporter(null, ['report' => $reportinstance]);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
// The exporter just returns two large pieces of HTML, assert they are non empty.
$this->assertNotEmpty($export->form);
$this->assertNotEmpty($export->helpicon);
}
}

View file

@ -0,0 +1,129 @@
<?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_generator;
use core_reportbuilder\manager;
use core_reportbuilder\local\helpers\report;
use core_user\reportbuilder\datasource\users;
/**
* Unit tests for custom report column sorting exporter
*
* @package core_reportbuilder
* @covers \core_reportbuilder\external\custom_report_columns_sorting_exporter
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_columns_sorting_exporter_test extends advanced_testcase {
/**
* Test exported data structure
*/
public function test_export(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
// Add a couple of columns.
$columnfullname = $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname']);
$columnemail = $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:email']);
// Enable sorting on the email column, move it to first place.
report::toggle_report_column_sorting($report->get('id'), $columnemail->get('id'), true, SORT_DESC);
report::reorder_report_column_sorting($report->get('id'), $columnemail->get('id'), 1);
$reportinstance = manager::get_report_from_persistent($report);
$exporter = new custom_report_columns_sorting_exporter(null, ['report' => $reportinstance]);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertTrue($export->hassortablecolumns);
$this->assertCount(2, $export->sortablecolumns);
[$sortcolumnemail, $sortcolumnfullname] = $export->sortablecolumns;
// Email column.
$this->assertEquals($columnemail->get('id'), $sortcolumnemail['id']);
$this->assertEquals('Email address', $sortcolumnemail['heading']);
$this->assertTrue($sortcolumnemail['sortenabled']);
$this->assertEquals(1, $sortcolumnemail['sortorder']);
$this->assertEquals(SORT_DESC, $sortcolumnemail['sortdirection']);
$this->assertEquals('Disable sorting for column \'Email address\'', $sortcolumnemail['sortenabledtitle']);
$this->assertEquals('Sort column \'Email address\' ascending', $sortcolumnemail['sorticon']['title']);
// Fullname column.
$this->assertEquals($columnfullname->get('id'), $sortcolumnfullname['id']);
$this->assertEquals('Full name', $sortcolumnfullname['heading']);
$this->assertFalse($sortcolumnfullname['sortenabled']);
$this->assertEquals(2, $sortcolumnfullname['sortorder']);
$this->assertEquals(SORT_ASC, $sortcolumnfullname['sortdirection']);
$this->assertEquals('Enable sorting for column \'Full name\'', $sortcolumnfullname['sortenabledtitle']);
$this->assertEquals('Sort column \'Full name\' descending', $sortcolumnfullname['sorticon']['title']);
$this->assertNotEmpty($export->helpicon);
}
/**
* Test exported data structure for report with columns, but they aren't sortable
*/
public function test_export_no_sortable_columns(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:picture']);
$reportinstance = manager::get_report_from_persistent($report);
$exporter = new custom_report_columns_sorting_exporter(null, ['report' => $reportinstance]);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertFalse($export->hassortablecolumns);
$this->assertEmpty($export->sortablecolumns);
}
/**
* Test exported data structure for report with no columns
*/
public function test_export_no_columns(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
$reportinstance = manager::get_report_from_persistent($report);
$exporter = new custom_report_columns_sorting_exporter(null, ['report' => $reportinstance]);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertFalse($export->hassortablecolumns);
$this->assertEmpty($export->sortablecolumns);
}
}

View file

@ -0,0 +1,104 @@
<?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_generator;
use core_reportbuilder\manager;
use core_course\reportbuilder\datasource\courses;
/**
* Unit tests for custom report conditions exporter
*
* @package core_reportbuilder
* @covers \core_reportbuilder\external\custom_report_conditions_exporter
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_conditions_exporter_test extends advanced_testcase {
/**
* Test exported data structure
*/
public function test_export(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => courses::class, 'default' => false]);
$generator->create_condition(['reportid' => $report->get('id'), 'uniqueidentifier' => 'course:shortname']);
$reportinstance = manager::get_report_from_persistent($report);
$exporter = new custom_report_conditions_exporter(null, ['report' => $reportinstance]);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
// The root of the available conditions property should contain two entities.
$this->assertTrue($export->hasavailableconditions);
$this->assertCount(2, $export->availableconditions);
[$conditionscategory, $conditionscourse] = $export->availableconditions;
// Course category conditions, assert structure of first item.
$this->assertEquals('Course category', $conditionscategory['optiongroup']['text']);
$this->assertGreaterThanOrEqual(1, $conditionscategory['optiongroup']['values']);
$this->assertEquals([
'value' => 'course_category:name',
'visiblename' => 'Category name',
], $conditionscategory['optiongroup']['values'][0]);
// Course conditions, assert structure of first item.
$this->assertEquals('Course', $conditionscourse['optiongroup']['text']);
$this->assertGreaterThanOrEqual(1, $conditionscourse['optiongroup']['values']);
$this->assertEquals([
'value' => 'course:fullname',
'visiblename' => 'Course full name',
], $conditionscourse['optiongroup']['values'][0]);
// Make sure the active condition we added, isn't present in available conditions.
$this->assertNotContains('course:shortname', array_column($conditionscourse['optiongroup']['values'], 'value'));
$this->assertTrue($export->hasactiveconditions);
$this->assertNotEmpty($export->activeconditionsform);
$this->assertNotEmpty($export->helpicon);
}
/**
* Test exported data structure for report with no conditions
*/
public function test_export_no_conditions(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => courses::class, 'default' => false]);
$reportinstance = manager::get_report_from_persistent($report);
$exporter = new custom_report_conditions_exporter(null, ['report' => $reportinstance]);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertFalse($export->hasactiveconditions);
$this->assertEmpty($export->activeconditionsform);
}
}

View file

@ -0,0 +1,152 @@
<?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_generator;
use moodle_url;
use core_reportbuilder\local\helpers\user_filter_manager;
use core_reportbuilder\local\filters\text;
use core_user\reportbuilder\datasource\users;
/**
* Unit tests for custom report exporter
*
* @package core_reportbuilder
* @covers \core_reportbuilder\external\custom_report_exporter
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_exporter_test extends advanced_testcase {
/**
* Test exported data structure when editing a report
*/
public function test_export_editing(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
$PAGE->set_url(new moodle_url('/'));
$exporter = new custom_report_exporter($report, [], true);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertNotEmpty($export->table);
$this->assertEquals(0, $export->filtersapplied);
$this->assertFalse($export->filterspresent);
$this->assertEmpty($export->filtersform);
$this->assertTrue($export->editmode);
// The following are all generated by additional exporters.
$this->assertNotEmpty($export->sidebarmenucards);
$this->assertNotEmpty($export->conditions);
$this->assertNotEmpty($export->filters);
$this->assertNotEmpty($export->sorting);
$this->assertNotEmpty($export->cardview);
}
/**
* Test exported data structure when viewing a report
*/
public function test_export_viewing(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
$PAGE->set_url(new moodle_url('/'));
$exporter = new custom_report_exporter($report, ['pagesize' => 10], false);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertNotEmpty($export->table);
$this->assertEquals(0, $export->filtersapplied);
$this->assertFalse($export->filterspresent);
$this->assertEmpty($export->filtersform);
$this->assertFalse($export->editmode);
// The following are all generated by additional exporters.
$this->assertEmpty($export->sidebarmenucards);
$this->assertEmpty($export->conditions);
$this->assertEmpty($export->filters);
$this->assertEmpty($export->sorting);
$this->assertEmpty($export->cardview);
}
/**
* Test exported data structure when filters are present
*/
public function test_export_filters_present(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
$generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:email']);
$PAGE->set_url(new moodle_url('/'));
$exporter = new custom_report_exporter($report, ['pagesize' => 10], false);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertTrue($export->filterspresent);
$this->assertNotEmpty($export->filtersform);
$this->assertEquals(0, $export->filtersapplied);
}
/**
* Test exported data structure when filters are applied
*/
public function test_export_filters_applied(): void {
global $PAGE;
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
$generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:email']);
// Apply filter.
user_filter_manager::set($report->get('id'), ['user:email_operator' => text::IS_NOT_EMPTY]);
$PAGE->set_url(new moodle_url('/'));
$exporter = new custom_report_exporter($report, ['pagesize' => 10], false);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertTrue($export->filterspresent);
$this->assertNotEmpty($export->filtersform);
$this->assertEquals(1, $export->filtersapplied);
}
}

View file

@ -0,0 +1,133 @@
<?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_generator;
use core_reportbuilder\manager;
use core_reportbuilder\local\helpers\report;
use core_course\reportbuilder\datasource\courses;
/**
* Unit tests for custom report filters exporter
*
* @package core_reportbuilder
* @covers \core_reportbuilder\external\custom_report_filters_exporter
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_report_filters_exporter_test extends advanced_testcase {
/**
* Test exported data structure
*/
public function test_export(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => courses::class, 'default' => false]);
// Add a couple of filters.
$filtercategoryname = $generator->create_filter([
'reportid' => $report->get('id'),
'uniqueidentifier' => 'course_category:name',
]);
$filtercourseidnumber = $generator->create_filter([
'reportid' => $report->get('id'),
'uniqueidentifier' => 'course:idnumber',
]);
// Move course ID number filter to first place.
report::reorder_report_filter($report->get('id'), $filtercourseidnumber->get('id'), 1);
$reportinstance = manager::get_report_from_persistent($report);
$exporter = new custom_report_filters_exporter(null, ['report' => $reportinstance]);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
// The root of the available filters property should contain two entities.
$this->assertTrue($export->hasavailablefilters);
$this->assertCount(2, $export->availablefilters);
[$filterscategory, $filterscourse] = $export->availablefilters;
// Course category filters, assert structure of first item.
$this->assertEquals('Course category', $filterscategory['optiongroup']['text']);
$this->assertGreaterThanOrEqual(1, $filterscategory['optiongroup']['values']);
$this->assertEquals([
'value' => 'course_category:idnumber',
'visiblename' => 'Category ID number',
], $filterscategory['optiongroup']['values'][0]);
// Course filters, assert structure of first item.
$this->assertEquals('Course', $filterscourse['optiongroup']['text']);
$this->assertGreaterThanOrEqual(1, $filterscourse['optiongroup']['values']);
$this->assertEquals([
'value' => 'course:fullname',
'visiblename' => 'Course full name',
], $filterscourse['optiongroup']['values'][0]);
// Make sure the active filters we added, aren't present in available filters.
$filterscourseavailable = array_column($filterscourse['optiongroup']['values'], 'value');
$this->assertNotContains('course_category:name', $filterscourseavailable);
$this->assertNotContains('course:idnumber', $filterscourseavailable);
$this->assertTrue($export->hasactivefilters);
$this->assertCount(2, $export->activefilters);
[$activefiltercourseidnumber, $activefiltercategoryname] = $export->activefilters;
// Course ID number filter.
$this->assertEquals($filtercourseidnumber->get('id'), $activefiltercourseidnumber['id']);
$this->assertEquals('Course', $activefiltercourseidnumber['entityname']);
$this->assertEquals('Course ID number', $activefiltercourseidnumber['heading']);
$this->assertEquals(1, $activefiltercourseidnumber['sortorder']);
// Course category filter.
$this->assertEquals($filtercategoryname->get('id'), $activefiltercategoryname['id']);
$this->assertEquals('Course category', $activefiltercategoryname['entityname']);
$this->assertEquals('Category name', $activefiltercategoryname['heading']);
$this->assertEquals(2, $activefiltercategoryname['sortorder']);
$this->assertNotEmpty($export->helpicon);
}
/**
* Test exported data structure for report with no filters
*/
public function test_export_no_filters(): void {
global $PAGE;
$this->resetAfterTest();
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
$report = $generator->create_report(['name' => 'My report', 'source' => courses::class, 'default' => false]);
$reportinstance = manager::get_report_from_persistent($report);
$exporter = new custom_report_filters_exporter(null, ['report' => $reportinstance]);
$export = $exporter->export($PAGE->get_renderer('core_reportbuilder'));
$this->assertFalse($export->hasactivefilters);
$this->assertEmpty($export->activefilters);
}
}

View file

@ -70,7 +70,7 @@ class get_test extends externallib_advanced_testcase {
$this->assertNotEmpty($result['javascript']);
$this->assertFalse($result['filterspresent']);
$this->assertEmpty($result['filtersform']);
$this->assertEquals(1, $result['editmode']);
$this->assertTrue($result['editmode']);
$this->assertTrue($result['filters']['hasavailablefilters']);
$this->assertNotEmpty($result['filters']['availablefilters']);
$this->assertTrue($result['filters']['hasactivefilters']);
@ -108,7 +108,7 @@ class get_test extends externallib_advanced_testcase {
$this->assertNotEmpty($result['javascript']);
$this->assertTrue($result['filterspresent']);
$this->assertNotEmpty($result['filtersform']);
$this->assertEquals(0, $result['editmode']);
$this->assertFalse($result['editmode']);
$this->assertEmpty($result['filters']);
$this->assertEmpty($result['conditions']);
$this->assertEmpty($result['sorting']);