diff --git a/admin/modules.php b/admin/modules.php index b5e61fa2763..a8a04b365f2 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -1,151 +1,163 @@ . - require_once('../config.php'); - require_once('../course/lib.php'); - require_once($CFG->libdir.'/adminlib.php'); - require_once($CFG->libdir.'/tablelib.php'); +/** + * A page to manage activity modules. + * + * @package core_admin + * @copyright 2023 Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ - // defines - define('MODULE_TABLE','module_administration_table'); +require_once('../config.php'); +require_once('../course/lib.php'); +require_once("{$CFG->libdir}/adminlib.php"); +require_once("{$CFG->libdir}/tablelib.php"); - admin_externalpage_setup('managemodules'); +define('MODULE_TABLE', 'module_administration_table'); - $show = optional_param('show', '', PARAM_PLUGIN); - $hide = optional_param('hide', '', PARAM_PLUGIN); +admin_externalpage_setup('managemodules'); +$show = optional_param('show', '', PARAM_PLUGIN); +$hide = optional_param('hide', '', PARAM_PLUGIN); -/// Print headings +// Print headings. +$stractivities = get_string("activities"); +$struninstall = get_string('uninstallplugin', 'core_admin'); +$strversion = get_string("version"); +$strhide = get_string("hide"); +$strshow = get_string("show"); +$strsettings = get_string("settings"); +$stractivities = get_string("activities"); +$stractivitymodule = get_string("activitymodule"); +$strshowmodulecourse = get_string('showmodulecourse'); - $stractivities = get_string("activities"); - $struninstall = get_string('uninstallplugin', 'core_admin'); - $strversion = get_string("version"); - $strhide = get_string("hide"); - $strshow = get_string("show"); - $strsettings = get_string("settings"); - $stractivities = get_string("activities"); - $stractivitymodule = get_string("activitymodule"); - $strshowmodulecourse = get_string('showmodulecourse'); +// If data submitted, then process and store. +if (!empty($hide) && confirm_sesskey()) { + $class = \core_plugin_manager::resolve_plugininfo_class('mod'); + if ($class::enable_plugin($hide, false)) { + // Settings not required - only pages. + admin_get_root(true, false); + } + redirect(new moodle_url('/admin/modules.php')); +} -/// If data submitted, then process and store. +if (!empty($show) && confirm_sesskey()) { + $class = \core_plugin_manager::resolve_plugininfo_class('mod'); + if ($class::enable_plugin($show, true)) { + // Settings not required - only pages. + admin_get_root(true, false); + } + redirect(new moodle_url('/admin/modules.php')); +} - if (!empty($hide) and confirm_sesskey()) { - $class = \core_plugin_manager::resolve_plugininfo_class('mod'); - $class::enable_plugin($hide, false); +echo $OUTPUT->header(); +echo $OUTPUT->heading($stractivities); - admin_get_root(true, false); // settings not required - only pages - redirect(new moodle_url('/admin/modules.php')); +// Get and sort the existing modules. +if (!$modules = $DB->get_records('modules', [], 'name ASC')) { + throw new \moodle_exception('moduledoesnotexist', 'error'); +} + +// Print the table of all modules. +// Construct the flexible table ready to display. +$table = new flexible_table(MODULE_TABLE); +$table->define_columns(['name', 'instances', 'version', 'hideshow', 'uninstall', 'settings']); +$table->define_headers([$stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall]); +$table->define_baseurl($CFG->wwwroot . '/' . $CFG->admin . '/modules.php'); +$table->set_attribute('id', 'modules'); +$table->set_attribute('class', 'admintable generaltable'); +$table->setup(); + +$pluginmanager = core_plugin_manager::instance(); + +foreach ($modules as $module) { + $plugininfo = $pluginmanager->get_plugin_info('mod_' . $module->name); + $status = $plugininfo->get_status(); + + if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) { + $strmodulename = '' . $module->name . ' (' . get_string('missingfromdisk') . ')'; + $missing = true; + } else { + $icon = "image_url('monologo', $module->name) . "\" class=\"icon\" alt=\"\" />"; + $strmodulename = $icon . ' ' . get_string('modulename', $module->name); + $missing = false; } - if (!empty($show) and confirm_sesskey()) { - $canenablemodule = true; - $modulename = $show; - - // Invoking a callback function that enables plugins to force additional actions (e.g. displaying notifications, - // modals, etc.) and also specify through its returned value (bool) whether the process of enabling the plugin - // should continue after these actions or not. - if (component_callback_exists("mod_{$modulename}", 'pre_enable_plugin_actions')) { - $canenablemodule = component_callback("mod_{$modulename}", 'pre_enable_plugin_actions'); - } - - if ($canenablemodule) { - $class = \core_plugin_manager::resolve_plugininfo_class('mod'); - $class::enable_plugin($show, true); - admin_get_root(true, false); // Settings not required - only pages. - redirect(new moodle_url('/admin/modules.php')); - } + $uninstall = ''; + if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_' . $module->name, 'manage')) { + $uninstall = html_writer::link($uninstallurl, $struninstall); } - echo $OUTPUT->header(); - echo $OUTPUT->heading($stractivities); - -/// Get and sort the existing modules - - if (!$modules = $DB->get_records('modules', array(), 'name ASC')) { - throw new \moodle_exception('moduledoesnotexist', 'error'); + if ( + file_exists("$CFG->dirroot/mod/$module->name/settings.php") || + file_exists("$CFG->dirroot/mod/$module->name/settingstree.php") + ) { + $settings = "name\">$strsettings"; + } else { + $settings = ""; } -/// Print the table of all modules - // construct the flexible table ready to display - $table = new flexible_table(MODULE_TABLE); - $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings')); - $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall)); - $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php'); - $table->set_attribute('id', 'modules'); - $table->set_attribute('class', 'admintable generaltable'); - $table->setup(); - - $pluginmanager = core_plugin_manager::instance(); - - foreach ($modules as $module) { - $plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name); - $status = $plugininfo->get_status(); - - if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) { - $strmodulename = ''.$module->name.' ('.get_string('missingfromdisk').')'; - $missing = true; - } else { - // took out hspace="\10\", because it does not validate. don't know what to replace with. - $icon = "image_url('monologo', $module->name) . "\" class=\"icon\" alt=\"\" />"; - $strmodulename = $icon.' '.get_string('modulename', $module->name); - $missing = false; - } - - $uninstall = ''; - if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) { - $uninstall = html_writer::link($uninstallurl, $struninstall); - } - - if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") || - file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) { - $settings = "name\">$strsettings"; - } else { - $settings = ""; - } - - try { - $count = $DB->count_records_select($module->name, "course<>0"); - } catch (dml_exception $e) { - $count = -1; - } - if ($count>0) { - $countlink = $OUTPUT->action_link(new moodle_url('/course/search.php', ['modulelist' => $module->name]), - $count, null, ['title' => $strshowmodulecourse]); - } else if ($count < 0) { - $countlink = get_string('error'); - } else { - $countlink = "$count"; - } - - if ($missing) { - $visible = ''; - $class = ''; - } else if ($module->visible) { - $visible = "name&sesskey=".sesskey()."\" title=\"$strhide\">". - $OUTPUT->pix_icon('t/hide', $strhide) . ''; - $class = ''; - } else { - $visible = "name&sesskey=".sesskey()."\" title=\"$strshow\">". - $OUTPUT->pix_icon('t/show', $strshow) . ''; - $class = 'dimmed_text'; - } - if ($module->name == "forum") { - $uninstall = ""; - $visible = ""; - $class = ""; - } - $version = get_config('mod_'.$module->name, 'version'); - - $table->add_data(array( - $strmodulename, - $countlink, - $version, - $visible, - $settings, - $uninstall, - ), $class); + try { + $count = $DB->count_records_select($module->name, "course<>0"); + } catch (dml_exception $e) { + $count = -1; + } + if ($count > 0) { + $countlink = $OUTPUT->action_link( + new moodle_url('/course/search.php', ['modulelist' => $module->name]), + $count, + null, + ['title' => $strshowmodulecourse] + ); + } else if ($count < 0) { + $countlink = get_string('error'); + } else { + $countlink = "$count"; } - $table->print_html(); + if ($missing) { + $visible = ''; + $class = ''; + } else if ($module->visible) { + $visible = "name&sesskey=" . sesskey() . "\" title=\"$strhide\">" . + $OUTPUT->pix_icon('t/hide', $strhide) . ''; + $class = ''; + } else { + $visible = "name&sesskey=" . sesskey() . "\" title=\"$strshow\">" . + $OUTPUT->pix_icon('t/show', $strshow) . ''; + $class = 'dimmed_text'; + } + if ($module->name == "forum") { + $uninstall = ""; + $visible = ""; + $class = ""; + } + $version = get_config('mod_' . $module->name, 'version'); - echo $OUTPUT->footer(); + $table->add_data([ + $strmodulename, + $countlink, + $version, + $visible, + $settings, + $uninstall, + ], $class); +} + +$table->finish_html(); + +echo $OUTPUT->footer(); diff --git a/lib/classes/plugininfo/mod.php b/lib/classes/plugininfo/mod.php index ce8ebccf1dd..58bcc54f8f5 100644 --- a/lib/classes/plugininfo/mod.php +++ b/lib/classes/plugininfo/mod.php @@ -51,6 +51,18 @@ class mod extends base { // Only set visibility if it's different from the current value. if ($module->visible != $enabled) { + if ($enabled && component_callback_exists("mod_{$pluginname}", 'pre_enable_plugin_actions')) { + // This callback may be used to perform actions that must be completed prior to enabling a plugin. + // Example of this may include: + // - making a configuration change + // - adding an alert + // - checking a pre-requisite + // + // If the return value is falsy, then the change will be prevented. + if (!component_callback("mod_{$pluginname}", 'pre_enable_plugin_actions')) { + return false; + } + } // Set module visibility. $DB->set_field('modules', 'visible', $enabled, ['id' => $module->id]); $haschanged = true; diff --git a/mod/bigbluebuttonbn/amd/build/accept_dpa.min.js b/mod/bigbluebuttonbn/amd/build/accept_dpa.min.js deleted file mode 100644 index 52b5e8e4020..00000000000 --- a/mod/bigbluebuttonbn/amd/build/accept_dpa.min.js +++ /dev/null @@ -1,11 +0,0 @@ -define("mod_bigbluebuttonbn/accept_dpa",["exports","core_form/modalform","core/notification","core/str"],(function(_exports,_modalform,_notification,_str){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} -/** - * Javascript module for confirming the acceptance of the current data processing agreement before enabling - * the BigBlueButton activity module. - * - * @module mod_bigbluebuttonbn/accept_dpa - * @copyright 2022 Mihail Geshoski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modalform=_interopRequireDefault(_modalform),_notification=_interopRequireDefault(_notification);_exports.init=()=>{const modalForm=new _modalform.default({modalConfig:{title:(0,_str.get_string)("enablingbigbluebutton","mod_bigbluebuttonbn"),large:!1},formClass:"mod_bigbluebuttonbn\\form\\accept_dpa",saveButtonText:(0,_str.get_string)("enable")});modalForm.addEventListener(modalForm.events.FORM_SUBMITTED,(event=>{event.detail.result?window.location.reload():_notification.default.addNotification({type:"error",message:event.detail.errors.join("
")})})),modalForm.show()}})); - -//# sourceMappingURL=accept_dpa.min.js.map \ No newline at end of file diff --git a/mod/bigbluebuttonbn/amd/build/accept_dpa.min.js.map b/mod/bigbluebuttonbn/amd/build/accept_dpa.min.js.map deleted file mode 100644 index 59c6d74dd45..00000000000 --- a/mod/bigbluebuttonbn/amd/build/accept_dpa.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"accept_dpa.min.js","sources":["../src/accept_dpa.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript module for confirming the acceptance of the current data processing agreement before enabling\n * the BigBlueButton activity module.\n *\n * @module mod_bigbluebuttonbn/accept_dpa\n * @copyright 2022 Mihail Geshoski \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalForm from 'core_form/modalform';\nimport Notification from 'core/notification';\nimport {get_string as getString} from 'core/str';\n\n/**\n * Initialize module.\n */\nexport const init = () => {\n\n const modalForm = new ModalForm({\n modalConfig: {\n title: getString('enablingbigbluebutton', 'mod_bigbluebuttonbn'),\n large: false,\n },\n formClass: 'mod_bigbluebuttonbn\\\\form\\\\accept_dpa',\n saveButtonText: getString('enable'),\n });\n\n // Once the form has been submitted and successfully processed, reload the page to enable the activity module.\n modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {\n if (event.detail.result) {\n window.location.reload();\n } else {\n Notification.addNotification({\n type: 'error',\n message: event.detail.errors.join('
')\n });\n }\n });\n\n modalForm.show();\n};\n"],"names":["modalForm","ModalForm","modalConfig","title","large","formClass","saveButtonText","addEventListener","events","FORM_SUBMITTED","event","detail","result","window","location","reload","addNotification","type","message","errors","join","show"],"mappings":";;;;;;;;kMA+BoB,WAEVA,UAAY,IAAIC,mBAAU,CAC5BC,YAAa,CACTC,OAAO,mBAAU,wBAAyB,uBAC1CC,OAAO,GAEXC,UAAW,wCACXC,gBAAgB,mBAAU,YAI9BN,UAAUO,iBAAiBP,UAAUQ,OAAOC,gBAAgBC,QACpDA,MAAMC,OAAOC,OACbC,OAAOC,SAASC,+BAEHC,gBAAgB,CACzBC,KAAM,QACNC,QAAUR,MAAMC,OAAOQ,OAAOC,KAAK,aAK/CpB,UAAUqB"} \ No newline at end of file diff --git a/mod/bigbluebuttonbn/amd/src/accept_dpa.js b/mod/bigbluebuttonbn/amd/src/accept_dpa.js deleted file mode 100644 index 4fd5fc868cd..00000000000 --- a/mod/bigbluebuttonbn/amd/src/accept_dpa.js +++ /dev/null @@ -1,56 +0,0 @@ -// 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 . - -/** - * Javascript module for confirming the acceptance of the current data processing agreement before enabling - * the BigBlueButton activity module. - * - * @module mod_bigbluebuttonbn/accept_dpa - * @copyright 2022 Mihail Geshoski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -import ModalForm from 'core_form/modalform'; -import Notification from 'core/notification'; -import {get_string as getString} from 'core/str'; - -/** - * Initialize module. - */ -export const init = () => { - - const modalForm = new ModalForm({ - modalConfig: { - title: getString('enablingbigbluebutton', 'mod_bigbluebuttonbn'), - large: false, - }, - formClass: 'mod_bigbluebuttonbn\\form\\accept_dpa', - saveButtonText: getString('enable'), - }); - - // Once the form has been submitted and successfully processed, reload the page to enable the activity module. - modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => { - if (event.detail.result) { - window.location.reload(); - } else { - Notification.addNotification({ - type: 'error', - message: event.detail.errors.join('
') - }); - } - }); - - modalForm.show(); -}; diff --git a/mod/bigbluebuttonbn/classes/form/accept_dpa.php b/mod/bigbluebuttonbn/classes/form/accept_dpa.php deleted file mode 100644 index 9caf1cf3646..00000000000 --- a/mod/bigbluebuttonbn/classes/form/accept_dpa.php +++ /dev/null @@ -1,104 +0,0 @@ -. - -namespace mod_bigbluebuttonbn\form; - -use context; -use moodle_exception; -use moodle_url; -use core_form\dynamic_form; -use mod_bigbluebuttonbn\local\config; - -/** - * Accept data processing agreement form presented before enabling the BigBlueButton activity module. - * - * @package mod_bigbluebuttonbn - * @copyright 2022 Mihail Geshoski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class accept_dpa extends dynamic_form { - - /** - * Form definition - */ - protected function definition() { - $this->_form->addElement('html', \html_writer::tag('p', - get_string('enablingbigbluebuttondpainfo', 'mod_bigbluebuttonbn', config::DEFAULT_DPA_URL))); - $this->_form->addElement('checkbox', 'acceptdefaultdpa', false, get_string('acceptdpa', 'mod_bigbluebuttonbn'), - ['class' => 'bold']); - $this->_form->addRule('acceptdefaultdpa', get_string('required'), 'required', null, 'client'); - } - - /** - * Return form context - * - * @return context - */ - protected function get_context_for_dynamic_submission(): context { - return \context_system::instance(); - } - - /** - * Check if current user has access to this form, otherwise throw exception. - * - * @return void - * @throws moodle_exception - */ - protected function check_access_for_dynamic_submission(): void { - require_capability('moodle/site:config', $this->get_context_for_dynamic_submission()); - } - - /** - * Process the form submission, used if form was submitted via AJAX. - * - * @return array - */ - public function process_dynamic_submission(): array { - $result = false; - $errors = []; - - if ($this->get_data()->acceptdefaultdpa) { - try { - set_config('bigbluebuttonbn_default_dpa_accepted', true); - $result = true; - } catch (\Exception $e) { - $errors[] = $e->getMessage(); - } - } - - return [ - 'result' => $result, - 'errors' => $errors, - ]; - } - - /** - * Load in existing data as form defaults (not applicable). - * - * @return void - */ - public function set_data_for_dynamic_submission(): void { - } - - /** - * Returns url to set in $PAGE->set_url() when form is being rendered or submitted via AJAX. - * - * @return moodle_url - */ - protected function get_page_url_for_dynamic_submission(): moodle_url { - return new moodle_url('/admin/modules.php', ['show' => 'bigbluebuttonbn', 'sesskey' => sesskey()]); - } -} diff --git a/mod/bigbluebuttonbn/classes/settings.php b/mod/bigbluebuttonbn/classes/settings.php index 588dd5b6003..8b71a87a0c7 100644 --- a/mod/bigbluebuttonbn/classes/settings.php +++ b/mod/bigbluebuttonbn/classes/settings.php @@ -136,6 +136,7 @@ class settings { * @throws \coding_exception */ protected function add_general_settings(): admin_settingpage { + global $CFG; $settingsgeneral = new admin_settingpage( $this->section, get_string('config_general', 'bigbluebuttonbn'), @@ -146,9 +147,19 @@ class settings { // Configuration for BigBlueButton. $item = new admin_setting_heading('bigbluebuttonbn_config_general', '', - get_string('config_general_description', 'bigbluebuttonbn')); - + get_string('config_general_description', 'bigbluebuttonbn') + ); $settingsgeneral->add($item); + + if (empty($CFG->bigbluebuttonbn_default_dpa_accepted)) { + $settingsgeneral->add(new admin_setting_configcheckbox( + 'bigbluebuttonbn_default_dpa_accepted', + get_string('acceptdpa', 'mod_bigbluebuttonbn'), + get_string('enablingbigbluebuttondpainfo', 'mod_bigbluebuttonbn', config::DEFAULT_DPA_URL), + 0 + )); + } + $item = new admin_setting_configtext( 'bigbluebuttonbn_server_url', get_string('config_server_url', 'bigbluebuttonbn'), diff --git a/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php b/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php index 3ec2201f921..00b13420ec2 100644 --- a/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php +++ b/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php @@ -49,6 +49,7 @@ $string['bigbluebuttondisablednotification'] = 'The BigBlueButton activity modul $string['cannotperformaction'] = 'Cannot perform action {$a} on this recording'; $string['enablingbigbluebutton'] = 'Enabling BigBlueButton activity'; $string['enablingbigbluebuttondpainfo'] = 'In order to meet your data protection obligations, prior to enabling this plugin, you may need to ensure that you have read and accepted the Blindside Networks data processing agreement. Please consult with your own privacy professionals for advice.'; +$string['dpainfonotsigned'] = 'Before enabling this plugin, you must confirm that you have read and accepted the Blindside Networks data processing agreement.'; $string['indicator:cognitivedepth'] = 'BigBlueButton cognitive'; $string['indicator:cognitivedepth_help'] = 'This indicator is based on the cognitive depth reached by the student in a BigBlueButton activity.'; $string['indicator:socialbreadth'] = 'BigBlueButton social'; diff --git a/mod/bigbluebuttonbn/lib.php b/mod/bigbluebuttonbn/lib.php index f5800c3daae..5f7187a2177 100644 --- a/mod/bigbluebuttonbn/lib.php +++ b/mod/bigbluebuttonbn/lib.php @@ -730,7 +730,11 @@ function bigbluebuttonbn_pre_enable_plugin_actions(): bool { // agreement, do not enable the plugin. Instead, display a dynamic form where the administrator can confirm that he // accepts the DPA prior to enabling the plugin. if (config::get('server_url') === config::DEFAULT_SERVER_URL && !config::get('default_dpa_accepted')) { - $PAGE->requires->js_call_amd('mod_bigbluebuttonbn/accept_dpa', 'init', []); + $url = new moodle_url('/admin/category.php', ['category' => 'modbigbluebuttonbnfolder']); + \core\notification::add( + get_string('dpainfonotsigned', 'mod_bigbluebuttonbn', $url->out(false)), + \core\notification::ERROR + ); return false; } // Otherwise, continue and enable the plugin. diff --git a/mod/bigbluebuttonbn/tests/generator/lib.php b/mod/bigbluebuttonbn/tests/generator/lib.php index 0f2db867243..544991d2dc6 100644 --- a/mod/bigbluebuttonbn/tests/generator/lib.php +++ b/mod/bigbluebuttonbn/tests/generator/lib.php @@ -50,6 +50,7 @@ class mod_bigbluebuttonbn_generator extends \testing_module_generator { */ public function create_instance($record = null, array $options = null) { // Prior to creating the instance, make sure that the BigBlueButton module is enabled. + set_config('bigbluebuttonbn_default_dpa_accepted', true); $modules = \core_plugin_manager::instance()->get_plugins_of_type('mod'); if (!$modules['bigbluebuttonbn']->is_enabled()) { mod::enable_plugin('bigbluebuttonbn', true); diff --git a/mod/bigbluebuttonbn/tests/lib_test.php b/mod/bigbluebuttonbn/tests/lib_test.php index f4d60610b90..b54be9fee76 100644 --- a/mod/bigbluebuttonbn/tests/lib_test.php +++ b/mod/bigbluebuttonbn/tests/lib_test.php @@ -698,4 +698,72 @@ class lib_test extends \advanced_testcase { $event->instance = 0; $this->assertFalse(mod_bigbluebuttonbn_core_calendar_is_event_visible($event)); } + + /** + * Check the bigbluebuttonbn_pre_enable_plugin_actions function. + * + * @covers ::bigbluebuttonbn_pre_enable_plugin_actions + * @dataProvider bigbluebuttonbn_pre_enable_plugin_actions_provider + * @param bool $initialstate + * @param bool $expected + * @param int $notificationcount + */ + public function test_bigbluebuttonbn_pre_enable_plugin_actions( + ?bool $initialstate, + bool $expected, + int $notificationcount + ): void { + $this->resetAfterTest(true); + + set_config('bigbluebuttonbn_default_dpa_accepted', $initialstate); + + $this->assertEquals($expected, bigbluebuttonbn_pre_enable_plugin_actions()); + $this->assertCount($notificationcount, \core\notification::fetch()); + } + + /** + * Check the bigbluebuttonbn_pre_enable_plugin_actions function. + * + * @covers ::bigbluebuttonbn_pre_enable_plugin_actions + * @dataProvider bigbluebuttonbn_pre_enable_plugin_actions_provider + * @param bool $initialstate + * @param bool $expected + * @param int $notificationcount + */ + public function test_enable_plugin( + ?bool $initialstate, + bool $expected, + int $notificationcount + ): void { + $this->resetAfterTest(true); + + set_config('bigbluebuttonbn_default_dpa_accepted', $initialstate); + $this->assertEquals($expected, \core\plugininfo\mod::enable_plugin('bigbluebuttonbn', 1)); + $this->assertCount($notificationcount, \core\notification::fetch()); + } + + /** + * Data provider for bigbluebuttonbn_pre_enable_plugin_actions tests. + * + * @return array + */ + public function bigbluebuttonbn_pre_enable_plugin_actions_provider(): array { + return [ + 'Initially unset' => [ + null, + false, + 1, + ], + 'Set to false' => [ + false, + false, + 1, + ], + 'Initially set' => [ + true, + true, + 0, + ], + ]; + } }