Skip to content

Commit

Permalink
Merge branch 'MDL-68571-master' of git://github.com/cescobedo/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed May 11, 2020
2 parents 80fd46e + 444b228 commit 36a3a25
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion admin/settings/h5p.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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'));
Expand Down
21 changes: 19 additions & 2 deletions h5p/classes/local/library/autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,27 @@ public static function get_all_handlers(): array {
}

/**
* 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)) {
Expand Down Expand Up @@ -81,7 +98,7 @@ public static function get_handler_classname(): string {
}
}

// 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.
Expand Down
21 changes: 21 additions & 0 deletions h5p/tests/h5p_core_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,25 @@ public function test_get_site_uuid(): void {
$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);
}
}

0 comments on commit 36a3a25

Please sign in to comment.