Skip to content

Commit

Permalink
MDL-81521 core: Update all possibly data providers to be static
Browse files Browse the repository at this point in the history
Note: Some data providers could not be automatically be converted to
being static. These will be handled in a separate issue.
  • Loading branch information
andrewnicols committed Nov 15, 2024
1 parent 269a8a8 commit a6acb01
Show file tree
Hide file tree
Showing 407 changed files with 1,449 additions and 1,430 deletions.
2 changes: 1 addition & 1 deletion admin/presets/tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function test_create_preset(?string $name = null, ?string $comments = nul
*
* @return array
*/
public function create_preset_provider(): array {
public static function create_preset_provider(): array {
return [
'Default values' => [
],
Expand Down
8 changes: 4 additions & 4 deletions admin/presets/tests/helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function test_create_preset(?string $name = null, ?string $comments = nul
*
* @return array
*/
public function create_preset_provider(): array {
public static function create_preset_provider(): array {
return [
'Default values' => [
],
Expand Down Expand Up @@ -177,7 +177,7 @@ public function test_add_item(string $name, string $value, ?string $plugin = 'no
*
* @return array
*/
public function add_item_provider(): array {
public static function add_item_provider(): array {
return [
'Setting without plugin' => [
'name' => 'settingname',
Expand Down Expand Up @@ -239,7 +239,7 @@ public function test_add_plugin(string $type, string $name, $enabled = 0): void
*
* @return array
*/
public function add_plugin_provider(): array {
public static function add_plugin_provider(): array {
return [
'Plugin: enabled (using int)' => [
'type' => 'plugintype',
Expand Down Expand Up @@ -321,7 +321,7 @@ public function test_change_default_preset(string $preset, ?array $settings = nu
*
* @return array
*/
public function change_default_preset_provider(): array {
public static function change_default_preset_provider(): array {
return [
'Starter preset' => [
'preset' => 'starter',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function test_save_value(int $settingvalue, bool $expectedsaved): void {
*
* @return array
*/
public function save_value_provider(): array {
public static function save_value_provider(): array {
return [
'Save the bloglevel and set blog_menu block visibility to true' => [
'setttingvalue' => BLOG_USER_LEVEL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function test_save_value(string $settingname, string $settingvalue, bool
*
* @return array
*/
public function save_value_provider(): array {
public static function save_value_provider(): array {
return [
'Fullname: different value' => [
'settingname' => 'fullname',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function test_save_value(string $category, string $settingplugin, string
*
* @return array
*/
public function save_value_provider(): array {
public static function save_value_provider(): array {
return [
'Core setting with the same value is not saved' => [
'category' => 'optionalsubsystems',
Expand Down Expand Up @@ -167,7 +167,7 @@ public function test_save_attributes_values(string $category, string $settingplu
*
* @return array
*/
public function save_attributes_values_provider(): array {
public static function save_attributes_values_provider(): array {
return [
'Plugin setting with the same value is not saved' => [
'category' => 'modsettinglesson',
Expand Down
4 changes: 2 additions & 2 deletions admin/presets/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public function test_export_preset(bool $includesensible = false, string $preset
*
* @return array
*/
public function export_preset_provider(): array {
public static function export_preset_provider(): array {
return [
'Export settings and plugins, excluding sensible' => [
'includesensible' => false,
Expand Down Expand Up @@ -531,7 +531,7 @@ public function test_import_preset(string $filecontents, bool $expectedpreset, b
*
* @return array
*/
public function import_preset_provider(): array {
public static function import_preset_provider(): array {
return [
'Import settings from an empty file' => [
'filecontents' => '',
Expand Down
2 changes: 1 addition & 1 deletion admin/tests/external/set_block_protection_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function test_execute(
*
* @return array
*/
public function execute_provider(): array {
public static function execute_provider(): array {
return [
[
'block_login',
Expand Down
4 changes: 2 additions & 2 deletions admin/tests/external/set_plugin_order_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function test_execute_editors(
*
* @return array
*/
public function execute_editor_provider(): array {
public static function execute_editor_provider(): array {
$pluginmanager = \core_plugin_manager::instance();
$allplugins = array_keys($pluginmanager->get_plugins_of_type('editor'));

Expand Down Expand Up @@ -142,7 +142,7 @@ public function test_execute_editors_non_orderable(string $plugin): void {
$this->assertIsArray(set_plugin_order::execute($plugin, 1));
}

public function execute_non_orderable_provider(): array {
public static function execute_non_orderable_provider(): array {
return [
// Activities do not support ordering.
['mod_assign'],
Expand Down
2 changes: 1 addition & 1 deletion admin/tests/external/set_plugin_state_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function test_execute(
*
* @return array
*/
public function execute_standard_provider(): array {
public static function execute_standard_provider(): array {
$generatetestsfor = function (string $plugin): array {
return [
[
Expand Down
2 changes: 1 addition & 1 deletion admin/tests/reportbuilder/datasource/task_logs_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function test_datasource_non_default_columns(): void {
*
* @return array[]
*/
public function datasource_filters_provider(): array {
public static function datasource_filters_provider(): array {
return [
'Filter name' => ['task_log:name', [
'task_log:name_values' => [send_schedules::class],
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/admin_presets/tests/local/action/base_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function test_base_log(string $action, string $mode, ?string $expectedcla
*
* @return array
*/
public function log_provider(): array {
public static function log_provider(): array {
return [
// Action = base.
'action=base and mode = show' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function test_export_execute(bool $includesensible = false, string $prese
*
* @return array
*/
public function export_execute_provider(): array {
public static function export_execute_provider(): array {
return [
'Export settings and plugins, excluding sensible' => [
'includesensible' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function test_import_execute(string $filecontents, bool $expectedpreset,
*
* @return array
*/
public function import_execute_provider(): array {
public static function import_execute_provider(): array {
$fixturesfolder = __DIR__ . '/../../../../../presets/tests/fixtures/';

return [
Expand Down
8 changes: 4 additions & 4 deletions admin/tool/behat/tests/behat_form_text_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class behat_form_text_test extends \basic_testcase {
*
* @return array of value and expectation pairs to be tested.
*/
public function provider_test_set_get_value() {
public static function provider_test_set_get_value(): array {
return [
'null' => [null, null],
'int' => [3, 3],
Expand All @@ -68,7 +68,7 @@ public function provider_test_set_get_value() {
*
* @param mixed $value value to be set.
* @param mixed $expectation value to be checked.
* @dataProvider provider_test_set_get_value()
* @dataProvider provider_test_set_get_value
*/
public function test_set_get_value($value, $expectation): void {
$session = $this->createMock(Session::class);
Expand All @@ -85,7 +85,7 @@ public function test_set_get_value($value, $expectation): void {
*
* @return array of decsep, value, match and result pairs to be tested.
*/
public function provider_test_matches() {
public static function provider_test_matches(): array {
return [
'lazy true' => ['.', 'hello', 'hello', true],
'lazy false' => ['.', 'hello', 'bye', false],
Expand Down Expand Up @@ -113,7 +113,7 @@ public function provider_test_matches() {
* @param mixed $value value to be set.
* @param mixed $match value to be matched.
* @param bool $result expected return status of the function.
* @dataProvider provider_test_matches()
* @dataProvider provider_test_matches
*/
public function test_matches($decsep, $value, $match, $result): void {
global $CFG;
Expand Down
10 changes: 5 additions & 5 deletions admin/tool/brickfield/tests/tool_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class tool_test extends \advanced_testcase {

/** @var string base 64 image */
protected $base64img = <<<EOF
protected static string $base64img = <<<EOF
<img src="data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+goOXMv8+fhw/v739/f+8PD98fH/
8mJl+fn/9ZWb8/PzWlwv///6wWGbImAPgTEMImIN9gUFCEm/gDALULDN8PAD6atYdCTX9gUNKlj8wZAKUsAOzZz+UMAOsJAP/Z2ccMDA8PD/95eX5N
WvsJCOVNQPtfX/8zM8+QePLl38MGBr8JCP+zs9myn/8GBqwpAP/GxgwJCPny78lzYLgjAJ8vAP9fX/+MjMUcAN8zM/9wcM8ZGcATEL+QePdZWf/29u
Expand Down Expand Up @@ -118,19 +118,19 @@ public function test_toplevel_arguments(): void {
* Base64 image provider.
* @return array
*/
public function base64_img_provider(): array {
public static function base64_img_provider(): array {
$img = '<img src="myimage.jpg" />';
return [
'Image tag alone (base64)' => [
$this->base64img,
self::$base64img,
true,
],
'Image tag alone (link)' => [
$img,
false,
],
'Image tag in string (base64)' => [
"This is my image {$this->base64img}.",
"This is my image " . self::$base64img,
true,
],
'Image tag in string (link)' => [
Expand Down Expand Up @@ -162,7 +162,7 @@ public function test_base64_img_detected(string $content, bool $expectation): vo
}

public function test_truncate_base64(): void {
$truncated = tool::truncate_base64($this->base64img);
$truncated = tool::truncate_base64(self::$base64img);
$this->assertStringContainsString('<img src="data:image/gif;base64..."', $truncated);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function test_fix_syntax(string $text, int $version, ?int $fromversion, s
*
* @return array
*/
public function fix_syntax_data(): array {
public static function fix_syntax_data(): array {
return [
// Syntax sanity v1 strings.
[
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/customlang/tests/local/mlang/phpparser_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function test_parse(string $phpcode, array $expected, bool $exception): v
*
* @return array
*/
public function parse_provider(): array {
public static function parse_provider(): array {
return [
'Invalid PHP code' => [
'No PHP code', [], false
Expand Down
16 changes: 8 additions & 8 deletions admin/tool/dataprivacy/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public function test_can_download_data_request_for_user(): void {
*
* @return array
*/
public function data_request_creation_provider() {
public static function data_request_creation_provider(): array {
return [
'Export request by user, automatic approval off' => [
false, api::DATAREQUEST_TYPE_EXPORT, 'automaticdataexportapproval', false, 0,
Expand Down Expand Up @@ -815,7 +815,7 @@ public function test_deny_data_request(): void {
*
* @return array
*/
public function get_data_requests_provider() {
public static function get_data_requests_provider(): array {
$completeonly = [api::DATAREQUEST_STATUS_COMPLETE, api::DATAREQUEST_STATUS_DOWNLOAD_READY, api::DATAREQUEST_STATUS_DELETED];
$completeandcancelled = array_merge($completeonly, [api::DATAREQUEST_STATUS_CANCELLED]);

Expand Down Expand Up @@ -1000,7 +1000,7 @@ public function test_get_approved_contextlist_collection_for_request(): void {
/**
* Data provider for test_has_ongoing_request.
*/
public function status_provider() {
public static function status_provider(): array {
return [
[api::DATAREQUEST_STATUS_AWAITING_APPROVAL, true],
[api::DATAREQUEST_STATUS_APPROVED, true],
Expand Down Expand Up @@ -1090,7 +1090,7 @@ public function test_is_site_dpo(): void {
*
* @return array
*/
public function notify_dpo_provider() {
public static function notify_dpo_provider(): array {
return [
[false, api::DATAREQUEST_TYPE_EXPORT, 'requesttypeexport', 'Export my user data'],
[false, api::DATAREQUEST_TYPE_DELETE, 'requesttypedelete', 'Delete my user data'],
Expand Down Expand Up @@ -1442,7 +1442,7 @@ public function test_effective_contextlevel_invalid_contextlevels($contextlevel)
/**
* Data provider for invalid contextlevel fetchers.
*/
public function invalid_effective_contextlevel_provider() {
public static function invalid_effective_contextlevel_provider(): array {
return [
[CONTEXT_COURSECAT],
[CONTEXT_COURSE],
Expand Down Expand Up @@ -2002,7 +2002,7 @@ public function test_get_approved_contextlist_collection_for_collection_delete_c
/**
* Data provider for \tool_dataprivacy_api_testcase::test_set_context_defaults
*/
public function set_context_defaults_provider() {
public static function set_context_defaults_provider(): array {
$contextlevels = [
[CONTEXT_COURSECAT],
[CONTEXT_COURSE],
Expand Down Expand Up @@ -2477,7 +2477,7 @@ public function test_can_create_data_deletion_request_for_children(): void {
*
* @return array
*/
public function queue_data_request_task_provider() {
public static function queue_data_request_task_provider(): array {
return [
'With user ID provided' => [true],
'Without user ID provided' => [false],
Expand Down Expand Up @@ -2514,7 +2514,7 @@ public function test_queue_data_request_task(bool $withuserid): void {
/**
* Data provider for test_is_automatic_request_approval_on().
*/
public function automatic_request_approval_setting_provider() {
public static function automatic_request_approval_setting_provider(): array {
return [
'Data export, not set' => [
'automaticdataexportapproval', api::DATAREQUEST_TYPE_EXPORT, null, false
Expand Down
6 changes: 3 additions & 3 deletions admin/tool/dataprivacy/tests/data_request_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class data_request_test extends data_privacy_testcase {
*
* @return array
*/
public function status_state_provider(): array {
public static function status_state_provider(): array {
return [
[
'state' => api::DATAREQUEST_STATUS_PENDING,
Expand Down Expand Up @@ -138,9 +138,9 @@ public function test_can_reset_others($status): void {
*
* @return array
*/
public function non_resettable_provider(): array {
public static function non_resettable_provider(): array {
$states = [];
foreach ($this->status_state_provider() as $thisstatus) {
foreach (self::status_state_provider() as $thisstatus) {
if (!$thisstatus['resettable']) {
$states[] = $thisstatus;
}
Expand Down
6 changes: 3 additions & 3 deletions admin/tool/dataprivacy/tests/expired_contexts_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ public function test_can_process_deletion($status, $expected): void {
*
* @return array
*/
public function can_process_deletion_provider(): array {
public static function can_process_deletion_provider(): array {
return [
'Pending' => [
expired_context::STATUS_EXPIRED,
Expand Down Expand Up @@ -1988,7 +1988,7 @@ public function test_is_complete($status, $expected): void {
*
* @return array
*/
public function is_complete_provider(): array {
public static function is_complete_provider(): array {
return [
'Pending' => [
expired_context::STATUS_EXPIRED,
Expand Down Expand Up @@ -2023,7 +2023,7 @@ public function test_is_fully_expired($record, $expected): void {
*
* @return array
*/
public function is_fully_expired_provider(): array {
public static function is_fully_expired_provider(): array {
return [
'Fully expired' => [
[
Expand Down
Loading

0 comments on commit a6acb01

Please sign in to comment.