+ |
+ {{#enabled}}
+ {{#pix}}t/hide, core,{{#str}}disable{{/str}}{{/pix}}
+ {{/enabled}}
+ {{^enabled}}
+ {{#pix}}t/show, core,{{#str}}enable{{/str}}{{/pix}}
+ {{/enabled}}
+ |
{{#icon}}
-
\ No newline at end of file
+
diff --git a/h5p/tests/api_test.php b/h5p/tests/api_test.php
index e1ec76e8350..24ea653b1e3 100644
--- a/h5p/tests/api_test.php
+++ b/h5p/tests/api_test.php
@@ -35,6 +35,7 @@ defined('MOODLE_INTERNAL') || die();
* @package core_h5p
* @copyright 2020 Sara Arjona
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @coversDefaultClass \core_h5p\api
*/
class api_testcase extends \advanced_testcase {
@@ -503,4 +504,98 @@ class api_testcase extends \advanced_testcase {
\core_h5p\file_storage::EXPORT_FILEAREA);
$this->assertNull($exportfile);
}
+
+ /**
+ * Test the behaviour of set_library_enabled().
+ *
+ * @covers ::set_library_enabled
+ * @dataProvider set_library_enabled_provider
+ *
+ * @param string $libraryname Library name to enable/disable.
+ * @param string $action Action to be done with the library. Supported values: enable, disable.
+ * @param int $expected Expected value for the enabled library field. -1 will be passed if the library doesn't exist.
+ */
+ public function test_set_library_enabled(string $libraryname, string $action, int $expected): void {
+ global $DB;
+
+ $this->resetAfterTest();
+
+ // Create libraries.
+ $generator = $this->getDataGenerator()->get_plugin_generator('core_h5p');
+ $generator->generate_h5p_data();
+
+ // Check by default the library is enabled.
+ $library = $DB->get_record('h5p_libraries', ['machinename' => $libraryname]);
+ if ($expected >= 0) {
+ $this->assertEquals(1, $library->enabled);
+ $libraryid = (int) $library->id;
+ } else {
+ // Unexisting library. Set libraryid to some unexisting id.
+ $libraryid = -1;
+ $this->expectException('dml_missing_record_exception');
+ }
+
+ \core_h5p\api::set_library_enabled($libraryid, ($action == 'enable'));
+
+ // Check the value of the "enabled" field after calling enable/disable method.
+ $libraries = $DB->get_records('h5p_libraries');
+ foreach ($libraries as $libraryid => $library) {
+ if ($library->machinename == $libraryname) {
+ $this->assertEquals($expected, $library->enabled);
+ } else {
+ // Check that only $libraryname has been enabled/disabled.
+ $this->assertEquals(1, $library->enabled);
+ }
+ }
+ }
+
+ /**
+ * Data provider for test_set_library_enabled().
+ *
+ * @return array
+ */
+ public function set_library_enabled_provider(): array {
+ return [
+ 'Disable existing library' => [
+ 'libraryname' => 'MainLibrary',
+ 'action' => 'disable',
+ 'expected' => 0,
+ ],
+ 'Enable existing library' => [
+ 'libraryname' => 'MainLibrary',
+ 'action' => 'enable',
+ 'expected' => 1,
+ ],
+ 'Disable existing library (not main)' => [
+ 'libraryname' => 'Library1',
+ 'action' => 'disable',
+ 'expected' => 0,
+ ],
+ 'Enable existing library (not main)' => [
+ 'libraryname' => 'Library1',
+ 'action' => 'enable',
+ 'expected' => 1,
+ ],
+ 'Disable existing library (not runnable)' => [
+ 'libraryname' => 'Library3',
+ 'action' => 'disable',
+ 'expected' => 1, // Not runnable libraries can't be disabled.
+ ],
+ 'Enable existing library (not runnable)' => [
+ 'libraryname' => 'Library3',
+ 'action' => 'enable',
+ 'expected' => 1,
+ ],
+ 'Enable unexisting library' => [
+ 'libraryname' => 'Unexisting library',
+ 'action' => 'enable',
+ 'expected' => -1,
+ ],
+ 'Disable unexisting library' => [
+ 'libraryname' => 'Unexisting library',
+ 'action' => 'disable',
+ 'expected' => -1,
+ ],
+ ];
+ }
}
diff --git a/h5p/tests/behat/h5p_libraries.feature b/h5p/tests/behat/h5p_libraries.feature
index 2d990b3e6d4..c5b255ade7e 100644
--- a/h5p/tests/behat/h5p_libraries.feature
+++ b/h5p/tests/behat/h5p_libraries.feature
@@ -61,3 +61,16 @@ Feature: Upload and list H5P libraries and content types installed
And I should not see "H5P.FontIcons"
And I should not see "Joubel UI"
And I should see "Transition"
+
+ @javascript
+ Scenario: Enable/disable H5P library
+ Given I log in as "admin"
+ And I navigate to "H5P > Manage H5P content types" in site administration
+ And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "H5P content type" filemanager
+ And I click on "Upload H5P content types" "button" in the "#fitem_id_uploadlibraries" "css_element"
+ When I click on "Disable" "link" in the "Fill in the Blanks" "table_row"
+ Then "Enable" "icon" should exist in the "Fill in the Blanks" "table_row"
+ And "Disable" "icon" should not exist in the "Fill in the Blanks" "table_row"
+ And I click on "Enable" "link" in the "Fill in the Blanks" "table_row"
+ And "Disable" "icon" should exist in the "Fill in the Blanks" "table_row"
+ And "Enable" "icon" should not exist in the "Fill in the Blanks" "table_row"
diff --git a/h5p/tests/editor_framework_test.php b/h5p/tests/editor_framework_test.php
index 8e3e220a8b3..1c93f87beb5 100644
--- a/h5p/tests/editor_framework_test.php
+++ b/h5p/tests/editor_framework_test.php
@@ -37,19 +37,24 @@ use core_h5p\local\library\autoloader;
*
* @runTestsInSeparateProcesses
*/
-class editor_framework_testcase extends \advanced_testcase {
+class editor_framework_test extends \advanced_testcase {
/** @var editor_framework H5P editor_framework instance */
protected $editorframework;
+ /**
+ * Setup to ensure that fixtures are loaded.
+ */
+ public static function setupBeforeClass(): void {
+ autoloader::register();
+ }
+
/**
* Set up function for tests.
*/
protected function setUp(): void {
parent::setUp();
- autoloader::register();
-
$this->editorframework = new editor_framework();
}
@@ -362,7 +367,7 @@ class editor_framework_testcase extends \advanced_testcase {
$expectedlibraries = [];
foreach ($data as $key => $value) {
- if (isset($value->data)) {
+ if (isset($value->data) && $value->data->runnable) {
$value->data->name = $value->data->machinename;
$value->data->majorVersion = $value->data->majorversion;
$value->data->minorVersion = $value->data->minorversion;
diff --git a/h5p/tests/generator/lib.php b/h5p/tests/generator/lib.php
index 78c234be536..15a13fe8a40 100644
--- a/h5p/tests/generator/lib.php
+++ b/h5p/tests/generator/lib.php
@@ -177,7 +177,7 @@ class core_h5p_generator extends \component_generator_base {
'http://tutorial.org', 'http://example.org');
$lib1 = $libraries[] = $this->create_library_record('Library1', 'Lib1', 2, 0, 1, '', null, null, 'http://example.org');
$lib2 = $libraries[] = $this->create_library_record('Library2', 'Lib2', 2, 1, 1, '', null, 'http://tutorial.org');
- $lib3 = $libraries[] = $this->create_library_record('Library3', 'Lib3', 3, 2);
+ $lib3 = $libraries[] = $this->create_library_record('Library3', 'Lib3', 3, 2, 1, '', null, null, null, true, 0);
$lib4 = $libraries[] = $this->create_library_record('Library4', 'Lib4', 1, 1);
$lib5 = $libraries[] = $this->create_library_record('Library5', 'Lib5', 1, 3);
@@ -251,20 +251,22 @@ class core_h5p_generator extends \component_generator_base {
* @param string $addto The plugin configuration data
* @param string $tutorial The tutorial URL
* @param string $examlpe The example URL
+ * @param bool $enabled Whether the library is enabled or not
+ * @param int $runnable Whether the library is runnable (1) or not (0)
* @return stdClass An object representing the added library record
*/
public function create_library_record(string $machinename, string $title, int $majorversion = 1,
int $minorversion = 0, int $patchversion = 1, string $semantics = '', string $addto = null,
- string $tutorial = null, string $example = null): stdClass {
+ string $tutorial = null, string $example = null, bool $enabled = true, int $runnable = 1): stdClass {
global $DB;
- $content = array(
+ $content = [
'machinename' => $machinename,
'title' => $title,
'majorversion' => $majorversion,
'minorversion' => $minorversion,
'patchversion' => $patchversion,
- 'runnable' => 1,
+ 'runnable' => $runnable,
'fullscreen' => 1,
'preloadedjs' => 'js/example.js',
'preloadedcss' => 'css/example.css',
@@ -272,8 +274,9 @@ class core_h5p_generator extends \component_generator_base {
'semantics' => $semantics,
'addto' => $addto,
'tutorial' => $tutorial,
- 'example' => $example
- );
+ 'example' => $example,
+ 'enabled' => $enabled,
+ ];
$libraryid = $DB->insert_record('h5p_libraries', $content);
diff --git a/h5p/tests/generator_test.php b/h5p/tests/generator_test.php
index b43df426dbb..8111ad07502 100644
--- a/h5p/tests/generator_test.php
+++ b/h5p/tests/generator_test.php
@@ -251,6 +251,7 @@ class generator_testcase extends \advanced_testcase {
'coremajor' => null,
'coreminor' => null,
'metadatasettings' => null,
+ 'enabled' => 1,
];
$this->assertEquals($expected, $data);
diff --git a/lib/db/install.xml b/lib/db/install.xml
index 53554a6cfe7..fdeba8596f2 100644
--- a/lib/db/install.xml
+++ b/lib/db/install.xml
@@ -1,5 +1,5 @@
-
@@ -4203,6 +4203,7 @@
+
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php
index 69c232acaf8..188906cf131 100644
--- a/lib/db/upgrade.php
+++ b/lib/db/upgrade.php
@@ -2549,5 +2549,20 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021033100.01);
}
+ if ($oldversion < 2021041300.01) {
+
+ // Define field enabled to be added to h5p_libraries.
+ $table = new xmldb_table('h5p_libraries');
+ $field = new xmldb_field('enabled', XMLDB_TYPE_INTEGER, '1', null, null, null, '1', 'example');
+
+ // Conditionally launch add field enabled.
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Main savepoint reached.
+ upgrade_main_savepoint(true, 2021041300.01);
+ }
+
return true;
}
diff --git a/theme/boost/scss/moodle/core.scss b/theme/boost/scss/moodle/core.scss
index 8bba6e735f0..e5b97391416 100644
--- a/theme/boost/scss/moodle/core.scss
+++ b/theme/boost/scss/moodle/core.scss
@@ -2466,6 +2466,10 @@ body.h5p-embed {
}
}
+#h5pcontenttypes td {
+ vertical-align: middle;
+}
+
.text-decoration-none {
text-decoration: none !important; /* stylelint-disable-line declaration-no-important */
}
diff --git a/theme/boost/style/moodle.css b/theme/boost/style/moodle.css
index fd40f2b204a..be864b45d12 100644
--- a/theme/boost/style/moodle.css
+++ b/theme/boost/style/moodle.css
@@ -11660,6 +11660,9 @@ body.h5p-embed #maincontent {
body.h5p-embed .h5pmessages {
min-height: 230px; }
+#h5pcontenttypes td {
+ vertical-align: middle; }
+
.text-decoration-none {
text-decoration: none !important;
/* stylelint-disable-line declaration-no-important */ }
diff --git a/theme/classic/style/moodle.css b/theme/classic/style/moodle.css
index a74b29670d3..02d3578909c 100644
--- a/theme/classic/style/moodle.css
+++ b/theme/classic/style/moodle.css
@@ -11878,6 +11878,9 @@ body.h5p-embed #maincontent {
body.h5p-embed .h5pmessages {
min-height: 230px; }
+#h5pcontenttypes td {
+ vertical-align: middle; }
+
.text-decoration-none {
text-decoration: none !important;
/* stylelint-disable-line declaration-no-important */ }
diff --git a/version.php b/version.php
index 62353e7fd37..51d334c0686 100644
--- a/version.php
+++ b/version.php
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2021041300.00; // 20201109 = branching date YYYYMMDD - do not modify!
+$version = 2021041300.01; // 20201109 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.11dev+ (Build: 20210413)';// Human-friendly version name
|