Merge branch 'MDL-68571-master' of git://github.com/cescobedo/moodle

This commit is contained in:
Sara Arjona
2020-05-11 16:52:48 +02:00
3 changed files with 41 additions and 3 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ $ADMIN->add('h5p', new admin_externalpage('h5pmanagelibraries', get_string('h5pm
new moodle_url('/h5p/libraries.php'), ['moodle/site:config', 'moodle/h5p:updatelibraries']));
// H5P settings.
$defaulth5plib = \core_h5p\local\library\autoloader::get_default_handler();
$defaulth5plib = \core_h5p\local\library\autoloader::get_default_handler_library();
if (!empty($defaulth5plib)) {
// As for now this page only has this setting, it will be hidden if there isn't any H5P libraries handler defined.
$settings = new admin_settingpage('h5psettings', new lang_string('h5psettings', 'core_h5p'));
+19 -2
View File
@@ -50,10 +50,27 @@ class autoloader {
}
/**
* Returns the default H5P library handler.
* Returns the default H5P library handler class.
*
* @return string|null H5P library handler class
*/
public static function get_default_handler(): ?string {
$default = null;
$handlers = self::get_all_handlers();
if (!empty($handlers)) {
// The default handler will be the first value in the list.
$default = array_shift($handlers);
}
return $default;
}
/**
* Returns the default H5P library handler.
*
* @return string|null H5P library handler
*/
public static function get_default_handler_library(): ?string {
$default = null;
$handlers = self::get_all_handlers();
if (!empty($handlers)) {
@@ -81,7 +98,7 @@ class autoloader {
}
}
// If no handler has been defined or it doesn't exist, return the default one.
// If no handler has been defined, return the default one.
$defaulthandler = self::get_default_handler();
if (empty($defaulthandler)) {
// If there is no default handler, throw an exception.
+21
View File
@@ -172,4 +172,25 @@ class h5p_core_testcase extends \advanced_testcase {
$siteuuid2 = $this->core->get_site_uuid();
$this->assertEquals( $siteuuid, $siteuuid2);
}
/**
* Test if no handler has been defined.
*/
public function test_get_default_handler() {
global $CFG;
$this->resetAfterTest(true);
// Emtpy the h5plibraryhandler setting.
$CFG->h5plibraryhandler = '';
// Get the default habdler library to use in the settings h5p page.
// For instance, h5plib_v124.
$handlerlib = autoloader::get_default_handler_library();
$this->assertNotNull($handlerlib);
$this->assertStringNotContainsString($handlerlib, '\local\library\handler');
// Get the default handler class.
// For instance, \h5plib_v124\local\library\handler.
$handlerclass = autoloader::get_default_handler();
$this->assertStringEndsWith('\local\library\handler', $handlerclass);
}
}