MDL-73938 reportbuilder: add filters API to support stress testing.
Filter types can now define sample values, to be used in forthcoming stress test helpers, in order for them to become active in a report.
This commit is contained in:
@@ -75,4 +75,15 @@ class autocomplete extends base {
|
||||
|
||||
return ["{$fieldsql} $insql", array_merge($params, $inparams)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_values" => [1],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,4 +120,14 @@ abstract class base {
|
||||
|
||||
return $filtersql !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values, that when applied to a report would activate the filter - that is, cause the filter to return
|
||||
* SQL snippet. Should be overridden in child classes, to ensure compatibility with stress tests of reports
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,4 +101,15 @@ class boolean_select extends base {
|
||||
|
||||
return [$fieldsql, $params];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_operator" => self::CHECKED,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,4 +90,15 @@ class category extends base {
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_value" => 1,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,4 +67,15 @@ class course_selector extends base {
|
||||
|
||||
return ["{$fieldsql} $courseselect", array_merge($params, $courseparams)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_values" => [1],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,4 +281,16 @@ class date extends base {
|
||||
$dateend->getTimestamp(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_operator" => self::DATE_CURRENT,
|
||||
"{$this->name}_unit" => self::DATE_UNIT_WEEK,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,4 +134,17 @@ class duration extends base {
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_operator" => self::DURATION_MAXIMUM,
|
||||
"{$this->name}_value" => 2,
|
||||
"{$this->name}_unit" => MINSECS,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,4 +197,16 @@ class number extends base {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_operator" => self::GREATER_THAN,
|
||||
"{$this->name}_value1" => 1,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,4 +137,16 @@ class select extends base {
|
||||
private function validate_filter_values(?int $operator, $value): bool {
|
||||
return !($operator === null || $value === '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_operator" => self::EQUAL_TO,
|
||||
"{$this->name}_value" => 1,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,4 +117,16 @@ class tags extends base {
|
||||
|
||||
return [$select, $params];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_operator" => self::EQUAL_TO,
|
||||
"{$this->name}_value" => [1],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,4 +192,16 @@ class text extends base {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_operator" => self::IS_EQUAL_TO,
|
||||
"{$this->name}_value" => 'test',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,4 +119,16 @@ class user extends base {
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sample filter values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sample_values(): array {
|
||||
return [
|
||||
"{$this->name}_operator" => self::USER_SELECT,
|
||||
"{$this->name}_value" => [1],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,5 @@ Information provided here is intended especially for developers.
|
||||
- `category` for reports containing course categories
|
||||
- `tags` for reports containing entities with support for core_tag API
|
||||
- `autocomplete` for reports that contain pre-defined values for selection.
|
||||
* The helper method `get_custom_report_content()` now accepts a list of filters and applies them to the report
|
||||
* New method `get_sample_values()` added to base filter class, to be overridden in all filter types to support stress testing
|
||||
* The test helper method `get_custom_report_content()` now accepts a list of filter values and applies them to the report
|
||||
|
||||
Reference in New Issue
Block a user