17 Commits

Author SHA1 Message Date
Dan Marsden
f45918a277 Merge pull request #371 from SashaAnastasi/TOTARA_19-fixes
Totara 19 fixes
2025-03-04 16:17:49 +13:00
Sasha Anastasi
478d0fc5c1 Run class in separate process ensuring tearDown method gets called 2025-03-04 08:18:47 +13:00
Sasha Anastasi
ca4a202752 Remove redundant use statements with non-compound name 2025-03-04 08:17:04 +13:00
Sasha Anastasi
25b9e553a5 update test fixture path 2025-02-27 15:33:10 +13:00
Sasha Anastasi
5cc215d819 add tearDown method to base runtest 2025-02-27 15:32:25 +13:00
Dan Marsden
e8c00be2dd Merge pull request #370 from SashaAnastasi/TOTARA_19-t19_fixes
[T19] Fixes for totara19
2025-02-27 14:27:17 +13:00
Sasha Anastasi
ca213e4c04 flatten test directory structure 2025-02-27 10:17:25 +13:00
Sasha Anastasi
eac1575f51 use imports instead of namespaces 2025-02-27 09:09:06 +13:00
Sasha Anastasi
cff0f3fbe3 update test classes 2025-02-27 08:59:31 +13:00
Sasha Anastasi
ffb9e27456 add tearDown method to runtests 2025-02-26 16:40:41 +13:00
Dan Marsden
f842e2baa4 Merge pull request #366 from SashaAnastasi/TOTARA_19-phpunit10
outagelib: adjust exception trigger for phpunit10
2025-02-20 14:46:57 +13:00
Sasha Anastasi
f3d91cb044 remove superfluous conditional 2025-02-20 14:36:26 +13:00
Sasha Anastasi
a63ffed1bc outagelib: adjust exception trigger for phpunit10 2025-02-20 12:33:01 +13:00
Dan Marsden
c99d8f12a0 Merge pull request #364 from catalyst/fix-t19-tests
[T19] Replace deprecated testcase classes with core_phpunit
2025-02-19 10:55:09 +13:00
Sasha Anastasi
d3b5ed73aa Replace deprecated testcase classes with core_phpunit 2025-02-18 15:12:09 +13:00
Matthew Hilton
03362c084c Merge pull request #362 from catalyst/fix-blocked-url
Fix URL is blocked message when not behind a proxy/load balancer
2025-02-11 09:02:02 +10:00
Rossco Hellmans
51db933862 Fix URL is blocked message when not behind a proxy/load balancer
When there is no proxy/load balancer and curlsecurityblockedhosts is set to
default (i.e. has 127.0.0.1 in it) fetching the outage page will result in
a "The URL is blocked." message. This resolves that issue by passing
ignoresecurity to the curl object.
2025-02-10 16:36:34 +10:00
25 changed files with 160 additions and 77 deletions

View File

@@ -8,4 +8,5 @@ jobs:
uses: catalyst/catalyst-moodle-workflows/.github/workflows/ci.yml@main
secrets:
moodle_org_token: ${{ secrets.MOODLE_ORG_TOKEN }}
with:
disable_behat: true

View File

@@ -57,7 +57,7 @@ class outagelib {
global $CFG;
require_once($CFG->libdir . '/filelib.php');
$curl = new curl();
$curl = new curl(['ignoresecurity' => true]);
$contents = $curl->get($file);
$info = $curl->get_info();
if (!empty($info['content_type'])) {
@@ -266,7 +266,7 @@ class outagelib {
// Used to test the try block in case of errors.
if (PHPUNIT_TEST && optional_param('auth_outage_break_code', false, PARAM_INT)) {
(new stdClass())->invalidfield; // Triggers an exception.
throw new coding_exception('Exception triggered');
}
// Nothing preventing the injection.

View File

@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace auth_outage;
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
@@ -35,7 +33,7 @@ use auth_outage\local\outage;
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class base_testcase extends \advanced_testcase {
abstract class base_testcase extends \core_phpunit\testcase {
/**
* Checks PHPUnit version and calls the functions accordingly.
* @param string $exception Expected exception class.
@@ -107,5 +105,6 @@ abstract class base_testcase extends \advanced_testcase {
foreach (outagedb::get_all() as $i => $outage) {
$DB->delete_records('auth_outage', ['id' => $outage->id]);
}
parent::tearDown();
}
}

View File

@@ -23,9 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\calendar;
use auth_outage\local\outage;
use auth_outage\calendar\calendar;
/**
* calendar_test test class.
@@ -39,7 +38,7 @@ use auth_outage\local\outage;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\calendar\calendar
*/
class calendar_test extends \advanced_testcase {
class calendar_test extends \core_phpunit\testcase {
/**
* @var outage|null The calendar entry owner.
*/

View File

@@ -23,10 +23,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\local\cli;
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
use auth_outage\local\cli\create;
use auth_outage\local\cli\cli_exception;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/cli_testcase.php');
@@ -40,7 +40,12 @@ require_once(__DIR__.'/cli_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\local\cli\create
*/
class create_test extends cli_testcase {
class cli_create_test extends cli_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Tests without any arguments.
*/

View File

@@ -23,10 +23,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\local\cli;
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
use auth_outage\local\cli\finish;
use auth_outage\local\cli\cli_exception;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/cli_testcase.php');
@@ -40,7 +40,12 @@ require_once(__DIR__.'/cli_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\local\cli\finish
*/
class finish_test extends cli_testcase {
class cli_finish_test extends cli_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Tests the constructor.
*/

View File

@@ -23,7 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\local\cli;
use auth_outage\local\cli\cli_exception;
use auth_outage\local\cli\create;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/cli_testcase.php');
@@ -38,6 +39,11 @@ require_once(__DIR__.'/cli_testcase.php');
* @covers \auth_outage\local\cli\create
*/
class cli_test extends cli_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Tests providing an unknown parameter.
*/

View File

@@ -23,10 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\local\cli;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../../base_testcase.php');
require_once(__DIR__.'/base_testcase.php');
/**
* cli_testcase class.
@@ -36,7 +34,12 @@ require_once(__DIR__.'/../../base_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class cli_testcase extends \auth_outage\base_testcase {
abstract class cli_testcase extends base_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Always enable the auth outage plugin, resets after test and set no parameters.
*/
@@ -73,7 +76,7 @@ abstract class cli_testcase extends \auth_outage\base_testcase {
*
* @return string The output text.
*/
protected function execute(clibase $cli) {
protected function execute(mixed $cli) {
ob_start();
try {
$cli->execute();

View File

@@ -23,10 +23,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\local\cli;
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
use auth_outage\local\cli\waitforit;
use auth_outage\local\cli\cli_exception;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/cli_testcase.php');
@@ -40,7 +40,12 @@ require_once(__DIR__.'/cli_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\local\cli\waitforit
*/
class waitforit_test extends cli_testcase {
class cli_waitforit_test extends cli_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Tests the constructor.
*/

View File

@@ -23,13 +23,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\local\controllers;
use auth_outage\local\outage;
use context_system;
use auth_outage\local\controllers\infopage;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../../base_testcase.php');
require_once(__DIR__.'/base_testcase.php');
/**
* Tests performed on infopage controller class and update_static_page task class.
@@ -40,7 +38,12 @@ require_once(__DIR__.'/../../base_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\local\controllers\infopage
*/
class infopage_test extends \auth_outage\base_testcase {
class controllers_infopage_test extends base_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Tests the constructor.
*/

View File

@@ -23,13 +23,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\local\controllers;
use auth_outage\task\update_static_page;
use DOMDocument;
use auth_outage\local\controllers\maintenance_static_page;
use auth_outage\local\controllers\maintenance_static_page_io;
use auth_outage\local\controllers\maintenance_static_page_generator;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../../base_testcase.php');
require_once(__DIR__.'/base_testcase.php');
/**
* maintenance_static_page_test class.
@@ -40,7 +40,12 @@ require_once(__DIR__.'/../../base_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\local\controllers\maintenance_static_page_generator
*/
class maintenance_static_page_test extends \auth_outage\base_testcase {
class controllers_maintenance_static_page_test extends base_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Test template file.
*/
@@ -122,7 +127,7 @@ class maintenance_static_page_test extends \auth_outage\base_testcase {
$page->generate();
// Check for css file.
self::assertFileExists($page->get_io()->get_resources_folder().'/53365950336b070c0b26ca50e7d0dad962c364e6.dGV4dC9wbGFpbg');
self::assertFileExists($page->get_io()->get_resources_folder().'/b09bd4b66cc3964d5fc5978752fc554f5666daa3.dGV4dC9wbGFpbg');
// Check for catalyst.png file referenced in url(..) of css.
self::assertFileExists($page->get_io()->get_resources_folder().'/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n');
@@ -140,7 +145,7 @@ class maintenance_static_page_test extends \auth_outage\base_testcase {
$page->generate();
// Check for css file.
self::assertFileExists($page->get_io()->get_resources_folder().'/e0b34925c1f939c247a4b50d6bf08c76088def39.dGV4dC9wbGFpbg');
self::assertFileExists($page->get_io()->get_resources_folder().'/2ec04228cc8bb37782f511aaeb01ee553cc884a4.dGV4dC9wbGFpbg');
// Check for catalyst.png file referenced in url(..) of css.
self::assertFileExists($page->get_io()->get_resources_folder().'/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n');
@@ -338,7 +343,7 @@ class maintenance_static_page_test extends \auth_outage\base_testcase {
* @return string
*/
private function get_fixture_path_location($file) {
return (string)new \moodle_url('/auth/outage/tests/local/controllers/fixtures/'.$file);
return (string)new \moodle_url('/auth/outage/tests/fixtures/'.$file);
}
/**
@@ -423,6 +428,37 @@ class maintenance_static_page_test extends \auth_outage\base_testcase {
maintenance_static_page_io::file_get_data(200);
}
/**
* Test file_get_data with curlsecurityblockedhosts.
* We will use an external URL to test passing ignoresecurity inside of file_get_data works,
* ideally in real code we should only be calling file_get_data with internal URLs.
*/
public function test_file_get_data_curlsecurityblockedhosts() {
global $CFG, $USER;
$testhtml = $this->getExternalTestFileUrl('/test.html');
$url = new \moodle_url($testhtml);
$host = $url->get_host();
set_config('curlsecurityblockedhosts', $host); // Blocks $host.
// Test a regular curl with the default security enabled does in fact get blocked.
$curl = new \curl();
$contents = $curl->get($testhtml);
$expected = $curl->get_security()->get_blocked_url_string();
self::assertSame($expected, $contents);
self::assertSame(0, $curl->get_errno());
if ($CFG->branch >= 403) {
self::assertDebuggingCalled(
"Blocked $testhtml: The URL is blocked. [user {$USER->id}]", DEBUG_NONE);
}
// Test file_get_data does return the page and isn't blocked by security.
$found = maintenance_static_page_io::file_get_data($url->out());
$expected = '47250a973d1b88d9445f94db4ef2c97a';
self::assertSame($expected, md5($found['contents']));
self::assertSame('text/html', $found['mime']);
}
/**
* Test remove css selector.
*/

View File

@@ -23,9 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\dml;
use auth_outage\local\outage;
use auth_outage\dml\outagedb;
/**
* events_test tests class.
@@ -39,7 +38,7 @@ use auth_outage\local\outage;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\dml\outagedb
*/
class events_test extends \advanced_testcase {
class dml_events_test extends \core_phpunit\testcase {
/**
* @var outage|null Outage used in the tests.
*/

View File

@@ -25,12 +25,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\dml;
use auth_outage\local\outage;
use auth_outage\dml\outagedb;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../base_testcase.php');
require_once(__DIR__.'/base_testcase.php');
/**
* installation_test test class.
@@ -43,7 +42,12 @@ require_once(__DIR__.'/../base_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\dml\outagedb
*/
class installation_test extends \auth_outage\base_testcase {
class dml_installation_test extends base_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Checks if plugin cleans up data after uninstall.
*

View File

@@ -23,12 +23,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\dml;
use auth_outage\local\outage;
use auth_outage\dml\outagedb;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../base_testcase.php');
require_once(__DIR__.'/base_testcase.php');
/**
* outagedb_test tests class.
@@ -39,7 +38,12 @@ require_once(__DIR__.'/../base_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\dml\outagedb
*/
class outagedb_test extends \auth_outage\base_testcase {
class dml_outagedb_test extends base_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Creates an array of ids in from the given outages array.
* @param outage[] $outages An array of outages.

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

7
tests/fixtures/withurls-quoted.css vendored Normal file
View File

@@ -0,0 +1,7 @@
a {
font-size: 200%;
}
div {
background-image: url('/moodle/auth/outage/tests/fixtures/catalyst.png');
}

7
tests/fixtures/withurls.css vendored Normal file
View File

@@ -0,0 +1,7 @@
a {
font-size: 200%;
}
div {
background-image: url(/moodle/auth/outage/tests/fixtures/catalyst.png);
}

View File

@@ -23,12 +23,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\form\outage;
use auth_outage\local\outage;
use auth_outage\form\outage\delete;
use auth_outage\form\outage\finish;
use auth_outage\form\outage\edit;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../../base_testcase.php');
require_once(__DIR__.'/base_testcase.php');
/**
* forms_test test class.
@@ -39,7 +40,12 @@ require_once(__DIR__.'/../../base_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\form\outage\edit
*/
class forms_test extends \auth_outage\base_testcase {
class forms_test extends base_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Create a delete form.
*/

View File

@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace auth_outage;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/base_testcase.php');
require_once(__DIR__.'/../lib.php');
@@ -29,7 +27,7 @@ require_once(__DIR__.'/../lib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers ::auth_outage_get_climaintenance_resource_file
*/
class lib_test extends base_testcase {
class lib_test extends \core_phpunit\testcase {
/**
* Test this plugin gets climaintenance resource file.
*/

View File

@@ -1,7 +0,0 @@
a {
font-size: 200%;
}
div {
background-image: url('/moodle/auth/outage/tests/local/controllers/fixtures/catalyst.png');
}

View File

@@ -1,7 +0,0 @@
a {
font-size: 200%;
}
div {
background-image: url(/moodle/auth/outage/tests/local/controllers/fixtures/catalyst.png);
}

View File

@@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace auth_outage\local;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../base_testcase.php');
require_once(__DIR__.'/base_testcase.php');
/**
* outage_test test class.
@@ -28,7 +28,12 @@ require_once(__DIR__.'/../base_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\local\outage
*/
class outage_test extends \auth_outage\base_testcase {
class outage_test extends base_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Tests the constructor.
*/

View File

@@ -14,14 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace auth_outage\local;
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
use auth_outage\local\outagelib;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir.'/adminlib.php');
require_once(__DIR__.'/../base_testcase.php');
require_once(__DIR__.'/base_testcase.php');
/**
* outagelib_test test class.
@@ -32,7 +32,12 @@ require_once(__DIR__.'/../base_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_outage\local\outagelib
*/
class outagelib_test extends \auth_outage\base_testcase {
class outagelib_test extends base_testcase {
public function tearDown(): void {
parent::tearDown();
}
/**
* Check if maintenance message is disabled as needed.
*/
@@ -742,7 +747,7 @@ EOT;
*
* We need this because we modify the request headers,
* see https://github.com/sebastianbergmann/phpunit/issues/720#issuecomment-10421092
* @runInSeparateProcess
* @runClassInSeparateProcess
*/
public function test_evaluation_maintenancepage(?string $allowedips, ?string $iptouse, ?string $accesskey,
?string $accesskeytouse, array $expectedoutputs) {