-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Poet - Completing the event restructuring.
- Loading branch information
Mike Churchward
committed
Apr 24, 2019
1 parent
ba47b58
commit c660e72
Showing
20 changed files
with
711 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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/>. | ||
|
||
/** | ||
* @package local_metadata | ||
* @subpackage metadatacontext_category | ||
* @author Mike Churchward <mike.churchward@poetopensource.org> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @copyright 2017, onwards Poet | ||
*/ | ||
|
||
namespace metadatacontext_category; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Local metadatacontext_category event handler. | ||
*/ | ||
class observer { | ||
/** | ||
* Triggered via course_category_deleted event. | ||
* - Removes category metadata | ||
* | ||
* @param \core\event\course_category_deleted $event | ||
* @return bool true on success | ||
*/ | ||
public static function course_category_deleted(\core\event\course_category_deleted $event) { | ||
return \local_metadata\observer::delete_metadata(CONTEXT_COURSECAT, $event->objectid); | ||
} | ||
} |
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,31 @@ | ||
<?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/>. | ||
|
||
/** | ||
* @package local_metadata | ||
* @subpackage metadatacontext_category | ||
* @author Mike Churchward <mike.churchward@poetopensource.org> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @copyright 2017, onwards Poet | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die; | ||
|
||
$observers = [ | ||
['eventname' => '\core\event\course_category_deleted', | ||
'callback' => '\metadatacontext_category\observer::course_category_deleted' | ||
], | ||
]; |
79 changes: 79 additions & 0 deletions
79
context/category/tests/metadatacontext_category_event_test.php
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,79 @@ | ||
<?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/>. | ||
|
||
/** | ||
* @package local_metadata | ||
* @subpackage metadatacontext_category | ||
* @author Mike Churchward <mike.churchward@poetopensource.org> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @copyright 2017, onwards Poet | ||
*/ | ||
|
||
/** | ||
* Test class for course category metadatacontext events. | ||
* | ||
* @package local_metadata | ||
* @subpackage metadatacontext_category | ||
* @copyright 2017, onwards Poet | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* @group local_metadata | ||
* @group metadatacontext_category | ||
*/ | ||
class metadatacontext_category_event_testcase extends local_metadataevent_testcase { | ||
|
||
/** | ||
* Setup tasks. | ||
*/ | ||
public function setUp() { | ||
$this->category = []; | ||
$this->category[] = $this->getDataGenerator()->create_category(); | ||
$this->category[] = $this->getDataGenerator()->create_category(); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* Performs unit tests for category deleted event. | ||
*/ | ||
public function test_categorydeleted() { | ||
global $DB; | ||
|
||
$this->resetAfterTest(true); | ||
|
||
// Create a custom field of textarea type. | ||
$id1 = $this->generator->create_metadata_field(CONTEXT_COURSECAT, 'frogdesc', 'Description of frog'); | ||
$this->generator->create_metadata($id1, $this->category[0]->id, 'Leopard frog'); | ||
$this->generator->create_metadata($id1, $this->category[1]->id, 'Bullfrog'); | ||
|
||
// Confirm expected data. | ||
$this->assertEquals(1, $DB->count_records('local_metadata_field')); | ||
$this->assertEquals(2, $DB->count_records('local_metadata')); | ||
$this->assertEquals(1, $DB->count_records('local_metadata', ['instanceid' => $this->category[0]->id])); | ||
|
||
// Deleting the course should trigger the event. | ||
$this->category[0]->delete_full(); | ||
|
||
// Check the field data has been deleted. | ||
$this->assertEquals(1, $DB->count_records('local_metadata_field')); | ||
$this->assertEquals(1, $DB->count_records('local_metadata')); | ||
$this->assertEquals(0, $DB->count_records('local_metadata', ['instanceid' => $this->category[0]->id])); | ||
} | ||
} |
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,43 @@ | ||
<?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/>. | ||
|
||
/** | ||
* @package local_metadata | ||
* @subpackage metadatacontext_cohort | ||
* @author Mike Churchward <mike.churchward@poetopensource.org> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @copyright 2017, onwards Poet | ||
*/ | ||
|
||
namespace metadatacontext_cohort; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Local metadatacontext_cohort event handler. | ||
*/ | ||
class observer { | ||
/** | ||
* Triggered via cohort_deleted event. | ||
* - Removes cohort metadata | ||
* | ||
* @param \core\event\cohort_deleted $event | ||
* @return bool true on success | ||
*/ | ||
public static function cohort_deleted(\core\event\cohort_deleted $event) { | ||
return \local_metadata\observer::delete_metadata(CONTEXT_COHORT, $event->objectid); | ||
} | ||
} |
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,31 @@ | ||
<?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/>. | ||
|
||
/** | ||
* @package local_metadata | ||
* @subpackage metadatacontext_cohort | ||
* @author Mike Churchward <mike.churchward@poetopensource.org> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @copyright 2017, onwards Poet | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die; | ||
|
||
$observers = [ | ||
['eventname' => '\core\event\cohort_deleted', | ||
'callback' => '\metadatacontext_cohort\observer::cohort_deleted' | ||
], | ||
]; |
80 changes: 80 additions & 0 deletions
80
context/cohort/tests/metadatacontext_cohort_event_test.php
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,80 @@ | ||
<?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/>. | ||
|
||
/** | ||
* @package local_metadata | ||
* @subpackage metadatacontext_cohort | ||
* @author Mike Churchward <mike.churchward@poetopensource.org> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @copyright 2017, onwards Poet | ||
*/ | ||
|
||
/** | ||
* Test class for cohort metadatacontext events. | ||
* | ||
* @package local_metadata | ||
* @subpackage metadatacontext_cohort | ||
* @copyright 2017, onwards Poet | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* @group local_metadata | ||
* @group metadatacontext_cohort | ||
*/ | ||
class metadatacontext_cohort_event_testcase extends local_metadataevent_testcase { | ||
|
||
/** | ||
* Setup tasks. | ||
*/ | ||
public function setUp() { | ||
$this->cohort = []; | ||
$this->cohort[] = $this->getDataGenerator()->create_cohort(); | ||
$this->cohort[] = $this->getDataGenerator()->create_cohort(); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* Performs unit tests for cohort deleted event. | ||
*/ | ||
public function test_cohortdeleted() { | ||
global $DB, $CFG; | ||
require_once($CFG->dirroot . '/local/metadata/context/cohort/classes/context_handler.php'); | ||
|
||
$this->resetAfterTest(true); | ||
|
||
// Create a custom field of textarea type. | ||
$id1 = $this->generator->create_metadata_field(CONTEXT_COHORT, 'frogdesc', 'Description of frog'); | ||
$this->generator->create_metadata($id1, $this->cohort[0]->id, 'Leopard frog'); | ||
$this->generator->create_metadata($id1, $this->cohort[1]->id, 'Bullfrog'); | ||
|
||
// Confirm expected data. | ||
$this->assertEquals(1, $DB->count_records('local_metadata_field')); | ||
$this->assertEquals(2, $DB->count_records('local_metadata')); | ||
$this->assertEquals(1, $DB->count_records('local_metadata', ['instanceid' => $this->cohort[0]->id])); | ||
|
||
// Deleting the cohort should trigger the event. | ||
cohort_delete_cohort($this->cohort[0]); | ||
|
||
// Check the field data has been deleted. | ||
$this->assertEquals(1, $DB->count_records('local_metadata_field')); | ||
$this->assertEquals(1, $DB->count_records('local_metadata')); | ||
$this->assertEquals(0, $DB->count_records('local_metadata', ['instanceid' => $this->cohort[0]->id])); | ||
} | ||
} |
Oops, something went wrong.