diff --git a/classes/local/query.php b/classes/local/query.php index d4bdc31..66c5f35 100644 --- a/classes/local/query.php +++ b/classes/local/query.php @@ -118,6 +118,7 @@ public function get_capability_string() { * * @param \context $context The context to check. * @return bool true if the user has this capability. Otherwise false. + * @covers \report_customsql\local\query */ public function can_edit(\context $context): bool { return has_capability('report/customsql:definequeries', $context); diff --git a/tests/external/external_get_users_test.php b/tests/external/external_get_users_test.php index 3996f5f..27bef1c 100644 --- a/tests/external/external_get_users_test.php +++ b/tests/external/external_get_users_test.php @@ -67,9 +67,11 @@ protected function setup_users(): array { return [$admin, $manager, $coursecreateor]; } - public function test_get_users_site_config() { + public function test_get_users_site_config(): void { + global $OUTPUT; + $defaultuserimage = $OUTPUT->image_url('u/f2'); + [$admin] = $this->setup_users(); - $defaultuserimage = 'https://www.example.com/moodle/theme/image.php/_s/boost/core/1/u/f2'; $result = get_users::execute('', 'moodle/site:config'); $result = \external_api::clean_returnvalue(get_users::execute_returns(), $result); @@ -85,9 +87,11 @@ public function test_get_users_site_config() { ], $result); } - public function test_get_users_site_viewreports() { + public function test_get_users_site_viewreports(): void { + global $OUTPUT; + $defaultuserimage = $OUTPUT->image_url('u/f2'); + [$admin, $manager] = $this->setup_users(); - $defaultuserimage = 'https://www.example.com/moodle/theme/image.php/_s/boost/core/1/u/f2'; $result = get_users::execute('', 'moodle/site:viewreports'); $result = \external_api::clean_returnvalue(get_users::execute_returns(), $result); @@ -110,43 +114,47 @@ public function test_get_users_site_viewreports() { ], $result); } - public function test_get_users_customsql_view() { + public function test_get_users_customsql_view(): void { + global $OUTPUT; + $defaultuserimage = $OUTPUT->image_url('u/f2'); + [$admin, $manager, $coursecreateor] = $this->setup_users(); - $defaultuserimage = 'https://www.example.com/moodle/theme/image.php/_s/boost/core/1/u/f2'; $result = get_users::execute('', 'report/customsql:view'); $result = \external_api::clean_returnvalue(get_users::execute_returns(), $result); $this->assertEquals([ - [ - 'id' => $coursecreateor->id, - 'fullname' => fullname($coursecreateor), - 'identity' => 'cc@example.com', - 'hasidentity' => true, - 'profileimageurlsmall' => $defaultuserimage, - ], - [ - 'id' => $manager->id, - 'fullname' => fullname($manager), - 'identity' => 'manager@example.com', - 'hasidentity' => true, - 'profileimageurlsmall' => $defaultuserimage, - ], - [ - 'id' => $admin->id, - 'fullname' => fullname($admin), - 'identity' => 'admin@example.com', - 'hasidentity' => true, - 'profileimageurlsmall' => $defaultuserimage, - ], + [ + 'id' => $coursecreateor->id, + 'fullname' => fullname($coursecreateor), + 'identity' => 'cc@example.com', + 'hasidentity' => true, + 'profileimageurlsmall' => $defaultuserimage, + ], + [ + 'id' => $manager->id, + 'fullname' => fullname($manager), + 'identity' => 'manager@example.com', + 'hasidentity' => true, + 'profileimageurlsmall' => $defaultuserimage, + ], + [ + 'id' => $admin->id, + 'fullname' => fullname($admin), + 'identity' => 'admin@example.com', + 'hasidentity' => true, + 'profileimageurlsmall' => $defaultuserimage, + ], ], $result); } - public function test_get_users_serch_without_admins() { + public function test_get_users_serch_without_admins(): void { + global $OUTPUT; + $defaultuserimage = $OUTPUT->image_url('u/f2'); + global $OUTPUT; [, $manager] = $this->setup_users(); - $defaultuserimage = $OUTPUT->image_url('u/f2'); $result = get_users::execute('Man', 'report/customsql:view'); $result = \external_api::clean_returnvalue(get_users::execute_returns(), $result); @@ -162,9 +170,11 @@ public function test_get_users_serch_without_admins() { ], $result); } - public function test_get_users_serch_with_admin() { + public function test_get_users_serch_with_admin(): void { + global $OUTPUT; + $defaultuserimage = $OUTPUT->image_url('u/f2'); + [$admin] = $this->setup_users(); - $defaultuserimage = 'https://www.example.com/moodle/theme/image.php/_s/boost/core/1/u/f2'; $result = get_users::execute('n U', 'report/customsql:view'); $result = \external_api::clean_returnvalue(get_users::execute_returns(), $result); diff --git a/tests/local/category_test.php b/tests/local/category_test.php index d1bd8ff..56cc30b 100644 --- a/tests/local/category_test.php +++ b/tests/local/category_test.php @@ -27,6 +27,7 @@ * @package report_customsql * @copyright 2021 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \report_customsql\local\category */ class category_test extends \advanced_testcase { /** diff --git a/tests/privacy_test.php b/tests/privacy_test.php index 6eaa4e5..55644dc 100644 --- a/tests/privacy_test.php +++ b/tests/privacy_test.php @@ -25,6 +25,7 @@ * @package report_customsql * @copyright 2021 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \report_customsql\privacy\provider */ class privacy_test extends \core_privacy\tests\provider_testcase { diff --git a/tests/report_test.php b/tests/report_test.php index 62b67ed..682a8df 100644 --- a/tests/report_test.php +++ b/tests/report_test.php @@ -61,6 +61,7 @@ public function get_week_starts_provider(): array { * @param string $lastweek * * @dataProvider get_week_starts_provider + * @covers ::report_customsql_get_week_starts */ public function test_get_week_starts( int $startwday, string $datestr, string $currentweek, string $lastweek): void { @@ -82,6 +83,7 @@ public function test_get_week_starts( * @return void * * @dataProvider get_week_starts_provider + * @covers ::report_customsql_get_week_starts */ public function test_get_week_starts_use_calendar_default( int $startwday, string $datestr, string $currentweek, string $lastweek): void { @@ -95,6 +97,7 @@ public function test_get_week_starts_use_calendar_default( $this->assertEquals($expected, report_customsql_get_week_starts(strtotime($datestr))); } + /** @covers ::report_customsql_get_month_starts */ public function test_get_month_starts_test(): void { $this->assertEquals([ strtotime('00:00 1 November 2009'), strtotime('00:00 1 October 2009')], @@ -109,6 +112,7 @@ public function test_get_month_starts_test(): void { report_customsql_get_month_starts(strtotime('23:59 29 November 2009'))); } + /** @covers ::report_customsql_get_element_type */ public function test_report_customsql_get_element_type(): void { $this->assertEquals('date_time_selector', report_customsql_get_element_type('start_date')); $this->assertEquals('date_time_selector', report_customsql_get_element_type('startdate')); @@ -120,12 +124,14 @@ public function test_report_customsql_get_element_type(): void { $this->assertEquals('text', report_customsql_get_element_type('mandated')); } + /** @covers ::report_customsql_substitute_user_token */ public function test_report_customsql_substitute_user_token(): void { $this->assertEquals('SELECT COUNT(*) FROM oh_quiz_attempts WHERE user = 123', report_customsql_substitute_user_token('SELECT COUNT(*) FROM oh_quiz_attempts '. 'WHERE user = %%USERID%%', 123)); } + /** @covers ::report_customsql_capability_options */ public function test_report_customsql_capability_options(): void { $capoptions = [ 'report/customsql:view' => get_string('anyonewhocanveiwthisreport', 'report_customsql'), @@ -136,6 +142,7 @@ public function test_report_customsql_capability_options(): void { } + /** @covers ::report_customsql_runable_options */ public function test_report_customsql_runable_options(): void { $options = [ 'manual' => get_string('manual', 'report_customsql'), @@ -147,6 +154,7 @@ public function test_report_customsql_runable_options(): void { $this->assertEquals($options, report_customsql_runable_options()); } + /** @covers ::report_customsql_daily_at_options */ public function test_report_customsql_daily_at_options(): void { $time = []; for ($h = 0; $h < 24; $h++) { @@ -156,6 +164,7 @@ public function test_report_customsql_daily_at_options(): void { $this->assertEquals($time, report_customsql_daily_at_options()); } + /** @covers ::report_customsql_email_options */ public function test_report_customsql_email_options(): void { $options = [ 'emailnumberofrows' => get_string('emailnumberofrows', 'report_customsql'), @@ -164,16 +173,19 @@ public function test_report_customsql_email_options(): void { $this->assertEquals($options, report_customsql_email_options()); } + /** @covers ::report_customsql_bad_words_list */ public function test_report_customsql_bad_words_list(): void { $options = ['ALTER', 'CREATE', 'DELETE', 'DROP', 'GRANT', 'INSERT', 'INTO', 'TRUNCATE', 'UPDATE']; $this->assertEquals($options, report_customsql_bad_words_list()); } + /** @covers ::report_customsql_bad_words_list */ public function test_report_customsql_contains_bad_word(): void { $string = 'DELETE * FROM prefix_user u WHERE u.id > 0'; $this->assertEquals(1, report_customsql_contains_bad_word($string)); } + /** @covers ::report_customsql_get_daily_time_starts */ public function test_report_customsql_get_ready_to_run_daily_reports(): void { global $DB; $this->resetAfterTest(true); @@ -247,6 +259,7 @@ public function test_report_customsql_get_ready_to_run_daily_reports(): void { $this->assertTrue(report_customsql_is_daily_report_ready($report, $timenow)); } + /** @covers ::report_customsql_is_integer */ public function test_report_customsql_is_integer(): void { $this->assertTrue(report_customsql_is_integer(1)); $this->assertTrue(report_customsql_is_integer('1')); @@ -254,6 +267,7 @@ public function test_report_customsql_is_integer(): void { $this->assertFalse(report_customsql_is_integer('2013-10-07')); } + /** @covers ::report_customsql_get_table_headers */ public function test_report_customsql_get_table_headers(): void { $rawheaders = [ 'String date', @@ -280,6 +294,7 @@ public function test_report_customsql_get_table_headers(): void { $this->assertEquals([3 => 4, 4 => -1, 5 => 7, 7 => -1], $linkcolumns); } + /** @covers ::report_customsql_pretify_column_names */ public function test_report_customsql_pretify_column_names(): void { $row = new \stdClass(); $row->column = 1; @@ -288,9 +303,9 @@ public function test_report_customsql_pretify_column_names(): void { $query = "SELECT 1 AS First, 2 AS Column_URL, 3 AS column_3"; $this->assertEquals(['column', 'Column URL', 'column 3'], report_customsql_pretify_column_names($row, $query)); - } + /** @covers ::report_customsql_pretify_column_names */ public function test_report_customsql_pretify_column_names_multi_line(): void { $row = new \stdClass(); $row->column = 1; @@ -303,9 +318,9 @@ public function test_report_customsql_pretify_column_names_multi_line(): void { FROM table"; $this->assertEquals(['column', 'Column URL', 'column 3'], report_customsql_pretify_column_names($row, $query)); - } + /** @covers ::report_customsql_pretify_column_names */ public function test_report_customsql_pretify_column_names_same_name_diff_capitialisation(): void { $row = new \stdClass(); $row->course = 'B747-19B'; @@ -316,6 +331,7 @@ public function test_report_customsql_pretify_column_names_same_name_diff_capiti } + /** @covers ::report_customsql_pretify_column_names */ public function test_report_customsql_pretify_column_names_issue(): void { $row = new \stdClass(); $row->website = 'B747-19B'; @@ -346,6 +362,7 @@ public function test_report_customsql_pretify_column_names_issue(): void { } + /** @covers ::report_customsql_display_row */ public function test_report_customsql_display_row(): void { $rawdata = [ 'Not a date', @@ -373,7 +390,7 @@ public function test_report_customsql_display_row(): void { /** * Test plugin emailing of reports * - * @return void + * @covers ::report_customsql_email_report */ public function test_report_customsql_email_report(): void { global $CFG, $DB; @@ -441,7 +458,7 @@ public function test_report_customsql_email_report(): void { /** * Test plugin downloading of reports. * - * @return void + * @covers ::report_customsql_downloadurl */ public function test_report_custom_sql_download_report_url(): void { global $DB; @@ -478,6 +495,7 @@ public function test_report_custom_sql_download_report_url(): void { $this->assertEquals($expected, $url->out(false)); } + /** @covers ::report_customsql_write_csv_row */ public function test_report_customsql_write_csv_row(): void { global $CFG; $this->resetAfterTest();