Issue #36 - Fixed missing or inconsistent PhpDocs. Version is now: 1.0.1

This commit is contained in:
Daniel Thee Roperto
2016-10-04 14:47:00 +11:00
parent b12ef98170
commit c7b0cc2410
45 changed files with 915 additions and 177 deletions

View File

@@ -15,12 +15,16 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* auth_plugin_outage class.
*
* This plugin allows for an outage window to be configured
* and then optionally allows only a subset of IPs to connect,
* it also shows an outage notification to users.
*
* @package auth_outage
* @author Marcus Boon<marcus@catalyst-au.net>
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
@@ -31,7 +35,17 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/authlib.php');
/**
* Class auth_plugin_outage
* auth_plugin_outage class.
*
* This plugin allows for an outage window to be configured
* and then optionally allows only a subset of IPs to connect,
* it also shows an outage notification to users.
*
* @package auth_outage
* @author Marcus Boon<marcus@catalyst-au.net>
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class auth_plugin_outage extends auth_plugin_base {
/**
@@ -42,6 +56,7 @@ class auth_plugin_outage extends auth_plugin_base {
}
/**
* Always returns false (password wrong or user does not exist).
* @param string $username Not used in this plugin.
* @param string $password Not used in this plugin.
* @return bool False

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* calendar class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\calendar;
use auth_outage\local\outage;
@@ -23,7 +32,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/calendar/lib.php');
/**
* Manages outages in the calendar.
* calendar class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -33,7 +42,6 @@ require_once($CFG->dirroot.'/calendar/lib.php');
class calendar {
/**
* Private constructor, use static methods instead.
* @codeCoverageIgnore
*/
private function __construct() {
}

View File

@@ -14,6 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* outagedb class.
*
* The DB Context to manipulate Outages.
* It will also commit changes to the calendar as you change outages.
*
* @package auth_outage
* @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
*/
namespace auth_outage\dml;
use auth_outage\calendar\calendar;
@@ -29,6 +41,8 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/calendar/lib.php');
/**
* outagedb class.
*
* The DB Context to manipulate Outages.
* It will also commit changes to the calendar as you change outages.
*
@@ -40,7 +54,6 @@ require_once($CFG->dirroot.'/calendar/lib.php');
class outagedb {
/**
* Private constructor, use static methods instead.
* @codeCoverageIgnore
*/
private function __construct() {
}
@@ -63,6 +76,7 @@ class outagedb {
}
/**
* Gets an outage based on the given id.
* @param int $id Outage id to get.
* @return outage|null Returns the outage or null if not found.
* @throws coding_exception

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Toutage_created class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\event;
use core\event\base;
@@ -22,7 +31,7 @@ use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* The auth_outage outage created class.
* outage_created class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>

View File

@@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* outage_deleted class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\event;
use core\event\base;
@@ -22,7 +30,7 @@ use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* The auth_outage outage deleted class.
* outage_deleted class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* outage_updated class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\event;
use core\event\base;
@@ -22,7 +31,7 @@ use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* The auth_outage outage updated class.
* outage_updated class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* baseform class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\form;
use moodleform;
@@ -23,7 +32,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
/**
* Outage base for forms, extends Moodle form to fix an issue in the validation method.
* baseform class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -32,16 +41,7 @@ require_once($CFG->libdir.'/formslib.php');
*/
abstract class baseform extends moodleform {
/**
* Validate the form.
*
* You almost always want to call {@link is_validated} instead of this
* because it calls {@link definition_after_data} first, before validating the form,
* which is what you want in 99% of cases.
*
* This is provided as a separate function for those special cases where
* you want the form validated before definition_after_data is called
* for example, to selectively add new elements depending on a no_submit_button press,
* but only when the form is valid when the no_submit_button is pressed,
* Validate the form. See MDL-56250.
*
* @param bool $validateonnosubmit optional, defaults to false. The default behaviour
* is NOT to validate the form when a no submit button has been pressed.
@@ -49,7 +49,6 @@ abstract class baseform extends moodleform {
*
* @return bool true if form data valid
* @SuppressWarnings(PHPMD) It is better to not refactor this method as it is linked to its parent functionality.
* @codeCoverageIgnore
*/
public function validate_defined_fields($validateonnosubmit = false) {
// One validation NOT is enough (if mocking). See parent method.

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* delete class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\form\outage;
defined('MOODLE_INTERNAL') || die();
@@ -23,7 +32,7 @@ require_once($CFG->libdir.'/formslib.php');
defined('MOODLE_INTERNAL') || die();
/**
* Outage delete confirmation form.
* delete class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* edit class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\form\outage;
use auth_outage\form\baseform;
@@ -25,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
/**
* Outage form.
* edit class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -33,6 +42,9 @@ require_once($CFG->libdir.'/formslib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit extends baseform {
/**
* @var int Maximum number of characters for a title.
*/
const TITLE_MAX_CHARS = 100;
/**

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* finish class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\form\outage;
use moodleform;
@@ -23,7 +32,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
/**
* Outage finish confirmation form.
* finish class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* cli_exception class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\local\cli;
use Exception;
@@ -21,7 +30,7 @@ use Exception;
defined('MOODLE_INTERNAL') || die();
/**
* Exception executing CLI.
* cli_exception class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -73,7 +82,7 @@ class cli_exception extends Exception {
* cliexception constructor.
* @param string $message An explanation of the exception.
* @param int $code Exit code to be used.
* @param Exception|null $previous Another exception as reference.
* @param Exception $previous Another exception as reference or null.
*/
public function __construct($message, $code = 1, Exception $previous = null) {
parent::__construct('*ERROR* '.$message, $code, $previous = null);

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* clibase class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\local\cli;
use coding_exception;
@@ -22,7 +31,7 @@ use core\session\manager;
defined('MOODLE_INTERNAL') || die();
/**
* Outage CLI base class.
* clibase class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -42,7 +51,7 @@ abstract class clibase {
/**
* clibase constructor.
* @param mixed[]|null $options The parameters to use or null to read from the command line.
* @param array $options The parameters to use.
* @throws cli_exception
*/
public function __construct(array $options = null) {

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* create class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\local\cli;
use auth_outage\dml\outagedb;
@@ -23,7 +32,7 @@ use coding_exception;
defined('MOODLE_INTERNAL') || die();
/**
* Outage CLI to create outage.
* create class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -182,6 +191,10 @@ class create extends clibase {
return $id;
}
/**
* Sets the defaults to the outage to clone.
* @throws cli_exception
*/
private function clone_defaults() {
$id = $this->options['clone'];
if (!is_number($id) || ($id <= 0)) {
@@ -201,7 +214,7 @@ class create extends clibase {
/**
* Check parameters converting their type as needed.
* @param mixed $options Input options.
* @param array $options Input options.
* @return mixed Output options.
* @throws cli_exception
*/
@@ -248,7 +261,6 @@ class create extends clibase {
* @return string The converted parameter.
* @throws cli_exception
*/
private function merge_options_check_parameters_string_nonempty($option, $param) {
if (!is_string($option)) {
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* finish class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\local\cli;
use auth_outage\dml\outagedb;
@@ -22,7 +31,7 @@ use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* Outage CLI to finish an outage.
* finish class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* waitforit class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\local\cli;
use auth_outage\dml\outagedb;
@@ -22,7 +31,7 @@ use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* Outage CLI to wait for an outage to start.
* waitforit class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* infopage class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\local\controllers;
use auth_outage\dml\outagedb;
@@ -29,7 +38,7 @@ use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* Controller for the info page.
* infopage class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -49,7 +58,7 @@ class infopage {
/**
* infopage_controller constructor.
* @param mixed[]|null $params Parameters to use or null to get from Moodle API (request).
* @param array $params Parameters to use or null to get from Moodle API (request).
*/
public function __construct(array $params = null) {
if (is_null($params)) {
@@ -142,6 +151,7 @@ class infopage {
}
/**
* Gets the default template file to use for static info page.
* @return string The default template file to use for static info page.
*/
public static function get_defaulttemplatefile() {

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* outage class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\local;
use coding_exception;
@@ -22,7 +31,7 @@ use stdClass;
defined('MOODLE_INTERNAL') || die();
/**
* Outage class with all information about one specific outage.
* outage class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -112,7 +121,7 @@ class outage {
/**
* outage constructor.
* @param stdClass|mixed[]|null The data for the outage.
* @param stdClass|array|null $data The data for the outage.
* @throws coding_exception
*/
public function __construct($data = null) {
@@ -248,7 +257,7 @@ class outage {
/**
* Returns the input string with all placeholders replaced.
* @param $str string Input string.
* @param string $str Input string.
* @return string Output string.
*/
private function replace_placeholders($str) {
@@ -267,6 +276,9 @@ class outage {
);
}
/**
* Converts the type of the fields as needed.
*/
private function adjust_field_types() {
// Adjust int fields.
$fs = ['createdby', 'id', 'lastmodified', 'modifiedby', 'starttime', 'stoptime', 'warntime', 'finished'];

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* outagelib class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\local;
use auth_outage\dml\outagedb;
@@ -26,7 +35,7 @@ use stdClass;
defined('MOODLE_INTERNAL') || die();
/**
* Outage related functions.
* outagelib class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -34,6 +43,9 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class outagelib {
/**
* @var bool Flags in the page was already injected with the warning bar if needed.
*/
private static $injected = false;
/**

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* base_table class.
*
* @package auth_outage
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\output\manage;
use auth_outage\local\outage;
@@ -26,7 +35,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/tablelib.php');
/**
* Manage outages table base.
* base_table class.
*
* @package auth_outage
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
@@ -34,6 +43,9 @@ require_once($CFG->libdir.'/tablelib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class base_table extends flexible_table {
/**
* @var int Autogenerated id.
*/
private static $autoid = 0;
/**

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* history_table class.
*
* @package auth_outage
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\output\manage;
use auth_outage\local\outage;
@@ -23,7 +32,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/tablelib.php');
/**
* Manage outages table.
* history_table class.
*
* @package auth_outage
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* planned_table class.
*
* @package auth_outage
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\output\manage;
use auth_outage\local\outage;
@@ -25,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/tablelib.php');
/**
* Manage outages table.
* planned_table class.
*
* @package auth_outage
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>

View File

@@ -14,11 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* auth_outage_renderer class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\output;
use auth_outage\local\outage;
use auth_outage\output\manage\history_table;
use auth_outage\output\manage\planned_table;
use coding_exception;
use core_user;
use html_writer;
@@ -28,7 +35,7 @@ use plugin_renderer_base;
defined('MOODLE_INTERNAL') || die();
/**
* auth_outage auth_outage_renderer
* auth_outage_renderer class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -117,10 +124,8 @@ class renderer extends plugin_renderer_base {
* @param bool $preview If in preview mode the warning bar will not check if we are back online.
* @return string HTML of the warning bar.
* @throws coding_exception
* @SuppressWarnings("unused") because $viewbag is used inside require()
*/
public function render_warningbar(outage $outage, $time, $static, $preview) {
global $CFG;
if (!is_int($time) || ($time <= 0)) {
throw new coding_exception('$time is not an positive int or null.', $time);
}

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* update_static_page class.
*
* @package auth_outage
* @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
*/
namespace auth_outage\task;
use auth_outage\local\controllers\infopage;
@@ -22,7 +31,8 @@ use core\task\scheduled_task;
defined('MOODLE_INTERNAL') || die();
/**
* Tasks information.
* update_static_page class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT

View File

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

View File

@@ -25,9 +25,10 @@
defined('MOODLE_INTERNAL') || die();
/**
* Outage plugin upgrade code
*
* @param int $oldversion the version we are upgrading from
* @return bool result
* @SuppressWarnings("unused")
*/
function xmldb_auth_outage_upgrade($oldversion) {
global $DB;

View File

@@ -27,14 +27,23 @@ use auth_outage\local\outagelib;
defined('MOODLE_INTERNAL') || die;
/**
* Used in Moodle 30+ when a user is logged on.
*/
function auth_outage_extend_navigation_user_settings() {
outagelib::inject();
}
/**
* Used in Moodle 30+ on the frontpage.
*/
function auth_outage_extend_navigation_frontpage() {
outagelib::inject();
}
/**
* Used in Moodle 31+ when a user is logged on.
*/
function auth_outage_extend_navigation_user() {
outagelib::inject();
}

View File

@@ -17,7 +17,7 @@
/**
* Strings for component 'local_outage', language 'en'.
*
* @package local_outage
* @package auth_outage
* @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

View File

@@ -17,7 +17,7 @@
/**
* local_outage plugin lib
*
* @package local_outage
* @package auth_outage
* @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
@@ -27,10 +27,16 @@ use auth_outage\local\outagelib;
defined('MOODLE_INTERNAL') || die();
/**
* Used since Moodle 29.
*/
function local_outage_extend_navigation() {
outagelib::inject();
}
/**
* Used since Moodle 29.
*/
function local_outage_extend_settings_navigation() {
outagelib::inject();
}

View File

@@ -17,7 +17,7 @@
/**
* Version information.
*
* @package local_outage
* @package auth_outage
* @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

View File

@@ -14,9 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* auth_outage_renderer class.
*
* auth_outage auth_outage_renderer should just extend our renderer class in the classes directory.
* This is done to keep code organized and make easier to run tests and check coverage.
*
* @package auth_outage
* @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
*/
defined('MOODLE_INTERNAL') || die();
/**
* auth_outage_renderer class.
*
* auth_outage auth_outage_renderer should just extend our renderer class in the classes directory.
* This is done to keep code organized and make easier to run tests and check coverage.
*

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Steps definitions related to auth_outage.
*
* @package auth_outage
* @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
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
use auth_outage\dml\outagedb;
@@ -39,7 +48,9 @@ class behat_auth_outage extends behat_base {
private $outage = null;
/**
* Checks if a authentication plugin is enabled
* @Given the authentication plugin :name is enabled
* @param string $name Name of authentication plugin to check.
*/
public function the_authentication_plugin_is_enabled($name) {
set_config('auth', $name);
@@ -48,6 +59,7 @@ class behat_auth_outage extends behat_base {
}
/**
* Opens the Outage Management page.
* @Given /^I am on Outage Management Page$/
*/
public function i_am_on_outage_management_page() {
@@ -55,6 +67,7 @@ class behat_auth_outage extends behat_base {
}
/**
* Logs into the system.
* @Given /^I am an administrator$/
*/
public function i_am_an_administrator() {
@@ -70,6 +83,7 @@ class behat_auth_outage extends behat_base {
}
/**
* Opens the create outage page.
* @Given /^I visit the Create Outage Page$/
*/
public function i_visit_the_create_outage_page() {
@@ -77,7 +91,9 @@ class behat_auth_outage extends behat_base {
}
/**
* Creates an outage of the given type.
* @Given there is a :type outage
* @param string $type Type (stage) of outage to create.
*/
public function there_is_a_outage($type) {
$data = [
@@ -120,11 +136,14 @@ class behat_auth_outage extends behat_base {
}
/**
* Check if there is an action button with the given name.
* @Then I should see the action :action
* @param string $action Action to check.
* @throws ExpectationException
*/
public function i_should_see_the_action($action) {
$expected = ($action == 'Edit') ? 2 : 1; // Edit is an action through the title or button.
$found = $this->can_i_see_action($action);
$found = $this->how_many_times_can_i_see_action($action);
if ($found != $expected) {
throw new ExpectationException('"'.$action.'" action not found, expected '.$expected.
' but found '.$found.'.', $this->getSession());
@@ -132,15 +151,23 @@ class behat_auth_outage extends behat_base {
}
/**
* Check if an specific action is not visible.
* @Then I should not see the action :action
* @param string $action Action to check.
* @throws ExpectationException
*/
public function i_should_not_see_the_action($action) {
if ($this->can_i_see_action($action) != 0) {
if ($this->how_many_times_can_i_see_action($action) != 0) {
throw new ExpectationException('"'.$action.'" action was found', $this->getSession());
}
}
private function can_i_see_action($action) {
/**
* Counts how many times an specific action is visible.
* @param string $action Action to check.
* @return int Number of times it is shown.
*/
private function how_many_times_can_i_see_action($action) {
$selector = 'css';
$locator = "div[role='main'] a[title='".$action."']";
$items = $this->getSession()->getPage()->findAll($selector, $locator);
@@ -148,7 +175,9 @@ class behat_auth_outage extends behat_base {
}
/**
* Click the given action button.
* @Then I click on the :action action button
* @param string $action Action button to click.
*/
public function i_click_on_the_action_button($action) {
$node = $this->get_selected_node('css_element', "div[role='main'] table nobr a[title='".$action."']");
@@ -157,7 +186,9 @@ class behat_auth_outage extends behat_base {
}
/**
* Check if a new window was opened.
* @Given I should be in a new window
* @throws ExpectationException
*/
public function i_should_be_in_a_new_window() {
$count = count($this->getSession()->getWindowNames());
@@ -167,7 +198,10 @@ class behat_auth_outage extends behat_base {
}
/**
* Checks if the warning bar is visible.
* @Then I should see :text in the warning bar
* @param string $text Text that should be in the warning bar.
* @throws ExpectationException
*/
public function i_should_see_in_the_warning_bar($text) {
$element = '#auth_outage_warningbar_box';
@@ -197,7 +231,9 @@ class behat_auth_outage extends behat_base {
}
/**
* Checks if the warning bar is not visible.
* @Then I should not see the warning bar
* @throws ExpectationException
*/
public function i_should_not_see_the_warning_bar() {
$selector = 'css';
@@ -209,7 +245,10 @@ class behat_auth_outage extends behat_base {
}
/**
* Creates an outage for the given data.
* @Given there is the following outage:
* @param TableNode $data Outage data.
* @throws Exception
*/
public function there_is_the_following_outage(TableNode $data) {
$time = time();
@@ -249,7 +288,10 @@ class behat_auth_outage extends behat_base {
}
/**
* Waits (sleep) until outage reaches a stage.
* @When /^I wait until the outage (?P<what>warns|starts|stops)$/
* @param string $what What to wait for.
* @throws Exception
*/
public function i_wait_until_outage($what) {
switch ($what) {

View File

@@ -0,0 +1,65 @@
<?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/>.
/**
* Base testcase for auth outage tests.
*
* We added this testcase to handle exceptions.
* Moodle 29 uses PHPUnit 3.7.38 which does not implement the expectException().
* Moodle 30 uses PHPUnit 4.8.21 which does not implement the expectException().
* Moodle 31 uses PHPUnit 4.8.27 which does not implement the expectException().
* Moodle 32 (as of now) uses PHPUnit 5.4.8 which deprecated setExpectedException().
* In PHPUnit 6 the setExpectedException() will be removed.
* We are not not using the annotation expectException as it is not accepted by Moodle Checker.
*
* @package auth_outage
* @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
*/
defined('MOODLE_INTERNAL') || die();
/**
* auth_outage_base_testcase class.
*
* @package auth_outage
* @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
*/
abstract class auth_outage_base_testcase extends advanced_testcase {
/**
* Checks PHPUnit version and calls the functions accordingly.
* @param string $exception Expected exception class.
* @param string|null $message Expected exception message.
* @param int|null $code Expected exception code.
*/
public function set_expected_exception($exception, $message = null, $code = null) {
global $CFG;
if ($CFG->branch < 32) {
$this->setExpectedException($exception, $message, $code);
} else {
$this->expectException($exception);
if (!is_null($message) && ($message !== '')) {
$this->expectExceptionMessage($message);
}
if (!is_null($code)) {
$this->expectExceptionCode($code);
}
}
}
}

View File

@@ -14,13 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* calendar_test test class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use auth_outage\calendar\calendar;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* Tests performed on outage class.
* calendar_test test class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -28,6 +37,10 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class calendar_test extends advanced_testcase {
/**
* Creates an outage and checks if its in the calendar.
* @return outage Created outage.
*/
public function test_create() {
self::setAdminUser();
$this->resetAfterTest(false);
@@ -49,7 +62,10 @@ class calendar_test extends advanced_testcase {
}
/**
* Updates an outage and checks the calendar.
* @depends test_create
* @param outage $outage Outage to be updated.
* @return outage Updated outage.
*/
public function test_update(outage $outage) {
self::setAdminUser();
@@ -63,7 +79,9 @@ class calendar_test extends advanced_testcase {
}
/**
* Deletes an outage and checks the calendar.
* @depends test_update
* @param outage $outage Outage to delete.
*/
public function test_delete($outage) {
self::setAdminUser();
@@ -73,6 +91,9 @@ class calendar_test extends advanced_testcase {
self::assertNull(calendar::load($outage->id));
}
/**
* Try to update a non existing outage.
*/
public function test_update_notfound() {
self::setAdminUser();
$this->resetAfterTest(true);
@@ -93,6 +114,9 @@ class calendar_test extends advanced_testcase {
phpunit_util::reset_debugging();
}
/**
* Try to delete a non existing outage.
*/
public function test_delete_notfound() {
self::setAdminUser();
$this->resetAfterTest(true);
@@ -101,6 +125,10 @@ class calendar_test extends advanced_testcase {
phpunit_util::reset_debugging();
}
/**
* Check if there is a calendar entry for the given outage.
* @param outage $outage Outage to check.
*/
private function check_calendar(outage $outage) {
$calendar = calendar::load($outage->id);
self::assertSame($outage->title, $calendar->name);

View File

@@ -14,13 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* Tests performed on outage class.
* outagedb_test tests class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -28,7 +23,23 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings("public") Allow this test to have as many tests as necessary.
*/
class outagedb_test extends advanced_testcase {
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../base_testcase.php');
/**
* outagedb_test tests class.
*
* @package auth_outage
* @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 this test to have as many tests as necessary.
*/
class outagedb_test extends auth_outage_base_testcase {
/**
* Creates an array of ids in from the given outages array.
* @param outage[] $outages An array of outages.
@@ -87,6 +98,9 @@ class outagedb_test extends advanced_testcase {
outagedb::save($outage);
}
/**
* Create a few outages, fetch them and check if fields match.
*/
public function test_saved_fields() {
$this->resetAfterTest(true);
for ($i = 0; $i < 4; $i++) {
@@ -211,6 +225,9 @@ class outagedb_test extends advanced_testcase {
}
}
/**
* Tests the outagedb::get_active() method.
*/
public function test_getactive() {
$this->resetAfterTest(true);
@@ -247,6 +264,9 @@ class outagedb_test extends advanced_testcase {
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
}
/**
* Tests the outagedb::get_all_unended() method.
*/
public function test_getallunended() {
$this->resetAfterTest(true);
@@ -295,6 +315,9 @@ class outagedb_test extends advanced_testcase {
self::createidarray(outagedb::get_all_unended($now)), 'Wrong future data.');
}
/**
* Tests the outagedb::get_all_ended() method.
*/
public function test_getallended() {
$this->resetAfterTest(true);
@@ -331,63 +354,78 @@ class outagedb_test extends advanced_testcase {
}
/**
* @expectedException coding_exception
* Tests the outagedb::get_by_id() with an invalid parameter.
*/
public function test_getbyid_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
outagedb::get_by_id(-1);
}
/**
* @expectedException coding_exception
* Tests the outagedb::delete() with an invalid parameter.
*/
public function test_delete_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
outagedb::delete(-1);
}
/**
* @expectedException coding_exception
* Tests the outagedb::get_active() with an invalid parameter.
*/
public function test_getactive_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
outagedb::get_active(-1);
}
/**
* @expectedException coding_exception
* Tests the outagedb::get_all_unended() with an invalid parameter.
*/
public function test_getallunended_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
outagedb::get_all_unended(-1);
}
/**
* Checks we can execute outagedb::get_all_unended() without parameters (now).
*/
public function test_getallunended_now() {
$this->resetAfterTest(true);
outagedb::get_all_unended();
self::assertEmpty(outagedb::get_all_unended());
}
/**
* @expectedException coding_exception
* Tests the outagedb::get_all_ended() with an invalid parameter.
*/
public function test_getallended_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
outagedb::get_all_ended(-1);
}
/**
* Checks we can execute outagedb::test_getallended_now() without parameters (now).
*/
public function test_getallended_now() {
$this->resetAfterTest(true);
outagedb::get_all_ended();
self::assertEmpty(outagedb::get_all_ended());
}
/**
* @expectedException coding_exception
* Tests the outagedb::finish() with an invalid parameter.
*/
public function test_finish_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
outagedb::finish(1, -1);
}
/**
* Tests the outagedb::finish() with a non existing outage.
*/
public function test_finish_now_notfound() {
$this->resetAfterTest(true);
outagedb::finish(1);
@@ -395,6 +433,9 @@ class outagedb_test extends advanced_testcase {
phpunit_util::reset_debugging();
}
/**
* Try to finish not ongoing outages.
*/
public function test_finish_notongoing() {
$this->resetAfterTest(true);
$time = time();
@@ -415,25 +456,26 @@ class outagedb_test extends advanced_testcase {
}
/**
* @expectedException coding_exception
* Tests the outagedb::get_next_starting() with an invalid parameter.
*/
public function test_getnextstartinginvalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
outagedb::get_next_starting(-1);
}
/**
* @expectedException coding_exception
* Tests the outagedb::get_next_autostarting() with an invalid parameter.
*/
public function test_getnextautostartinginvalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
outagedb::get_next_autostarting(-1);
}
/**
* Helper function to create an outage for tests.
*
* @param $i int Used to populate the information.
* @param int $i Used to populate the information.
* @return outage The created outage.
*/
private function createoutage($i) {

View File

@@ -14,13 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* events_test tests class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* Tests performed on outage class.
* events_test tests class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -28,6 +37,10 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class events_test extends advanced_testcase {
/**
* Saves an outage and check if the event was created.
* @return array With the outage id and the event id.
*/
public function test_save() {
global $DB;
self::setAdminUser();
@@ -59,10 +72,12 @@ class events_test extends advanced_testcase {
}
/**
* @param int[] $ids
* Updates an outage and checks if the event was updated.
* @param int[] $ids Outage id and event id.
* @return int[] same as input parameter.
* @depends test_save
*/
public function test_update($ids) {
public function test_update(array $ids) {
global $DB;
self::setAdminUser();
@@ -88,7 +103,8 @@ class events_test extends advanced_testcase {
}
/**
* @param int[] $ids
* Deletes an outage and checks if the event was deleted.
* @param int[] $ids Outage id and event id.
* @depends test_update
*/
public function test_delete($ids) {

View File

@@ -14,30 +14,49 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use auth_outage\form\outage\delete;
use auth_outage\form\outage\edit;
use auth_outage\form\outage\finish;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* Tests performed on forms classes.
* forms_test test class.
*
* @package auth_outage
* @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
*/
class forms_test extends advanced_testcase {
use auth_outage\form\outage\delete;
use auth_outage\form\outage\edit;
use auth_outage\form\outage\finish;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../base_testcase.php');
/**
* forms_test test class.
*
* @package auth_outage
* @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
*/
class forms_test extends auth_outage_base_testcase {
/**
* Create a delete form.
*/
public function test_delete() {
new delete();
}
/**
* Create a finish form.
*/
public function test_finish() {
new finish();
}
/**
* Mock some data and check values.
*/
public function test_edit_valid() {
$this->mock_edit_post();
$edit = new edit();
@@ -52,6 +71,9 @@ class forms_test extends advanced_testcase {
self::assertSame('The <b>description</b>.', $outage->description);
}
/**
* Check invalid warning duration.
*/
public function test_edit_invalid_warning() {
$this->mock_edit_post();
$_POST['warningduration'] = ['number' => '-1', 'timeunit' => '60'];
@@ -60,6 +82,9 @@ class forms_test extends advanced_testcase {
self::assertNull($outage);
}
/**
* Check invalid outage duration.
*/
public function test_edit_invalid_duration() {
$this->mock_edit_post();
$_POST['outageduration'] = ['number' => '-2', 'timeunit' => '3600'];
@@ -67,6 +92,9 @@ class forms_test extends advanced_testcase {
self::assertNull($edit->get_data());
}
/**
* Check invalid title (empty).
*/
public function test_edit_invalid_title() {
$this->mock_edit_post();
$_POST['title'] = '';
@@ -74,6 +102,9 @@ class forms_test extends advanced_testcase {
self::assertNull($edit->get_data());
}
/**
* Check invalid title (too long).
*/
public function test_edit_invalid_title_toolong() {
$this->mock_edit_post();
$_POST['title'] = 'This is a very long time, it is so long that at some point it should not be valid. '.
@@ -83,6 +114,9 @@ class forms_test extends advanced_testcase {
self::assertNull($edit->get_data());
}
/**
* Check invalid format for description.
*/
public function test_edit_description_invalid_format() {
$this->mock_edit_post();
$_POST['description'] = ['text' => 'The <b>description</b>.', 'format' => '2'];
@@ -92,6 +126,9 @@ class forms_test extends advanced_testcase {
phpunit_util::reset_debugging();
}
/**
* Check if set data works properly.
*/
public function test_setdata() {
$outage = new outage([
'autostart' => false,
@@ -106,15 +143,18 @@ class forms_test extends advanced_testcase {
}
/**
* @expectedException coding_exception
* Check edit::set_data() with invalid parameter.
*/
public function test_setdata_invalid() {
$edit = new edit();
$this->set_expected_exception(coding_exception::class);
$edit->set_data(null);
}
/**
* Mock a post, see MDL-56233.
*/
private function mock_edit_post() {
// There is a bug in moodleform::mock_submit so we make our own version.
$_POST = [
'id' => '1',
'sesskey' => sesskey(),

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* cli_test test class.
*
* @package auth_outage
* @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
*/
use auth_outage\local\cli\cli_exception;
use auth_outage\local\cli\create;
@@ -21,7 +30,7 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/cli_testcase.php');
/**
* Tests performed on CLI base and exception class.
* cli_test test class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -29,24 +38,27 @@ require_once(__DIR__.'/cli_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings("public")
*/
class cli_test extends cli_testcase {
class cli_test extends auth_outage_cli_testcase {
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 2
* Tests providing an unknown parameter.
*/
public function test_invalidargumentparam() {
$this->set_parameters(['--aninvalidparameter']);
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_UNKNOWN);
new create();
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 2
* Tests providing another unknow parameter (without --).
*/
public function test_invalidargumentgiven() {
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_UNKNOWN);
new create(['anotherinvalidparameter']);
}
/**
* Tests setting reference times.
*/
public function test_setreferencetime() {
$cli = new create(['start' => 0]);
$cli->set_referencetime(1);
@@ -54,14 +66,18 @@ class cli_test extends cli_testcase {
}
/**
* @expectedException coding_exception
* Tests setting an invalid reference time.
*/
public function test_setreferencetime_invalid() {
$this->set_parameters(['--start=60']);
$cli = new create();
$this->set_expected_exception(coding_exception::class);
$cli->set_referencetime(-1);
}
/**
* Tests the help.
*/
public function test_help() {
$this->set_parameters(['-h']);
$cli = new create();
@@ -71,16 +87,15 @@ class cli_test extends cli_testcase {
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 1
* Tests the cli_exception.
*/
public function test_exception() {
$this->set_expected_cli_exception(cli_exception::ERROR_UNDEFINED);
throw new cli_exception('An CLI exception.');
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 8
* Tests with the auth_outage plugin disabled.
*/
public function test_authdisabled() {
// Disable all auth plugins.
@@ -88,6 +103,7 @@ class cli_test extends cli_testcase {
\core\session\manager::gc(); // Remove stale sessions.
core_plugin_manager::reset_caches();
// Try to create an CLI object.
$this->set_expected_cli_exception(cli_exception::ERROR_PLUGIN_DISABLED);
new create();
}
}

View File

@@ -14,19 +14,33 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use auth_outage\local\cli\clibase;
defined('MOODLE_INTERNAL') || die();
/**
* Tests performed on CLIs.
* auth_outage_cli_testcase class.
*
* @package auth_outage
* @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
*/
class cli_testcase extends advanced_testcase {
use auth_outage\local\cli\cli_exception;
use auth_outage\local\cli\clibase;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../../base_testcase.php');
/**
* auth_outage_cli_testcase class.
*
* @package auth_outage
* @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
*/
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() {
// Enable auth plugins.
set_config('auth', 'outage');
@@ -63,4 +77,12 @@ class cli_testcase extends advanced_testcase {
ob_end_clean();
}
}
/**
* Sets the expected exception as cli_exception with the given error code.
* @param int $errorcode Error code.
*/
protected function set_expected_cli_exception($errorcode) {
$this->set_expected_exception(cli_exception::class, null, $errorcode);
}
}

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* create_test test class.
*
* @package auth_outage
* @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
*/
use auth_outage\dml\outagedb;
use auth_outage\local\cli\cli_exception;
use auth_outage\local\cli\create;
@@ -23,7 +32,7 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/cli_testcase.php');
/**
* Tests performed on CLI create class.
* create_test test class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -31,19 +40,18 @@ require_once(__DIR__.'/cli_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings("public") Allow this test to have as many tests as necessary.
*/
class create_test extends cli_testcase {
class create_test extends auth_outage_cli_testcase {
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 4
* Tests without any arguments.
*/
public function test_noarguments() {
$cli = new create();
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_MISSING);
$this->execute($cli);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 3
* Tests when the start time is not a valid number.
*/
public function test_invalidparam_notanumber() {
$cli = new create(['start' => 'some day']);
@@ -54,12 +62,12 @@ class create_test extends cli_testcase {
'title' => 'Default Title',
'description' => 'Default Description',
]);
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$this->execute($cli);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 3
* Tests when providing a negative start time.
*/
public function test_invalidparam_negative() {
$cli = new create(['start' => -1]);
@@ -70,12 +78,12 @@ class create_test extends cli_testcase {
'title' => 'Default Title',
'description' => 'Default Description',
]);
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$this->execute($cli);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 3
* Tests providing an empty title.
*/
public function test_invalidparam_emptystring() {
$cli = new create(['start' => 0, 'title' => '']);
@@ -86,12 +94,12 @@ class create_test extends cli_testcase {
'title' => 'Default Title',
'description' => 'Default Description',
]);
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$this->execute($cli);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 3
* Tests if not providing the title (it will be send as true).
*/
public function test_invalidparam_notastring() {
$cli = new create(['start' => 0, 'title' => true]);
@@ -102,9 +110,13 @@ class create_test extends cli_testcase {
'title' => 'Default Title',
'description' => 'Default Description',
]);
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$this->execute($cli);
}
/**
* Tests the help.
*/
public function test_help() {
$this->set_parameters(['--help']);
$cli = new create();
@@ -113,6 +125,9 @@ class create_test extends cli_testcase {
self::assertContains('--help', $output);
}
/**
* Tests the options and shortcuts.
*/
public function test_options() {
$cli = new create();
@@ -127,6 +142,9 @@ class create_test extends cli_testcase {
}
}
/**
* Tests creating with all given options.
*/
public function test_create_withoptions() {
$this->set_parameters([
'--autostart=true',
@@ -153,6 +171,9 @@ class create_test extends cli_testcase {
self::assertSame('A Description', $outage->description);
}
/**
* Tests creating with the onlyid parameter.
*/
public function test_create_onlyid() {
$this->set_parameters([
'--onlyid',
@@ -181,6 +202,9 @@ class create_test extends cli_testcase {
self::assertSame('Description', $outage->description);
}
/**
* Tests creating using some default values.
*/
public function test_create_withdefaults() {
$this->set_parameters([
'--warn=100',
@@ -211,6 +235,9 @@ class create_test extends cli_testcase {
self::assertSame('Default Description', $outage->description);
}
/**
* Tests creating with clone.
*/
public function test_create_withclone() {
self::setAdminUser();
$now = time();
@@ -243,8 +270,7 @@ class create_test extends cli_testcase {
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 3
* Tests creating with an invalid clone id.
*/
public function test_create_withclone_invalid() {
$this->set_parameters([
@@ -252,9 +278,13 @@ class create_test extends cli_testcase {
'--clone=-1',
]);
$cli = new create();
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$this->execute($cli);
}
/**
* Tests creating with the block flag.
*/
public function test_create_withblock() {
// Not an extensive test in the blocking API, cliwaitforit tests should cover them deeper.
$this->set_parameters([
@@ -275,16 +305,16 @@ class create_test extends cli_testcase {
}
/**
* @expectedException coding_exception
* Tests providing an invalid option as default.
*/
public function test_setdefaults_extra() {
$cli = new create([]);
$this->set_expected_exception(coding_exception::class);
$cli->set_defaults(['aninvalidparameter' => 'value']);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 3
* Tests with an invalud autostart bool value.
*/
public function test_invalid_bool() {
$this->set_parameters([
@@ -296,6 +326,7 @@ class create_test extends cli_testcase {
'--description=Description',
]);
$cli = new create();
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$cli->execute();
}
}

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* finish_test test class.
*
* @package auth_outage
* @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
*/
use auth_outage\dml\outagedb;
use auth_outage\local\cli\cli_exception;
use auth_outage\local\cli\finish;
@@ -23,19 +32,25 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/cli_testcase.php');
/**
* Tests performed on CLI finish class.
* finish_test test class.
*
* @package auth_outage
* @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
*/
class finish_test extends cli_testcase {
class finish_test extends auth_outage_cli_testcase {
/**
* Tests the constructor.
*/
public function test_constructor() {
$cli = new finish();
self::assertNotNull($cli);
}
/**
* Tests the generated options and shortcuts.
*/
public function test_options() {
$cli = new finish();
@@ -50,6 +65,9 @@ class finish_test extends cli_testcase {
}
}
/**
* Tests the help.
*/
public function test_help() {
$this->set_parameters(['--help']);
$cli = new finish();
@@ -59,17 +77,16 @@ class finish_test extends cli_testcase {
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 4
* Tests if running without arguments.
*/
public function test_noarguments() {
$cli = new finish();
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_MISSING);
$this->execute($cli);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 5
* Tests finishing an already ended outage.
*/
public function test_endedoutage() {
self::setAdminUser();
@@ -85,9 +102,13 @@ class finish_test extends cli_testcase {
$this->set_parameters(['-id='.$id]);
$cli = new finish();
$cli->set_referencetime($now);
$this->set_expected_cli_exception(cli_exception::ERROR_OUTAGE_INVALID);
$this->execute($cli);
}
/**
* Tests finishing an outage.
*/
public function test_finish() {
self::setAdminUser();
$now = time();
@@ -106,35 +127,35 @@ class finish_test extends cli_testcase {
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 6
* Tests finishing an active outage when it does not exists.
*/
public function test_activenotfound() {
self::setAdminUser();
$this->set_parameters(['-a']);
$cli = new finish();
$this->set_expected_cli_exception(cli_exception::ERROR_OUTAGE_NOT_FOUND);
$this->execute($cli);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 3
* Tests providing an invalid outage id.
*/
public function test_invalidid() {
self::setAdminUser();
$this->set_parameters(['-id=theid']);
$cli = new finish();
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$this->execute($cli);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 6
* Tests when the outage is not found.
*/
public function test_idnotfound() {
self::setAdminUser();
$this->set_parameters(['-id=99999']);
$cli = new finish();
$this->set_expected_cli_exception(cli_exception::ERROR_OUTAGE_NOT_FOUND);
$this->execute($cli);
}
}

View File

@@ -14,15 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use auth_outage\dml\outagedb;
use auth_outage\local\cli\waitforit;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/cli_testcase.php');
/**
* Tests performed on CLI waitforit class.
* waitforit_test test class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -30,12 +23,36 @@ require_once(__DIR__.'/cli_testcase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings("public")
*/
class waitforit_test extends cli_testcase {
use auth_outage\dml\outagedb;
use auth_outage\local\cli\cli_exception;
use auth_outage\local\cli\waitforit;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/cli_testcase.php');
/**
* waitforit_test test class.
*
* @package auth_outage
* @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")
*/
class waitforit_test extends auth_outage_cli_testcase {
/**
* Tests the constructor.
*/
public function test_constructor() {
$cli = new waitforit();
self::assertNotNull($cli);
}
/**
* Tests the generated options.
*/
public function test_generateoptions() {
$cli = new waitforit();
$options = $cli->generate_options();
@@ -44,6 +61,9 @@ class waitforit_test extends cli_testcase {
}
}
/**
* Tests the generated shortcut options.
*/
public function test_generateshortcuts() {
$cli = new waitforit();
$options = $cli->generate_options();
@@ -53,6 +73,9 @@ class waitforit_test extends cli_testcase {
}
}
/**
* Tests if help works.
*/
public function test_help() {
$this->set_parameters(['--help']);
$cli = new waitforit();
@@ -62,38 +85,37 @@ class waitforit_test extends cli_testcase {
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 3
* Checks if providing an outageid and active parameter.
*/
public function test_bothparams() {
$this->set_parameters(['--outageid=1', '--active']);
$cli = new waitforit();
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$cli->execute();
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 3
* Tests with an invalid outage id
*/
public function test_invalidoutageid() {
$this->set_parameters(['-id=-1']);
$cli = new waitforit();
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
$this->execute($cli);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 6
* Tests with an active outage when it does not exists.
*/
public function test_outagenotfound() {
$this->set_parameters(['-a']);
$cli = new waitforit();
$this->set_expected_cli_exception(cli_exception::ERROR_OUTAGE_NOT_FOUND);
$this->execute($cli);
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 5
* Tests with an outage that already ended.
*/
public function test_endedoutage() {
self::setAdminUser();
@@ -109,9 +131,13 @@ class waitforit_test extends cli_testcase {
$this->set_parameters(['-id='.$id]);
$cli = new waitforit();
$cli->set_referencetime($now);
$this->set_expected_cli_exception(cli_exception::ERROR_OUTAGE_INVALID);
$this->execute($cli);
}
/**
* Tests waiting for an existing active outage, verbose mode.
*/
public function test_activeverbose() {
self::setAdminUser();
$now = time();
@@ -132,6 +158,9 @@ class waitforit_test extends cli_testcase {
self::assertContains('started', $output);
}
/**
* Tests the countdown.
*/
public function test_countdown() {
self::setAdminUser();
$now = time();
@@ -159,8 +188,7 @@ class waitforit_test extends cli_testcase {
}
/**
* @expectedException auth_outage\local\cli\cli_exception
* @expectedExceptionCode 7
* Tests if the outage changed while waiting.
*/
public function test_outagechanged() {
self::setAdminUser();
@@ -184,6 +212,7 @@ class waitforit_test extends cli_testcase {
// Pretend it is time to start, but it should get an error instead.
return $outage->starttime;
});
$this->set_expected_cli_exception(cli_exception::ERROR_OUTAGE_CHANGED);
$this->execute($cli);
}
}

View File

@@ -14,12 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests performed on infopage controller class and update_static_page task class.
*
* @package auth_outage
* @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
*/
use auth_outage\dml\outagedb;
use auth_outage\local\controllers\infopage;
use auth_outage\local\outage;
use auth_outage\task\update_static_page;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../../base_testcase.php');
/**
* Tests performed on infopage controller class and update_static_page task class.
@@ -30,7 +40,10 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings("public") Allow this test to have as many tests as necessary.
*/
class infopagecontroller_test extends advanced_testcase {
class infopagecontroller_test extends auth_outage_base_testcase {
/**
* Ensures the template file does not exist when starting a test.
*/
public function setUp() {
$file = infopage::get_defaulttemplatefile();
if (file_exists($file)) {
@@ -42,17 +55,23 @@ class infopagecontroller_test extends advanced_testcase {
}
}
/**
* Tests the constructor.
*/
public function test_constructor() {
new infopage();
}
/**
* Tests the constructor with given parameters.
*/
public function test_constructor_withparams() {
$_GET = ['id' => 1, 'static' => 'true'];
new infopage();
}
/**
* @expectedException coding_exception
* Tests the constructor with different id and outage id.
*/
public function test_constructor_idmismatch() {
$outage = new outage([
@@ -64,16 +83,21 @@ class infopagecontroller_test extends advanced_testcase {
'title' => 'Title',
'description' => 'Description',
]);
$this->set_expected_exception(coding_exception::class);
new infopage(['id' => 2, 'outage' => $outage]);
}
/**
* @expectedException coding_exception
* Tests the constructor with an invalid outage.
*/
public function test_constructor_invalidoutage() {
$this->set_expected_exception(coding_exception::class);
new infopage(['outage' => 'My outage']);
}
/**
* Tests the static page contents.
*/
public function test_staticpage_output() {
global $PAGE;
$this->resetAfterTest(true);
@@ -104,6 +128,9 @@ class infopagecontroller_test extends advanced_testcase {
self::assertSame($outage->id, infopage::find_outageid_from_infopage($html));
}
/**
* Tests the static page file contents.
*/
public function test_staticpage_file() {
$now = time();
$outage = new outage([
@@ -124,6 +151,9 @@ class infopagecontroller_test extends advanced_testcase {
unlink($file);
}
/**
* Checks if the default template file is a valid string with the name templage.
*/
public function test_getdefaulttemplatefile() {
$file = infopage::get_defaulttemplatefile();
self::assertTrue(is_string($file));
@@ -131,12 +161,16 @@ class infopagecontroller_test extends advanced_testcase {
}
/**
* @expectedException coding_exception
* Tests infopage::find_outageid_from_infopage() with an invalid parameter.
*/
public function test_findoutageid_notstring() {
$this->set_expected_exception(coding_exception::class);
infopage::find_outageid_from_infopage(new stdClass());
}
/**
* Tests infopage::find_outageid_from_infopage() when the id is not found.
*/
public function test_findoutageid_notfound() {
self::assertNull(
infopage::find_outageid_from_infopage(
@@ -146,14 +180,15 @@ class infopagecontroller_test extends advanced_testcase {
}
/**
* @expectedException coding_exception
* Tests infopage::save_static_page() with an invalid parameter.
*/
public function test_savestaticpage_filenotstring() {
$this->set_expected_exception(coding_exception::class);
infopage::save_static_page(new outage(), 1);
}
/**
* @expectedException file_exception
* Tests infopage::save_static_page() with an invalid filename.
*/
public function test_savestaticpage_fileinvalid() {
global $CFG;
@@ -165,30 +200,38 @@ class infopagecontroller_test extends advanced_testcase {
'title' => 'Title',
'description' => 'Description',
]);
$this->set_expected_exception(file_exception::class);
infopage::save_static_page($outage, $CFG->dataroot.'/someinvalidpath/someinvalidfile');
}
/**
* @expectedException invalid_state_exception
* Tests infopage::test_sanity_notstring() with invalid contents: an int.
*/
public function test_sanity_notstring() {
$this->set_expected_exception(invalid_state_exception::class);
infopage::save_static_page_sanitycheck(404);
}
/**
* @expectedException invalid_state_exception
* Tests infopage::test_sanity_notstring() with invalid contents: an empty string.
*/
public function test_sanity_empty() {
$this->set_expected_exception(invalid_state_exception::class);
infopage::save_static_page_sanitycheck(' ');
}
/**
* @expectedException invalid_state_exception
* Tests infopage::test_sanity_notstring() with invalid contents: an empty HTML.
*/
public function test_sanity_clearhtml() {
$this->set_expected_exception(invalid_state_exception::class);
infopage::save_static_page_sanitycheck('<html><head></head><body><b> <!-- Nothing --> </b></body></html>');
}
/**
* Tests updating the static page.
*/
public function test_updatestaticpage() {
$this->resetAfterTest(true);
self::setAdminUser();
@@ -210,10 +253,16 @@ class infopagecontroller_test extends advanced_testcase {
unlink($file);
}
/**
* Tests updating the static page when there is no outage.
*/
public function test_updatestaticpage_nooutage() {
infopage::update_static_page();
}
/**
* Tests updating the static page when there is no outage but the file existed before.
*/
public function test_updatestaticpage_hasfile() {
$file = infopage::get_defaulttemplatefile();
touch($file);
@@ -223,12 +272,16 @@ class infopagecontroller_test extends advanced_testcase {
}
/**
* @expectedException coding_exception
* Tests updating the static page with an invalid filename.
*/
public function test_updatestaticpage_invalidfile() {
$this->set_expected_exception(coding_exception::class);
infopage::update_static_page(123);
}
/**
* Checks if infopage::has_admin_options() works as expected.
*/
public function test_hasadminoptions() {
$this->resetAfterTest(true);
$static = new infopage(['static' => true]);
@@ -245,22 +298,27 @@ class infopagecontroller_test extends advanced_testcase {
}
/**
* @expectedException coding_exception
* Tries to output a static page without a defined outage.
*/
public function test_output_static_nooutage() {
$info = new infopage(['static' => true]);
$this->set_expected_exception(coding_exception::class);
$info->output();
}
/**
* We should have an exception because CLI cannot redirect.
* @expectedException moodle_exception
*/
public function test_output_nonstatic_nooutage() {
$info = new infopage(['static' => false]);
$this->set_expected_exception(moodle_exception::class);
$info->output();
}
/**
* Checks the output of the info page.
*/
public function test_output() {
$now = time();
$outage = new outage([
@@ -277,6 +335,9 @@ class infopagecontroller_test extends advanced_testcase {
self::assertContains('auth_outage_info', $output);
}
/**
* Checks if we can create and execute a task to update outage pages.
*/
public function test_tasks() {
$task = new update_static_page();
self::assertNotEmpty($task->get_name());

View File

@@ -14,19 +14,32 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* Tests performed on outage class.
* outage_test test class.
*
* @package auth_outage
* @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
*/
class outage_test extends basic_testcase {
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../base_testcase.php');
/**
* outage_test test class.
*
* @package auth_outage
* @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
*/
class outage_test extends auth_outage_base_testcase {
/**
* Tests the constructor.
*/
public function test_constructor() {
$outage = new outage();
// Very important, this should never change.
@@ -37,6 +50,9 @@ class outage_test extends basic_testcase {
}
}
/**
* Tests the constructor, giving data as an object.
*/
public function test_constructor_object() {
$obj = new stdClass();
$obj->id = 1;
@@ -59,12 +75,16 @@ class outage_test extends basic_testcase {
}
/**
* @expectedException coding_exception
* Tests the constructor with invalid data.
*/
public function test_constructor_invalid() {
$this->set_expected_exception(coding_exception::class);
new outage('My outage');
}
/**
* Tests getting the stage considering the current time (now).
*/
public function test_getstage_now() {
$now = time();
// Make sure it is in the past.
@@ -79,13 +99,17 @@ class outage_test extends basic_testcase {
}
/**
* @expectedException coding_exception
* Tests getting the stage providing an invalid time reference.
*/
public function test_getstage_invalidtime() {
$outage = new outage();
$this->set_expected_exception(coding_exception::class);
$outage->get_stage(-1);
}
/**
* Tests is_ongoing() with different outage stages.
*/
public function test_isongoing() {
$now = time();
@@ -120,6 +144,9 @@ class outage_test extends basic_testcase {
self::assertFalse($outage->is_ongoing($now));
}
/**
* Tests is_active() with different outage stages.
*/
public function test_isactive() {
$now = time();
@@ -164,6 +191,9 @@ class outage_test extends basic_testcase {
self::assertFalse($outage->is_active($now));
}
/**
* Tests different outage stages.
*/
public function test_stages() {
$now = time();
@@ -236,6 +266,9 @@ class outage_test extends basic_testcase {
self::assertTrue($outage->has_ended());
}
/**
* Tests if getting title and description replaces the placeholders.
*/
public function test_gettitle_getdescription() {
$now = time();
$outage = new outage([
@@ -254,6 +287,9 @@ class outage_test extends basic_testcase {
self::assertNotContains('}', $description);
}
/**
* Tests getting the durations.
*/
public function test_getdurations() {
$outage = new outage(['starttime' => 1000]);
self::assertNull($outage->get_duration_actual());

View File

@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* outagelib_test test class.
*
* @package auth_outage
* @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
*/
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
use auth_outage\local\outagelib;
@@ -21,7 +30,7 @@ use auth_outage\local\outagelib;
defined('MOODLE_INTERNAL') || die();
/**
* Tests performed on outagelib class.
* outagelib_test test class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
@@ -29,6 +38,9 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class outagelib_test extends advanced_testcase {
/**
* Check if maintenance message is disabled as needed.
*/
public function test_maintenancemessage() {
$this->resetAfterTest(true);
static::setAdminUser();
@@ -50,6 +62,9 @@ class outagelib_test extends advanced_testcase {
phpunit_util::reset_debugging();
}
/**
* Check if maintenance later is removed if no outage set.
*/
public function test_maintenancelater_nonext() {
$this->resetAfterTest(true);
set_config('maintenance_later', time() + (60 * 60 * 24 * 7)); // In 1 week.
@@ -58,6 +73,9 @@ class outagelib_test extends advanced_testcase {
self::assertEmpty(get_config('moodle', 'maintenance_later'));
}
/**
* Check outagelib::inject() works as expected.
*/
public function test_inject() {
global $CFG;
@@ -85,6 +103,9 @@ class outagelib_test extends advanced_testcase {
self::assertSame($size, strlen($CFG->additionalhtmltopofbody));
}
/**
* Check outagelib::inject() will not break the page if something goes wrong.
*/
public function test_inject_broken() {
$_GET = ['auth_outage_break_code' => '1'];
outagelib::reinject();
@@ -92,6 +113,9 @@ class outagelib_test extends advanced_testcase {
phpunit_util::reset_debugging();
}
/**
* Check if injection works with preview.
*/
public function test_inject_preview() {
global $CFG;
$this->resetAfterTest(true);
@@ -114,6 +138,9 @@ class outagelib_test extends advanced_testcase {
self::assertContains('<script>', $CFG->additionalhtmltopofbody);
}
/**
* Check if injection works with invalid preview without stopping the page.
*/
public function test_inject_preview_notfound() {
global $CFG;
self::assertEmpty($CFG->additionalhtmltopofbody);
@@ -123,6 +150,9 @@ class outagelib_test extends advanced_testcase {
self::assertEmpty($CFG->additionalhtmltopofbody);
}
/**
* Test injection with preview and delta.
*/
public function test_inject_preview_withdelta() {
global $CFG;
$this->resetAfterTest(true);
@@ -144,10 +174,16 @@ class outagelib_test extends advanced_testcase {
self::assertEmpty($CFG->additionalhtmltopofbody);
}
/**
* Test injection without active outage.
*/
public function test_inject_noactive() {
outagelib::reinject();
}
/**
* Check if get config works without getting defaults.
*/
public function test_get_config() {
$this->resetAfterTest(true);
$keys = [
@@ -158,7 +194,7 @@ class outagelib_test extends advanced_testcase {
'default_title',
'default_warning_duration',
];
// Set config with invalid values.
// Set config with values.
foreach ($keys as $k) {
set_config($k, $k.'_value', 'auth_outage');
}
@@ -169,6 +205,9 @@ class outagelib_test extends advanced_testcase {
}
}
/**
* Check if get config works getting defaults when needed.
*/
public function test_get_config_invalid() {
$this->resetAfterTest(true);
// Set config with invalid values.

View File

@@ -28,7 +28,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = "auth_outage";
$plugin->version = 2016100300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = '1.0.0'; // Human-readable release information.
$plugin->version = 2016100400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = '1.0.1'; // Human-readable release information.
$plugin->requires = 2014051200; // Requires Moodle 2.7 or later. Moodle 2.9 or later recommended.
$plugin->maturity = MATURITY_STABLE; // Not suitable for PRODUCTION environments yet!