-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
054c3aa
commit 1a5fca3
Showing
8 changed files
with
243 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Internal library of functions for the townsquaresupport plugin | ||
* | ||
* @package local_townsquaresupport | ||
* @copyright 2024 Tamaro Walter | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace local_townsquaresupport; | ||
|
||
/** | ||
* Helper function for townsquaresupport_get_subplugin_events, that checks if an amount | ||
* of events have all the required attributes from the townsquaresupport interface. | ||
* | ||
* @param array $subevents | ||
* @return int | ||
*/ | ||
function townsquaresupport_check_subplugin_events($subevents): int { | ||
if (!gettype($subevents == 'array')) { | ||
return false; | ||
} | ||
|
||
if ($subevents == []) { | ||
// If no events are available, then everything is okay. | ||
return true; | ||
} else { | ||
|
||
// Check every event. | ||
foreach ($subevents as $event) { | ||
if (gettype($event) != 'object') { | ||
return false; | ||
} | ||
|
||
// Check if all variables are set. | ||
$issetcheck = townsquaresupport_check_isset($event, 'courseid') && | ||
townsquaresupport_check_isset($event, 'modulename') && | ||
townsquaresupport_check_isset($event, 'instancename') && | ||
townsquaresupport_check_isset($event, 'content') && | ||
townsquaresupport_check_isset($event, 'timestart') && | ||
townsquaresupport_check_isset($event, 'coursemoduleid') && | ||
townsquaresupport_check_isset($event, 'eventtype'); | ||
|
||
if (!$issetcheck) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Helper function for check_subplugin_events function that proves if a variable is set in an array. | ||
* | ||
* @param array $event Event that is checked. | ||
* @param string $variablename Name of the variable | ||
* @return bool | ||
*/ | ||
function townsquaresupport_check_isset($event, $variablename): bool { | ||
return isset($event->$variablename); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Unit tests for the local_townsquaresupport. | ||
* | ||
* @package local_townsquaresupport | ||
* @copyright 2024 Tamaro Walter | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace local_townsquaresupport; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
global $CFG; | ||
require_once($CFG->dirroot . '/local/townsquaresupport/locallib.php'); | ||
|
||
/** | ||
* PHPUnit tests for testing the logic of proving if subplugin events satisfy the requirements of the townsquaresupport interface. | ||
* | ||
* @package local_townsquaresupport | ||
* @copyright 2024 Tamaro Walter | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* | ||
* @covers ::\local_townsquaresupport\townsquaresupport_check_subplugin_events() | ||
*/ | ||
final class eventcheck_test extends \advanced_testcase { | ||
|
||
// Attributes. | ||
|
||
/** @var object The data that will be used for testing */ | ||
private $testdata; | ||
|
||
|
||
// Construct functions. | ||
|
||
public function setUp(): void { | ||
$this->testdata = new \stdClass(); | ||
$this->resetAfterTest(); | ||
$this->helper_test_set_up(); | ||
} | ||
|
||
public function tearDown(): void { | ||
$this->testdata = null; | ||
} | ||
|
||
// Tests. | ||
|
||
/** | ||
* Test, if the check_subplugin_events function works correctly. | ||
* @return void | ||
*/ | ||
public function test_checkevents(): void { | ||
// Test the subevents. | ||
$this->assertEquals(false, townsquaresupport_check_subplugin_events($this->testdata->subevents1)); | ||
$this->assertEquals(false, townsquaresupport_check_subplugin_events($this->testdata->subevents2)); | ||
$this->assertEquals(true, townsquaresupport_check_subplugin_events($this->testdata->subevents3)); | ||
$this->assertEquals(false, townsquaresupport_check_subplugin_events($this->testdata->subevents4)); | ||
} | ||
|
||
// Helper functions. | ||
|
||
/** | ||
* Helper function that sets up the testdata. | ||
* @return void | ||
*/ | ||
private function helper_test_set_up(): void { | ||
// Build different arrays of events that are incorrect (and one correct array). | ||
|
||
// First incorrect event: variable 'content' is missing. | ||
$incorrecteevent1 = ['courseid' => 12, 'modulename' => 'pluginname', 'instancename' => 'instance1', | ||
'timestart' => 123456789, 'coursemoduleid' => 13, 'eventtype' => 'eventtypeone', ]; | ||
|
||
// Second incorrect event: variable 'courseid' is not a integer. | ||
$incorrecteevent2 = ['courseid' => '6', 'modulename' => 'pluginname', 'instancename' => 'instance1', 'content' => 'hello', | ||
'timestart' => 123456789, 'coursemoduleid' => 13, 'eventtype' => 'eventtypeone', ]; | ||
|
||
// Two completely correct events. | ||
$correctevent1 = ['courseid' => 12, 'modulename' => 'pluginname', 'instancename' => 'instance1', 'content' => 'hello', | ||
'timestart' => 123456789, 'coursemoduleid' => 13, 'eventtype' => 'eventtypeone', ]; | ||
|
||
$correctevent2 = ['courseid' => 15, 'modulename' => 'pluginname', 'instancename' => 'instance2', 'content' => 'bye', | ||
'timestart' => 123456787, 'coursemoduleid' => 16, 'eventtype' => 'eventtypeone', ]; | ||
|
||
// Build different combinations of the events. | ||
$this->testdata->subevents1 = [$incorrecteevent1, $correctevent1]; | ||
$this->testdata->subevents2 = [$incorrecteevent2, $correctevent2]; | ||
$this->testdata->subevents3 = [$correctevent1, $correctevent2]; | ||
$this->testdata->subevents4 = ['arraykey' => 'incorrectsubevent']; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="lib/phpunit/phpunit.xsd" | ||
bootstrap="lib/phpunit/bootstrap.php" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
cacheResult="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
beStrictAboutTestsThatDoNotTestAnything="false" | ||
beStrictAboutOutputDuringTests="true" | ||
> | ||
|
||
<php> | ||
<!--<const name="PHPUNIT_LONGTEST" value="1"/> uncomment to execute also slow or otherwise expensive tests--> | ||
<const name="PHPUNIT_SEQUENCE_START" value="195000"/> | ||
|
||
<!--Following constants instruct tests to fetch external test files from alternative location | ||
or skip tests if empty, clone https://github.com/moodlehq/moodle-exttests to local web server--> | ||
<!--<const name="TEST_EXTERNAL_FILES_HTTP_URL" value="http://download.moodle.org/unittest"/> | ||
uncomment and alter to fetch external test files from alternative location--> | ||
<!--<const name="TEST_EXTERNAL_FILES_HTTPS_URL" value="https://download.moodle.org/unittest"/> | ||
uncomment and alter to fetch external test files from alternative location--> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="local_townsquaresupport_testsuite"> | ||
<directory suffix="_test.php">local/townsquaresupport/tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
</phpunit> |