5 Commits

Author SHA1 Message Date
Jerome Charaoui
c4fc4b4396 Include filelib.php to fix class not found exception 2021-05-06 10:29:33 +12:00
Dan Marsden
e632b1c2f9 We haven't been testing postgres on 3.5 - it needs pg12
disable pg test for now, but we should think about adding it back.
2021-05-06 10:04:50 +12:00
Dan Marsden
b4d996125d Update Readme with new branch naming. 2021-05-06 10:04:24 +12:00
Dan Marsden
f8d0d658fa tidy up github action config. 2021-05-05 20:23:22 +12:00
Dan Marsden
a38deb7abf Test 3.5 and 3.8 on this branch. 2021-05-05 14:53:07 +12:00
46 changed files with 348 additions and 498 deletions

View File

@@ -1,9 +1,126 @@
name: ci
name: Moodle plugin CI for master
# Controls when the action will run.
on: [push, pull_request]
jobs:
test:
uses: catalyst/catalyst-moodle-workflows/.github/workflows/group-39-plus-ci.yml@main
with:
disable_behat: true
citest:
name: CI test
runs-on: 'ubuntu-latest'
services:
postgres:
image: postgres
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 5432:5432
mariadb:
image: mariadb
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 3
strategy:
fail-fast: false
matrix:
database: ['mariadb']
moodle-branch: ['MOODLE_35_STABLE']
node: ['14.15.1']
php: ['7.1']
include:
- {moodle-branch: 'MOODLE_38_STABLE', php: '7.1', node: '14.15.1', database: 'mariadb'}
- {moodle-branch: 'MOODLE_38_STABLE', php: '7.4', node: '14.15.1', database: 'pgsql'}
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
path: plugin
- name: Install node ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pgsql, zip, gd, xmlrpc, soap
coverage: none
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
# Add dirs to $PATH
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
# PHPUnit depends on en_AU.UTF-8 locale
sudo locale-gen en_AU.UTF-8
- name: Install Moodle
run: |
mkdir ~/.npm-global
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
moodle-plugin-ci install -vvv --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
- name: Run phplint
if: ${{ always() }}
run: moodle-plugin-ci phplint
- name: Run phpcpd
if: ${{ always() }}
run: moodle-plugin-ci phpcpd || true
- name: Run phpmd
if: ${{ always() }}
run: moodle-plugin-ci phpmd
- name: Run codechecker
if: ${{ always() }}
run: moodle-plugin-ci codechecker
- name: Run validate
if: ${{ always() }}
run: moodle-plugin-ci validate
- name: Run savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints
- name: Run mustache
if: ${{ always() }}
run: moodle-plugin-ci phpcpd
- name: Run grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt
- name: Run phpdoc
if: ${{ always() }}
run: moodle-plugin-ci phpdoc
- name: Run phpunit
if: ${{ always() }}
run: moodle-plugin-ci phpunit
# - name: Run behat
# if: ${{ always() }}
# run: moodle-plugin-ci behat --profile chrome

View File

@@ -1,21 +0,0 @@
#
# Whenever version.php is changed, add the latest version
# to the Moodle Plugins directory at https://moodle.org/plugins
#
name: Releasing in the Plugins directory
on:
push:
branches:
- MOODLE_39_STABLE
paths:
- 'version.php'
jobs:
workflow_group_39_plus_release:
uses: catalyst/catalyst-moodle-workflows/.github/workflows/group-39-plus-release.yml@main
with:
plugin_name: auth_outage
disable_behat: true
secrets:
moodle_org_token: ${{ secrets.MOODLE_ORG_TOKEN }}

View File

@@ -1,4 +1,6 @@
[![Build Status](https://github.com/catalyst/moodle-auth_outage/workflows/Run%20all%20tests%20for%20Moodle%2039+/badge.svg)](https://github.com/catalyst/moodle-auth_outage/actions)
<a href="https://travis-ci.org/catalyst/moodle-auth_outage">
<img src="https://travis-ci.org/catalyst/moodle-auth_outage.svg?branch=master">
</a>
# Moodle Outage manager plugin
* [Version Support](#version-support)
@@ -24,7 +26,10 @@ this plugin creates the concept of graduated outages where at predefined times b
an outage and after, different levels of warning and access can be provided to students
and testers letting them know what is about to happen and why.
![image](https://user-images.githubusercontent.com/187449/149717343-1d2c5237-dbc6-4d2a-a08c-2bdb343e87d2.png)
<img alt="Default" src="https://cdn.rawgit.com/catalyst/moodle-auth_outage/master/docs/default.svg" width="520">
<img alt="Manager" src="https://cdn.rawgit.com/catalyst/moodle-auth_outage/master/docs/outage.svg" width="520">
Moodle Requirements
-------------------
@@ -37,12 +42,14 @@ need to manually add one extra plugin, please check:
Branches
--------
| Moodle version | Totara | Branch | PHP |
| ------------------ | --------------- | ---------------- | ---- |
| Moodle 3.9+ | Totara 13+ | MOODLE_39_STABLE | 7.2+ |
| Moodle 3.3 to 3.8 | Totara 11 to 12 | MOODLE_38_STABLE | 7.1+ |
| Moodle 2.7 to 3.2 | | MOODLE_32_STABLE | 5.5+ |
| | Totara up to 10 | TOTARA_10 | 5.5+ |
| Moodle version | Branch | PHP |
| ----------------- | ----------- | ---- |
| Moodle 2.7 to 3.2 | MOODLE_32_STABLE | 5.5+ |
| Totara up to 10 | TOTARA_10 | 5.5+ |
| Moodle 3.3 to 3.8 | MOODLE_38_STABLE | 7.1+ |
| Totara 11 to 12 | MOODLE_38_STABLE | 7.1+ |
| Moodle 3.9+ | MOODLE_39_STABLE | 7.2+ |
| Totara 13+ | MOODLE_39_STABLE | 7.2+ |
Screenshots
-----------

View File

@@ -31,7 +31,7 @@
// This call is required by Moodle, but this script should have been called by config.php anyway.
// @codingStandardsIgnoreStart
require_once(__DIR__.'/../../../config.php');
require_once(__DIR__.'/../../config.php');
// @codingStandardsIgnoreEnd
// We need the CFG->dataroot, if not set yet this script is called too early in config.php file.
@@ -42,13 +42,13 @@ if (!isset($CFG->dataroot)) {
// 1) Make sure we replace the configurations for behat as we have not ran 'lib/setup.php' yet.
if (!empty($CFG->behat_wwwroot) or !empty($CFG->behat_dataroot) or !empty($CFG->behat_prefix)) {
require_once(__DIR__.'/../../lib/behat/lib.php');
behat_update_vars_for_process($CFG);
if (behat_is_test_site($CFG)) {
behat_update_vars_for_process();
if (behat_is_test_site()) {
$beforebehatcfg = $CFG;
$CFG = clone($CFG);
clearstatcache();
behat_check_config_vars($CFG);
behat_clean_init_config($CFG);
behat_check_config_vars();
behat_clean_init_config();
$CFG->wwwroot = $CFG->behat_wwwroot;
$CFG->dataroot = $CFG->behat_dataroot;
// We should not access database in bootstrap.

View File

@@ -211,20 +211,21 @@ class outagedb {
throw new coding_exception('$time must be null or a positive int.', $time);
}
// Get cached outage, or null.
$outageinfo = get_config('moodle', 'auth_outage_active_outage');
$select = ':datetime2 <= stoptime AND (finished IS NULL OR :datetime3 <= finished)'; // End condition.
$select = "(warntime <= :datetime1 AND (${select}))"; // Full select part.
$data = $DB->get_records_select(
'auth_outage',
$select,
['datetime1' => $time, 'datetime2' => $time, 'datetime3' => $time],
'starttime ASC, stoptime DESC, title ASC',
'*',
0,
1
);
if (!$outageinfo) {
return null;
} else {
$outagecache = new outage(json_decode($outageinfo));
}
if ($outagecache && $outagecache->warntime <= $time && $outagecache->stoptime >= $time
&& (!$outagecache->finished || $outagecache->finished >= $time)) {
return $outagecache;
}
return null;
// Not using $DB->get_record_select instead because there is no 'limit' parameter.
// Allowing multiple records still raises an internal error.
return (count($data) == 0) ? null : new outage(array_shift($data));
}
/**

View File

@@ -28,6 +28,8 @@ namespace auth_outage\event;
use core\event\base;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* outage_created class.
*

View File

@@ -27,6 +27,8 @@ namespace auth_outage\event;
use core\event\base;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* outage_deleted class.
*

View File

@@ -28,6 +28,8 @@ namespace auth_outage\event;
use core\event\base;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* outage_updated class.
*

View File

@@ -27,6 +27,8 @@ namespace auth_outage\local\cli;
use Exception;
defined('MOODLE_INTERNAL') || die();
/**
* cli_exception class.
*

View File

@@ -29,6 +29,8 @@ use auth_outage\local\outagelib;
use coding_exception;
use core\session\manager;
defined('MOODLE_INTERNAL') || die();
/**
* clibase class.
*
@@ -122,7 +124,7 @@ abstract class clibase {
*/
protected function become_admin_user() {
global $DB;
$user = get_admin();
$user = $DB->get_record('user', ['id' => 2]);
unset($user->description);
unset($user->access);
unset($user->preference);

View File

@@ -29,6 +29,8 @@ use auth_outage\dml\outagedb;
use auth_outage\local\outage;
use coding_exception;
defined('MOODLE_INTERNAL') || die();
/**
* create class.
*

View File

@@ -28,6 +28,8 @@ namespace auth_outage\local\cli;
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* finish class.
*

View File

@@ -28,6 +28,8 @@ namespace auth_outage\local\cli;
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* waitforit class.
*

View File

@@ -32,6 +32,8 @@ use coding_exception;
use context_system;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* infopage class.
*
@@ -46,11 +48,6 @@ class infopage {
*/
private $outage;
/**
* @var bool|null Defines if the page is generated for a static outage page.
*/
private $static;
/**
* infopage_controller constructor.
* @param array $params Parameters to use or null to get from Moodle API (request).
@@ -65,13 +62,11 @@ class infopage {
$params = [
'id' => optional_param('id', null, PARAM_INT),
'outage' => null,
'static' => optional_param('static', false, PARAM_BOOL),
];
} else {
$defaults = [
'id' => null,
'outage' => null,
'static' => false,
];
$params = array_merge($defaults, $params);
}
@@ -106,10 +101,6 @@ class infopage {
redirect(new moodle_url('/'));
}
// If it's not static outage page, then check access, then redirect if not allowed.
if (!$this->static && !has_capability('auth/outage:viewinfo', context_system::instance())) {
redirect(new moodle_url('/'));
}
$PAGE->set_context(context_system::instance());
$PAGE->set_title($this->outage->get_title());
$PAGE->set_heading($this->outage->get_title());
@@ -152,6 +143,5 @@ class infopage {
}
$this->outage = $params['outage'];
$this->static = $params['static'];
}
}

View File

@@ -29,6 +29,8 @@ use auth_outage\local\outage;
use coding_exception;
use DOMDocument;
defined('MOODLE_INTERNAL') || die();
/**
* maintenance_static_page class.
*
@@ -59,7 +61,7 @@ class maintenance_static_page {
$html = '<html></html>';
} else {
$data = maintenance_static_page_io::file_get_data(
$CFG->wwwroot.'/auth/outage/info.php?auth_outage_hide_warning=1&static=1&id='.$outage->id);
$CFG->wwwroot.'/auth/outage/info.php?auth_outage_hide_warning=1&id='.$outage->id);
$html = $data['contents'];
}

View File

@@ -27,12 +27,13 @@ namespace auth_outage\local\controllers;
use auth_outage\local\outagelib;
use coding_exception;
use core_php_time_limit;
use DOMDocument;
use DOMElement;
use invalid_state_exception;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* maintenance_static_page_generator class.
*
@@ -42,15 +43,6 @@ use moodle_url;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class maintenance_static_page_generator {
/** PATTERN
* The pattern should match the attribute values that
* go as 'url(xxxxx)', but make sure 'url(data:xxxxx)' is not
* rewritten. Must be case insensitive to match 'URL(xxxxx)'.
* It should be possible to specify other background attributes as
* 'background: color url(xxxxx) no-repeat'.
*/
protected const PATTERN = '/url\s*\(\s*[\'"]?(?![\'"]?data:)([^\s\'"]+)[\'"]?\s*\)/i';
/** @var DOMDocument */
protected $dom;
@@ -83,10 +75,6 @@ class maintenance_static_page_generator {
$this->io->cleanup();
if (!is_null($this->dom)) {
// This can take a while to process using repeated curls.
core_php_time_limit::raise();
$this->io->create_resources_path();
$this->remove_script_tags();
@@ -95,7 +83,6 @@ class maintenance_static_page_generator {
$this->update_link_favicon();
$this->update_images();
$this->remove_configured_css_selectors();
$this->update_inline_background_images();
$html = $this->dom->saveHTML();
if (trim($html) == '') {
@@ -163,18 +150,6 @@ class maintenance_static_page_generator {
return $matches;
}
/**
* Retrieves a URL from inline style using regular expressions.
*
* @param string $style Content of the style attribute
* @return array Array containing match
*/
public function get_url_from_inline_style($style) {
preg_match(self::PATTERN, $style, $match);
return $match;
}
/**
* Checks for urls inside filename.
*
@@ -243,31 +218,6 @@ class maintenance_static_page_generator {
}
}
/**
* Fetch and fixes all inline background images.
*/
private function update_inline_background_images() {
global $CFG;
$xpath = new \DOMXPath($this->dom);
$elements = $xpath->query("//*[contains(@style,'background')]");
foreach ($elements as $element) {
$style = $element->getAttribute("style");
$matches = $this->get_url_from_inline_style($style);
if (isset($matches[1])) {
// Allow incomplete URLs in style, assume it is from moodle root.
if (maintenance_static_page_io::is_url($matches[1])) {
$fullurl = $matches[1];
} else {
$fullurl = (string) new moodle_url($matches[1]);
}
$newurl = $this->io->generate_file_url($fullurl);
$updated = preg_replace(self::PATTERN, ' url('.$newurl.') ', $style);
$element->setAttribute('style', $updated);
}
}
}
/**
* Remove from DOM the CSS selectores defined in the plugin settings.
*/

View File

@@ -31,6 +31,8 @@ use finfo;
use invalid_parameter_exception;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* maintenance_static_page_io class.
*

View File

@@ -28,6 +28,8 @@ namespace auth_outage\local;
use coding_exception;
use stdClass;
defined('MOODLE_INTERNAL') || die();
/**
* outage class.
*
@@ -297,12 +299,4 @@ class outage {
// Adjust bool fields.
$this->autostart = ($this->autostart === null) ? null : (bool)$this->autostart;
}
/**
* Return json encoded outage.
* @return string Json string.
*/
public function __toString() {
return json_encode(get_object_vars($this));
}
}

View File

@@ -168,12 +168,7 @@ class outagelib {
}
}
$config = array_merge(self::get_config_defaults(), $config);
// Combine allowed IPs config values together.
if (isset($config['allowedips_forced'])) {
$config['allowedips'] = trim($config['allowedips'] . "\n" . $config['allowedips_forced']);
}
return (object)$config;
return (object)array_merge(self::get_config_defaults(), $config);
}
/**
@@ -210,10 +205,6 @@ class outagelib {
} else {
$ongoingoutage = true;
}
// Set json formatted outage string to cache.
set_config('auth_outage_active_outage', (string)$outage);
maintenance_static_page::create_from_outage($outage)->generate();
self::update_climaintenance_code($outage);
if (!$ongoingoutage || $reenablemaint || is_null($outage)) {

View File

@@ -33,6 +33,8 @@ use html_writer;
use moodle_url;
use plugin_renderer_base;
defined('MOODLE_INTERNAL') || die();
/**
* auth_outage_renderer class.
*

View File

@@ -23,6 +23,8 @@
namespace auth_outage\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\legacy_polyfill;
/**

View File

@@ -29,6 +29,8 @@ use auth_outage\local\controllers\infopage;
use auth_outage\local\outagelib;
use core\task\scheduled_task;
defined('MOODLE_INTERNAL') || die();
/**
* update_static_page class.
*

View File

@@ -1,37 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Define capabilities for plugin.
*
* @package auth_outage
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = [
'auth/outage:viewinfo' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'guest' => CAP_ALLOW,
'user' => CAP_ALLOW,
)
),
];

View File

@@ -24,6 +24,8 @@
*/
use auth_outage\local\controllers\maintenance_static_page;
defined('MOODLE_INTERNAL') || die();
/**
* Auth Outage plugin uninstall code.
* @return bool result

View File

@@ -22,6 +22,7 @@
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Outage plugin upgrade code

View File

@@ -26,8 +26,6 @@
$string['auth_outagedescription'] = 'Auxiliary plugin that warns users about a future outage and prevents them from logging in once the outage starts.';
$string['autostart'] = 'Auto start maintenance mode.';
$string['autostart_help'] = 'If selected, when the outage starts it will automatically turn on Moodle maintenance mode.';
$string['builtinallowediplist'] = 'Builtin Allowed IP List';
$string['builtinallowediplist_desc'] = 'A second allowed IP list which makes it easier to have some IPs forced in config.php and others editable in the UI';
$string['clicreatehelp'] = 'Creates a new outage.';
$string['clicreateexamples'] = "Create an outage starting in 10 seconds\n\n> php create.php -s=10";
$string['clicreateparamautostart'] = 'must be Y or N, sets if the outage automatically triggers maintenance mode.';
@@ -102,7 +100,6 @@ $string['infostart'] = 'start';
$string['infostartofwarning'] = 'start of warning';
$string['infostaticpage'] = 'static page';
$string['infopagestaticgenerated'] = 'This warning was generated on {$a->time}.';
$string['ips_combine'] = 'The IPs listed above will be combined with the IPs listed below.';
$string['allowedipsempty'] = 'When the allowed IPs list is empty we will not block anyone. You can add your own IP address (<i>{$a->ip}</i>) and block all other IPs.';
$string['allowedipshasmyip'] = 'Your IP (<i>{$a->ip}</i>) is in the list and you will not be blocked out during an Outage.';
$string['allowedipshasntmyip'] = 'Your IP (<i>{$a->ip}</i>) is not in the list and you will be blocked out during an outage.';
@@ -115,7 +112,6 @@ $string['messageoutageongoing'] = 'Back online at {$a->stop}.';
$string['messageoutagewarning'] = 'Shutting down in {{countdown}}';
$string['na'] = 'n/a';
$string['notfound'] = 'No outages found.';
$string['outage:viewinfo'] = 'View outage info';
$string['outageedit'] = 'Edit outage';
$string['outageeditcrumb'] = 'Edit';
$string['outageclone'] = 'Clone outage';

View File

@@ -25,6 +25,8 @@
use auth_outage\local\outagelib;
defined('MOODLE_INTERNAL') || die;
/**
* Used for adminlib::set_updatedcallback which requires a string that resolves to a function.
*
@@ -84,4 +86,4 @@ function auth_outage_get_fontawesome_icon_map() {
function auth_outage_before_standard_top_of_body_html() {
// Get code to inject.
return outagelib::get_inject_code();
}
}

View File

@@ -26,6 +26,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* auth_outage_renderer class.
*

View File

@@ -110,8 +110,6 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
$description .= $OUTPUT->notification(get_string($message, 'auth_outage', ['ip' => getremoteaddr()]), $type);
$description .= '<p>'.get_string('ipblockersyntax', 'admin').'</p>';
$description .= '<p>'.get_string('ips_combine', 'auth_outage').'</p>';
$iplist = new admin_setting_configiplist(
'auth_outage/allowedips',
get_string('allowediplist', 'admin'),
@@ -121,14 +119,6 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
$iplist->set_updatedcallback('auth_outage_outagelib_prepare_next_outage');
$settings->add($iplist);
$iplist = new admin_setting_configiplist(
'auth_outage/allowedips_forced',
get_string('builtinallowediplist', 'auth_outage'),
get_string('builtinallowediplist_desc', 'auth_outage'),
''
);
$settings->add($iplist);
// Create 'Static Page - Elements to Remove' settings.
$toremove = new admin_setting_configtextarea(
'auth_outage/remove_selectors',

View File

@@ -32,7 +32,8 @@
*/
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* auth_outage_base_testcase class.
@@ -64,37 +65,6 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
}
}
/**
* Revoke permission to see info page.
*/
protected function revoke_info_page_permissions() {
global $DB;
$guestrole = $DB->get_record('role', array('shortname' => 'guest'));
role_change_permission($guestrole->id, context_system::instance(), 'auth/outage:viewinfo', CAP_PREVENT);
$this->setGuestUser();
}
/**
* Get an outage object.
*
* @return \auth_outage\local\outage
*/
protected function get_dummy_outage() {
$now = time();
return new outage([
'id' => 1,
'autostart' => false,
'warntime' => $now - 100,
'starttime' => $now + 100,
'stoptime' => $now + 200,
'title' => 'Title',
'description' => 'Description',
]);
}
/**
* Setup testcase.
*/

View File

@@ -26,6 +26,8 @@
use auth_outage\calendar\calendar;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* calendar_test test class.
*
@@ -37,7 +39,7 @@ use auth_outage\local\outage;
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_calendar_test extends advanced_testcase {
class calendar_test extends advanced_testcase {
/**
* @var outage|null The calendar entry owner.
*/
@@ -132,8 +134,8 @@ class auth_outage_calendar_test extends advanced_testcase {
]);
calendar::update($outage);
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
}
/**
@@ -144,8 +146,8 @@ class auth_outage_calendar_test extends advanced_testcase {
self::setAdminUser();
calendar::delete(1);
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
}
/**

View File

@@ -37,7 +37,7 @@ require_once(__DIR__.'/../base_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_outagedb_test extends auth_outage_base_testcase {
class outagedb_test extends auth_outage_base_testcase {
/**
* Creates an array of ids in from the given outages array.
* @param outage[] $outages An array of outages.
@@ -244,15 +244,6 @@ class auth_outage_outagedb_test extends auth_outage_base_testcase {
$activeid = self::saveoutage(false, $now, -2, 1, 2, 'An outage in warning period.');
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
$activeid = self::saveoutage(false, $now, -2, 0, 2, 'An outage starts now.');
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
self::saveoutage(false, $now, -2, 0, -1, 'Invalid outage.');
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
self::saveoutage(false, $now, -2, 0, 0, 'Invalid outage.');
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
self::saveoutage(false, $now, -1, 2, 3,
'Another outage in warning period, but ignored as it starts after the previous one.');
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
@@ -436,8 +427,8 @@ class auth_outage_outagedb_test extends auth_outage_base_testcase {
public function test_finish_now_notfound() {
$this->resetAfterTest(true);
outagedb::finish(1);
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
}
/**
@@ -458,8 +449,8 @@ class auth_outage_outagedb_test extends auth_outage_base_testcase {
self::assertTrue(!$outage->is_ongoing($time));
outagedb::finish($id, $time);
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
}
/**

View File

@@ -26,6 +26,8 @@
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* events_test tests class.
*
@@ -37,7 +39,7 @@ use auth_outage\local\outage;
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_events_test extends advanced_testcase {
class events_test extends advanced_testcase {
/**
* @var outage|null Outage used in the tests.
*/

View File

@@ -39,7 +39,7 @@ require_once(__DIR__.'/../base_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_forms_test extends auth_outage_base_testcase {
class forms_test extends auth_outage_base_testcase {
/**
* Create a delete form.
*/
@@ -146,8 +146,8 @@ class auth_outage_forms_test extends auth_outage_base_testcase {
$_POST['description'] = ['text' => 'The <b>description</b>.', 'format' => '2'];
$edit = new edit();
self::assertNull($edit->get_data());
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
}
/**

View File

@@ -40,7 +40,7 @@ require_once(__DIR__.'/base_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_installation_test extends auth_outage_base_testcase {
class installation_test extends auth_outage_base_testcase {
/**
* Checks if plugin cleans up data after uninstall.
*
@@ -71,7 +71,7 @@ class auth_outage_installation_test extends auth_outage_base_testcase {
$progress = new progress_trace_buffer(new text_progress_trace(), false);
core_plugin_manager::instance()->uninstall_plugin('auth_outage', $progress);
$progress->finished();
self::assertStringContainsString('++ Success ++', $progress->get_buffer());
self::assertContains('++ Success ++', $progress->get_buffer());
// Check ...
self::assertSame(0, $DB->count_records_select('event', "eventtype = 'auth_outage'", null),

View File

@@ -35,7 +35,7 @@ require_once(__DIR__.'/../../lib.php');
* @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_lib_test extends auth_outage_base_testcase {
class lib_test extends auth_outage_base_testcase {
/**
* Test this plugin gets climaintenance resource file.
*/

View File

@@ -37,7 +37,7 @@ require_once(__DIR__.'/cli_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_cli_test extends auth_outage_cli_testcase {
class cli_test extends auth_outage_cli_testcase {
/**
* Tests providing an unknown parameter.
*/
@@ -81,8 +81,8 @@ class auth_outage_cli_test extends auth_outage_cli_testcase {
$this->set_parameters(['-h']);
$cli = new create();
$output = $this->execute($cli);
self::assertStringContainsString('-h', $output);
self::assertStringContainsString('--help', $output);
self::assertContains('-h', $output);
self::assertContains('--help', $output);
}
/**

View File

@@ -39,7 +39,7 @@ require_once(__DIR__.'/cli_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_create_test extends auth_outage_cli_testcase {
class create_test extends auth_outage_cli_testcase {
/**
* Tests without any arguments.
*/
@@ -120,8 +120,8 @@ class auth_outage_create_test extends auth_outage_cli_testcase {
$this->set_parameters(['--help']);
$cli = new create();
$output = $this->execute($cli);
self::assertStringContainsString('Creates', $output);
self::assertStringContainsString('--help', $output);
self::assertContains('Creates', $output);
self::assertContains('--help', $output);
}
/**
@@ -157,7 +157,7 @@ class auth_outage_create_test extends auth_outage_cli_testcase {
$cli = new create();
$cli->set_referencetime($now);
$text = $this->execute($cli);
self::assertStringContainsString('created', $text);
self::assertContains('created', $text);
// Check creted outage.
list(, $id) = explode(':', $text);
$id = (int)$id;
@@ -221,7 +221,7 @@ class auth_outage_create_test extends auth_outage_cli_testcase {
'description' => 'Default Description',
]);
$text = $this->execute($cli);
self::assertStringContainsString('created', $text);
self::assertContains('created', $text);
// Check creted outage.
list(, $id) = explode(':', $text);
$id = (int)$id;
@@ -299,8 +299,8 @@ class auth_outage_create_test extends auth_outage_cli_testcase {
$cli = new create();
$cli->set_referencetime($now);
$text = $this->execute($cli);
self::assertStringContainsString('created', $text);
self::assertStringContainsString('started', $text);
self::assertContains('created', $text);
self::assertContains('started', $text);
}
/**

View File

@@ -39,7 +39,7 @@ require_once(__DIR__.'/cli_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_finish_test extends auth_outage_cli_testcase {
class finish_test extends auth_outage_cli_testcase {
/**
* Tests the constructor.
*/
@@ -72,8 +72,8 @@ class auth_outage_finish_test extends auth_outage_cli_testcase {
$this->set_parameters(['--help']);
$cli = new finish();
$text = $this->execute($cli);
self::assertStringContainsString('Finishes', $text);
self::assertStringContainsString('--help', $text);
self::assertContains('Finishes', $text);
self::assertContains('--help', $text);
}
/**

View File

@@ -39,7 +39,7 @@ require_once(__DIR__.'/cli_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_waitforit_test extends auth_outage_cli_testcase {
class waitforit_test extends auth_outage_cli_testcase {
/**
* Tests the constructor.
*/
@@ -78,8 +78,8 @@ class auth_outage_waitforit_test extends auth_outage_cli_testcase {
$this->set_parameters(['--help']);
$cli = new waitforit();
$text = $this->execute($cli);
self::assertStringContainsString('Waits', $text);
self::assertStringContainsString('--help', $text);
self::assertContains('Waits', $text);
self::assertContains('--help', $text);
}
/**
@@ -151,9 +151,9 @@ class auth_outage_waitforit_test extends auth_outage_cli_testcase {
$cli = new waitforit();
$cli->set_referencetime($now);
$output = $this->execute($cli);
self::assertStringContainsString('Verbose mode', $output);
self::assertStringContainsString('starting in 1 sec', $output);
self::assertStringContainsString('started', $output);
self::assertContains('Verbose mode', $output);
self::assertContains('starting in 1 sec', $output);
self::assertContains('started', $output);
}
/**
@@ -178,11 +178,11 @@ class auth_outage_waitforit_test extends auth_outage_cli_testcase {
return $now;
});
$output = $this->execute($cli);
self::assertStringContainsString("starting in 45", $output);
self::assertStringContainsString("sleep 30 second", $output);
self::assertStringContainsString("starting in 15", $output);
self::assertStringContainsString("sleep 15 second", $output);
self::assertStringContainsString("started!", $output);
self::assertContains("starting in 45", $output);
self::assertContains("sleep 30 second", $output);
self::assertContains("starting in 15", $output);
self::assertContains("sleep 15 second", $output);
self::assertContains("started!", $output);
}
/**

View File

@@ -37,13 +37,11 @@ require_once(__DIR__.'/../../base_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_infopagecontroller_test extends auth_outage_base_testcase {
class infopagecontroller_test extends auth_outage_base_testcase {
/**
* Tests the constructor.
*/
public function test_constructor() {
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
new infopage();
}
@@ -51,8 +49,6 @@ class auth_outage_infopagecontroller_test extends auth_outage_base_testcase {
* Tests the constructor with given parameters.
*/
public function test_constructor_withparams() {
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
$_GET = ['id' => 1, 'static' => 'true'];
new infopage();
}
@@ -61,10 +57,16 @@ class auth_outage_infopagecontroller_test extends auth_outage_base_testcase {
* Tests the constructor with different id and outage id.
*/
public function test_constructor_idmismatch() {
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
$outage = $this->get_dummy_outage();
$this->set_expected_exception('coding_exception', 'Provided id and outage->id do not match. (2/1)');
$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => time() - 60,
'starttime' => time(),
'stoptime' => time() + 60,
'title' => 'Title',
'description' => 'Description',
]);
$this->set_expected_exception('coding_exception');
new infopage(['id' => 2, 'outage' => $outage]);
}
@@ -72,82 +74,36 @@ class auth_outage_infopagecontroller_test extends auth_outage_base_testcase {
* Tests the constructor with an invalid outage.
*/
public function test_constructor_invalidoutage() {
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
$this->set_expected_exception('coding_exception', 'Provided outage is not a valid outage object. (My outage)');
$this->set_expected_exception('coding_exception');
new infopage(['outage' => 'My outage']);
}
/**
* We should have an exception because CLI cannot redirect.
*/
public function test_output_nonstatic_nooutage() {
$info = new infopage(['static' => false]);
$this->set_expected_exception('moodle_exception');
$info->output();
}
/**
* Checks the output of the info page.
*/
public function test_output() {
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
$outage = $this->get_dummy_outage();
$now = time();
$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $now - 100,
'starttime' => $now + 100,
'stoptime' => $now + 200,
'title' => 'Title',
'description' => 'Description',
]);
$info = new infopage(['outage' => $outage]);
$output = $info->get_output();
self::assertStringContainsString('auth_outage_info', $output);
}
/**
* Checks the output of the info page.
*/
public function test_output_without_permission() {
$this->revoke_info_page_permissions();
$this->assertFalse(has_capability('auth/outage:viewinfo', context_system::instance()));
$outage = $this->get_dummy_outage();
$info = new infopage(['outage' => $outage]);
$this->set_expected_exception('moodle_exception', 'Unsupported redirect detected, script execution terminated');
$output = $info->get_output();
}
/**
* Checks the output of the info page.
*/
public function test_output_without_permission_but_static() {
$this->revoke_info_page_permissions();
$this->assertFalse(has_capability('auth/outage:viewinfo', context_system::instance()));
$outage = $this->get_dummy_outage();
$info = new infopage(['outage' => $outage, 'static' => true]);
$output = $info->get_output();
self::assertStringContainsString('auth_outage_info', $output);
}
/**
* Checks the output of the info page.
*/
public function test_output_with_forcelogin() {
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
set_config('forcelogin', true);
$outage = $this->get_dummy_outage();
$info = new infopage(['outage' => $outage]);
$this->set_expected_exception('moodle_exception', 'Unsupported redirect detected, script execution terminated');
$info->get_output();
}
/**
* Checks the output of the info page.
*/
public function test_output_with_forcelogin_if_static() {
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
set_config('forcelogin', true);
$outage = $this->get_dummy_outage();
$info = new infopage(['outage' => $outage, 'static' => true]);
$output = $info->get_output();
self::assertStringContainsString('auth_outage_info', $output);
self::assertContains('auth_outage_info', $output);
}
/**
@@ -155,9 +111,6 @@ class auth_outage_infopagecontroller_test extends auth_outage_base_testcase {
*/
public function test_svgicons_is_true() {
global $CFG;
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
$CFG->svgicons = false;
new infopage();
self::assertTrue($CFG->svgicons);

View File

@@ -39,7 +39,7 @@ require_once(__DIR__.'/../../base_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase {
class maintenance_static_page_test extends auth_outage_base_testcase {
/**
* Test template file.
*/
@@ -90,7 +90,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
maintenance_static_page::create_from_html($html)->generate();
$generated = $this->generated_page_html($html);
self::assertStringNotContainsString('<script', $generated);
self::assertNotContains('<script', $generated);
}
/**
@@ -104,9 +104,9 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
'<body>Content<link rel="stylesheet" href="'.$externalcsslink.'"></body></html>';
$generated = $this->generated_page_html($html);
self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertStringNotContainsString($localcsslink, $generated);
self::assertStringContainsString($externalcsslink, $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertNotContains($localcsslink, $generated);
self::assertContains($externalcsslink, $generated);
}
/**
@@ -174,9 +174,9 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
'<body><img src="'.$localimglink.'">Content<img src="'.$externalimglink.'" /></body></html>';
$generated = $this->generated_page_html($html);
self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertStringNotContainsString($localimglink, $generated);
self::assertStringContainsString($externalimglink, $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertNotContains($localimglink, $generated);
self::assertContains($externalimglink, $generated);
}
/**
@@ -189,62 +189,8 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
'<body>Content</body></html>';
$generated = $this->generated_page_html($html);
self::assertStringNotContainsString($link, $generated);
self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=', $generated);
}
/**
* Data provider for test_update_inline_background_images
* @return array
*/
public function test_update_inline_background_images_provider() {
return [
// Empty string.
["", false],
// URLs that should be retrieved.
["color: #FF00FF; background: lightblue url(/pluginfile.php/1/theme_custom/banner/251298630/0001.png) no-repeat", true],
["background: lightblue url(https://www.example.com/moodle/pluginfile.php/1/theme_custom/banner/251298630/0001.png) no-repeat", true],
["background:url('https://www.example.com/moodle/pluginfile.php/1/theme_custom/banner/251298630/0001.png')", true],
["background-image : url( /pix/help.png);", true],
["background-image: url ('/pix/help.png')", true],
// URLs that should not be retrieved.
["background-image:url(data:image/gif;base64,R0lGODlhYADIAP=)", false],
["background-image:url('data:image/gif;base64,R0lGODlhYADIAP=')", false]
];
}
/**
* Tests update_inline_background_images() method to update the background images.
*
* @dataProvider test_update_inline_background_images_provider
* @param string $stylecontent Content of the style to test
* @param bool $rewrite Flag if URL should be rewritten
* @throws coding_exception
*/
public function test_update_inline_background_images($stylecontent, $rewrite) {
global $CFG;
$this->resetAfterTest(true);
$generator = new maintenance_static_page_generator(new DOMDocument(), new maintenance_static_page_io());
$html = '<!DOCTYPE html>\n'.
'<html><head><title>Title</title></head>'.
'<body><div style="'.$stylecontent.'">Content</div></body></html>';
// Temporarily disable debugging to prevent errors because file does not exist
$debuglevel = $CFG->debug;
$CFG->debug = '';
$generated = $this->generated_page_html($html);
// Restore debugging level
$CFG->debug = $debuglevel;
$matches = $generator->get_url_from_inline_style($stylecontent);
if ($rewrite) {
self::assertStringNotContainsString($matches[1], $generated);
self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertIsArray($matches);
} else {
self::assertStringContainsString($stylecontent, $generated);
}
self::assertNotContains($link, $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
}
/**
@@ -260,8 +206,8 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
$page->generate();
$generated = trim(file_get_contents($page->get_io()->get_template_file()));
self::assertStringNotContainsString($link, $generated);
self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=preview%2F', $generated);
self::assertNotContains($link, $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=preview%2F', $generated);
}
/**
@@ -297,12 +243,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
touch($file);
self::assertFileExists($file);
maintenance_static_page::create_from_outage(null)->generate();
// Backwards compatibility with older PHPUnit - use old assertFile method.
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist($file);
} else {
self::assertFileNotExists($file);
}
self::assertFileNotExists($file);
}
/**
@@ -362,7 +303,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
*/
public function test_get_url_for_file() {
$io = new maintenance_static_page_io();
self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png'));
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png'));
}
/**
@@ -406,8 +347,8 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
$found = maintenance_static_page_io::file_get_data(__DIR__.'/fixtures/invalidfile');
self::assertSame('', $found['contents']);
self::assertSame('unknown', $found['mime']);
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
}
/**
@@ -429,8 +370,8 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
set_config('remove_selectors', '.removeme', 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
self::assertNotContains('removeme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
@@ -444,8 +385,8 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
set_config('remove_selectors', '#removeme', 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
self::assertNotContains('removeme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
@@ -462,9 +403,9 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
set_config('remove_selectors', ".removeme\n.deleteme", 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('deleteme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
self::assertNotContains('removeme', $generated);
self::assertNotContains('deleteme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
@@ -481,9 +422,9 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
set_config('remove_selectors', " .removeme \n .deleteme ", 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('deleteme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
self::assertNotContains('removeme', $generated);
self::assertNotContains('deleteme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
@@ -500,9 +441,9 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
set_config('remove_selectors', "\n\n.removeme\n\n\n\n.deleteme\n\n", 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('deleteme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
self::assertNotContains('removeme', $generated);
self::assertNotContains('deleteme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
@@ -516,8 +457,8 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
set_config('remove_selectors', '#invalidid', 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertStringContainsString('removeme', $generated);
self::assertStringContainsString('Goodbye cruel world', $generated);
self::assertContains('removeme', $generated);
self::assertContains('Goodbye cruel world', $generated);
}
/**
@@ -531,7 +472,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
set_config('remove_selectors', '#invalidid', 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertStringContainsString('<meta http-equiv="refresh" content="300">', $generated);
self::assertContains('<meta http-equiv="refresh" content="300">', $generated);
}
/**
@@ -549,7 +490,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
$generated = trim(file_get_contents($page->get_io()->get_template_file()));
return $generated;
self::assertStringContainsString('<meta http-equiv="refresh" content="5">', $generated);
self::assertContains('<meta http-equiv="refresh" content="5">', $generated);
}
/**
@@ -588,7 +529,7 @@ class auth_outage_maintenance_static_page_test extends auth_outage_base_testcase
$generator = new maintenance_static_page_generator(new DOMDocument(), new maintenance_static_page_io());
$matches = $generator->get_urls_from_stylesheet($filecontent);
self::assertIsArray($matches);
self::assertInternalType('array', $matches);
self::assertCount(2, $matches);
self::assertCount($count, $matches[1]);
}

View File

@@ -36,7 +36,7 @@ require_once(__DIR__.'/../base_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_outage_test extends auth_outage_base_testcase {
class outage_test extends auth_outage_base_testcase {
/**
* Tests the constructor.
*/
@@ -280,11 +280,11 @@ class auth_outage_outage_test extends auth_outage_base_testcase {
'description' => 'Description {{start}} {{stop}} {{duration}}',
]);
$title = $outage->get_title();
self::assertStringNotContainsString('{', $title);
self::assertStringNotContainsString('}', $title);
self::assertNotContains('{', $title);
self::assertNotContains('}', $title);
$description = $outage->get_description();
self::assertStringNotContainsString('{', $description);
self::assertStringNotContainsString('}', $description);
self::assertNotContains('{', $description);
self::assertNotContains('}', $description);
}
/**

View File

@@ -41,7 +41,7 @@ require_once(__DIR__.'/../base_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_outagelib_test extends auth_outage_base_testcase {
class outagelib_test extends auth_outage_base_testcase {
/**
* Check if maintenance message is disabled as needed.
*/
@@ -62,8 +62,8 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
set_config('maintenance_message', 'A message.');
outagedb::save($outage);
self::assertFalse((bool)get_config('moodle', 'maintenance_message'));
self::assertCount(2, $this->getDebuggingMessages());
$this->resetDebugging();
self::assertCount(2, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
}
/**
@@ -99,14 +99,14 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
outagelib::reset_injectcalled();
// Get full header to avoid interactions with other single inject plugins.
$header1 = $OUTPUT->standard_top_of_body_html();
self::assertStringContainsString('<style>', $header1);
self::assertStringContainsString('<script>', $header1);
self::assertContains('<style>', $header1);
self::assertContains('<script>', $header1);
// Should not inject more than once.
$size = strlen($OUTPUT->standard_top_of_body_html());
self::assertSame($size, strlen($OUTPUT->standard_top_of_body_html()));
// Check styles aren't reinjected.
self::assertStringNotContainsString('<style>', $OUTPUT->standard_top_of_body_html());
self::assertNotContains('<style>', $OUTPUT->standard_top_of_body_html());
}
/**
@@ -116,8 +116,8 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
$_GET = ['auth_outage_break_code' => '1'];
outagelib::reset_injectcalled();
$header = outagelib::get_inject_code();
self::assertCount(2, $this->getDebuggingMessages());
$this->resetDebugging();
self::assertCount(2, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
}
/**
@@ -142,8 +142,8 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
outagelib::reset_injectcalled();
$header = outagelib::get_inject_code();
self::assertStringContainsString('<style>', $header);
self::assertStringContainsString('<script>', $header);
self::assertContains('<style>', $header);
self::assertContains('<script>', $header);
}
/**
@@ -216,10 +216,6 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
foreach ($keys as $k) {
self::assertSame($config->$k, $k.'_value', 'auth_outage');
}
set_config('allowedips_forced', 'allowedips_forced_value', 'auth_outage');
$config = outagelib::get_config();
self::assertSame($config->allowedips, "allowedips_value\nallowedips_forced_value", 'auth_outage');
}
/**
@@ -340,10 +336,8 @@ EOT;
/**
* Test create maintenance php code without age
*
* @dataProvider test_createmaintenancephpcode_withoutage_provider
*/
public function test_createmaintenancephpcode_withoutage($configkey) {
public function test_createmaintenancephpcode_withoutage() {
global $CFG;
$this->resetAfterTest(true);
@@ -386,7 +380,7 @@ EOT;
'stoptime' => 456,
]);
$file = $CFG->dataroot.'/climaintenance.php';
set_config($configkey, '127.0.0.1', 'auth_outage');
set_config('allowedips', '127.0.0.1', 'auth_outage');
outagelib::update_climaintenance_code($outage);
self::assertFileExists($file);
@@ -394,10 +388,6 @@ EOT;
self::assertSame($found, $expected);
}
public function test_createmaintenancephpcode_withoutage_provider(): array {
return [['allowedips'], ['allowedips_forced']];
}
/**
* Test create maintenance php code without IPs
*/
@@ -411,16 +401,10 @@ EOT;
]);
$file = $CFG->dataroot.'/climaintenance.php';
set_config('allowedips', '', 'auth_outage');
set_config('allowedips_forced', '', 'auth_outage');
touch($file);
outagelib::update_climaintenance_code($outage);
// Backwards compatibility with older PHPUnit - use old assertFile method.
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist($file);
} else {
self::assertFileNotExists($file);
}
self::assertFileNotExists($file);
}
/**
@@ -432,12 +416,7 @@ EOT;
touch($file);
outagelib::update_climaintenance_code(null);
// Backwards compatibility with older PHPUnit - use old assertFile method.
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist($file);
} else {
self::assertFileNotExists($file);
}
self::assertFileNotExists($file);
}
/**
@@ -464,7 +443,9 @@ EOT;
$this->create_outage();
// Change settings.
set_config('s_auth_outage_allowedips', '127', 'auth_outage');
admin_write_settings((object)[
's_auth_outage_allowedips' => '127',
]);
// The method outagelib::prepare_next_outage() should have been called from admin_write_settings().
foreach ([$CFG->dataroot.'/climaintenance.template.html', $CFG->dataroot.'/climaintenance.php'] as $file) {
@@ -482,7 +463,9 @@ EOT;
$this->create_outage();
// Change settings.
set_config('s_auth_outage_remove_selectors', '.something', 'auth_outage');
admin_write_settings((object)[
's_auth_outage_remove_selectors' => '.something',
]);
// The method outagelib::prepare_next_outage() should have been called from admin_write_settings().
foreach ([$CFG->dataroot.'/climaintenance.template.html', $CFG->dataroot.'/climaintenance.php'] as $file) {
@@ -513,12 +496,7 @@ EOT;
// The method outagelib::prepare_next_outage() should have been called by save().
self::assertFalse(get_config('moodle', 'maintenance_later'));
// This file should not exist even if the statement above fails as Moodle does not create it immediately but test anyway.
// Backwards compatibility with older PHPUnit - use old assertFile method.
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist($CFG->dataroot.'/climaintenance.html');
} else {
self::assertFileNotExists($CFG->dataroot.'/climaintenance.html');
}
self::assertFileNotExists($CFG->dataroot.'/climaintenance.html');
}
/**

View File

@@ -28,8 +28,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = "auth_outage";
$plugin->version = 2022051200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2022051200; // Human-readable release information.
$plugin->requires = 2017111309; // 2017111309 = T13, but this really requires 3.9 and higher.
$plugin->version = 2021032500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2021032500; // Human-readable release information.
$plugin->requires = 2017051500; // Requires 3.3 and higher.
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!
$plugin->supported = [39, 311]; // A range of branch numbers of supported moodle versions.

View File

@@ -56,8 +56,6 @@ var authOutageWarningBar = {
},
tickOngoing: function() {
const MINSECS = 60;
if (this.finished) {
return;
}
@@ -80,8 +78,13 @@ var authOutageWarningBar = {
xmlhttp.open("GET", this.checkfinishedurl, true);
xmlhttp.send();
// Checking if the site is back online every 4-6 minutes.
var sleepSeconds = 4 * MINSECS + (2 * MINSECS * Math.random());
var estimatedServerTime = this.servertime + (Date.now() - this.clienttime);
var sleepSeconds = this.stops - estimatedServerTime; // How long to sleep until it stops.
if (sleepSeconds <= 0) {
sleepSeconds = 5; // It should be back, keep checking every 5 seconds.
} else {
sleepSeconds = Math.min(sleepSeconds, (5 * 60)); // Check at least every 5 minutes.
}
setTimeout(function() {
$this.tickOngoing();