diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99e7afd..9969610 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,18 +43,12 @@ jobs: fail-fast: false matrix: database: ['pgsql', 'mariadb'] - moodle-branch: ['MOODLE_39_STABLE', 'MOODLE_38_STABLE', 'MOODLE_37_STABLE'] + moodle-branch: ['MOODLE_39_STABLE'] node: ['14.15.1'] php: ['7.2', '7.3'] include: - {moodle-branch: 'MOODLE_35_STABLE', php: '7.1', node: '14.15.1', database: 'mariadb'} - {moodle-branch: 'MOODLE_35_STABLE', php: '7.2', node: '14.15.1', database: 'mariadb'} - - {moodle-branch: 'MOODLE_37_STABLE', php: '7.1', node: '14.15.1', database: 'mariadb'} - - {moodle-branch: 'MOODLE_37_STABLE', php: '7.1', node: '14.15.1', database: 'pgsql'} - - {moodle-branch: 'MOODLE_38_STABLE', php: '7.1', node: '14.15.1', database: 'mariadb'} - - {moodle-branch: 'MOODLE_38_STABLE', php: '7.1', node: '14.15.1', database: 'pgsql'} - - {moodle-branch: 'MOODLE_38_STABLE', php: '7.4', node: '14.15.1', database: 'mariadb'} - - {moodle-branch: 'MOODLE_38_STABLE', php: '7.4', node: '14.15.1', database: 'pgsql'} - {moodle-branch: 'MOODLE_39_STABLE', php: '7.4', node: '14.15.1', database: 'mariadb'} - {moodle-branch: 'MOODLE_39_STABLE', php: '7.4', node: '14.15.1', database: 'pgsql'} diff --git a/auth.php b/auth.php index b9c0e4c..4bf8c85 100644 --- a/auth.php +++ b/auth.php @@ -58,7 +58,6 @@ class auth_plugin_outage extends auth_plugin_base { /** * Always returns false (password wrong or user does not exist). * - * @inheritdoc PHPMD will not warn about unused parameters if overriding. * @param string $username Not used in this plugin. * @param string $password Not used in this plugin. * @return bool False diff --git a/checkfinished.php b/checkfinished.php index e090ad5..f7e15b9 100644 --- a/checkfinished.php +++ b/checkfinished.php @@ -26,7 +26,9 @@ use auth_outage\dml\outagedb; define('NO_MOODLE_COOKIES', true); + // @codingStandardsIgnoreStart header('Cache-Control: public, max-age=10,s-maxage=10'); + // @codingStandardsIgnoreEnd define('NO_AUTH_OUTAGE', true); require_once(__DIR__.'/../../config.php'); diff --git a/classes/local/controllers/infopage.php b/classes/local/controllers/infopage.php index 003750c..eb7b0dc 100644 --- a/classes/local/controllers/infopage.php +++ b/classes/local/controllers/infopage.php @@ -93,7 +93,6 @@ class infopage { /** * Generates and outputs the HTML for the info page. * @uses redirect - * @SuppressWarnings(PHPMD.UnusedLocalVariable) $viewbag is used inside 'require'. */ public function output() { global $PAGE, $CFG, $OUTPUT; diff --git a/classes/local/controllers/maintenance_static_page.php b/classes/local/controllers/maintenance_static_page.php index 3b334fe..41def14 100644 --- a/classes/local/controllers/maintenance_static_page.php +++ b/classes/local/controllers/maintenance_static_page.php @@ -122,6 +122,7 @@ class maintenance_static_page { } /** + * Gets generator io. * @return maintenance_static_page_io */ public function get_io() { diff --git a/classes/local/controllers/maintenance_static_page_generator.php b/classes/local/controllers/maintenance_static_page_generator.php index 986750a..75abc12 100644 --- a/classes/local/controllers/maintenance_static_page_generator.php +++ b/classes/local/controllers/maintenance_static_page_generator.php @@ -95,6 +95,7 @@ class maintenance_static_page_generator { } /** + * Gets maintenance_static_page_io. * @return maintenance_static_page_io */ public function get_io() { @@ -252,7 +253,7 @@ class maintenance_static_page_generator { /** * Fetches all elements based on the given selector. * - * @param $selector + * @param string $selector element selector * * @return DOMElement[] */ @@ -270,7 +271,7 @@ class maintenance_static_page_generator { /** * Fetch all elements which contains the given class. * - * @param $class + * @param string $class element class * * @return DOMElement[] */ @@ -286,6 +287,9 @@ class maintenance_static_page_generator { return $matches; } + /** + * Adds meta refresh to head element. + */ private function add_meta_refresh() { $meta = $this->dom->createElement('meta'); $meta->setAttribute('http-equiv', 'refresh'); @@ -298,6 +302,7 @@ class maintenance_static_page_generator { } /** + * Gets refresh time. * @return int */ public function get_refresh_time() { @@ -305,6 +310,7 @@ class maintenance_static_page_generator { } /** + * Sets refresh time. * @param int $refreshtime */ public function set_refresh_time($refreshtime) { diff --git a/classes/local/controllers/maintenance_static_page_io.php b/classes/local/controllers/maintenance_static_page_io.php index 6ec6e97..5642522 100644 --- a/classes/local/controllers/maintenance_static_page_io.php +++ b/classes/local/controllers/maintenance_static_page_io.php @@ -46,7 +46,7 @@ class maintenance_static_page_io { * Checks if the given string starts with "http://" or "https://". * Also checks for "//" at the start of image, which setting_file_url still uses. * - * @param $url + * @param string $url url string for check * @return bool */ public static function is_url($url) { @@ -82,6 +82,7 @@ class maintenance_static_page_io { protected $preview = false; /** + * Sets preview * @param boolean $preview */ public function set_preview($preview) { diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index e17dce1..a5526dc 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -49,8 +49,10 @@ require_once(__DIR__.'/../../lib.php'); */ class outagelib { + /** Outage start. */ const OUTAGE_START = ''; + /** Outage end. */ const OUTAGE_END = ''; /** @@ -58,6 +60,10 @@ class outagelib { */ private static $injectcalled = false; + /** + * Fetches page. + * @param string $file file to be fetched + */ public static function fetch_page($file) { $curl = new curl(); $contents = $curl->get($file); @@ -79,6 +85,7 @@ class outagelib { /** * Given a time, usually now, when is the next outage window? + * @param int $time time for next window */ public static function get_next_window($time = null) { @@ -202,6 +209,9 @@ class outagelib { } } + /** + * Checks if wwwroot accessible. + */ private static function check_wwwroot_accessible() { global $CFG; $result = self::fetch_page($CFG->wwwroot); @@ -359,9 +369,6 @@ EOT; * Generates a warning message in case the plugin is not active and configured. * * @return string - * - * @internal stdClass $CFG - * @internal bootstrap_renderer $OUTPUT */ public static function generate_plugin_configuration_warning() { global $CFG, $OUTPUT, $PAGE; diff --git a/classes/output/manage/base_table.php b/classes/output/manage/base_table.php index 8848d40..2366d36 100644 --- a/classes/output/manage/base_table.php +++ b/classes/output/manage/base_table.php @@ -48,6 +48,10 @@ class base_table extends flexible_table { */ private static $autoid = 0; + /** + * Creates start time string. + * @param string $starttime start time + */ protected static function create_starttime_string($starttime) { $absolute = userdate($starttime, get_string('datetimeformat', 'auth_outage')); $relative = $starttime - time(); diff --git a/db/uninstall.php b/db/uninstall.php index 4da1ad7..49d6242 100644 --- a/db/uninstall.php +++ b/db/uninstall.php @@ -31,7 +31,6 @@ defined('MOODLE_INTERNAL') || die(); * @return bool result * @throws moodle_exception */ - function xmldb_auth_outage_uninstall() { global $DB; diff --git a/file.php b/file.php index d534a2d..878424e 100644 --- a/file.php +++ b/file.php @@ -57,7 +57,6 @@ header('Accept-Ranges: none'); /** * Callback used in bootstrap. - * @SupressWarnings(PHPMD) */ function auth_outage_bootstrap_callback() { // Not using classes as classloader has not been initialized yet. Keep it minimalist. diff --git a/lib.php b/lib.php index d403d41..92d88c9 100644 --- a/lib.php +++ b/lib.php @@ -41,7 +41,7 @@ function auth_outage_outagelib_prepare_next_outage() { * * To keep it minimalist it was not added to the outagelib.php class. * - * @param $file string Filename to fetch from sitedata + * @param string $file Filename to fetch from sitedata * @return string|null Full path to the sitedata file or null if file is not valid. */ function auth_outage_get_climaintenance_resource_file($file) { diff --git a/tests/behat/behat_auth_outage.php b/tests/behat/behat_auth_outage.php index ad2c4f4..9ce380c 100644 --- a/tests/behat/behat_auth_outage.php +++ b/tests/behat/behat_auth_outage.php @@ -39,7 +39,6 @@ require_once(__DIR__.'/../../../../lib/behat/behat_base.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class behat_auth_outage extends behat_base { /** @@ -155,6 +154,7 @@ class behat_auth_outage extends behat_base { } /** + * Check if an specific action is not visible. * @Then /^I should see an empty settings text area "([^"]*)"$/ * @param string $name */ @@ -163,6 +163,7 @@ class behat_auth_outage extends behat_base { } /** + * Check if an specific action is not visible. * @When /^I go to the "Outage Settings" page$/ */ public function i_go_to_the_outage_settings_page() { diff --git a/tests/phpunit/base_testcase.php b/tests/phpunit/base_testcase.php index 307a0c4..b4f030e 100644 --- a/tests/phpunit/base_testcase.php +++ b/tests/phpunit/base_testcase.php @@ -42,7 +42,6 @@ defined('MOODLE_INTERNAL') || die(); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ abstract class auth_outage_base_testcase extends advanced_testcase { /** @@ -66,6 +65,9 @@ abstract class auth_outage_base_testcase extends advanced_testcase { } } + /** + * Setup testcase. + */ public function setUp() { global $CFG; @@ -73,6 +75,9 @@ abstract class auth_outage_base_testcase extends advanced_testcase { $this->resetAfterTest(true); } + /** + * Tear down to restore the original DB reference. + */ public function tearDown() { global $DB; diff --git a/tests/phpunit/dml/outagedb_test.php b/tests/phpunit/dml/outagedb_test.php index d19bb6a..af9af0c 100644 --- a/tests/phpunit/dml/outagedb_test.php +++ b/tests/phpunit/dml/outagedb_test.php @@ -36,7 +36,6 @@ require_once(__DIR__.'/../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class outagedb_test extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/form/forms_test.php b/tests/phpunit/form/forms_test.php index c7d2b2e..58e7102 100644 --- a/tests/phpunit/form/forms_test.php +++ b/tests/phpunit/form/forms_test.php @@ -198,6 +198,10 @@ class forms_test extends auth_outage_base_testcase { ]; } + /** + * Skip tests for moodle below 30. + * @param string $reason reason to be filled + */ private function skip_because_moodle_is_below_30($reason = '') { global $CFG; diff --git a/tests/phpunit/installation_test.php b/tests/phpunit/installation_test.php index 4a51d28..d0636ae 100644 --- a/tests/phpunit/installation_test.php +++ b/tests/phpunit/installation_test.php @@ -39,7 +39,6 @@ require_once(__DIR__.'/base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class installation_test extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/lib_test.php b/tests/phpunit/lib_test.php index cbc5a29..6c276e0 100644 --- a/tests/phpunit/lib_test.php +++ b/tests/phpunit/lib_test.php @@ -34,9 +34,11 @@ require_once(__DIR__.'/../../lib.php'); * @author Daniel Thee Roperto * @copyright 2017 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class lib_test extends auth_outage_base_testcase { + /** + * Test this plugin gets climaintenance resource file. + */ public function test_auth_outage_get_climaintenance_resource_file_resolves_a_file() { global $CFG; $dir = $CFG->dataroot.'/auth_outage/climaintenance'; @@ -88,6 +90,9 @@ class lib_test extends auth_outage_base_testcase { self::assertSame($realfile, $actual); } + /** + * Test this plugin gets climaintenance resource file and prevents path traversal attack. + */ public function test_auth_outage_get_climaintenance_resource_file_prevent_path_traversal() { global $CFG; diff --git a/tests/phpunit/local/cli/cli_test.php b/tests/phpunit/local/cli/cli_test.php index d05fa7f..d589ccf 100644 --- a/tests/phpunit/local/cli/cli_test.php +++ b/tests/phpunit/local/cli/cli_test.php @@ -36,7 +36,6 @@ require_once(__DIR__.'/cli_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class cli_test extends auth_outage_cli_testcase { /** diff --git a/tests/phpunit/local/cli/cli_testcase.php b/tests/phpunit/local/cli/cli_testcase.php index 47412a7..88aa77f 100644 --- a/tests/phpunit/local/cli/cli_testcase.php +++ b/tests/phpunit/local/cli/cli_testcase.php @@ -35,7 +35,6 @@ require_once(__DIR__.'/../../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ abstract class auth_outage_cli_testcase extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/local/cli/create_test.php b/tests/phpunit/local/cli/create_test.php index 5194d6a..4e8d707 100644 --- a/tests/phpunit/local/cli/create_test.php +++ b/tests/phpunit/local/cli/create_test.php @@ -38,7 +38,6 @@ require_once(__DIR__.'/cli_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class create_test extends auth_outage_cli_testcase { /** diff --git a/tests/phpunit/local/cli/finish_test.php b/tests/phpunit/local/cli/finish_test.php index 4defa93..ee97767 100644 --- a/tests/phpunit/local/cli/finish_test.php +++ b/tests/phpunit/local/cli/finish_test.php @@ -38,7 +38,6 @@ require_once(__DIR__.'/cli_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class finish_test extends auth_outage_cli_testcase { /** diff --git a/tests/phpunit/local/cli/waitforit_test.php b/tests/phpunit/local/cli/waitforit_test.php index 948bea2..419e8be 100644 --- a/tests/phpunit/local/cli/waitforit_test.php +++ b/tests/phpunit/local/cli/waitforit_test.php @@ -38,7 +38,6 @@ require_once(__DIR__.'/cli_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class waitforit_test extends auth_outage_cli_testcase { /** diff --git a/tests/phpunit/local/controllers/infopage_test.php b/tests/phpunit/local/controllers/infopage_test.php index 9c3bc5a..bcaf9a4 100644 --- a/tests/phpunit/local/controllers/infopage_test.php +++ b/tests/phpunit/local/controllers/infopage_test.php @@ -36,7 +36,6 @@ require_once(__DIR__.'/../../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class infopagecontroller_test extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/local/controllers/maintenance_static_page_test.php b/tests/phpunit/local/controllers/maintenance_static_page_test.php index 2318ff8..cd8f575 100644 --- a/tests/phpunit/local/controllers/maintenance_static_page_test.php +++ b/tests/phpunit/local/controllers/maintenance_static_page_test.php @@ -38,10 +38,11 @@ require_once(__DIR__.'/../../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. - * @SuppressWarnings(methods) Allow as many methods as needed. */ class maintenance_static_page_test extends auth_outage_base_testcase { + /** + * Test template file. + */ public function test_templatefile() { global $CFG; $page = maintenance_static_page::create_from_html(''); @@ -51,6 +52,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { $page->get_io()->get_template_file()); } + /** + * Test resources folder. + */ public function test_resourcesfolder() { global $CFG; $page = maintenance_static_page::create_from_html(''); @@ -59,10 +63,16 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertSame($CFG->dataroot.'/auth_outage/climaintenance/preview', $page->get_io()->get_resources_folder()); } + /** + * Test create from outage. + */ public function test_createfromoutage() { // How to fetch a page from PHPUnit environment? } + /** + * Test create from HTML. + */ public function test_createfromhtml() { $html = "\nTitleContent"; $expected = "\nTitle". @@ -70,6 +80,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertSame($expected, $this->generated_page_html($html)); } + /** + * Test remove script tags. + */ public function test_removescripttags() { $html = "\n". 'Title'. @@ -80,6 +93,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertNotContains('get_fixture_path('simple.css'); $externalcsslink = 'http://google.com/coolstuff.css'; @@ -93,6 +109,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertContains($externalcsslink, $generated); } + /** + * Test update link style sheet urls. + */ public function test_updatelinkstylesheet_urls() { $localcsslink = $this->get_fixture_path('withurls.css'); $html = "\n". @@ -108,6 +127,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertFileExists($page->get_io()->get_resources_folder().'/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n'); } + /** + * Test update link style sheet urls quoted. + */ public function test_updatelinkstylesheet_urls_quoted() { $localcsslink = $this->get_fixture_path('withurls-quoted.css'); $html = "\n". @@ -123,6 +145,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertFileExists($page->get_io()->get_resources_folder().'/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n'); } + /** + * Test update link style sheet urls with sub dir. + */ public function test_updatelinkstylesheet_urls_subdir() { $localcsslink = $this->get_fixture_path('subdir/withurls-subdir.css'); $html = "\n". @@ -138,6 +163,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertFileExists($page->get_io()->get_resources_folder().'/a02a8a442fa82d5205ffb24722d9df7f35161f56.dGV4dC9wbGFpbg'); } + /** + * Test update images to file.php style link. + */ public function test_updateimages() { $localimglink = $this->get_fixture_path('catalyst.png'); $externalimglink = 'http://google.com/coolstyle.css'; @@ -151,6 +179,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertContains($externalimglink, $generated); } + /** + * Test update favicon to file.php style link. + */ public function test_updatelinkfavicon() { $link = $this->get_fixture_path('catalyst.png'); $html = "\n". @@ -162,6 +193,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated); } + /** + * Test update preview path to file.php style link. + */ public function test_previewpath() { $link = $this->get_fixture_path('catalyst.png'); $html = "\n". @@ -212,6 +246,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertFileNotExists($file); } + /** + * Tests created file. + */ public function test_createdfile() { global $CFG; @@ -235,7 +272,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase { /** * Gets a fixture file for this test case. * - * @param $file + * @param string $file file name * * @return string */ @@ -243,23 +280,35 @@ class maintenance_static_page_test extends auth_outage_base_testcase { return (string)new moodle_url('/auth/outage/tests/phpunit/local/controllers/fixtures/'.$file); } + /** + * Test saving empty string for template file. + */ public function test_invalid_string_saving_template_empty() { $io = new maintenance_static_page_io(); $this->set_expected_exception('coding_exception'); $io->save_template_file(''); } + /** + * Test saving non string for template file. + */ public function test_invalid_string_saving_template_nostring() { $io = new maintenance_static_page_io(); $this->set_expected_exception('coding_exception'); $io->save_template_file(50); } + /** + * Test get url for file. + */ public function test_get_url_for_file() { $io = new maintenance_static_page_io(); self::assertContains('www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png')); } + /** + * Return array of url data provider and true or false. + */ public function is_url_dataprovider() { return [ [true, 'http://catalyst.net.nz'], @@ -272,12 +321,18 @@ class maintenance_static_page_test extends auth_outage_base_testcase { } /** + * Test if it is url * @dataProvider is_url_dataprovider + * @param string $result expected result + * @param string $url url to be checked */ public function test_is_url($result, $url) { self::assertEquals($result, maintenance_static_page_io::is_url($url)); } + /** + * Test file get_data. + */ public function test_file_get_data() { $file = __DIR__.'/fixtures/catalyst.png'; $found = maintenance_static_page_io::file_get_data($file); @@ -285,6 +340,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertSame('image/png', $found['mime']); } + /** + * Test invalid file get_data. + */ public function test_file_get_data_invalidfile() { $found = maintenance_static_page_io::file_get_data(__DIR__.'/fixtures/invalidfile'); self::assertSame('', $found['contents']); @@ -293,11 +351,17 @@ class maintenance_static_page_test extends auth_outage_base_testcase { phpunit_util::reset_debugging(); } + /** + * Test invalid file get_data. + */ public function test_file_get_data_invalidfilename() { $this->set_expected_exception('coding_exception'); maintenance_static_page_io::file_get_data(200); } + /** + * Test remove css selector. + */ public function test_remove_css_selector() { $this->resetAfterTest(true); $html = "\n". @@ -310,6 +374,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertNotContains('Goodbye cruel world', $generated); } + /** + * Test remove css selector id. + */ public function test_remove_css_selector_id() { $this->resetAfterTest(true); $html = "\n". @@ -322,6 +389,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertNotContains('Goodbye cruel world', $generated); } + /** + * Test remove css selector with multi lines. + */ public function test_remove_css_selector_with_multiline() { $this->resetAfterTest(true); $html = "\n". @@ -338,6 +408,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertNotContains('Goodbye cruel world', $generated); } + /** + * Test remove css selector needs trim. + */ public function test_remove_css_selector_needing_trim() { $this->resetAfterTest(true); $html = "\n". @@ -354,6 +427,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertNotContains('Goodbye cruel world', $generated); } + /** + * Test remove css selector with empty line. + */ public function test_remove_css_selector_with_empty_line() { $this->resetAfterTest(true); $html = "\n". @@ -370,6 +446,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertNotContains('Goodbye cruel world', $generated); } + /** + * Test remove css selector with invalid id. + */ public function test_remove_css_selector_with_invalid_id() { $this->resetAfterTest(true); $html = "\n". @@ -382,6 +461,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertContains('Goodbye cruel world', $generated); } + /** + * Test meta refresh 5 minutes. + */ public function test_meta_refresh_5minutes() { $this->resetAfterTest(true); $html = "\n". @@ -393,6 +475,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase { self::assertContains('', $generated); } + /** + * Test meta refresh maximum 5 minutes. + */ public function test_meta_refresh_maximum_5seconds() { $this->resetAfterTest(true); $html = "\n". diff --git a/tests/phpunit/local/outage_test.php b/tests/phpunit/local/outage_test.php index 61ee4ec..fd1d5a8 100644 --- a/tests/phpunit/local/outage_test.php +++ b/tests/phpunit/local/outage_test.php @@ -35,7 +35,6 @@ require_once(__DIR__.'/../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class outage_test extends auth_outage_base_testcase { /** diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index 01dfab1..4ff8567 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -40,7 +40,6 @@ require_once(__DIR__.'/../base_testcase.php'); * @author Daniel Thee Roperto * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @SuppressWarnings(public) Allow as many methods as needed. */ class outagelib_test extends auth_outage_base_testcase { /** @@ -291,6 +290,9 @@ class outagelib_test extends auth_outage_base_testcase { self::assertEmpty($header); } + /** + * Test create maintenance php code + */ public function test_createmaintenancephpcode() { $expected = <<<'EOT' resetAfterTest(true); @@ -383,6 +388,9 @@ EOT; self::assertSame($found, $expected); } + /** + * Test create maintenance php code without IPs + */ public function test_createmaintenancephpcode_withoutips() { global $CFG; $this->resetAfterTest(true); @@ -399,6 +407,9 @@ EOT; self::assertFileNotExists($file); } + /** + * Test create maintenance php code without outage + */ public function test_createmaintenancephpcode_withoutoutage() { global $CFG; $file = $CFG->dataroot.'/climaintenance.php'; @@ -517,6 +528,9 @@ EOT; self::assertNotEmpty($header); } + /** + * Creates outage for tests. + */ private function create_outage() { $this->resetAfterTest(true); self::setAdminUser();