Línea 20... |
Línea 20... |
20 |
|
20 |
|
21 |
use context_system;
|
21 |
use context_system;
|
22 |
use core_reportbuilder_generator;
|
22 |
use core_reportbuilder_generator;
|
23 |
use core_external\external_api;
|
23 |
use core_external\external_api;
|
24 |
use externallib_advanced_testcase;
|
24 |
use externallib_advanced_testcase;
|
- |
|
25 |
use core_reportbuilder\exception\report_access_exception;
|
- |
|
26 |
use core_reportbuilder\manager;
|
25 |
use core_reportbuilder\report_access_exception;
|
27 |
use core_reportbuilder\output\report_action;
|
Línea 26... |
Línea 28... |
26 |
use core_user\reportbuilder\datasource\users;
|
28 |
use core_user\reportbuilder\datasource\users;
|
Línea 27... |
Línea 29... |
27 |
|
29 |
|
Línea 36... |
Línea 38... |
36 |
* @package core_reportbuilder
|
38 |
* @package core_reportbuilder
|
37 |
* @covers \core_reportbuilder\external\reports\get
|
39 |
* @covers \core_reportbuilder\external\reports\get
|
38 |
* @copyright 2021 David Matamoros <davidmc@moodle.com>
|
40 |
* @copyright 2021 David Matamoros <davidmc@moodle.com>
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
41 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
40 |
*/
|
42 |
*/
|
41 |
class get_test extends externallib_advanced_testcase {
|
43 |
final class get_test extends externallib_advanced_testcase {
|
Línea 42... |
Línea 44... |
42 |
|
44 |
|
43 |
/**
|
45 |
/**
|
44 |
* Text execute method for edit mode
|
46 |
* Text execute method for edit mode
|
45 |
*/
|
47 |
*/
|
46 |
public function test_execute_editmode(): void {
|
48 |
public function test_execute_editmode(): void {
|
47 |
$this->resetAfterTest();
|
49 |
$this->resetAfterTest();
|
Línea 48... |
Línea 50... |
48 |
$this->setAdminUser();
|
50 |
$this->setAdminUser();
|
49 |
|
51 |
|
- |
|
52 |
/** @var core_reportbuilder_generator $generator */
|
Línea 50... |
Línea 53... |
50 |
/** @var core_reportbuilder_generator $generator */
|
53 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
|
51 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
|
54 |
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
|
52 |
|
55 |
|
53 |
$report = $generator->create_report([
|
- |
|
54 |
'name' => 'My report',
|
- |
|
Línea 55... |
Línea 56... |
55 |
'source' => users::class,
|
56 |
$instance = manager::get_report_from_persistent($report);
|
56 |
'default' => false,
|
57 |
$instance->set_report_action(new report_action('Add', ['class' => 'btn', 'data-action' => 'action']));
|
57 |
]);
|
58 |
$instance->set_report_info_container('Hello');
|
Línea 66... |
Línea 67... |
66 |
$this->assertEquals($result['id'], $report->get('id'));
|
67 |
$this->assertEquals($result['id'], $report->get('id'));
|
67 |
$this->assertEquals($result['name'], 'My report');
|
68 |
$this->assertEquals($result['name'], 'My report');
|
68 |
$this->assertEquals($result['source'], users::class);
|
69 |
$this->assertEquals($result['source'], users::class);
|
69 |
$this->assertNotEmpty($result['table']);
|
70 |
$this->assertNotEmpty($result['table']);
|
70 |
$this->assertNotEmpty($result['javascript']);
|
71 |
$this->assertNotEmpty($result['javascript']);
|
- |
|
72 |
$this->assertEquals('Hello', $result['infocontainer']);
|
71 |
$this->assertFalse($result['filterspresent']);
|
73 |
$this->assertFalse($result['filterspresent']);
|
72 |
$this->assertEmpty($result['filtersform']);
|
74 |
$this->assertEmpty($result['filtersform']);
|
73 |
$this->assertTrue($result['editmode']);
|
75 |
$this->assertTrue($result['editmode']);
|
Línea 74... |
Línea 76... |
74 |
|
76 |
|
Línea 81... |
Línea 83... |
81 |
$this->assertTrue($result['filters']['hasactivefilters']);
|
83 |
$this->assertTrue($result['filters']['hasactivefilters']);
|
82 |
$this->assertEquals($filterfullname->get('id'), $result['filters']['activefilters'][0]['id']);
|
84 |
$this->assertEquals($filterfullname->get('id'), $result['filters']['activefilters'][0]['id']);
|
83 |
$this->assertEquals($filteremail->get('id'), $result['filters']['activefilters'][1]['id']);
|
85 |
$this->assertEquals($filteremail->get('id'), $result['filters']['activefilters'][1]['id']);
|
84 |
$this->assertNotEmpty($result['sorting']);
|
86 |
$this->assertNotEmpty($result['sorting']);
|
85 |
$this->assertNotEmpty($result['cardview']);
|
87 |
$this->assertNotEmpty($result['cardview']);
|
- |
|
88 |
|
- |
|
89 |
// The following should not be present when editing.
|
- |
|
90 |
$this->assertArrayNotHasKey('button', $result);
|
86 |
}
|
91 |
}
|
Línea 87... |
Línea 92... |
87 |
|
92 |
|
88 |
/**
|
93 |
/**
|
89 |
* Text execute method for preview mode
|
94 |
* Text execute method for preview mode
|
Línea 92... |
Línea 97... |
92 |
$this->resetAfterTest();
|
97 |
$this->resetAfterTest();
|
93 |
$this->setAdminUser();
|
98 |
$this->setAdminUser();
|
Línea 94... |
Línea 99... |
94 |
|
99 |
|
95 |
/** @var core_reportbuilder_generator $generator */
|
100 |
/** @var core_reportbuilder_generator $generator */
|
- |
|
101 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
|
Línea 96... |
Línea 102... |
96 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
|
102 |
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
|
97 |
|
103 |
|
98 |
$report = $generator->create_report([
|
104 |
$instance = manager::get_report_from_persistent($report);
|
99 |
'name' => 'My report',
|
- |
|
100 |
'source' => users::class,
|
- |
|
Línea 101... |
Línea 105... |
101 |
'default' => false,
|
105 |
$instance->set_report_action(new report_action('Add', ['class' => 'btn', 'data-action' => 'action']));
|
102 |
]);
|
106 |
$instance->set_report_info_container('Hello');
|
103 |
|
107 |
|
Línea 111... |
Línea 115... |
111 |
$this->assertEquals($result['id'], $report->get('id'));
|
115 |
$this->assertEquals($result['id'], $report->get('id'));
|
112 |
$this->assertEquals($result['name'], 'My report');
|
116 |
$this->assertEquals($result['name'], 'My report');
|
113 |
$this->assertEquals($result['source'], users::class);
|
117 |
$this->assertEquals($result['source'], users::class);
|
114 |
$this->assertNotEmpty($result['table']);
|
118 |
$this->assertNotEmpty($result['table']);
|
115 |
$this->assertNotEmpty($result['javascript']);
|
119 |
$this->assertNotEmpty($result['javascript']);
|
- |
|
120 |
$this->assertEquals([
|
- |
|
121 |
'tag' => 'button',
|
- |
|
122 |
'title' => 'Add',
|
- |
|
123 |
'attributes' => [
|
- |
|
124 |
['name' => 'class', 'value' => 'btn'],
|
- |
|
125 |
['name' => 'data-action', 'value' => 'action'],
|
- |
|
126 |
],
|
- |
|
127 |
], $result['button']);
|
- |
|
128 |
$this->assertEquals('Hello', $result['infocontainer']);
|
116 |
$this->assertTrue($result['filterspresent']);
|
129 |
$this->assertTrue($result['filterspresent']);
|
117 |
$this->assertNotEmpty($result['filtersform']);
|
130 |
$this->assertNotEmpty($result['filtersform']);
|
118 |
$this->assertFalse($result['editmode']);
|
131 |
$this->assertFalse($result['editmode']);
|
Línea 119... |
Línea 132... |
119 |
|
132 |
|
120 |
// Confirm editor-specific data is not returned.
|
133 |
// The following should not be present when viewing.
|
121 |
$this->assertArrayNotHasKey('sidebarmenucards', $result);
|
134 |
$this->assertArrayNotHasKey('sidebarmenucards', $result);
|
122 |
$this->assertArrayNotHasKey('conditions', $result);
|
135 |
$this->assertArrayNotHasKey('conditions', $result);
|
123 |
$this->assertArrayNotHasKey('filters', $result);
|
136 |
$this->assertArrayNotHasKey('filters', $result);
|
124 |
$this->assertArrayNotHasKey('sorting', $result);
|
137 |
$this->assertArrayNotHasKey('sorting', $result);
|