mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
Merge branch 'MDL-61759-master-nonexistinghandler' of git://github.com/mudrd8mz/moodle
This commit is contained in:
commit
0683abccfc
@ -61,10 +61,17 @@ class manager {
|
||||
*/
|
||||
public function get_handler_classname() {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($CFG->sitepolicyhandler)) {
|
||||
$sitepolicyhandlers = $this->get_all_handlers();
|
||||
$classname = $sitepolicyhandlers[$CFG->sitepolicyhandler];
|
||||
return $classname;
|
||||
|
||||
if (!isset($sitepolicyhandlers[$CFG->sitepolicyhandler])) {
|
||||
return default_handler::class;
|
||||
|
||||
} else {
|
||||
return $sitepolicyhandlers[$CFG->sitepolicyhandler];
|
||||
}
|
||||
|
||||
} else {
|
||||
return default_handler::class;
|
||||
}
|
||||
|
@ -37,6 +37,29 @@ global $CFG;
|
||||
*/
|
||||
class sitepolicy_test extends advanced_testcase {
|
||||
|
||||
|
||||
/**
|
||||
* Tests for \core_privacy\local\sitepolicy\manager::get_handler_classname() behaviour.
|
||||
*/
|
||||
public function test_get_handler_classname() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$manager = $this->get_mock_manager_with_handler();
|
||||
|
||||
// If no handler is specified, then we should get the default one.
|
||||
$CFG->sitepolicyhandler = '';
|
||||
$this->assertEquals($manager->get_handler_classname(), \core_privacy\local\sitepolicy\default_handler::class);
|
||||
|
||||
// If non-existing handler is specified, we should get the default one too.
|
||||
$CFG->sitepolicyhandler = 'non_existing_plugin_which_i_really_hope_will_never_exist';
|
||||
$this->assertEquals($manager->get_handler_classname(), \core_privacy\local\sitepolicy\default_handler::class);
|
||||
|
||||
// If the defined handler is among known handlers, we should get its class name.
|
||||
$CFG->sitepolicyhandler = 'testtool_testhandler';
|
||||
$this->assertEquals($manager->get_handler_classname(), 'mock_sitepolicy_handler');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for \core_privacy\local\sitepolicy\manager::is_defined()
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user