From cbbb861fd808051040061447c8ae11254492f8f8 Mon Sep 17 00:00:00 2001 From: Daniel Thee Roperto Date: Mon, 12 Sep 2016 17:52:08 +1000 Subject: [PATCH] Issue #8 - Fixed failing phpunit tests. --- classes/outagedb.php | 12 +++++++++--- tests/outagedb_test.php | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/classes/outagedb.php b/classes/outagedb.php index 85da1d9..260f4a6 100644 --- a/classes/outagedb.php +++ b/classes/outagedb.php @@ -16,6 +16,12 @@ namespace auth_outage; +if (!defined('MOODLE_INTERNAL')) { + die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. +} + +require_once($CFG->dirroot . '/calendar/lib.php'); + use auth_outage\models\outage; /** @@ -245,7 +251,7 @@ class outagedb { $event = self::calendar_load($outage->id); if (is_null($event)) { - debugging('Cannot update calendar entry for outage #'.$outage->id.', event not found. Creating it...'); + debugging('Cannot update calendar entry for outage #' . $outage->id . ', event not found. Creating it...'); self::calendar_create($outage); } else { $event->update(self::calendar_data($outage)); @@ -257,8 +263,8 @@ class outagedb { // If not found (was not created before) ignore it. if (is_null($event)) { - debugging('Cannot delete calendar entry for outage #'.$outageid.', event not found. Ignoring it...'); - }else{ + debugging('Cannot delete calendar entry for outage #' . $outageid . ', event not found. Ignoring it...'); + } else { $event->delete(); } } diff --git a/tests/outagedb_test.php b/tests/outagedb_test.php index d00112f..adb83b3 100644 --- a/tests/outagedb_test.php +++ b/tests/outagedb_test.php @@ -30,6 +30,14 @@ defined('MOODLE_INTERNAL') || die(); class outagedb_test extends advanced_testcase { + /** + * Ensure DB tests run as admin. + */ + public function setUp() { + parent::setUp(); + $this->setAdminUser(); + } + /** * Creates an array of ids in from the given outages array. * @param $outages