78 Commits

Author SHA1 Message Date
Sasha Anastasi
313a6e2044 replace deprecated strftime function for Moodle 4.2 2023-05-29 08:51:52 +12:00
Dan Marsden
5cebaf9227 Merge pull request #307 from sarahjcotton/moodle-41-fixes
Fix for Moodle 4.1 [#306]
2023-02-09 09:15:36 +13:00
Sarah Cotton
a8aa5c49c5 Version bump 2023-02-08 10:23:01 +00:00
Sarah Cotton
85bcca8d38 Update ci workflow and badge 2023-02-08 10:23:01 +00:00
Sarah Cotton
3b87330bb1 Fix for Moodle 4.1
The settings page is ignored on install so when the admin settings page
is next loaded, the default settings cannot be found and undefined offset
warnings are thrown.
2023-02-08 10:22:54 +00:00
Brendan Heywood
1627bced86 Merge pull request #311 from QihuiChan/logging-maint-mode
Add logging for maint mode and fix failed CI tests
2022-12-21 12:23:09 +11:00
Qihui Chan
89e2621bf6 Fix failed Github CI tests 2022-12-20 22:12:05 +10:00
Qihui Chan
9473db8c6e Modify unit tests to declare expected output 2022-12-20 16:58:57 +10:00
Qihui Chan
b9cbf015ac Add logging for maint mode config 2022-12-20 16:58:57 +10:00
Brendan Heywood
42d4744534 Merge pull request #309 from QihuiChan/Issue-308-patch
Issue#308 force autostart off when maint mode managed by CI
2022-12-20 15:53:25 +11:00
Qihui Chan
b95fb97af5 Issue#308 Freeze the autostart in form if it is set in admin level config 2022-12-20 14:48:48 +10:00
Brendan Heywood
bbde2f74d3 Merge pull request #310 from QihuiChan/update-doc
Update the maintenance description in QUICKGUIDE.md
2022-12-20 11:59:20 +11:00
Qihui Chan
0791b39744 Update the maintenance description in QUICKGUIDE.md 2022-12-16 17:57:06 +10:00
Matt Dawson
21fe888862 ISSUE304 - css change for warning box header and title (#305)
* ISSUE304 - css change for warning box header and title

* Issue304-css to hopefully override existing theme hacks

* Issue#304 - updated README file with additional scss and css code to fix issues with custom themes

Co-authored-by: Matt Dawson <mattd@catalyst-au.net>
2022-12-07 08:58:30 +11:00
Peterburnett
12f43447b7 Merge pull request #299 from catalyst/MOODLE_39_STABLE_ISSUE209
Issue#209 Remove as much db calls as possible in outage plugin
2022-07-26 14:21:45 +10:00
Qihui Chan
5465e5fe40 Issue#209 Remove db calls in get_active of outage 2022-07-25 11:13:25 +10:00
Dan Marsden
8eb86bce44 Merge pull request #302 from catalyst/MOODLE_39_STABLE_issue_301
clibase.php: replace hardcoded admin userid
2022-07-25 13:12:43 +12:00
Sasha Anastasi
fe18931334 clibase.php: replace hardcoded admin userid 2022-07-22 10:34:52 +12:00
Brendan Heywood
0344500671 Merge pull request #293 from catalyst/split-ip-settings
Issue #288: Split allowed IPs settings into two.
2022-04-28 13:38:06 +10:00
Jason den Dulk
1f08a44a1a Change builtinallowediplist_desc.
Move the new lang strings to be in alphabetical order.
2022-04-28 13:16:40 +10:00
Jason den Dulk
c64a33c345 Issue #288: Split allowed IPs settings into two.
Merge two settings when accessing config.
Bump version.
2022-04-28 09:47:58 +10:00
Brendan Heywood
afc96d347d Merge pull request #290 from catalyst/ci-workflow-alignment-for-MOODLE_39_STABLE
[#289] chore: ci usage alignment and cleanup
2022-03-24 19:38:46 +11:00
Kevin Pham
59fbdee57b [#289] chore: ci usage alignment and cleanup 2022-03-23 14:58:42 +11:00
Dan Marsden
2b554967d9 Merge pull request #285 from aneno-m-e/fix-deprecation-warnings
Update assertFileNotExists() to assertFileDoesNotExist()
2022-02-28 10:45:21 +13:00
Noemie Ariste
5bf0496c79 Update assertFileNotExists() to assertFileDoesNotExist() 2022-02-25 20:17:58 +13:00
golenkovm
015300d098 Slow down warning bar checkfinished calls (#280)
* Slow down warning bar checkfinished calls

* Fix coding style after review
2022-01-28 09:58:03 +11:00
Brendan Heywood
ddfb17f5f8 Update README.md 2022-01-17 17:19:13 +11:00
Anupama Dharmajan
a98029f41e Fix workflow status badge and bump version number 2022-01-14 12:46:32 +11:00
Anupama Thundiyil Dharmajan
6dc2227034 Merge pull request #277 from catalyst/MOODLE_39_STABLE-fix-unsupported-versions
Moodle 39 stable fix supported versions
2022-01-13 17:49:31 +11:00
Anupama Dharmajan
c628cd8218 Add plugin supported moodle branches and update readme file 2022-01-13 17:27:56 +11:00
Brendan Heywood
c47d102326 Merge pull request #273 from catalyst/MOODLE_39_STABLE-reusing-workflows
Add reusable workflows
2022-01-13 16:42:12 +11:00
Anupama Dharmajan
1f5927c394 Add reusable workflows 2022-01-13 15:38:29 +11:00
tuanngocnguyen
6e8aa6d007 Merge pull request #275 from SashaAnastasi/auth_outage_totara15_runtest_fixes_39_STABLE
Issue#271: Fix refactored phpunit_util causing unit test error
2021-12-29 13:01:46 +11:00
Sasha Anastasi
3181522f63 Issue#271: Fix refactored phpunit_util causing unit test error
substitute in platform-agnostic functions ->getDebuggingMessages and ->resetDebugging
2021-12-23 08:59:35 +13:00
Andrew Madden
690d90f3bc Merge pull request #264 from catalyst/issue263
Bypass permissions check when generating a static page to fix #263
2021-09-02 16:09:48 +10:00
Dmitrii Metelkin
94fc6fb540 Bypass permissions check when generating a static page to fix #263 2021-09-02 15:44:37 +10:00
Kevin Pham
43ff1f9301 Merge pull request #262 from catalyst/generation-time
Raised time limit for page generation
2021-07-28 10:30:08 +10:00
Peter Burnett
34a716226e Raised time limit for page generation 2021-07-28 10:09:00 +10:00
Dmitrii Metelkin
6af9317240 Fix ci issues (#260)
* Fix mariadb version

* Fix coding style

* Actually fix mariadb version
2021-07-22 12:38:27 +10:00
Dmitrii Metelkin
eea4029f57 Fix build status in readme for MOODLE_39_STABLE 2021-07-22 11:51:35 +10:00
Kevin Pham
f95fd64871 Merge pull request #258 from catalyst/issue253-MOODLE_39_STABLE
Rename test classes to fix #253
2021-07-06 13:19:03 +10:00
Dmitrii Metelkin
cf8c88aefc Rename test classes to fix #253 2021-07-06 12:51:47 +10:00
Brendan Heywood
c0fa33a559 Merge pull request #257 from catalyst/issue256_outage_view_info_cap
Closes #256 Add capability to control viewing outage info
2021-06-23 17:27:11 +10:00
Andrew Madden
7c9bb96f1a Closes #256 Add capability to control viewing outage info 2021-06-23 11:23:08 +10:00
Brendan Heywood
45987b9259 Merge pull request #255 from catalyst/MOODLE_39_STABLE-fix-234-inline-background-image
Fix #234 pick up images from inline style background image.
2021-05-31 14:55:04 +10:00
Kateryna Degtyariova
17463f0d3e Fix #234 pick up images from inline style background image. 2021-05-31 14:15:00 +10:00
Tomo
2aec03911a Merge pull request #252 from catalyst/cherry-pick-update_test_using_set_config
Replace admin_write_settings to set_config
2021-05-11 16:46:40 +10:00
Tomo Tsuyuki
a262467d58 Replace admin_write_settings to set_config 2021-05-11 16:29:55 +10:00
Dan Marsden
207223fc2d Merge pull request #250 from jcharaoui/fix-class-curl-not-found
Include filelib.php to fix class not found exception, fix #247
2021-05-06 10:22:40 +12:00
Dan Marsden
b40fb047e2 Bump requires version to T13. 2021-05-06 10:14:10 +12:00
Dan Marsden
4bda39434d update gitub workflow - 3.9 and higher branch. 2021-05-06 10:03:33 +12:00
Dan Marsden
50511d1e46 Merge remote-tracking branch 'origin/fixphpunit' into MOODLE_39_STABLE 2021-05-06 10:03:06 +12:00
Dan Marsden
baa7138a01 Update Readme with new branch naming. 2021-05-06 09:44:03 +12:00
Dan Marsden
802acbd26c PHPunit 9 fixes. 2021-05-05 14:09:09 +12:00
Gus Auwerda
9c2b529831 auth_outage: Use assertStringNotContainsString() for PHPUnit 9 compliance 2021-05-05 13:54:26 +12:00
Gus Auwerda
e1d7d2d3f4 auth_outage: Update function calls to conform to PHPUnit 9 deprecations 2021-05-05 13:53:50 +12:00
Dan Marsden
1f03af1968 Fix order of abstract/public - coding guideline failure. 2021-05-05 13:18:11 +12:00
Dan Marsden
b29e7e914b Fix node install. 2021-05-05 13:07:59 +12:00
Dan Marsden
6255ebb311 Revert "update github actions - fix node version."
This reverts commit 18d5864cac.
2021-05-05 13:03:05 +12:00
Dan Marsden
18d5864cac update github actions - fix node version. 2021-05-05 12:55:12 +12:00
Dan Marsden
0a34a368d6 add 3.10 and 3.11 tests to github actions. 2021-05-05 12:45:05 +12:00
Jerome Charaoui
84ad9759f4 Include filelib.php to fix class not found exception 2021-04-11 11:44:44 -04:00
Brendan Heywood
bfc3c2317b Merge pull request #246 from catalyst/issue245
Fix root URL path
2021-03-30 22:03:03 +11:00
Matt P
5fef56cb2f Merge pull request #223 from catalyst/issue222
Fix banner overlap
2021-03-25 13:29:59 +11:00
Mikhail Golenkov
c55b9271c4 Fix banner overlap 2021-03-25 13:20:51 +11:00
Mikhail Golenkov
77ce63e4f9 Fix root URL path 2021-03-18 15:50:39 +11:00
Matt Porritt
47154e545f fix unit test signature to be compatible with Moodle 3.10+ 2021-03-12 03:31:06 +00:00
Matt Porritt
2d59580d36 fix unit test signature to be compatible with Moodle 3.10+ 2021-03-12 03:29:55 +00:00
Brendan Heywood
49ea2a142e Merge pull request #242 from catalyst/issue241
Fix issue #241 hide warningbar under h5p-embed
2021-03-04 14:02:34 +11:00
Tomo Tsuyuki
a6bb7f4bc2 Fix #241 Do not render if layout are from some specific ones 2021-03-04 12:22:34 +11:00
Brendan Heywood
f40f52bdc3 Merge pull request #244 from catalyst/issue243
Partially fix #243: fix codingcheck error and disable behat test
2021-03-04 12:19:38 +11:00
Tomo Tsuyuki
07a8a41ad4 Partially fix #243: fix codingcheck error and disable behat test 2021-03-04 12:02:57 +11:00
Brendan Heywood
19bc18512d Merge pull request #238 from yao9394/master-fix-233-no-outage-check
Fix #233 Add no_outage check to allow checkfinished.php to be execpt …
2021-02-26 11:49:06 +11:00
John Yao
116467429e Fix issues for phpdoc check
Get rid of ci for moodle 37,38
2021-02-16 11:12:40 +11:00
John Yao
def6e997a9 add github actions and remove travis ci 2021-02-12 16:51:14 +11:00
John Yao
c53a629bc8 Fix #233 Add no_outage check to allow checkfinished.php to be execpt from the 503 maintenance logic 2021-02-12 09:38:57 +11:00
Scott Verbeek
8f7d38f355 Merge pull request #237 from catalyst/test-envbar-interact-fix
Fixed logic for sequenced calls of outage injection to central method
2021-02-05 13:47:03 +10:00
Peter Burnett
e58f7b73b3 Fixed logic for sequenced calls of outage injection to centralised method 2021-02-05 13:42:05 +10:00
60 changed files with 900 additions and 400 deletions

10
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,10 @@
# .github/workflows/ci.yml
name: ci
on: [push, pull_request]
jobs:
ci:
uses: catalyst/catalyst-moodle-workflows/.github/workflows/ci.yml@main
with:
disable_behat: true

21
.github/workflows/moodle-release.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
#
# 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,75 +0,0 @@
language: php
services:
- mysql
addons:
firefox: "47.0.1"
postgresql: "9.6"
apt:
packages:
- openjdk-8-jre
cache:
directories:
- $HOME/.composer/cache
- $HOME/.npm
php:
- 7.2
env:
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE NODEJS=8
- DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE NODEJS=8
- DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_39_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_39_STABLE
matrix:
include:
- php: 7.0
env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE
- php: 7.0
env: DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE NODEJS=8
- php: 7.2
env: DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
- php: 7.2
env: DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE
- php: 7.4
env: DB=pgsql MOODLE_BRANCH=MOODLE_39_STABLE
- php: 7.2
env: DB=mysqli MOODLE_BRANCH=MOODLE_39_STABLE
before_install:
- export MOODLE_VERSION=$(echo "$MOODLE_BRANCH" | cut -d'_' -f 2)
- phpenv config-rm xdebug.ini
- if [ "$NODEJS" = 8 ]; then
nvm install 8.9;
nvm use 8.9;
else
nvm install 14.0.0;
nvm use 14.0.0;
fi
- cd ../..
- composer selfupdate
- composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3;
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
install:
- moodle-plugin-ci install
script:
- moodle-plugin-ci phplint
- moodle-plugin-ci phpcpd
- moodle-plugin-ci phpmd
- moodle-plugin-ci codechecker
- moodle-plugin-ci validate
- moodle-plugin-ci savepoints
- moodle-plugin-ci mustache
- moodle-plugin-ci grunt
- moodle-plugin-ci phpunit
# Behat tests are failing due to issue:
# https://github.com/blackboard-open-source/moodle-plugin-ci/issues/70
# Commenting it out until the issue is fixed.
# - moodle-plugin-ci behat

View File

@@ -59,6 +59,9 @@ Basic Usage
_Anyone who tries to use Moodle now will receive a maintenance message._
**Note:** If the outage starts with the option `Auto start maintenance mode` checked, the maint mode won't exit automatically.
It will need to be disabled through command line.
1) Perform the maintenance activities.
At this point it is safe to perform the required maintenance as no one can use the system, not even admins.

View File

@@ -1,6 +1,4 @@
<a href="https://travis-ci.org/catalyst/moodle-auth_outage">
<img src="https://travis-ci.org/catalyst/moodle-auth_outage.svg?branch=master">
</a>
![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/catalyst/moodle-auth_outage/ci.yml?branch=MOODLE_39_STABLE)
# Moodle Outage manager plugin
* [Version Support](#version-support)
@@ -26,10 +24,7 @@ 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.
<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">
![image](https://user-images.githubusercontent.com/187449/149717343-1d2c5237-dbc6-4d2a-a08c-2bdb343e87d2.png)
Moodle Requirements
-------------------
@@ -42,12 +37,12 @@ need to manually add one extra plugin, please check:
Branches
--------
| 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+ | master | 7.0+ |
| Totara 11+ | master | 7.0+ |
| 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+ |
Screenshots
-----------
@@ -105,6 +100,48 @@ This can be found at:
Custom Theme Additional SCSS
-------------------
Custom themes generally do not have the same `$navbar-height` variable set to 80px (MOODLE), therefore custom themes will not calculate the change in navbar height with page elements that calculate the navbar total height.
Add the following SCSS For Moodle 3.11+
```
body.auth_outage {
#page-wrapper {
#nav-drawer {
top: $navbar-height + 100px;
height: calc(100% - (#{$navbar-height} + 100px));
}
#page {
margin-top: $navbar-height + 100px;
}
}
[data-region=right-hand-drawer].drawer {
top: $navbar-height + 100px;
height: calc(100% - (#{$navbar-height} + 100px));
}
}
```
Totara is a little different with version 13+ and no variables are used to set the `totaraNav` height
Add the following CSS For Totara 13+
```
.totaraNav {
margin-top: 100px;
}
.local_envbar .totaraNav {
margin-top: 50px;
}
body.auth_outage #page {
margin-top: 0;
}
```
How to use
----------

View File

@@ -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

View File

@@ -30,7 +30,9 @@
*/
// This call is required by Moodle, but this script should have been called by config.php anyway.
// @codingStandardsIgnoreStart
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.
if (!isset($CFG->dataroot)) {
@@ -71,7 +73,7 @@ if (!empty($_SERVER['REQUEST_URI'])) {
$rooturl = parse_url($CFG->wwwroot);
$path = '';
if (array_key_exists('path', $rooturl) && !empty($rooturl['path'])) {
$path = $rooturl['url'];
$path = $rooturl['path'];
}
$url = $path.'/auth/outage/info.php';
$outageinfo = strpos($_SERVER['REQUEST_URI'], $url) === 0 ? true : false;
@@ -79,7 +81,8 @@ if (!empty($_SERVER['REQUEST_URI'])) {
$allowed = !file_exists($CFG->dataroot.'/climaintenance.php') // Not in maintenance mode.
|| (defined('ABORT_AFTER_CONFIG') && ABORT_AFTER_CONFIG) // Only config requested.
|| (defined('CLI_SCRIPT') && CLI_SCRIPT) // Allow CLI scripts.
|| $outageinfo; // Allow outage info requests.
|| $outageinfo // Allow outage info requests.
|| (defined('NO_AUTH_OUTAGE') && NO_AUTH_OUTAGE); // Allow any page should not be blocked by maintenance mode.
if (!$allowed) {
// Call the climaintenance.php which will check for allowed IPs.
$CFG->dirroot = dirname(dirname(dirname(__FILE__))); // It is not defined yet but the script below needs it.

View File

@@ -26,7 +26,10 @@
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');

View File

@@ -211,21 +211,20 @@ class outagedb {
throw new coding_exception('$time must be null or a positive int.', $time);
}
$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
);
// Get cached outage, or null.
$outageinfo = get_config('moodle', 'auth_outage_active_outage');
// 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));
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;
}
/**

View File

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

View File

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

View File

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

View File

@@ -147,7 +147,7 @@ class edit extends moodleform {
* @throws coding_exception
*/
public function set_data($outage) {
global $OUTPUT;
global $OUTPUT, $CFG;
$mform = $this->_form;
// Cannot change method signature, check type.
@@ -162,6 +162,15 @@ class edit extends moodleform {
'description' => ['text' => $outage->description, 'format' => '1'],
]);
// If the default_autostart is configured in config, then force autostart to be the default value.
if (array_key_exists('auth_outage', $CFG->forced_plugin_settings)
&& array_key_exists('default_autostart', $CFG->forced_plugin_settings['auth_outage'])) {
$this->_form->setDefaults([
'autostart' => $CFG->forced_plugin_settings['auth_outage']['default_autostart']
]);
$mform->freeze('autostart');
}
if (!empty($outage->id) && $outage->autostart && $outage->starttime < time() && $outage->stoptime > time()) {
$warning = $mform->getElement('warningreenablemaintenancemode');
$warning->setValue($OUTPUT->notification(get_string('warningreenablemaintenancemode', 'auth_outage'),

View File

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

View File

@@ -29,8 +29,6 @@ use auth_outage\local\outagelib;
use coding_exception;
use core\session\manager;
defined('MOODLE_INTERNAL') || die();
/**
* clibase class.
*
@@ -102,38 +100,29 @@ abstract class clibase {
$this->time = $time;
}
/**
* Gets the reference time for creating outages.
*/
public function get_referencetime()
{
return $this->time;
}
/**
* Generates all options (parameters) available for the CLI command.
* @return mixed[] Options.
*/
public abstract function generate_options();
abstract public function generate_options();
/**
* Generate all short forms for the available options.
* @return string[] Short form options.
*/
public abstract function generate_shortcuts();
abstract public function generate_shortcuts();
/**
* Executes the CLI script.
*/
public abstract function execute();
abstract public function execute();
/**
* Change session to admin user.
*/
protected function become_admin_user() {
global $DB;
$user = $DB->get_record('user', ['id' => 2]);
$user = get_admin();
unset($user->description);
unset($user->access);
unset($user->preference);

View File

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

View File

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

View File

@@ -28,8 +28,6 @@ namespace auth_outage\local\cli;
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* waitforit class.
*
@@ -131,7 +129,7 @@ class waitforit extends clibase {
return;
}
$time = strftime('%F %T %Z');
$time = \core_date::strftime('%F %T %Z');
printf("[%s] %s\n", $time, $message);
}

View File

@@ -32,8 +32,6 @@ use coding_exception;
use context_system;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* infopage class.
*
@@ -48,6 +46,11 @@ 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).
@@ -62,11 +65,13 @@ 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);
}
@@ -93,7 +98,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;
@@ -102,6 +106,10 @@ 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());
@@ -144,5 +152,6 @@ class infopage {
}
$this->outage = $params['outage'];
$this->static = $params['static'];
}
}

View File

@@ -29,8 +29,6 @@ use auth_outage\local\outage;
use coding_exception;
use DOMDocument;
defined('MOODLE_INTERNAL') || die();
/**
* maintenance_static_page class.
*
@@ -61,7 +59,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&id='.$outage->id);
$CFG->wwwroot.'/auth/outage/info.php?auth_outage_hide_warning=1&static=1&id='.$outage->id);
$html = $data['contents'];
}
@@ -122,6 +120,7 @@ class maintenance_static_page {
}
/**
* Gets generator io.
* @return maintenance_static_page_io
*/
public function get_io() {

View File

@@ -27,13 +27,12 @@ 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.
*
@@ -43,6 +42,15 @@ defined('MOODLE_INTERNAL') || die();
* @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;
@@ -75,6 +83,10 @@ 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();
@@ -83,6 +95,7 @@ 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) == '') {
@@ -95,6 +108,7 @@ class maintenance_static_page_generator {
}
/**
* Gets maintenance_static_page_io.
* @return maintenance_static_page_io
*/
public function get_io() {
@@ -149,6 +163,18 @@ 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.
*
@@ -217,6 +243,31 @@ 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.
*/
@@ -252,7 +303,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 +321,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 +337,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 +352,7 @@ class maintenance_static_page_generator {
}
/**
* Gets refresh time.
* @return int
*/
public function get_refresh_time() {
@@ -305,6 +360,7 @@ class maintenance_static_page_generator {
}
/**
* Sets refresh time.
* @param int $refreshtime
*/
public function set_refresh_time($refreshtime) {

View File

@@ -31,8 +31,6 @@ use finfo;
use invalid_parameter_exception;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* maintenance_static_page_io class.
*
@@ -46,7 +44,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 +80,7 @@ class maintenance_static_page_io {
protected $preview = false;
/**
* Sets preview
* @param boolean $preview
*/
public function set_preview($preview) {

View File

@@ -28,8 +28,6 @@ namespace auth_outage\local;
use coding_exception;
use stdClass;
defined('MOODLE_INTERNAL') || die();
/**
* outage class.
*
@@ -299,4 +297,12 @@ 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

@@ -49,8 +49,10 @@ require_once(__DIR__.'/../../lib.php');
*/
class outagelib {
/** Outage start. */
const OUTAGE_START = '<!-- OUTAGESTART -->';
/** Outage end. */
const OUTAGE_END = '<!-- OUTAGEEND -->';
/**
@@ -58,7 +60,14 @@ class outagelib {
*/
private static $injectcalled = false;
/**
* Fetches page.
* @param string $file file to be fetched
*/
public static function fetch_page($file) {
global $CFG;
require_once($CFG->libdir . '/filelib.php');
$curl = new curl();
$contents = $curl->get($file);
$info = $curl->get_info();
@@ -79,6 +88,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) {
@@ -158,7 +168,12 @@ class outagelib {
}
}
return (object)array_merge(self::get_config_defaults(), $config);
$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;
}
/**
@@ -195,6 +210,10 @@ 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)) {
@@ -202,6 +221,9 @@ class outagelib {
}
}
/**
* Checks if wwwroot accessible.
*/
private static function check_wwwroot_accessible() {
global $CFG;
$result = self::fetch_page($CFG->wwwroot);
@@ -224,6 +246,7 @@ class outagelib {
unset_config('maintenance_message');
}
set_config('maintenance_later', $outage->starttime);
self::maintenance_config_log($outage);
}
}
@@ -359,16 +382,14 @@ 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;
$message = [];
if (trim(self::get_config()->allowedips) != '' && (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded)) {
if (trim(self::get_config()->allowedips) != ''
&& (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded)) {
$message[] = get_string('configurationwarning', 'auth_outage');
}
@@ -394,4 +415,18 @@ EOT;
return $message;
}
/**
* Logging for maintenance mode configuration.
*
* @param outage|null $outage Outage or null if no scheduled outage.
*/
private static function maintenance_config_log(outage $outage) {
mtrace(get_string('logformaintmodeconfig', 'auth_outage'));
$timezone = ' (Timezone ' . \core_date::get_server_timezone_object()->getName() . ')';
mtrace('... updated at ' . date('H:i:s'));
$time = date("Y-m-d H:i:s", $outage->starttime);
mtrace("... enable maintenance mode at $time $timezone");
mtrace(get_string('logformaintmodeconfigcomplete', 'auth_outage'));
}
}

View File

@@ -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();

View File

@@ -33,8 +33,6 @@ use html_writer;
use moodle_url;
use plugin_renderer_base;
defined('MOODLE_INTERNAL') || die();
/**
* auth_outage_renderer class.
*
@@ -66,6 +64,13 @@ class renderer extends plugin_renderer_base {
* @return string The rendered view code.
*/
public function render_view($view, $viewbag = []) {
// Do not render if the request are from some layouts.
$excludelayout = ['embedded', 'popup', 'secure', 'maintenance'];
if (in_array($this->page->pagelayout, $excludelayout)) {
return '';
}
ob_start();
$this->output_view($view, $viewbag);
$html = ob_get_contents();

View File

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

View File

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

37
db/access.php Normal file
View File

@@ -0,0 +1,37 @@
<?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,14 +24,11 @@
*/
use auth_outage\local\controllers\maintenance_static_page;
defined('MOODLE_INTERNAL') || die();
/**
* Auth Outage plugin uninstall code.
* @return bool result
* @throws moodle_exception
*/
function xmldb_auth_outage_uninstall() {
global $DB;

View File

@@ -22,7 +22,6 @@
* @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

@@ -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.
@@ -74,7 +73,9 @@ function auth_outage_bootstrap_callback() {
exit(0);
}
// @codingStandardsIgnoreStart
require_once(__DIR__.'/../../config.php');
// @codingStandardsIgnoreEnd
// We should never reach here if config.php and auth/outage/bootstrap.php intercepted it correctly.
// If config.php did not execute the callback function we can use the debugging function here.

View File

@@ -25,7 +25,9 @@
use auth_outage\local\controllers\infopage;
// @codingStandardsIgnoreStart
require_once(__DIR__.'/../../config.php');
// @codingStandardsIgnoreEnd
$info = new infopage();
$info->output();

View File

@@ -26,6 +26,8 @@
$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.';
@@ -100,10 +102,13 @@ $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.';
$string['allowedipsnoconfig'] = 'Your config.php does not have the extra setup to allow blocking via IP.<br />Please refer to our <a href="https://github.com/catalyst/moodle-auth_outage#installation" target="_blank">README.md</a> file for more information.';
$string['logformaintmodeconfig'] = 'Update maintenance mode configuration.';
$string['logformaintmodeconfigcomplete'] = 'Updating maintenance mode configuration complete.';
$string['menusettings'] = 'Settings';
$string['menumanage'] = 'Manage outages';
$string['messageoutagebackonline'] = 'We are back online!';
@@ -112,6 +117,7 @@ $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,8 +25,6 @@
use auth_outage\local\outagelib;
defined('MOODLE_INTERNAL') || die;
/**
* Used for adminlib::set_updatedcallback which requires a string that resolves to a function.
*
@@ -41,7 +39,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) {
@@ -86,4 +84,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

@@ -28,7 +28,9 @@
use auth_outage\dml\outagedb;
use auth_outage\local\controllers\maintenance_static_page;
// @codingStandardsIgnoreStart
require_once(__DIR__.'/../../config.php');
// @codingStandardsIgnoreEnd
$id = optional_param('id', null, PARAM_INT);
$outage = is_null($id) ? outagedb::get_next_starting() : outagedb::get_by_id($id);
if (is_null($outage)) {

View File

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

View File

@@ -26,25 +26,30 @@
* @var admin_settingpage $settings
* @var bootstrap_renderer $OUTPUT
* @var admin_root $ADMIN
* @var moodle_page $PAGE
*/
use auth_outage\local\outagelib;
defined('MOODLE_INTERNAL') || die;
if ($hassiteconfig && is_enabled_auth('outage')) {
if ($hassiteconfig) {
$defaults = outagelib::get_config_defaults();
$settings->visiblename = get_string('menusettings', 'auth_outage');
$description = outagelib::generate_plugin_configuration_warning();
$settings->add(new admin_setting_heading(
'defaults',
get_string('settingssectiondefaults', 'auth_outage'),
get_string('settingssectiondefaultsdescription', 'auth_outage')));
get_string('settingssectiondefaultsdescription', 'auth_outage') . $description
));
$settings->add(new admin_setting_configcheckbox(
'auth_outage/default_autostart',
get_string('defaultoutageautostart', 'auth_outage'),
get_string('defaultoutageautostartdescription', 'auth_outage'),
$defaults['default_autostart']
));
$settings->add(new admin_setting_configduration(
'auth_outage/default_warning_duration',
get_string('defaultwarningduration', 'auth_outage'),
@@ -96,20 +101,23 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
// Create 'Allowed IPs' settings.
$allowedips = outagelib::get_config()->allowedips;
$description = outagelib::generate_plugin_configuration_warning();
if (trim($allowedips) == '') {
$message = 'allowedipsempty';
$type = 'notifymessage';
} else if (remoteip_in_list($allowedips)) {
$message = 'allowedipshasmyip';
$type = 'notifysuccess';
} else {
$message = 'allowedipshasntmyip';
$type = 'notifyerror';
if (remoteip_in_list($allowedips)) {
$message = 'allowedipshasmyip';
$type = 'notifysuccess';
} else {
$message = 'allowedipshasntmyip';
$type = 'notifyerror';
}
};
$description .= $OUTPUT->notification(get_string($message, 'auth_outage', ['ip' => getremoteaddr()]), $type);
$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>';
$description .= '<p>'.get_string('ipblockersyntax', 'admin').'</p>';
$iplist = new admin_setting_configiplist(
'auth_outage/allowedips',
get_string('allowediplist', 'admin'),
@@ -119,6 +127,14 @@ 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',
@@ -140,7 +156,7 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
new admin_externalpage(
'auth_outage_manage',
get_string('menumanage', 'auth_outage'),
new moodle_url($CFG->wwwroot.'/auth/outage/manage.php')
new moodle_url($CFG->wwwroot . '/auth/outage/manage.php')
)
);
}

View File

@@ -39,7 +39,6 @@ require_once(__DIR__.'/../../../../lib/behat/behat_base.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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() {
@@ -321,7 +322,7 @@ class behat_auth_outage extends behat_base {
}
if ($seconds >= 0) {
$seconds++; // Give one extra second for things to happen.
$this->getSession()->wait($seconds * 1000, false);
$this->getSession()->wait($seconds * 1000);
}
}

View File

@@ -0,0 +1,48 @@
@auth @auth_outage @javascript @_file_upload @_switch_iframe
Feature: Disable warning bar in embedded layout
In order alert users about an outage
As any user
I need to view the warning bar, but not in embedded layout
Background:
Given the authentication plugin "outage" is enabled
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "activities" exist:
| activity | name | intro | introformat | course | content | contentformat | idnumber |
| page | PageName1 | PageDesc1 | 1 | C1 | H5Ptest | 1 | 1 |
And the "displayh5p" filter is "on"
Scenario: Disable warning bar in embedded h5p in book activity
Given I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I add a "File" to section "1"
And I set the following fields to these values:
| Name | ipsumFile |
And I upload "h5p/tests/fixtures/ipsums.h5p" file to "Select files" filemanager
And I press "Save and return to course"
And I follow "PageName1"
And I navigate to "Edit settings" in current page administration
And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element"
And I click on "Browse repositories..." "button" in the "Insert H5P" "dialogue"
And I click on "Server files" "link" in the ".fp-repo-area" "css_element"
And I click on "ipsumFile (File)" "link"
And I click on "ipsums.h5p" "link"
And I click on "Select this file" "button"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
And I click on "Save and display" "button"
When there is the following outage:
| warnbefore | startsin |
| 0 | 0 |
And I reload the page
Then I should see "Back online at" in the warning bar
And I should not see "Lorum ipsum"
# Switch to iframe created by filter
And I switch to "h5p-iframe" class iframe
And I should not see the warning bar
# Switch to iframe created by embed.php page
And I switch to "h5p-iframe" class iframe
And I should see "Lorum ipsum"
And I should not see the warning bar

View File

@@ -32,8 +32,7 @@
*/
use auth_outage\dml\outagedb;
defined('MOODLE_INTERNAL') || die();
use auth_outage\local\outage;
/**
* auth_outage_base_testcase class.
@@ -42,7 +41,6 @@ defined('MOODLE_INTERNAL') || die();
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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,14 +64,51 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
}
}
public function setUp() {
/**
* 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.
*/
public function setUp(): void {
global $CFG;
parent::setUp();
$this->resetAfterTest(true);
}
public function tearDown() {
/**
* Tear down to restore the original DB reference.
*/
public function tearDown(): void {
global $DB;
foreach (outagedb::get_all() as $i => $outage) {

View File

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

View File

@@ -36,9 +36,8 @@ require_once(__DIR__.'/../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_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.
@@ -79,7 +78,7 @@ class outagedb_test extends auth_outage_base_testcase {
/**
* Ensure DB tests run as admin.
*/
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->setAdminUser();
}
@@ -95,8 +94,6 @@ class outagedb_test extends auth_outage_base_testcase {
$outage = $this->createoutage(2);
$outage->id = $id;
outagedb::save($outage);
// Ensure an id was given.
self::assertNotEquals(0, $id);
}
/**
@@ -247,6 +244,15 @@ class 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.');
@@ -430,8 +436,8 @@ class outagedb_test extends auth_outage_base_testcase {
public function test_finish_now_notfound() {
$this->resetAfterTest(true);
outagedb::finish(1);
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
}
/**
@@ -452,8 +458,8 @@ class outagedb_test extends auth_outage_base_testcase {
self::assertTrue(!$outage->is_ongoing($time));
outagedb::finish($id, $time);
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
}
/**

View File

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

View File

@@ -39,21 +39,19 @@ require_once(__DIR__.'/../base_testcase.php');
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class forms_test extends auth_outage_base_testcase {
class auth_outage_forms_test extends auth_outage_base_testcase {
/**
* Create a delete form.
*/
public function test_delete() {
$form = new delete();
self::assertNotNull($form);
new delete();
}
/**
* Create a finish form.
*/
public function test_finish() {
$form = new finish();
self::assertNotNull($form);
new finish();
}
/**
@@ -148,8 +146,8 @@ class 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, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
}
/**
@@ -166,7 +164,6 @@ class forms_test extends auth_outage_base_testcase {
]);
$edit = new edit();
$edit->set_data($outage);
self::assertTrue(true, "set_data did not return any error");
}
/**
@@ -201,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;

View File

@@ -39,9 +39,8 @@ require_once(__DIR__.'/base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_installation_test extends auth_outage_base_testcase {
/**
* Checks if plugin cleans up data after uninstall.
*
@@ -64,7 +63,11 @@ class installation_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
\auth_outage\dml\outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
self::assertSame(1, $DB->count_records_select('event', "eventtype = 'auth_outage'", null));
// Uninstall plugin.
@@ -72,7 +75,7 @@ class 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::assertContains('++ Success ++', $progress->get_buffer());
self::assertStringContainsString('++ Success ++', $progress->get_buffer());
// Check ...
self::assertSame(0, $DB->count_records_select('event', "eventtype = 'auth_outage'", null),

View File

@@ -34,9 +34,11 @@ require_once(__DIR__.'/../../lib.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_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;

View File

@@ -36,9 +36,8 @@ require_once(__DIR__.'/cli_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_cli_test extends auth_outage_cli_testcase {
/**
* Tests providing an unknown parameter.
*/
@@ -61,12 +60,8 @@ class cli_test extends auth_outage_cli_testcase {
*/
public function test_setreferencetime() {
$cli = new create(['start' => 0]);
$cli->set_referencetime(1);
self::assertEquals(1, $cli->get_referencetime());
$cli->set_referencetime(60 * 60 * 24 * 7);
self::assertEquals(604800, $cli->get_referencetime());
}
/**
@@ -86,8 +81,8 @@ class cli_test extends auth_outage_cli_testcase {
$this->set_parameters(['-h']);
$cli = new create();
$output = $this->execute($cli);
self::assertContains('-h', $output);
self::assertContains('--help', $output);
self::assertStringContainsString('-h', $output);
self::assertStringContainsString('--help', $output);
}
/**

View File

@@ -35,13 +35,12 @@ require_once(__DIR__.'/../../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
/**
* Always enable the auth outage plugin, resets after test and set no parameters.
*/
public function setUp() {
public function setUp(): void {
global $CFG;
// PHPUnit does not load config.php file.

View File

@@ -38,9 +38,8 @@ require_once(__DIR__.'/cli_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_create_test extends auth_outage_cli_testcase {
/**
* Tests without any arguments.
*/
@@ -121,8 +120,8 @@ class create_test extends auth_outage_cli_testcase {
$this->set_parameters(['--help']);
$cli = new create();
$output = $this->execute($cli);
self::assertContains('Creates', $output);
self::assertContains('--help', $output);
self::assertStringContainsString('Creates', $output);
self::assertStringContainsString('--help', $output);
}
/**
@@ -158,10 +157,10 @@ class create_test extends auth_outage_cli_testcase {
$cli = new create();
$cli->set_referencetime($now);
$text = $this->execute($cli);
self::assertContains('created', $text);
self::assertStringContainsString('created', $text);
// Check creted outage.
list(, $id) = explode(':', $text);
$id = (int)$id;
$clioutput = explode(':', $text);
$id = (int)end($clioutput);
$outage = outagedb::get_by_id($id);
self::assertSame($now, $outage->starttime);
self::assertSame(10, $outage->get_warning_duration());
@@ -222,10 +221,10 @@ class create_test extends auth_outage_cli_testcase {
'description' => 'Default Description',
]);
$text = $this->execute($cli);
self::assertContains('created', $text);
self::assertStringContainsString('created', $text);
// Check creted outage.
list(, $id) = explode(':', $text);
$id = (int)$id;
$clioutput = explode(':', $text);
$id = (int)end($clioutput);
$outage = outagedb::get_by_id($id);
self::assertSame($now + 50, $outage->starttime, 'Wrong starttime.');
self::assertSame($outage->starttime - 100, $outage->warntime, 'Wrong warntime.');
@@ -300,8 +299,8 @@ class create_test extends auth_outage_cli_testcase {
$cli = new create();
$cli->set_referencetime($now);
$text = $this->execute($cli);
self::assertContains('created', $text);
self::assertContains('started', $text);
self::assertStringContainsString('created', $text);
self::assertStringContainsString('started', $text);
}
/**

View File

@@ -38,9 +38,8 @@ require_once(__DIR__.'/cli_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_finish_test extends auth_outage_cli_testcase {
/**
* Tests the constructor.
*/
@@ -73,8 +72,8 @@ class finish_test extends auth_outage_cli_testcase {
$this->set_parameters(['--help']);
$cli = new finish();
$text = $this->execute($cli);
self::assertContains('Finishes', $text);
self::assertContains('--help', $text);
self::assertStringContainsString('Finishes', $text);
self::assertStringContainsString('--help', $text);
}
/**
@@ -121,16 +120,10 @@ class finish_test extends auth_outage_cli_testcase {
'title' => 'Title',
'description' => 'Description',
]));
$outage = outagedb::get_by_id($id);
self::assertNull($outage->finished, "outage should not be finished");
$this->set_parameters(['-id='.$id]);
$cli = new finish();
$cli->set_referencetime($now);
$this->execute($cli);
$outage = outagedb::get_by_id($id);
self::assertNotNull($outage->finished, "outage should be finished");
}
/**

View File

@@ -38,9 +38,8 @@ require_once(__DIR__.'/cli_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_waitforit_test extends auth_outage_cli_testcase {
/**
* Tests the constructor.
*/
@@ -79,8 +78,8 @@ class waitforit_test extends auth_outage_cli_testcase {
$this->set_parameters(['--help']);
$cli = new waitforit();
$text = $this->execute($cli);
self::assertContains('Waits', $text);
self::assertContains('--help', $text);
self::assertStringContainsString('Waits', $text);
self::assertStringContainsString('--help', $text);
}
/**
@@ -152,9 +151,9 @@ class waitforit_test extends auth_outage_cli_testcase {
$cli = new waitforit();
$cli->set_referencetime($now);
$output = $this->execute($cli);
self::assertContains('Verbose mode', $output);
self::assertContains('starting in 1 sec', $output);
self::assertContains('started', $output);
self::assertStringContainsString('Verbose mode', $output);
self::assertStringContainsString('starting in 1 sec', $output);
self::assertStringContainsString('started', $output);
}
/**
@@ -179,11 +178,11 @@ class waitforit_test extends auth_outage_cli_testcase {
return $now;
});
$output = $this->execute($cli);
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);
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);
}
/**

View File

@@ -36,40 +36,35 @@ require_once(__DIR__.'/../../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_infopagecontroller_test extends auth_outage_base_testcase {
/**
* Tests the constructor.
*/
public function test_constructor() {
$infopage = new infopage();
self::assertNotNull($infopage);
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
new infopage();
}
/**
* 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'];
$infopage = new infopage();
self::assertNotNull($infopage);
new infopage();
}
/**
* Tests the constructor with different id and outage id.
*/
public function test_constructor_idmismatch() {
$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');
$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)');
new infopage(['id' => 2, 'outage' => $outage]);
}
@@ -77,36 +72,82 @@ class infopagecontroller_test extends auth_outage_base_testcase {
* Tests the constructor with an invalid outage.
*/
public function test_constructor_invalidoutage() {
$this->set_expected_exception('coding_exception');
new infopage(['outage' => 'My outage']);
}
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
/**
* 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();
$this->set_expected_exception('coding_exception', 'Provided outage is not a valid outage object. (My outage)');
new infopage(['outage' => 'My outage']);
}
/**
* Checks the output of the info page.
*/
public function test_output() {
$now = time();
$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $now - 100,
'starttime' => $now + 100,
'stoptime' => $now + 200,
'title' => 'Title',
'description' => 'Description',
]);
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
$outage = $this->get_dummy_outage();
$info = new infopage(['outage' => $outage]);
$output = $info->get_output();
self::assertContains('auth_outage_info', $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);
}
/**
@@ -114,6 +155,9 @@ class 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

@@ -38,10 +38,11 @@ require_once(__DIR__.'/../../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_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('<html></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('<html></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() {
self::markTestSkipped("How to fetch a page from PHPUnit environment?");
// How to fetch a page from PHPUnit environment?
}
/**
* Test create from HTML.
*/
public function test_createfromhtml() {
$html = "<!DOCTYPE html>\n<html><head><title>Title</title></head><body>Content</body></html>";
$expected = "<!DOCTYPE html>\n<html><head><title>Title</title><meta http-equiv=\"refresh\" content=\"300\">".
@@ -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 = "<!DOCTYPE html>\n".
'<html><head><script type="text/javascript" src="http://xyz"></script><title>Title</title></head>'.
@@ -77,9 +90,12 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
maintenance_static_page::create_from_html($html)->generate();
$generated = $this->generated_page_html($html);
self::assertNotContains('<script', $generated);
self::assertStringNotContainsString('<script', $generated);
}
/**
* Test remove script tags.
*/
public function test_updatelinkstylesheet() {
$localcsslink = $this->get_fixture_path('simple.css');
$externalcsslink = 'http://google.com/coolstuff.css';
@@ -88,11 +104,14 @@ class 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::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertNotContains($localcsslink, $generated);
self::assertContains($externalcsslink, $generated);
self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertStringNotContainsString($localcsslink, $generated);
self::assertStringContainsString($externalcsslink, $generated);
}
/**
* Test update link style sheet urls.
*/
public function test_updatelinkstylesheet_urls() {
$localcsslink = $this->get_fixture_path('withurls.css');
$html = "<!DOCTYPE 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 = "<!DOCTYPE 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 = "<!DOCTYPE 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';
@@ -146,11 +174,14 @@ class 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::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertNotContains($localimglink, $generated);
self::assertContains($externalimglink, $generated);
self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=', $generated);
self::assertStringNotContainsString($localimglink, $generated);
self::assertStringContainsString($externalimglink, $generated);
}
/**
* Test update favicon to file.php style link.
*/
public function test_updatelinkfavicon() {
$link = $this->get_fixture_path('catalyst.png');
$html = "<!DOCTYPE html>\n".
@@ -158,10 +189,67 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
'<body>Content</body></html>';
$generated = $this->generated_page_html($html);
self::assertNotContains($link, $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
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);
}
}
/**
* Test update preview path to file.php style link.
*/
public function test_previewpath() {
$link = $this->get_fixture_path('catalyst.png');
$html = "<!DOCTYPE html>\n".
@@ -172,8 +260,8 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
$page->generate();
$generated = trim(file_get_contents($page->get_io()->get_template_file()));
self::assertNotContains($link, $generated);
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=preview%2F', $generated);
self::assertStringNotContainsString($link, $generated);
self::assertStringContainsString('www.example.com/moodle/auth/outage/file.php?file=preview%2F', $generated);
}
/**
@@ -209,9 +297,17 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
touch($file);
self::assertFileExists($file);
maintenance_static_page::create_from_outage(null)->generate();
self::assertFileNotExists($file);
// Backwards compatibility with older PHPUnit - use old assertFile method.
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist($file);
} else {
self::assertFileNotExists($file);
}
}
/**
* Tests created file.
*/
public function test_createdfile() {
global $CFG;
@@ -235,7 +331,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 +339,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'));
self::assertStringContainsString('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 +380,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,19 +399,28 @@ 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']);
self::assertSame('unknown', $found['mime']);
self::assertCount(1, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
self::assertCount(1, $this->getDebuggingMessages());
$this->resetDebugging();
}
/**
* 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 = "<!DOCTYPE html>\n".
@@ -306,10 +429,13 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
set_config('remove_selectors', '.removeme', 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertNotContains('removeme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
}
/**
* Test remove css selector id.
*/
public function test_remove_css_selector_id() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -318,10 +444,13 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
set_config('remove_selectors', '#removeme', 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertNotContains('removeme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
}
/**
* Test remove css selector with multi lines.
*/
public function test_remove_css_selector_with_multiline() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -333,11 +462,14 @@ class 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::assertNotContains('removeme', $generated);
self::assertNotContains('deleteme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('deleteme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
}
/**
* Test remove css selector needs trim.
*/
public function test_remove_css_selector_needing_trim() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -349,11 +481,14 @@ class 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::assertNotContains('removeme', $generated);
self::assertNotContains('deleteme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('deleteme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
}
/**
* Test remove css selector with empty line.
*/
public function test_remove_css_selector_with_empty_line() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -365,11 +500,14 @@ class 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::assertNotContains('removeme', $generated);
self::assertNotContains('deleteme', $generated);
self::assertNotContains('Goodbye cruel world', $generated);
self::assertStringNotContainsString('removeme', $generated);
self::assertStringNotContainsString('deleteme', $generated);
self::assertStringNotContainsString('Goodbye cruel world', $generated);
}
/**
* Test remove css selector with invalid id.
*/
public function test_remove_css_selector_with_invalid_id() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -378,10 +516,13 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
set_config('remove_selectors', '#invalidid', 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertContains('removeme', $generated);
self::assertContains('Goodbye cruel world', $generated);
self::assertStringContainsString('removeme', $generated);
self::assertStringContainsString('Goodbye cruel world', $generated);
}
/**
* Test meta refresh 5 minutes.
*/
public function test_meta_refresh_5minutes() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -390,9 +531,12 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
set_config('remove_selectors', '#invalidid', 'auth_outage');
$generated = $this->generated_page_html($html);
self::assertContains('<meta http-equiv="refresh" content="300">', $generated);
self::assertStringContainsString('<meta http-equiv="refresh" content="300">', $generated);
}
/**
* Test meta refresh maximum 5 minutes.
*/
public function test_meta_refresh_maximum_5seconds() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -403,15 +547,16 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
$page->set_max_refresh_time(5);
$page->generate();
$generated = trim(file_get_contents($page->get_io()->get_template_file()));
return $generated;
self::assertContains('<meta http-equiv="refresh" content="5">', $generated);
self::assertStringContainsString('<meta http-equiv="refresh" content="5">', $generated);
}
/**
* Data provider for test_get_urls_from_stylesheet
* @return array
*/
public function get_urls_from_stylesheet_provider() {
public function test_get_urls_from_stylesheet_provider() {
return [
// Empty string.
["", 0],
@@ -433,7 +578,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
/**
* Tests get_urls_from_stylesheet() method to get all appropriate URLS from the file.
*
* @dataProvider get_urls_from_stylesheet_provider
* @dataProvider test_get_urls_from_stylesheet_provider
* @param string $filecontent Content of the file
* @param int $count Expected quantity of found URLs
* @throws coding_exception
@@ -443,7 +588,7 @@ class 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::assertInternalType('array', $matches);
self::assertIsArray($matches);
self::assertCount(2, $matches);
self::assertCount($count, $matches[1]);
}

View File

@@ -35,9 +35,8 @@ require_once(__DIR__.'/../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_outage_test extends auth_outage_base_testcase {
/**
* Tests the constructor.
*/
@@ -281,11 +280,11 @@ class outage_test extends auth_outage_base_testcase {
'description' => 'Description {{start}} {{stop}} {{duration}}',
]);
$title = $outage->get_title();
self::assertNotContains('{', $title);
self::assertNotContains('}', $title);
self::assertStringNotContainsString('{', $title);
self::assertStringNotContainsString('}', $title);
$description = $outage->get_description();
self::assertNotContains('{', $description);
self::assertNotContains('}', $description);
self::assertStringNotContainsString('{', $description);
self::assertStringNotContainsString('}', $description);
}
/**

View File

@@ -40,9 +40,8 @@ require_once(__DIR__.'/../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @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 {
class auth_outage_outagelib_test extends auth_outage_base_testcase {
/**
* Check if maintenance message is disabled as needed.
*/
@@ -61,10 +60,14 @@ class outagelib_test extends auth_outage_base_testcase {
]);
set_config('maintenance_message', 'A message.');
ob_start();
outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
self::assertFalse((bool)get_config('moodle', 'maintenance_message'));
self::assertCount(2, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
self::assertCount(2, $this->getDebuggingMessages());
$this->resetDebugging();
}
/**
@@ -95,16 +98,23 @@ class outagelib_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
outagelib::reset_injectcalled();
$header1 = outagelib::get_inject_code();
self::assertContains('<style>', $header1);
self::assertContains('<script>', $header1);
// 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);
// 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());
}
/**
@@ -114,8 +124,8 @@ class outagelib_test extends auth_outage_base_testcase {
$_GET = ['auth_outage_break_code' => '1'];
outagelib::reset_injectcalled();
$header = outagelib::get_inject_code();
self::assertCount(2, phpunit_util::get_debugging_messages());
phpunit_util::reset_debugging();
self::assertCount(2, $this->getDebuggingMessages());
$this->resetDebugging();
}
/**
@@ -134,14 +144,18 @@ class outagelib_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
$_GET = ['auth_outage_preview' => (string)$outage->id];
outagelib::reset_injectcalled();
$header = outagelib::get_inject_code();
self::assertContains('<style>', $header);
self::assertContains('<script>', $header);
self::assertStringContainsString('<style>', $header);
self::assertStringContainsString('<script>', $header);
}
/**
@@ -173,8 +187,11 @@ class outagelib_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
$_GET = ['auth_outage_preview' => (string)$outage->id, 'auth_outage_delta' => '500'];
outagelib::reset_injectcalled();
$header = outagelib::get_inject_code();
@@ -187,8 +204,7 @@ class outagelib_test extends auth_outage_base_testcase {
*/
public function test_inject_noactive() {
outagelib::reset_injectcalled();
$code = outagelib::get_inject_code();
self::assertNull($code);
outagelib::get_inject_code();
}
/**
@@ -215,6 +231,10 @@ class 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');
}
/**
@@ -277,7 +297,11 @@ class outagelib_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
// Pretend we are there...
$_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test.
@@ -289,6 +313,9 @@ class outagelib_test extends auth_outage_base_testcase {
self::assertEmpty($header);
}
/**
* Test create maintenance php code
*/
public function test_createmaintenancephpcode() {
$expected = <<<'EOT'
<?php
@@ -330,7 +357,13 @@ EOT;
self::assertSame($expected, $found);
}
public function test_createmaintenancephpcode_withoutage() {
/**
* Test create maintenance php code without age
*
* @param string $configkey The key of the config.
* @dataProvider test_createmaintenancephpcode_withoutage_provider
*/
public function test_createmaintenancephpcode_withoutage($configkey) {
global $CFG;
$this->resetAfterTest(true);
@@ -373,7 +406,7 @@ EOT;
'stoptime' => 456,
]);
$file = $CFG->dataroot.'/climaintenance.php';
set_config('allowedips', '127.0.0.1', 'auth_outage');
set_config($configkey, '127.0.0.1', 'auth_outage');
outagelib::update_climaintenance_code($outage);
self::assertFileExists($file);
@@ -381,6 +414,13 @@ EOT;
self::assertSame($found, $expected);
}
public function test_createmaintenancephpcode_withoutage_provider(): array {
return [['allowedips'], ['allowedips_forced']];
}
/**
* Test create maintenance php code without IPs
*/
public function test_createmaintenancephpcode_withoutips() {
global $CFG;
$this->resetAfterTest(true);
@@ -391,19 +431,33 @@ EOT;
]);
$file = $CFG->dataroot.'/climaintenance.php';
set_config('allowedips', '', 'auth_outage');
set_config('allowedips_forced', '', 'auth_outage');
touch($file);
outagelib::update_climaintenance_code($outage);
self::assertFileNotExists($file);
// Backwards compatibility with older PHPUnit - use old assertFile method.
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist($file);
} else {
self::assertFileNotExists($file);
}
}
/**
* Test create maintenance php code without outage
*/
public function test_createmaintenancephpcode_withoutoutage() {
global $CFG;
$file = $CFG->dataroot.'/climaintenance.php';
touch($file);
outagelib::update_climaintenance_code(null);
self::assertFileNotExists($file);
// Backwards compatibility with older PHPUnit - use old assertFile method.
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist($file);
} else {
self::assertFileNotExists($file);
}
}
/**
@@ -430,9 +484,7 @@ EOT;
$this->create_outage();
// Change settings.
admin_write_settings((object)[
's_auth_outage_allowedips' => '127',
]);
set_config('s_auth_outage_allowedips', '127', 'auth_outage');
// 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) {
@@ -450,9 +502,7 @@ EOT;
$this->create_outage();
// Change settings.
admin_write_settings((object)[
's_auth_outage_remove_selectors' => '.something',
]);
set_config('s_auth_outage_remove_selectors', '.something', 'auth_outage');
// 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) {
@@ -483,7 +533,12 @@ 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.
self::assertFileNotExists($CFG->dataroot.'/climaintenance.html');
// 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');
}
}
/**
@@ -503,8 +558,11 @@ EOT;
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
// Pretend we are there...
$_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test.
$_SERVER['SCRIPT_NAME'] = '/admin/settings.php';
@@ -515,6 +573,9 @@ EOT;
self::assertNotEmpty($header);
}
/**
* Creates outage for tests.
*/
private function create_outage() {
$this->resetAfterTest(true);
self::setAdminUser();

View File

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

View File

@@ -12,12 +12,21 @@ If you need to make changes here, remember to update your settings inside Moodle
padding: 0;
position: fixed;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
top: 0;
transition: background 3s ease-out;
width: 100%;
z-index: 9999;
}
#auth_outage_warningbar_box .auth_outage_warningbar_center {
/* fix to prevent existing theme hacks to fix issue */
margin-top: 0;
position: static;
}
#auth_outage_warningbar_box.auth_outage_warning_period {
background:
repeating-linear-gradient(
@@ -66,16 +75,10 @@ If you need to make changes here, remember to update your settings inside Moodle
background-color: #090;
}
.auth_outage_warningbar_center {
margin-top: -35px;
position: relative;
top: 50%;
}
#auth_outage_warningbar_message {
font-size: 200%;
font-weight: bold;
margin: 10px 0;
margin: 0;
}
a.auth_outage_warningbar_box_title {
@@ -87,6 +90,7 @@ a.auth_outage_warningbar_box_finish {
border: 1px solid black;
border-radius: 5px;
color: darkgray;
white-space: nowrap;
font-weight: bold;
margin-left: 10px;
padding-left: 5px;
@@ -99,14 +103,36 @@ a.auth_outage_warningbar_box_finish:hover {
background-color: black;
}
.auth_outage_warningbar_spacer {
height: 80px;
}
body.auth_outage #nav-drawer {
top: 150px;
}
body.auth_outage nav.fixed-top.navbar {
top: 100px;
}
}
body.auth_outage #page {
margin-top: 150px;
}
body.auth_outage.path-mod-assign [data-region="grading-navigation-panel"] {
top: 100px;
}
body.auth_outage.path-mod-assign [data-region="grade-panel"] {
top: 185px;
}
body.auth_outage .layout.fullscreen {
top: 150px;
}
body.auth_outage .modal-dialog {
margin: calc(150px + 1.75rem) auto;
}
@media (max-width: 767px) {
#auth_outage_warningbar_message {
font-size: 120%;
}
}

View File

@@ -56,6 +56,8 @@ var authOutageWarningBar = {
},
tickOngoing: function() {
const MINSECS = 60;
if (this.finished) {
return;
}
@@ -78,13 +80,8 @@ var authOutageWarningBar = {
xmlhttp.open("GET", this.checkfinishedurl, true);
xmlhttp.send();
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.
}
// Checking if the site is back online every 4-6 minutes.
var sleepSeconds = 4 * MINSECS + (2 * MINSECS * Math.random());
setTimeout(function() {
$this.tickOngoing();

View File

@@ -74,8 +74,6 @@ if (!$viewbag['static']) {
</div>
</div>
<div class="auth_outage_warningbar_spacer">&nbsp;</div>
<?php if (!$viewbag['static']): ?>
<script>
document.body.className += ' auth_outage';