From e8b7ff09db8cc3b4456aaba23d4d67f399aba323 Mon Sep 17 00:00:00 2001 From: Safat Date: Thu, 19 Feb 2026 14:17:40 +1100 Subject: [PATCH] MDL-87959 tool_installaddon: Add support for marketplace --- .../tool/installaddon/amd/build/footer.min.js | 3 + .../installaddon/amd/build/footer.min.js.map | 1 + admin/tool/installaddon/amd/src/footer.js | 25 ++++++++ admin/tool/installaddon/classes/installer.php | 19 +++++++ .../classes/task/post_install.php | 38 +++++++++++++ admin/tool/installaddon/db/install.php | 37 ++++++++++++ admin/tool/installaddon/db/upgrade.php | 41 +++++++++++++ .../lang/en/tool_installaddon.php | 3 + admin/tool/installaddon/lib.php | 48 ++++++++++++++++ admin/tool/installaddon/settings.php | 6 ++ .../templates/chooser_footer.mustache | 30 ++++++++++ .../templates/marketplace_link.mustache | 36 ++++++++++++ .../behat/activity_chooser_footer.feature | 25 ++++++++ .../testable_installer_without_site_info.php | 46 +++++++++++++++ .../installaddon/tests/installer_test.php | 57 ++++++++++++++++--- admin/tool/installaddon/tests/lib_test.php | 53 +++++++++++++++++ .../tests/task/post_install_test.php | 47 +++++++++++++++ admin/tool/installaddon/version.php | 2 +- 18 files changed, 508 insertions(+), 9 deletions(-) create mode 100644 admin/tool/installaddon/amd/build/footer.min.js create mode 100644 admin/tool/installaddon/amd/build/footer.min.js.map create mode 100644 admin/tool/installaddon/amd/src/footer.js create mode 100644 admin/tool/installaddon/classes/task/post_install.php create mode 100644 admin/tool/installaddon/db/install.php create mode 100644 admin/tool/installaddon/db/upgrade.php create mode 100644 admin/tool/installaddon/lib.php create mode 100644 admin/tool/installaddon/templates/chooser_footer.mustache create mode 100644 admin/tool/installaddon/templates/marketplace_link.mustache create mode 100644 admin/tool/installaddon/tests/behat/activity_chooser_footer.feature create mode 100644 admin/tool/installaddon/tests/fixtures/testable_installer_without_site_info.php create mode 100644 admin/tool/installaddon/tests/lib_test.php create mode 100644 admin/tool/installaddon/tests/task/post_install_test.php diff --git a/admin/tool/installaddon/amd/build/footer.min.js b/admin/tool/installaddon/amd/build/footer.min.js new file mode 100644 index 00000000000..957899463e2 --- /dev/null +++ b/admin/tool/installaddon/amd/build/footer.min.js @@ -0,0 +1,3 @@ +define("tool_installaddon/footer",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.footerClickListener=void 0;_exports.footerClickListener=()=>null})); + +//# sourceMappingURL=footer.min.js.map \ No newline at end of file diff --git a/admin/tool/installaddon/amd/build/footer.min.js.map b/admin/tool/installaddon/amd/build/footer.min.js.map new file mode 100644 index 00000000000..321e708ee96 --- /dev/null +++ b/admin/tool/installaddon/amd/build/footer.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"footer.min.js","sources":["../src/footer.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 * Activity chooser footer handlers for tool_installaddon.\n *\n * @module tool_installaddon/footer\n * @copyright 2026 Safat Shahin \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n// The footer is a plain link, so the chooser does not need extra click handling.\nexport const footerClickListener = () => null;\n"],"names":[],"mappings":"2LAwBmC,IAAM"} \ No newline at end of file diff --git a/admin/tool/installaddon/amd/src/footer.js b/admin/tool/installaddon/amd/src/footer.js new file mode 100644 index 00000000000..60ecb152185 --- /dev/null +++ b/admin/tool/installaddon/amd/src/footer.js @@ -0,0 +1,25 @@ +// 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 . + +/** + * Activity chooser footer handlers for tool_installaddon. + * + * @module tool_installaddon/footer + * @copyright 2026 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// The footer is a plain link, so the chooser does not need extra click handling. +export const footerClickListener = () => null; diff --git a/admin/tool/installaddon/classes/installer.php b/admin/tool/installaddon/classes/installer.php index e8a4e150fb8..80f04bc9b4e 100644 --- a/admin/tool/installaddon/classes/installer.php +++ b/admin/tool/installaddon/classes/installer.php @@ -70,6 +70,25 @@ class tool_installaddon_installer { $url = 'https://moodle.org/plugins/get.php'; } + return $this->get_external_service_url($url); + } + + /** + * Returns URL to Moodle Marketplace. + * + * @return moodle_url + */ + public function get_marketplace_url(): moodle_url { + return $this->get_external_service_url('https://marketplace.moodle.com/'); + } + + /** + * Returns URL to external service with optional encoded site information. + * + * @param string $url The external service base URL. + * @return moodle_url + */ + protected function get_external_service_url(string $url): moodle_url { if (!$this->should_send_site_info()) { return new moodle_url($url); } diff --git a/admin/tool/installaddon/classes/task/post_install.php b/admin/tool/installaddon/classes/task/post_install.php new file mode 100644 index 00000000000..c4898e536ce --- /dev/null +++ b/admin/tool/installaddon/classes/task/post_install.php @@ -0,0 +1,38 @@ +. + +declare(strict_types=1); + +namespace tool_installaddon\task; + +/** + * Ad-hoc task to perform post install tasks. + * We use this to set the active activity chooser footer plugin to tool_installaddon. + * We couldn't do this directly in install.php, because there is an admin_apply_default_settings() call after all plugins are + * installed and that would reset whatever value we had set earlier to 'hidden'. + * + * @package tool_installaddon + * @copyright 2026 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class post_install extends \core\task\adhoc_task { + /** + * Sets the active activity chooser footer plugin after install defaults are applied. + */ + public function execute(): void { + set_config('activitychooseractivefooter', 'tool_installaddon'); + } +} diff --git a/admin/tool/installaddon/db/install.php b/admin/tool/installaddon/db/install.php new file mode 100644 index 00000000000..fa848ae2cd6 --- /dev/null +++ b/admin/tool/installaddon/db/install.php @@ -0,0 +1,37 @@ +. + +/** + * Install script for tool_installaddon. + * + * @package tool_installaddon + * @copyright 2026 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Perform the post-install procedures. + */ +function xmldb_tool_installaddon_install(): void { + // Use an ad-hoc task to set the active activity chooser footer plugin to tool_installaddon. + // We couldn't do this in admin/settings/courses.php for 2 reasons: + // - First, because it would be a breach of component communications principles to do so there. + // - Second, because we can't call get_plugins_with_function() during install and upgrade (or it will return []). + // We couldn't do this directly here either, because there is an admin_apply_default_settings() call after all plugins are + // installed and that would reset whatever value we set here to 'hidden'. + $postinstall = new tool_installaddon\task\post_install(); + core\task\manager::queue_adhoc_task($postinstall); +} diff --git a/admin/tool/installaddon/db/upgrade.php b/admin/tool/installaddon/db/upgrade.php new file mode 100644 index 00000000000..9977d5e6026 --- /dev/null +++ b/admin/tool/installaddon/db/upgrade.php @@ -0,0 +1,41 @@ +. + +/** + * Upgrade script for tool_installaddon. + * + * @package tool_installaddon + * @copyright 2026 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Upgrade the plugin. + * + * @param int $oldversion + * @return bool always true + */ +function xmldb_tool_installaddon_upgrade(int $oldversion): bool { + if ($oldversion < 2024100701) { + // Set the activity chooser active footer to include marketplace regardless of the previous setting. + // We are deliberately setting this to increase awareness of marketplace. + set_config('activitychooseractivefooter', 'tool_installaddon'); + + upgrade_plugin_savepoint(true, 2024100701, 'tool', 'installaddon'); + } + + return true; +} diff --git a/admin/tool/installaddon/lang/en/tool_installaddon.php b/admin/tool/installaddon/lang/en/tool_installaddon.php index e0dac15caa8..c104eb0b723 100644 --- a/admin/tool/installaddon/lang/en/tool_installaddon.php +++ b/admin/tool/installaddon/lang/en/tool_installaddon.php @@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die(); $string['acknowledgement'] = 'Acknowledgement'; $string['acknowledgementtext'] = 'I understand that it is my responsibility to have full backups of this site prior to installing additional plugins. I accept and understand that plugins (especially but not only those originating in unofficial sources) may contain security holes, can make the site unavailable, or cause private data leaks or loss.'; +$string['activitychooserfootertext'] = 'Browse more activities on'; $string['featuredisabled'] = 'The plugin installer is disabled on this site.'; $string['installaddon'] = 'Install plugin!'; $string['installaddons'] = 'Install plugins'; @@ -44,6 +45,8 @@ $string['installfromzipsubmit'] = 'Install plugin from the ZIP file'; $string['installfromziptype'] = 'Plugin type'; $string['installfromziptype_help'] = 'For plugins that correctly declare their component name, the installer is able to detect the plugin type automatically. If the auto-detection fails, choose the correct type of plugin manually. Warning: The installation procedure can fail badly if an incorrect plugin type is specified.'; $string['installfromziptype_link'] = 'Development:Plugins'; +$string['marketplaceadminlinktext'] = 'Browse new plugins'; +$string['marketplacelink'] = 'Moodle Marketplace'; $string['permcheck'] = 'Make sure the plugin type root location is writable by the web server process.'; $string['permcheckerror'] = 'Error while checking for write permission'; $string['permcheckprogress'] = 'Checking for write permission ...'; diff --git a/admin/tool/installaddon/lib.php b/admin/tool/installaddon/lib.php new file mode 100644 index 00000000000..ebeecf1d10e --- /dev/null +++ b/admin/tool/installaddon/lib.php @@ -0,0 +1,48 @@ +. + +/** + * Public API for tool_installaddon. + * + * @package tool_installaddon + * @copyright 2026 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use core_course\local\entity\activity_chooser_footer; + +/** + * Build activity chooser footer content for Marketplace. + * + * @param int $courseid The selected course id. + * @param int $sectionid The selected section id. + * @return activity_chooser_footer + */ +function tool_installaddon_custom_chooser_footer(int $courseid, int $sectionid): activity_chooser_footer { + global $OUTPUT; + + $installer = tool_installaddon_installer::instance(); + $marketplaceurl = $installer->get_marketplace_url(); + + $renderedfooter = $OUTPUT->render_from_template('tool_installaddon/chooser_footer', [ + 'url' => $marketplaceurl->out(false), + ]); + + return new activity_chooser_footer( + 'tool_installaddon/footer', + $renderedfooter + ); +} diff --git a/admin/tool/installaddon/settings.php b/admin/tool/installaddon/settings.php index 17f0d51e91d..8a42859bb41 100644 --- a/admin/tool/installaddon/settings.php +++ b/admin/tool/installaddon/settings.php @@ -26,6 +26,12 @@ defined('MOODLE_INTERNAL') || die(); if ($hassiteconfig and empty($CFG->disableupdateautodeploy)) { + $installer = tool_installaddon_installer::instance(); + $ADMIN->add('modules', new admin_externalpage( + 'tool_installaddon_marketplace', + get_string('marketplaceadminlinktext', 'tool_installaddon'), + $installer->get_marketplace_url()->out(false) + ), 'modsettings'); $ADMIN->add('modules', new admin_externalpage('tool_installaddon_index', get_string('installaddons', 'tool_installaddon'), diff --git a/admin/tool/installaddon/templates/chooser_footer.mustache b/admin/tool/installaddon/templates/chooser_footer.mustache new file mode 100644 index 00000000000..fb88aa65c24 --- /dev/null +++ b/admin/tool/installaddon/templates/chooser_footer.mustache @@ -0,0 +1,30 @@ +{{! + 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 . +}} +{{! + @template tool_installaddon/chooser_footer + + Activity chooser footer link to Marketplace. + + Example context (json): + { + "url": "https://marketplace.moodle.com/?site=hash" + } +}} +
+ {{#str}} activitychooserfootertext, tool_installaddon {{/str}} + {{> tool_installaddon/marketplace_link }} +
diff --git a/admin/tool/installaddon/templates/marketplace_link.mustache b/admin/tool/installaddon/templates/marketplace_link.mustache new file mode 100644 index 00000000000..5ac949b80f9 --- /dev/null +++ b/admin/tool/installaddon/templates/marketplace_link.mustache @@ -0,0 +1,36 @@ +{{! + 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 . +}} +{{! + @template tool_installaddon/marketplace_link + + Reusable link to Moodle Marketplace. + + Example context (json): + { + "url": "https://marketplace.moodle.com/?site=hash" + } +}} + + {{#str}} marketplacelink, tool_installaddon {{/str}} + + + diff --git a/admin/tool/installaddon/tests/behat/activity_chooser_footer.feature b/admin/tool/installaddon/tests/behat/activity_chooser_footer.feature new file mode 100644 index 00000000000..5a53b7c97b8 --- /dev/null +++ b/admin/tool/installaddon/tests/behat/activity_chooser_footer.feature @@ -0,0 +1,25 @@ +@tool @tool_installaddon @javascript +Feature: Marketplace activity chooser footer + In order to browse plugins from the activity chooser + As a teacher + I need to see the Marketplace footer link when installaddon is the active footer plugin + + Background: + Given the following config values are set as admin: + | activitychooseractivefooter | tool_installaddon | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | format | + | Course 1 | C1 | 0 | topics | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + + Scenario: Activity chooser footer includes Marketplace link + Given I log in as "teacher1" + When I am on "Course 1" course homepage with editing mode on + And I open the activity chooser + Then "Browse more activities on" "text" should exist in the "Add an activity or resource" "dialogue" + And "Marketplace" "link" should exist in the "Add an activity or resource" "dialogue" diff --git a/admin/tool/installaddon/tests/fixtures/testable_installer_without_site_info.php b/admin/tool/installaddon/tests/fixtures/testable_installer_without_site_info.php new file mode 100644 index 00000000000..2e7223663f7 --- /dev/null +++ b/admin/tool/installaddon/tests/fixtures/testable_installer_without_site_info.php @@ -0,0 +1,46 @@ +. + +/** + * Provides a mock testable_tool_installaddon_installer_without_site_info class. + * + * @package tool_installaddon + * @subpackage fixtures + * @category test + * @copyright 2026 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once(__DIR__ . '/testable_installer.php'); + +/** + * Testable subclass with site-info sharing disabled. + * + * @copyright 2026 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class testable_tool_installaddon_installer_without_site_info extends testable_tool_installaddon_installer { + /** + * Disable site info sharing. + * + * @return bool + */ + protected function should_send_site_info() { + return false; + } +} diff --git a/admin/tool/installaddon/tests/installer_test.php b/admin/tool/installaddon/tests/installer_test.php index f0f2fa2af3e..ac2645c0f14 100644 --- a/admin/tool/installaddon/tests/installer_test.php +++ b/admin/tool/installaddon/tests/installer_test.php @@ -18,12 +18,14 @@ namespace tool_installaddon; use testable_tool_installaddon_installer; +use testable_tool_installaddon_installer_without_site_info; use tool_installaddon_installer; defined('MOODLE_INTERNAL') || die(); global $CFG; -require_once(__DIR__.'/fixtures/testable_installer.php'); +require_once(__DIR__ . '/fixtures/testable_installer.php'); +require_once(__DIR__ . '/fixtures/testable_installer_without_site_info.php'); /** * Unit tests for the {@link tool_installaddon_installer} class @@ -32,16 +34,14 @@ require_once(__DIR__.'/fixtures/testable_installer.php'); * @category test * @copyright 2013 David Mudrak * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_installaddon_installer */ final class installer_test extends \advanced_testcase { public function test_get_addons_repository_url(): void { $installer = testable_tool_installaddon_installer::instance(); $url = $installer->get_addons_repository_url(); - $query = parse_url($url, PHP_URL_QUERY); - $this->assertEquals(1, preg_match('~^site=(.+)$~', $query, $matches)); - $site = rawurldecode($matches[1]); - $site = json_decode(base64_decode($site), true); + $site = $this->decode_site_info_from_url($url); $this->assertIsArray($site); $this->assertEquals(3, count($site)); $this->assertSame('Nasty site', $site['fullname']); @@ -49,6 +49,34 @@ final class installer_test extends \advanced_testcase { $this->assertSame("2.5'; DROP TABLE mdl_user; --", $site['majorversion']); } + /** + * Tests that marketplace URL includes expected host, scheme and site payload. + */ + public function test_get_marketplace_url(): void { + $installer = testable_tool_installaddon_installer::instance(); + $addonsurl = $installer->get_addons_repository_url(); + $marketplaceurl = $installer->get_marketplace_url(); + + $this->assertSame('marketplace.moodle.com', parse_url($marketplaceurl, PHP_URL_HOST)); + $this->assertSame('https', parse_url($marketplaceurl, PHP_URL_SCHEME)); + $this->assertSame( + $this->decode_site_info_from_url($addonsurl), + $this->decode_site_info_from_url($marketplaceurl), + ); + } + + /** + * Tests that marketplace URL has no query string when site info is unavailable. + */ + public function test_get_marketplace_url_without_site_info(): void { + $installer = testable_tool_installaddon_installer_without_site_info::instance(); + $marketplaceurl = $installer->get_marketplace_url(); + + $this->assertSame('marketplace.moodle.com', parse_url($marketplaceurl, PHP_URL_HOST)); + $this->assertSame('https', parse_url($marketplaceurl, PHP_URL_SCHEME)); + $this->assertEmpty(parse_url($marketplaceurl, PHP_URL_QUERY)); + } + public function test_decode_remote_request(): void { $installer = testable_tool_installaddon_installer::instance(); @@ -132,7 +160,7 @@ $plugin->version = 2014121300; $versionphp = file_get_contents($fixtures.'/github/moodle-repository_mahara-master/version.php'); $this->assertEquals('repository_mahara', $installer->testable_detect_plugin_component_from_versionphp($versionphp)); - $versionphp = file_get_contents($fixtures.'/nocomponent/baz/version.php'); + $versionphp = file_get_contents($fixtures . '/nocomponent/baz/version.php'); $this->assertFalse($installer->testable_detect_plugin_component_from_versionphp($versionphp)); } @@ -143,15 +171,28 @@ $plugin->version = 2014121300; $storage1 = $installer->make_installfromzip_storage(); $this->assertTrue(is_dir($storage1)); $this->assertTrue(is_writable($storage1)); - file_put_contents($storage1.'/hello.txt', 'Find me if you can!'); + file_put_contents($storage1 . '/hello.txt', 'Find me if you can!'); // Check we get unique directory on each call. $storage2 = $installer->make_installfromzip_storage(); $this->assertTrue(is_dir($storage2)); $this->assertTrue(is_writable($storage2)); - $this->assertFalse(file_exists($storage2.'/hello.txt')); + $this->assertFalse(file_exists($storage2 . '/hello.txt')); // Check both are in the same parent directory. $this->assertEquals(dirname($storage1), dirname($storage2)); } + + /** + * Decodes the encoded 'site' URL query parameter. + * + * @param moodle_url $url + * @return array + */ + private function decode_site_info_from_url(\moodle_url $url): array { + $query = parse_url($url, PHP_URL_QUERY); + $this->assertEquals(1, preg_match('~^site=(.+)$~', $query, $matches)); + $site = rawurldecode($matches[1]); + return json_decode(base64_decode($site), true); + } } diff --git a/admin/tool/installaddon/tests/lib_test.php b/admin/tool/installaddon/tests/lib_test.php new file mode 100644 index 00000000000..d215534a4eb --- /dev/null +++ b/admin/tool/installaddon/tests/lib_test.php @@ -0,0 +1,53 @@ +. + +/** + * Unit tests for tool_installaddon lib. + * + * @package tool_installaddon + * @copyright 2026 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_installaddon; + +use core_course\local\entity\activity_chooser_footer; + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/admin/tool/installaddon/lib.php'); + +/** + * Test installaddon lib functions. + */ +final class lib_test extends \advanced_testcase { + /** + * Tests chooser footer generation for marketplace link content. + * + * @covers ::tool_installaddon_custom_chooser_footer + */ + public function test_tool_installaddon_custom_chooser_footer(): void { + $this->resetAfterTest(); + + $footer = \tool_installaddon_custom_chooser_footer(1, 1); + + $this->assertInstanceOf(activity_chooser_footer::class, $footer); + $this->assertSame('tool_installaddon/footer', $footer->get_footer_js_file()); + $this->assertStringContainsString('https://marketplace.moodle.com/', $footer->get_footer_template()); + $this->assertStringContainsString('site=', $footer->get_footer_template()); + } +} diff --git a/admin/tool/installaddon/tests/task/post_install_test.php b/admin/tool/installaddon/tests/task/post_install_test.php new file mode 100644 index 00000000000..9a984ad5f2c --- /dev/null +++ b/admin/tool/installaddon/tests/task/post_install_test.php @@ -0,0 +1,47 @@ +. + +declare(strict_types=1); + +namespace tool_installaddon\task; + +/** + * Unit tests for the post install task. + * + * @package tool_installaddon + * @category test + * @copyright 2026 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_installaddon\task\post_install + */ +final class post_install_test extends \advanced_testcase { + /** + * Tests that the task sets the activity chooser footer plugin to tool_installaddon. + */ + public function test_execute_sets_activitychooseractivefooter_config(): void { + $this->resetAfterTest(); + + set_config('activitychooseractivefooter', 'hidden'); + + $task = new post_install(); + $task->execute(); + + $this->assertSame( + 'tool_installaddon', + get_config('core', 'activitychooseractivefooter'), + ); + } +} diff --git a/admin/tool/installaddon/version.php b/admin/tool/installaddon/version.php index bd9eb653235..69ded7c6111 100644 --- a/admin/tool/installaddon/version.php +++ b/admin/tool/installaddon/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'tool_installaddon'; -$plugin->version = 2024100700; +$plugin->version = 2024100701; $plugin->requires = 2024100100; $plugin->maturity = MATURITY_STABLE;