mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
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 …
This commit is contained in:
134
.github/workflows/ci.yml
vendored
Normal file
134
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
name: Moodle plugin CI for master
|
||||
|
||||
# Controls when the action will run. Triggers the workflow on push or pull request
|
||||
# events but only for the master branch
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
citest:
|
||||
name: CI test
|
||||
runs-on: 'ubuntu-latest'
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres
|
||||
env:
|
||||
POSTGRES_USER: 'postgres'
|
||||
POSTGRES_HOST_AUTH_METHOD: 'trust'
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 3
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
||||
mariadb:
|
||||
image: mariadb
|
||||
env:
|
||||
MYSQL_USER: 'root'
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
|
||||
ports:
|
||||
- 3306:3306
|
||||
options: >-
|
||||
--health-cmd="mysqladmin ping"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 3
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
database: ['pgsql', 'mariadb']
|
||||
moodle-branch: ['MOODLE_39_STABLE']
|
||||
node: ['14.15.1']
|
||||
php: ['7.2', '7.3']
|
||||
include:
|
||||
- {moodle-branch: 'MOODLE_35_STABLE', php: '7.1', node: '14.15.1', database: 'mariadb'}
|
||||
- {moodle-branch: 'MOODLE_35_STABLE', php: '7.2', node: '14.15.1', database: 'mariadb'}
|
||||
- {moodle-branch: 'MOODLE_39_STABLE', php: '7.4', node: '14.15.1', database: 'mariadb'}
|
||||
- {moodle-branch: 'MOODLE_39_STABLE', php: '7.4', node: '14.15.1', database: 'pgsql'}
|
||||
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: plugin
|
||||
|
||||
- name: Install node ${{ matrix.node }}
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
|
||||
- name: Setup PHP ${{ matrix.php }}
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: pgsql, zip, gd, xmlrpc, soap
|
||||
coverage: none
|
||||
|
||||
- name: Initialise moodle-plugin-ci
|
||||
run: |
|
||||
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
|
||||
# Add dirs to $PATH
|
||||
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
|
||||
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
|
||||
# PHPUnit depends on en_AU.UTF-8 locale
|
||||
sudo locale-gen en_AU.UTF-8
|
||||
- name: Install Moodle
|
||||
run: |
|
||||
mkdir ~/.npm-global
|
||||
npm config set prefix '~/.npm-global'
|
||||
export PATH=~/.npm-global/bin:$PATH
|
||||
source ~/.profile
|
||||
moodle-plugin-ci install -vvv --plugin ./plugin --db-host=127.0.0.1
|
||||
env:
|
||||
DB: ${{ matrix.database }}
|
||||
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
|
||||
|
||||
- name: Run phplint
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phplint
|
||||
|
||||
- name: Run phpcpd
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phpcpd || true
|
||||
|
||||
- name: Run phpmd
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phpmd
|
||||
|
||||
- name: Run codechecker
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci codechecker
|
||||
|
||||
- name: Run validate
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci validate
|
||||
|
||||
- name: Run savepoints
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci savepoints
|
||||
|
||||
- name: Run mustache
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phpcpd
|
||||
|
||||
- name: Run grunt
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci grunt
|
||||
|
||||
- name: Run phpdoc
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phpdoc
|
||||
|
||||
- name: Run phpunit
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci phpunit
|
||||
|
||||
- name: Run behat
|
||||
if: ${{ always() }}
|
||||
run: moodle-plugin-ci behat --profile chrome
|
||||
75
.travis.yml
75
.travis.yml
@@ -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
|
||||
1
auth.php
1
auth.php
@@ -58,7 +58,6 @@ class auth_plugin_outage extends auth_plugin_base {
|
||||
/**
|
||||
* Always returns false (password wrong or user does not exist).
|
||||
*
|
||||
* @inheritdoc PHPMD will not warn about unused parameters if overriding.
|
||||
* @param string $username Not used in this plugin.
|
||||
* @param string $password Not used in this plugin.
|
||||
* @return bool False
|
||||
|
||||
@@ -79,7 +79,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.
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -93,7 +93,6 @@ class infopage {
|
||||
/**
|
||||
* Generates and outputs the HTML for the info page.
|
||||
* @uses redirect
|
||||
* @SuppressWarnings(PHPMD.UnusedLocalVariable) $viewbag is used inside 'require'.
|
||||
*/
|
||||
public function output() {
|
||||
global $PAGE, $CFG, $OUTPUT;
|
||||
|
||||
@@ -122,6 +122,7 @@ class maintenance_static_page {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets generator io.
|
||||
* @return maintenance_static_page_io
|
||||
*/
|
||||
public function get_io() {
|
||||
|
||||
@@ -95,6 +95,7 @@ class maintenance_static_page_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets maintenance_static_page_io.
|
||||
* @return maintenance_static_page_io
|
||||
*/
|
||||
public function get_io() {
|
||||
@@ -252,7 +253,7 @@ class maintenance_static_page_generator {
|
||||
/**
|
||||
* Fetches all elements based on the given selector.
|
||||
*
|
||||
* @param $selector
|
||||
* @param string $selector element selector
|
||||
*
|
||||
* @return DOMElement[]
|
||||
*/
|
||||
@@ -270,7 +271,7 @@ class maintenance_static_page_generator {
|
||||
/**
|
||||
* Fetch all elements which contains the given class.
|
||||
*
|
||||
* @param $class
|
||||
* @param string $class element class
|
||||
*
|
||||
* @return DOMElement[]
|
||||
*/
|
||||
@@ -286,6 +287,9 @@ class maintenance_static_page_generator {
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds meta refresh to head element.
|
||||
*/
|
||||
private function add_meta_refresh() {
|
||||
$meta = $this->dom->createElement('meta');
|
||||
$meta->setAttribute('http-equiv', 'refresh');
|
||||
@@ -298,6 +302,7 @@ class maintenance_static_page_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets refresh time.
|
||||
* @return int
|
||||
*/
|
||||
public function get_refresh_time() {
|
||||
@@ -305,6 +310,7 @@ class maintenance_static_page_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets refresh time.
|
||||
* @param int $refreshtime
|
||||
*/
|
||||
public function set_refresh_time($refreshtime) {
|
||||
|
||||
@@ -46,7 +46,7 @@ class maintenance_static_page_io {
|
||||
* Checks if the given string starts with "http://" or "https://".
|
||||
* Also checks for "//" at the start of image, which setting_file_url still uses.
|
||||
*
|
||||
* @param $url
|
||||
* @param string $url url string for check
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_url($url) {
|
||||
@@ -82,6 +82,7 @@ class maintenance_static_page_io {
|
||||
protected $preview = false;
|
||||
|
||||
/**
|
||||
* Sets preview
|
||||
* @param boolean $preview
|
||||
*/
|
||||
public function set_preview($preview) {
|
||||
|
||||
@@ -49,8 +49,10 @@ require_once(__DIR__.'/../../lib.php');
|
||||
*/
|
||||
class outagelib {
|
||||
|
||||
/** Outage start. */
|
||||
const OUTAGE_START = '<!-- OUTAGESTART -->';
|
||||
|
||||
/** Outage end. */
|
||||
const OUTAGE_END = '<!-- OUTAGEEND -->';
|
||||
|
||||
/**
|
||||
@@ -58,6 +60,10 @@ class outagelib {
|
||||
*/
|
||||
private static $injectcalled = false;
|
||||
|
||||
/**
|
||||
* Fetches page.
|
||||
* @param string $file file to be fetched
|
||||
*/
|
||||
public static function fetch_page($file) {
|
||||
$curl = new curl();
|
||||
$contents = $curl->get($file);
|
||||
@@ -79,6 +85,7 @@ class outagelib {
|
||||
|
||||
/**
|
||||
* Given a time, usually now, when is the next outage window?
|
||||
* @param int $time time for next window
|
||||
*/
|
||||
public static function get_next_window($time = null) {
|
||||
|
||||
@@ -202,6 +209,9 @@ class outagelib {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if wwwroot accessible.
|
||||
*/
|
||||
private static function check_wwwroot_accessible() {
|
||||
global $CFG;
|
||||
$result = self::fetch_page($CFG->wwwroot);
|
||||
@@ -359,9 +369,6 @@ EOT;
|
||||
* Generates a warning message in case the plugin is not active and configured.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @internal stdClass $CFG
|
||||
* @internal bootstrap_renderer $OUTPUT
|
||||
*/
|
||||
public static function generate_plugin_configuration_warning() {
|
||||
global $CFG, $OUTPUT, $PAGE;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -31,7 +31,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @return bool result
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
|
||||
function xmldb_auth_outage_uninstall() {
|
||||
global $DB;
|
||||
|
||||
|
||||
1
file.php
1
file.php
@@ -57,7 +57,6 @@ header('Accept-Ranges: none');
|
||||
|
||||
/**
|
||||
* Callback used in bootstrap.
|
||||
* @SupressWarnings(PHPMD)
|
||||
*/
|
||||
function auth_outage_bootstrap_callback() {
|
||||
// Not using classes as classloader has not been initialized yet. Keep it minimalist.
|
||||
|
||||
2
lib.php
2
lib.php
@@ -41,7 +41,7 @@ function auth_outage_outagelib_prepare_next_outage() {
|
||||
*
|
||||
* To keep it minimalist it was not added to the outagelib.php class.
|
||||
*
|
||||
* @param $file string Filename to fetch from sitedata
|
||||
* @param string $file Filename to fetch from sitedata
|
||||
* @return string|null Full path to the sitedata file or null if file is not valid.
|
||||
*/
|
||||
function auth_outage_get_climaintenance_resource_file($file) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -42,7 +42,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,6 +65,9 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup testcase.
|
||||
*/
|
||||
public function setUp() {
|
||||
global $CFG;
|
||||
|
||||
@@ -73,6 +75,9 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
|
||||
$this->resetAfterTest(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down to restore the original DB reference.
|
||||
*/
|
||||
public function tearDown() {
|
||||
global $DB;
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ 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 {
|
||||
/**
|
||||
|
||||
@@ -198,6 +198,10 @@ class forms_test extends auth_outage_base_testcase {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip tests for moodle below 30.
|
||||
* @param string $reason reason to be filled
|
||||
*/
|
||||
private function skip_because_moodle_is_below_30($reason = '') {
|
||||
global $CFG;
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ 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 {
|
||||
/**
|
||||
|
||||
@@ -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 {
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ 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 {
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,6 @@ 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 {
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,6 @@ 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 {
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,6 @@ 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 {
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,6 @@ 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 {
|
||||
/**
|
||||
|
||||
@@ -36,7 +36,6 @@ 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 {
|
||||
/**
|
||||
|
||||
@@ -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 {
|
||||
/**
|
||||
* 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() {
|
||||
// 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>'.
|
||||
@@ -80,6 +93,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertNotContains('<script', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test remove script tags.
|
||||
*/
|
||||
public function test_updatelinkstylesheet() {
|
||||
$localcsslink = $this->get_fixture_path('simple.css');
|
||||
$externalcsslink = 'http://google.com/coolstuff.css';
|
||||
@@ -93,6 +109,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertContains($externalcsslink, $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update link style sheet urls.
|
||||
*/
|
||||
public function test_updatelinkstylesheet_urls() {
|
||||
$localcsslink = $this->get_fixture_path('withurls.css');
|
||||
$html = "<!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';
|
||||
@@ -151,6 +179,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertContains($externalimglink, $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update favicon to file.php style link.
|
||||
*/
|
||||
public function test_updatelinkfavicon() {
|
||||
$link = $this->get_fixture_path('catalyst.png');
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
@@ -162,6 +193,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update preview path to file.php style link.
|
||||
*/
|
||||
public function test_previewpath() {
|
||||
$link = $this->get_fixture_path('catalyst.png');
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
@@ -212,6 +246,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertFileNotExists($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests created file.
|
||||
*/
|
||||
public function test_createdfile() {
|
||||
global $CFG;
|
||||
|
||||
@@ -235,7 +272,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
/**
|
||||
* Gets a fixture file for this test case.
|
||||
*
|
||||
* @param $file
|
||||
* @param string $file file name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -243,23 +280,35 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
return (string)new moodle_url('/auth/outage/tests/phpunit/local/controllers/fixtures/'.$file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test saving empty string for template file.
|
||||
*/
|
||||
public function test_invalid_string_saving_template_empty() {
|
||||
$io = new maintenance_static_page_io();
|
||||
$this->set_expected_exception('coding_exception');
|
||||
$io->save_template_file('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test saving non string for template file.
|
||||
*/
|
||||
public function test_invalid_string_saving_template_nostring() {
|
||||
$io = new maintenance_static_page_io();
|
||||
$this->set_expected_exception('coding_exception');
|
||||
$io->save_template_file(50);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get url for file.
|
||||
*/
|
||||
public function test_get_url_for_file() {
|
||||
$io = new maintenance_static_page_io();
|
||||
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of url data provider and true or false.
|
||||
*/
|
||||
public function is_url_dataprovider() {
|
||||
return [
|
||||
[true, 'http://catalyst.net.nz'],
|
||||
@@ -272,12 +321,18 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if it is url
|
||||
* @dataProvider is_url_dataprovider
|
||||
* @param string $result expected result
|
||||
* @param string $url url to be checked
|
||||
*/
|
||||
public function test_is_url($result, $url) {
|
||||
self::assertEquals($result, maintenance_static_page_io::is_url($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test file get_data.
|
||||
*/
|
||||
public function test_file_get_data() {
|
||||
$file = __DIR__.'/fixtures/catalyst.png';
|
||||
$found = maintenance_static_page_io::file_get_data($file);
|
||||
@@ -285,6 +340,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertSame('image/png', $found['mime']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid file get_data.
|
||||
*/
|
||||
public function test_file_get_data_invalidfile() {
|
||||
$found = maintenance_static_page_io::file_get_data(__DIR__.'/fixtures/invalidfile');
|
||||
self::assertSame('', $found['contents']);
|
||||
@@ -293,11 +351,17 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
phpunit_util::reset_debugging();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid file get_data.
|
||||
*/
|
||||
public function test_file_get_data_invalidfilename() {
|
||||
$this->set_expected_exception('coding_exception');
|
||||
maintenance_static_page_io::file_get_data(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test remove css selector.
|
||||
*/
|
||||
public function test_remove_css_selector() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
@@ -310,6 +374,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertNotContains('Goodbye cruel world', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test remove css selector id.
|
||||
*/
|
||||
public function test_remove_css_selector_id() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
@@ -322,6 +389,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertNotContains('Goodbye cruel world', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test remove css selector with multi lines.
|
||||
*/
|
||||
public function test_remove_css_selector_with_multiline() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
@@ -338,6 +408,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertNotContains('Goodbye cruel world', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test remove css selector needs trim.
|
||||
*/
|
||||
public function test_remove_css_selector_needing_trim() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
@@ -354,6 +427,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertNotContains('Goodbye cruel world', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test remove css selector with empty line.
|
||||
*/
|
||||
public function test_remove_css_selector_with_empty_line() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
@@ -370,6 +446,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertNotContains('Goodbye cruel world', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test remove css selector with invalid id.
|
||||
*/
|
||||
public function test_remove_css_selector_with_invalid_id() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
@@ -382,6 +461,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertContains('Goodbye cruel world', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test meta refresh 5 minutes.
|
||||
*/
|
||||
public function test_meta_refresh_5minutes() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n".
|
||||
@@ -393,6 +475,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertContains('<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".
|
||||
|
||||
@@ -35,7 +35,6 @@ 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 {
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,6 @@ 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 {
|
||||
/**
|
||||
@@ -291,6 +290,9 @@ class outagelib_test extends auth_outage_base_testcase {
|
||||
self::assertEmpty($header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create maintenance php code
|
||||
*/
|
||||
public function test_createmaintenancephpcode() {
|
||||
$expected = <<<'EOT'
|
||||
<?php
|
||||
@@ -332,6 +334,9 @@ EOT;
|
||||
self::assertSame($expected, $found);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create maintenance php code without age
|
||||
*/
|
||||
public function test_createmaintenancephpcode_withoutage() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest(true);
|
||||
@@ -383,6 +388,9 @@ EOT;
|
||||
self::assertSame($found, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create maintenance php code without IPs
|
||||
*/
|
||||
public function test_createmaintenancephpcode_withoutips() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest(true);
|
||||
@@ -399,6 +407,9 @@ EOT;
|
||||
self::assertFileNotExists($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create maintenance php code without outage
|
||||
*/
|
||||
public function test_createmaintenancephpcode_withoutoutage() {
|
||||
global $CFG;
|
||||
$file = $CFG->dataroot.'/climaintenance.php';
|
||||
@@ -517,6 +528,9 @@ EOT;
|
||||
self::assertNotEmpty($header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates outage for tests.
|
||||
*/
|
||||
private function create_outage() {
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
|
||||
Reference in New Issue
Block a user