From c406bcecc344e1df0d69f5d4c1453f17d4dc6dad Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Fri, 22 Nov 2024 12:17:14 +0100 Subject: [PATCH] MDL-82034 mod_subsection: Enable by default --- .../tests/external/create_module_test.php | 3 -- course/format/tests/stateactions_test.php | 8 ----- course/tests/externallib_test.php | 2 -- lib/tests/modinfolib_test.php | 21 ++--------- mod/subsection/db/install.php | 36 ------------------- .../courseformat/sectiondelegate_test.php | 3 -- .../sectiondelegatemodule_test.php | 13 +------ mod/subsection/tests/manager_test.php | 4 +-- 8 files changed, 4 insertions(+), 86 deletions(-) delete mode 100644 mod/subsection/db/install.php diff --git a/course/format/tests/external/create_module_test.php b/course/format/tests/external/create_module_test.php index 1ce792d49f9..539efe2dc0d 100644 --- a/course/format/tests/external/create_module_test.php +++ b/course/format/tests/external/create_module_test.php @@ -85,9 +85,6 @@ final class create_module_test extends \externallib_advanced_testcase { public function test_execute_with_format_override(): void { $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - // Create a course. $course = $this->getDataGenerator()->create_course(['format' => 'theunittest', 'numsections' => 1, 'initsections' => 1]); $targetsection = get_fast_modinfo($course->id)->get_section_info(1); diff --git a/course/format/tests/stateactions_test.php b/course/format/tests/stateactions_test.php index 7e4badc8c67..d0919ffc49d 100644 --- a/course/format/tests/stateactions_test.php +++ b/course/format/tests/stateactions_test.php @@ -1433,8 +1433,6 @@ final class stateactions_test extends \advanced_testcase { $this->resetAfterTest(); $course = $this->create_course('topics', 4, []); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); $subsection1 = $this->getDataGenerator()->create_module( 'subsection', ['course' => $course, 'section' => 1, 'name' => 'subsection1'] ); @@ -1621,9 +1619,6 @@ final class stateactions_test extends \advanced_testcase { $this->resetAfterTest(); $this->setAdminUser(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(); $subsection = $this->getDataGenerator()->create_module('subsection', ['course' => $course]); $otheractvity = $this->getDataGenerator()->create_module('forum', ['course' => $course]); @@ -1703,9 +1698,6 @@ final class stateactions_test extends \advanced_testcase { $this->resetAfterTest(); $this->setAdminUser(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(); $subsection = $this->getDataGenerator()->create_module('subsection', ['course' => $course]); $otheractvity = $this->getDataGenerator()->create_module('forum', ['course' => $course]); diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index a5dd6d58285..538a3477c99 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -1907,8 +1907,6 @@ final class externallib_test extends externallib_advanced_testcase { list($course, $forumcm, $datacm, $pagecm, $labelcm, $urlcm) = $this->prepare_get_course_contents_test(); // Add subsection. - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); $modsubsection = $this->getDataGenerator()->create_module('subsection', ['course' => $course->id, 'section' => 2]); // This is needed until MDL-76728 is resolved. diff --git a/lib/tests/modinfolib_test.php b/lib/tests/modinfolib_test.php index 68ebc196e18..09b722703f3 100644 --- a/lib/tests/modinfolib_test.php +++ b/lib/tests/modinfolib_test.php @@ -1796,9 +1796,6 @@ final class modinfolib_test extends advanced_testcase { public function test_get_sections_delegated_by_cm(): void { $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['numsections' => 1]); $modinfo = get_fast_modinfo($course); @@ -1828,9 +1825,6 @@ final class modinfolib_test extends advanced_testcase { public function test_get_delegated_section_info(): void { $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['numsections' => 1]); // Add a section delegated by a course module. @@ -1867,9 +1861,6 @@ final class modinfolib_test extends advanced_testcase { ): void { $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['numsections' => 1]); $subsection = $this->getDataGenerator()->create_module('subsection', ['course' => $course], ['section' => 1]); @@ -1971,9 +1962,6 @@ final class modinfolib_test extends advanced_testcase { ): void { $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['numsections' => 1]); $subsection = $this->getDataGenerator()->create_module('subsection', ['course' => $course], ['section' => 1]); @@ -1983,6 +1971,7 @@ final class modinfolib_test extends advanced_testcase { $user = $this->getDataGenerator()->create_and_enrol($course, $role); if (!$enabled) { + $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); $manager::enable_plugin('subsection', 0); rebuild_course_cache($course->id, true); } @@ -2063,9 +2052,6 @@ final class modinfolib_test extends advanced_testcase { ] ); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['numsections' => 1]); $cmparams = ['section' => 1]; @@ -2173,13 +2159,9 @@ final class modinfolib_test extends advanced_testcase { * @return void */ public function test_is_orphan(): void { - global $DB; $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['numsections' => 1]); $subsection = $this->getDataGenerator()->create_module('subsection', ['course' => $course], ['section' => 1]); @@ -2191,6 +2173,7 @@ final class modinfolib_test extends advanced_testcase { $this->assertFalse($delegatedsection->is_orphan()); // Delegated sections without a component instance (disabled mod_subsection) is considered orphan. + $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); $manager::enable_plugin('subsection', 0); rebuild_course_cache($course->id, true); diff --git a/mod/subsection/db/install.php b/mod/subsection/db/install.php deleted file mode 100644 index 6578ac2bcd3..00000000000 --- a/mod/subsection/db/install.php +++ /dev/null @@ -1,36 +0,0 @@ -. - -/** - * Code to be executed after the plugin's database scheme has been installed is defined here. - * - * @package mod_subsection - * @category upgrade - * @copyright 2023 Amaia Anabitarte - * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Custom code to be run on installing the plugin. - */ -function xmldb_subsection_install() { - global $DB; - - // Disable the chat activity module on new installs by default. - $DB->set_field('modules', 'visible', 0, ['name' => 'subsection']); - - return true; -} diff --git a/mod/subsection/tests/courseformat/sectiondelegate_test.php b/mod/subsection/tests/courseformat/sectiondelegate_test.php index 9c403561ec1..760bba20f09 100644 --- a/mod/subsection/tests/courseformat/sectiondelegate_test.php +++ b/mod/subsection/tests/courseformat/sectiondelegate_test.php @@ -47,9 +47,6 @@ final class sectiondelegate_test extends \advanced_testcase { $this->resetAfterTest(); $this->setAdminUser(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]); $this->getDataGenerator()->create_module('subsection', ['course' => $course->id, 'section' => 1]); diff --git a/mod/subsection/tests/courseformat/sectiondelegatemodule_test.php b/mod/subsection/tests/courseformat/sectiondelegatemodule_test.php index 96b7ebfd973..620cafd1d7c 100644 --- a/mod/subsection/tests/courseformat/sectiondelegatemodule_test.php +++ b/mod/subsection/tests/courseformat/sectiondelegatemodule_test.php @@ -40,9 +40,6 @@ final class sectiondelegatemodule_test extends \advanced_testcase { public function test_get_parent_section(): void { $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 2]); $module = $this->getDataGenerator()->create_module('subsection', (object)['course' => $course->id, 'section' => 2]); @@ -66,9 +63,6 @@ final class sectiondelegatemodule_test extends \advanced_testcase { public function test_get_cm(): void { $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]); $module = $this->getDataGenerator()->create_module('subsection', (object)['course' => $course->id, 'section' => 1]); @@ -92,9 +86,6 @@ final class sectiondelegatemodule_test extends \advanced_testcase { public function test_get_course(): void { $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]); $module = $this->getDataGenerator()->create_module('subsection', (object)['course' => $course->id, 'section' => 1]); @@ -113,9 +104,6 @@ final class sectiondelegatemodule_test extends \advanced_testcase { public function test_instance_plugin_disabled(): void { $this->resetAfterTest(); - $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $manager::enable_plugin('subsection', 1); - $course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 2]); $module = $this->getDataGenerator()->create_module( 'subsection', @@ -130,6 +118,7 @@ final class sectiondelegatemodule_test extends \advanced_testcase { $this->assertTrue($delegated->is_enabled()); // Disabling the plugin should disable the delegate. + $manager = \core_plugin_manager::resolve_plugininfo_class('mod'); $manager::enable_plugin('subsection', 0); rebuild_course_cache($course->id, true); diff --git a/mod/subsection/tests/manager_test.php b/mod/subsection/tests/manager_test.php index 20e1ecd0f95..8f3e3f9f728 100644 --- a/mod/subsection/tests/manager_test.php +++ b/mod/subsection/tests/manager_test.php @@ -47,9 +47,6 @@ final class manager_test extends \advanced_testcase { $this->resetAfterTest(); - $pluginmanager = \core_plugin_manager::resolve_plugininfo_class('mod'); - $pluginmanager::enable_plugin('subsection', 1); - // Set up the availability settings. $availabilityjson = null; if ($hasavailability) { @@ -83,6 +80,7 @@ final class manager_test extends \advanced_testcase { // When subsections are disabled, all subsections are considered orphaned // and can be removed without affecting the course_module. This should regenerate // the delegated section once the module is re-enabled. + $pluginmanager = \core_plugin_manager::resolve_plugininfo_class('mod'); $pluginmanager::enable_plugin('subsection', 0); formatactions::section($course)->delete($sectioninfo); rebuild_course_cache($course->id, true);