Version 1.0.2 - Updated code standards to comply with Moodle CI Bot checks.

This commit is contained in:
Daniel Thee Roperto
2016-10-12 15:04:30 +11:00
parent c7b0cc2410
commit 50689c3b4c
18 changed files with 99 additions and 114 deletions

View File

@@ -60,7 +60,6 @@ class auth_plugin_outage extends auth_plugin_base {
* @param string $username Not used in this plugin.
* @param string $password Not used in this plugin.
* @return bool False
* @SuppressWarnings("unused")
*/
public function user_login($username, $password) {
return false;

View File

@@ -57,7 +57,6 @@ class calendar {
/**
* Updates an event on the calendar based on this outage.
* @param outage $outage Outage to be updated in the calendar.
* @SuppressWarnings("comment") Allow this test to have as many tests as necessary.
*/
public static function update(outage $outage) {
$event = self::load($outage->id);

View File

@@ -48,7 +48,6 @@ abstract class baseform extends moodleform {
* pass true here to override this behaviour
*
* @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.
*/
public function validate_defined_fields($validateonnosubmit = false) {
// One validation NOT is enough (if mocking). See parent method.

View File

@@ -137,7 +137,7 @@ class outage {
// Load data from array.
foreach ($data as $k => $v) {
if (property_exists(self::class, $k)) {
if (property_exists($this, $k)) {
$this->$k = $v;
}
}

View File

@@ -39,7 +39,6 @@ require_once(__DIR__.'/../../../../lib/behat/behat_base.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings("public") Allow this test to have as many tests as necessary.
*/
class behat_auth_outage extends behat_base {
/**

View File

@@ -31,22 +31,29 @@ defined('MOODLE_INTERNAL') || die();
/**
* calendar_test test class.
*
* We are using static variables instead of test dependencies as the
* annotation 'depends' is not accepted in moodle checker.
*
* @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
*/
class calendar_test extends advanced_testcase {
/**
* @var outage|null The calendar entry owner.
*/
private static $outage = null;
/**
* Creates an outage and checks if its in the calendar.
* @return outage Created outage.
*/
public function test_create() {
self::setAdminUser();
$this->resetAfterTest(false);
$time = time();
$outage = new outage([
self::$outage = new outage([
'id' => 1,
'autostart' => false,
'warntime' => $time - 100,
@@ -55,40 +62,31 @@ class calendar_test extends advanced_testcase {
'title' => 'Title',
'description' => 'Description',
]);
calendar::create($outage);
$this->check_calendar($outage);
return $outage;
calendar::create(self::$outage);
$this->check_calendar(self::$outage);
}
/**
* 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) {
public function test_update() {
self::setAdminUser();
$this->resetAfterTest(false);
$outage->title = 'New Title';
calendar::update($outage);
$this->check_calendar($outage);
return $outage;
self::$outage->title = 'New Title';
calendar::update(self::$outage);
$this->check_calendar(self::$outage);
}
/**
* Deletes an outage and checks the calendar.
* @depends test_update
* @param outage $outage Outage to delete.
*/
public function test_delete($outage) {
public function test_delete() {
self::setAdminUser();
$this->resetAfterTest(true);
calendar::delete($outage->id);
self::assertNull(calendar::load($outage->id));
calendar::delete(self::$outage->id);
self::assertNull(calendar::load(self::$outage->id));
}
/**
@@ -127,14 +125,13 @@ class calendar_test extends advanced_testcase {
/**
* 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);
self::assertSame($outage->description, $calendar->description);
private function check_calendar() {
$calendar = calendar::load(self::$outage->id);
self::assertSame(self::$outage->title, $calendar->name);
self::assertSame(self::$outage->description, $calendar->description);
self::assertSame('auth_outage', $calendar->eventtype);
self::assertEquals($outage->starttime, $calendar->timestart);
self::assertEquals($outage->get_duration_planned(), $calendar->timeduration);
self::assertEquals(self::$outage->starttime, $calendar->timestart);
self::assertEquals(self::$outage->get_duration_planned(), $calendar->timeduration);
}
}

View File

@@ -21,7 +21,6 @@
* @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.
*/
use auth_outage\dml\outagedb;
@@ -37,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 this test to have as many tests as necessary.
*/
class outagedb_test extends auth_outage_base_testcase {
/**
@@ -358,7 +356,7 @@ class outagedb_test extends auth_outage_base_testcase {
*/
public function test_getbyid_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
outagedb::get_by_id(-1);
}
@@ -367,7 +365,7 @@ class outagedb_test extends auth_outage_base_testcase {
*/
public function test_delete_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
outagedb::delete(-1);
}
@@ -376,7 +374,7 @@ class outagedb_test extends auth_outage_base_testcase {
*/
public function test_getactive_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
outagedb::get_active(-1);
}
@@ -385,7 +383,7 @@ class outagedb_test extends auth_outage_base_testcase {
*/
public function test_getallunended_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
outagedb::get_all_unended(-1);
}
@@ -402,7 +400,7 @@ class outagedb_test extends auth_outage_base_testcase {
*/
public function test_getallended_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
outagedb::get_all_ended(-1);
}
@@ -419,7 +417,7 @@ class outagedb_test extends auth_outage_base_testcase {
*/
public function test_finish_invalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
outagedb::finish(1, -1);
}
@@ -460,7 +458,7 @@ class outagedb_test extends auth_outage_base_testcase {
*/
public function test_getnextstartinginvalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
outagedb::get_next_starting(-1);
}
@@ -469,7 +467,7 @@ class outagedb_test extends auth_outage_base_testcase {
*/
public function test_getnextautostartinginvalid() {
$this->resetAfterTest(true);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
outagedb::get_next_autostarting(-1);
}

View File

@@ -31,12 +31,25 @@ defined('MOODLE_INTERNAL') || die();
/**
* events_test tests class.
*
* We are using static variables instead of test dependencies as the
* annotation 'depends' is not accepted in moodle checker.
*
* @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
*/
class events_test extends advanced_testcase {
/**
* @var outage|null Outage used in the tests.
*/
private static $outage = null;
/**
* @var stdClass|null Data for the created event.
*/
private static $event = null;
/**
* Saves an outage and check if the event was created.
* @return array With the outage id and the event id.
@@ -48,79 +61,69 @@ class events_test extends advanced_testcase {
// Save new outage.
$now = time();
$id = outagedb::save(new outage([
$outage = new outage([
'autostart' => false,
'warntime' => $now - 60,
'starttime' => 60,
'stoptime' => 120,
'title' => 'Title',
'description' => 'Description',
]));
]);
$outage->id = outagedb::save($outage);
self::$outage = $outage;
// Check existance.
$event = $DB->get_record_select(
self::$event = $DB->get_record_select(
'event',
"(eventtype = 'auth_outage' AND instance = :outageid)",
['outageid' => $id],
['outageid' => self::$outage->id],
'id',
IGNORE_MISSING
);
self::assertTrue(is_object($event));
// Another test will use it.
return [$id, $event->id];
self::assertTrue(is_object(self::$event));
}
/**
* 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(array $ids) {
public function test_update() {
global $DB;
self::setAdminUser();
$this->resetAfterTest(false);
list($idoutage, $idevent) = $ids;
$outage = outagedb::get_by_id($idoutage);
$outage->starttime += 10;
outagedb::save($outage);
self::$outage->starttime += 10;
outagedb::save(self::$outage);
// Should still exist.
$event = $DB->get_record_select(
'event',
"(eventtype = 'auth_outage' AND instance = :idoutage)",
['idoutage' => $idoutage],
['idoutage' => self::$outage->id],
'id',
IGNORE_MISSING
);
self::assertTrue(is_object($event));
self::assertSame($idevent, $event->id);
return $ids;
self::assertSame(self::$event->id, $event->id);
self::$event = $event;
}
/**
* 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) {
public function test_delete() {
global $DB;
self::setAdminUser();
$this->resetAfterTest(true);
list($idoutage, $idevent) = $ids;
outagedb::delete($idoutage);
outagedb::delete(self::$outage->id);
// Should not exist.
$event = $DB->get_record_select(
'event',
"(eventtype = 'auth_outage' AND instance = :idoutage) OR (id = :idevent)",
['idoutage' => $idoutage, 'idevent' => $idevent],
['idoutage' => self::$outage->id, 'idevent' => self::$event->id],
'id',
IGNORE_MISSING
);

View File

@@ -62,7 +62,7 @@ class forms_test extends auth_outage_base_testcase {
$edit = new edit();
self::assertFalse($edit->is_cancelled());
$outage = $edit->get_data();
self::assertInstanceOf(outage::class, $outage);
self::assertInstanceOf('\\auth_outage\\local\\outage', $outage);
self::assertSame(false, $outage->autostart);
self::assertSame(60, $outage->get_warning_duration());
self::assertSame(mktime(14, 15, 0, 2, 1, 2013), $outage->starttime);
@@ -147,7 +147,7 @@ class forms_test extends auth_outage_base_testcase {
*/
public function test_setdata_invalid() {
$edit = new edit();
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
$edit->set_data(null);
}

View File

@@ -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")
*/
class cli_test extends auth_outage_cli_testcase {
/**
@@ -71,7 +70,7 @@ class cli_test extends auth_outage_cli_testcase {
public function test_setreferencetime_invalid() {
$this->set_parameters(['--start=60']);
$cli = new create();
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
$cli->set_referencetime(-1);
}

View File

@@ -83,6 +83,6 @@ abstract class auth_outage_cli_testcase extends auth_outage_base_testcase {
* @param int $errorcode Error code.
*/
protected function set_expected_cli_exception($errorcode) {
$this->set_expected_exception(cli_exception::class, null, $errorcode);
$this->set_expected_exception('\\auth_outage\\local\\cli\\cli_exception', null, $errorcode);
}
}

View File

@@ -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 this test to have as many tests as necessary.
*/
class create_test extends auth_outage_cli_testcase {
/**
@@ -309,7 +308,7 @@ class create_test extends auth_outage_cli_testcase {
*/
public function test_setdefaults_extra() {
$cli = new create([]);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
$cli->set_defaults(['aninvalidparameter' => 'value']);
}

View File

@@ -21,7 +21,6 @@
* @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")
*/
use auth_outage\dml\outagedb;
@@ -39,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")
*/
class waitforit_test extends auth_outage_cli_testcase {
/**

View File

@@ -38,7 +38,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 this test to have as many tests as necessary.
*/
class infopagecontroller_test extends auth_outage_base_testcase {
/**
@@ -83,7 +82,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
new infopage(['id' => 2, 'outage' => $outage]);
}
@@ -91,7 +90,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
* Tests the constructor with an invalid outage.
*/
public function test_constructor_invalidoutage() {
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
new infopage(['outage' => 'My outage']);
}
@@ -164,7 +163,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
* Tests infopage::find_outageid_from_infopage() with an invalid parameter.
*/
public function test_findoutageid_notstring() {
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
infopage::find_outageid_from_infopage(new stdClass());
}
@@ -183,7 +182,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
* Tests infopage::save_static_page() with an invalid parameter.
*/
public function test_savestaticpage_filenotstring() {
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
infopage::save_static_page(new outage(), 1);
}
@@ -201,7 +200,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
'description' => 'Description',
]);
$this->set_expected_exception(file_exception::class);
$this->set_expected_exception('file_exception');
infopage::save_static_page($outage, $CFG->dataroot.'/someinvalidpath/someinvalidfile');
}
@@ -209,7 +208,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
* Tests infopage::test_sanity_notstring() with invalid contents: an int.
*/
public function test_sanity_notstring() {
$this->set_expected_exception(invalid_state_exception::class);
$this->set_expected_exception('invalid_state_exception');
infopage::save_static_page_sanitycheck(404);
}
@@ -217,7 +216,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
* Tests infopage::test_sanity_notstring() with invalid contents: an empty string.
*/
public function test_sanity_empty() {
$this->set_expected_exception(invalid_state_exception::class);
$this->set_expected_exception('invalid_state_exception');
infopage::save_static_page_sanitycheck(' ');
}
@@ -225,7 +224,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
* Tests infopage::test_sanity_notstring() with invalid contents: an empty HTML.
*/
public function test_sanity_clearhtml() {
$this->set_expected_exception(invalid_state_exception::class);
$this->set_expected_exception('invalid_state_exception');
infopage::save_static_page_sanitycheck('<html><head></head><body><b> <!-- Nothing --> </b></body></html>');
}
@@ -275,7 +274,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
* Tests updating the static page with an invalid filename.
*/
public function test_updatestaticpage_invalidfile() {
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
infopage::update_static_page(123);
}
@@ -303,7 +302,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
public function test_output_static_nooutage() {
$info = new infopage(['static' => true]);
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
$info->output();
}
@@ -312,7 +311,7 @@ class infopagecontroller_test extends auth_outage_base_testcase {
*/
public function test_output_nonstatic_nooutage() {
$info = new infopage(['static' => false]);
$this->set_expected_exception(moodle_exception::class);
$this->set_expected_exception('moodle_exception');
$info->output();
}

View File

@@ -78,7 +78,7 @@ class outage_test extends auth_outage_base_testcase {
* Tests the constructor with invalid data.
*/
public function test_constructor_invalid() {
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
new outage('My outage');
}
@@ -103,7 +103,7 @@ class outage_test extends auth_outage_base_testcase {
*/
public function test_getstage_invalidtime() {
$outage = new outage();
$this->set_expected_exception(coding_exception::class);
$this->set_expected_exception('coding_exception');
$outage->get_stage(-1);
}

View File

@@ -28,7 +28,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = "auth_outage";
$plugin->version = 2016100400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = '1.0.1'; // Human-readable release information.
$plugin->version = 2016101200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = '1.0.2'; // 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!
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!

View File

@@ -1,5 +1,6 @@
var auth_outage_warningbar = {
init: function (params) {
/* exported authOutageWarningBar */
var authOutageWarningBar = {
init: function(params) {
this.preview = params.preview;
this.countdown = params.countdown;
this.ongoing = params.ongoing;
@@ -18,7 +19,7 @@ var auth_outage_warningbar = {
this.startWarning();
},
startWarning: function () {
startWarning: function() {
if (this.finishbutton) {
this.finishbutton.style.display = 'none';
}
@@ -26,7 +27,7 @@ var auth_outage_warningbar = {
this.tickWarning();
},
tickWarning: function () {
tickWarning: function() {
var elapsed = Math.round((Date.now() - this.clienttime) / 1000);
var missing = (this.starts - this.servertime) - elapsed;
@@ -39,13 +40,13 @@ var auth_outage_warningbar = {
this.divtext.innerHTML = this.countdown.replace('{{countdown}}', this.seconds2hms(missing));
var $this = this;
setTimeout(function () {
setTimeout(function() {
$this.tickWarning();
}, 1000);
}
},
startOngoing: function () {
startOngoing: function() {
this.divblock.className = 'auth_outage_ongoing_period';
if (this.finishbutton) {
this.finishbutton.style.display = '';
@@ -54,7 +55,7 @@ var auth_outage_warningbar = {
this.tickOngoing();
},
tickOngoing: function () {
tickOngoing: function() {
if (this.finished) {
return;
}
@@ -63,8 +64,7 @@ var auth_outage_warningbar = {
// If one second before finish time, enfore finish. Otherwise, never finish it.
if (this.servertime === this.stops - 1) {
this.finish();
}
else {
} else {
return;
}
}
@@ -72,7 +72,7 @@ var auth_outage_warningbar = {
var $this = this;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
xmlhttp.onreadystatechange = function() {
$this.ajaxCheckFinished(this);
};
xmlhttp.open("GET", this.checkfinishedurl, true);
@@ -82,17 +82,16 @@ var auth_outage_warningbar = {
var sleepSeconds = this.stops - estimatedServerTime; // How long to sleep until it stops.
if (sleepSeconds <= 0) {
sleepSeconds = 5; // It should be back, keep checking every 5 seconds.
}
else {
} else {
sleepSeconds = Math.min(sleepSeconds, (5 * 60)); // Check at least every 5 minutes.
}
setTimeout(function () {
setTimeout(function() {
$this.tickOngoing();
}, sleepSeconds * 1000);
},
ajaxCheckFinished: function (ajax) {
ajaxCheckFinished: function(ajax) {
if (ajax.readyState === XMLHttpRequest.DONE) {
if (ajax.status === 200) {
if (ajax.responseText.trim() === 'finished') {
@@ -102,7 +101,7 @@ var auth_outage_warningbar = {
}
},
finish: function () {
finish: function() {
this.finished = true;
this.divblock.className = 'auth_outage_finished_period';
if (this.finishbutton) {
@@ -112,7 +111,7 @@ var auth_outage_warningbar = {
this.divtitle.innerHTML = this.backonlinedescription;
},
seconds2hms: function (seconds) {
seconds2hms: function(seconds) {
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
seconds %= 60;
@@ -127,6 +126,3 @@ var auth_outage_warningbar = {
return hours + ':' + minutes + ':' + seconds;
}
};
// auth_outage_countdown is used outside this js file.
/* jshint unused:false */

View File

@@ -87,7 +87,7 @@ echo html_writer::tag('style', outagelib::get_config()->css);
'preview' => $viewbag['preview'],
'checkfinishedurl' => (string)(new moodle_url('/auth/outage/checkfinished.php')),
]);
echo 'auth_outage_warningbar.init('.$json.');';
echo 'authOutageWarningBar.init('.$json.');';
?>
</script>
<?php endif;