Merge branch 'MDL-76221-400' of https://github.com/paulholden/moodle into MOODLE_400_STABLE

This commit is contained in:
Sara Arjona
2023-01-04 13:09:46 +01:00
11 changed files with 87 additions and 72 deletions
+27 -3
View File
@@ -73,7 +73,15 @@ class core_reportbuilder_generator extends component_generator_base {
throw new coding_exception('Record must contain \'uniqueidentifier\' property');
}
return helper::add_report_column($record['reportid'], $record['uniqueidentifier']);
$column = helper::add_report_column($record['reportid'], $record['uniqueidentifier']);
// Update additional record properties.
unset($record['reportid'], $record['uniqueidentifier']);
if ($properties = array_intersect_key($record, column::properties_definition())) {
$column->set_many($properties)->update();
}
return $column;
}
/**
@@ -93,7 +101,15 @@ class core_reportbuilder_generator extends component_generator_base {
throw new coding_exception('Record must contain \'uniqueidentifier\' property');
}
return helper::add_report_filter($record['reportid'], $record['uniqueidentifier']);
$filter = helper::add_report_filter($record['reportid'], $record['uniqueidentifier']);
// Update additional record properties.
unset($record['reportid'], $record['uniqueidentifier']);
if ($properties = array_intersect_key($record, filter::properties_definition())) {
$filter->set_many($properties)->update();
}
return $filter;
}
/**
@@ -113,7 +129,15 @@ class core_reportbuilder_generator extends component_generator_base {
throw new coding_exception('Record must contain \'uniqueidentifier\' property');
}
return helper::add_report_condition($record['reportid'], $record['uniqueidentifier']);
$condition = helper::add_report_condition($record['reportid'], $record['uniqueidentifier']);
// Update additional record properties.
unset($record['reportid'], $record['uniqueidentifier']);
if ($properties = array_intersect_key($record, filter::properties_definition())) {
$condition->set_many($properties)->update();
}
return $condition;
}
/**
@@ -52,14 +52,12 @@ class avg_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended'])
->set('aggregation', avg::get_class_name())
->update();
$generator->create_column(
['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended', 'aggregation' => avg::get_class_name()]
);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertEquals([
@@ -54,14 +54,12 @@ class count_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastname'])
->set('aggregation', count::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastname', 'aggregation' => count::get_class_name()]
);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertEquals([
@@ -54,14 +54,14 @@ class countdistinct_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastname'])
->set('aggregation', countdistinct::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'),
'uniqueidentifier' => 'user:lastname',
'aggregation' => countdistinct::get_class_name(),
]);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertEquals([
@@ -90,9 +90,11 @@ class countdistinct_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname'])
->set('aggregation', countdistinct::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'),
'uniqueidentifier' => 'user:fullname',
'aggregation' => countdistinct::get_class_name(),
]);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertCount(1, $content);
@@ -54,14 +54,14 @@ class groupconcat_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastname'])
->set('aggregation', groupconcat::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'),
'uniqueidentifier' => 'user:lastname',
'aggregation' => groupconcat::get_class_name(),
]);
// Assert lastname column was aggregated, and sorted predictably.
$content = $this->get_custom_report_content($report->get('id'));
@@ -93,14 +93,14 @@ class groupconcat_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:confirmed'])
->set('aggregation', groupconcat::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'),
'uniqueidentifier' => 'user:confirmed',
'aggregation' => groupconcat::get_class_name(),
]);
// Assert confirmed column was aggregated, and sorted predictably with callback applied.
$content = $this->get_custom_report_content($report->get('id'));
@@ -66,14 +66,14 @@ class groupconcatdistinct_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastname'])
->set('aggregation', groupconcatdistinct::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'),
'uniqueidentifier' => 'user:lastname',
'aggregation' => groupconcatdistinct::get_class_name(),
]);
// Assert lastname column was aggregated, and sorted predictably.
$content = $this->get_custom_report_content($report->get('id'));
@@ -105,14 +105,14 @@ class groupconcatdistinct_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:confirmed'])
->set('aggregation', groupconcatdistinct::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'),
'uniqueidentifier' => 'user:confirmed',
'aggregation' => groupconcatdistinct::get_class_name(),
]);
// Assert confirmed column was aggregated, and sorted predictably with callback applied.
$content = $this->get_custom_report_content($report->get('id'));
@@ -53,14 +53,12 @@ class max_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended'])
->set('aggregation', max::get_class_name())
->update();
$generator->create_column(
['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended', 'aggregation' => max::get_class_name()]
);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertEquals([
@@ -53,14 +53,12 @@ class min_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended'])
->set('aggregation', min::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended', 'aggregation' => min::get_class_name()]
);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertEquals([
@@ -53,14 +53,12 @@ class percent_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended'])
->set('aggregation', percent::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended', 'aggregation' => percent::get_class_name()]
);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertEquals([
@@ -53,14 +53,12 @@ class sum_test extends core_reportbuilder_testcase {
$report = $generator->create_report(['name' => 'Users', 'source' => users::class, 'default' => 0]);
// First column, sorted.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname'])
->set('sortenabled', true)
->update();
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstname', 'sortenabled' => 1]);
// This is the column we'll aggregate.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended'])
->set('aggregation', sum::get_class_name())
->update();
$generator->create_column([
'reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended', 'aggregation' => sum::get_class_name()
]);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertEquals([
+1
View File
@@ -4,6 +4,7 @@ Information provided here is intended especially for developers.
=== 4.0.6 ===
* The `datasource_stress_test_columns` test helper now enables sorting on those columns that support it
* The `create_[column|filter|condition]` test generator methods now allow for setting all persistent properties
=== 4.0.4 ===