refactor!: retire legacy administration
Moodle Plugin CI / test (push) Successful in 3m26s

BREAKING CHANGE: legacy management routes now fail closed and the legacy helper API is removed.
This commit is contained in:
2026-08-20 08:08:30 +00:00
parent 297e4ab7cd
commit 82ba9222ff
17 changed files with 127 additions and 737 deletions
-6
View File
@@ -36,7 +36,6 @@ final class autonomy_test extends \advanced_testcase {
global $CFG;
require_once($CFG->dirroot . '/local/webhooks/lib.php');
require_once($CFG->dirroot . '/local/webhooks/classes/service_edit_form.php');
$debugsettings = [$CFG->debug, $CFG->debugdisplay, $CFG->debugdeveloper];
$choices = \local_webhooks_get_event_choices();
@@ -82,10 +81,5 @@ final class autonomy_test extends \advanced_testcase {
}
$this->assertFalse(class_exists('report_eventlist_list_generator', false));
$form = new \service_edit_form(new \moodle_url('/local/webhooks/editservice.php'));
$html = $form->render();
$this->assertStringContainsString($coreevent, $html);
$this->assertStringContainsString($localevent, $html);
$this->assertFalse(class_exists('report_eventlist_list_generator', false));
}
}
+104
View File
@@ -0,0 +1,104 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* Legacy management surface tests.
*
* @package local_webhooks
* @copyright 2026 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_webhooks;
/**
* Legacy management surface tests.
*/
#[\PHPUnit\Framework\Attributes\CoversNothing]
final class legacy_ui_test extends \advanced_testcase {
/**
* Legacy management is unavailable without leaving dead links or write helpers.
*/
public function test_legacy_management_is_retired(): void {
global $CFG;
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
foreach (['index.php', 'editservice.php', 'restorebackup.php'] as $entrypoint) {
try {
require($CFG->dirroot . '/local/webhooks/' . $entrypoint);
$this->fail($entrypoint . ' allowed a user without site configuration capability.');
} catch (\required_capability_exception $exception) {
$this->assertSame('nopermissions', $exception->errorcode);
}
}
$this->setAdminUser();
foreach (['index.php', 'editservice.php', 'restorebackup.php'] as $entrypoint) {
try {
require($CFG->dirroot . '/local/webhooks/' . $entrypoint);
$this->fail($entrypoint . ' did not fail closed.');
} catch (\moodle_exception $exception) {
$this->assertSame('legacyuidisabled', $exception->errorcode);
}
}
require_once($CFG->libdir . '/adminlib.php');
$this->assertNull(admin_get_root(true)->locate('local_webhooks'));
foreach (['classes/service_edit_form.php', 'classes/service_form.php', 'locallib.php'] as $file) {
$this->assertFileDoesNotExist($CFG->dirroot . '/local/webhooks/' . $file);
}
require_once($CFG->dirroot . '/local/webhooks/lib.php');
$this->assertTrue(function_exists('local_webhooks_get_event_choices'));
$helpers = [
'local_webhooks_get_list_records',
'local_webhooks_get_record',
'local_webhooks_remove_list_records',
'local_webhooks_remove_record',
'local_webhooks_update_record',
'local_webhooks_create_backup',
'local_webhooks_restore_backup',
'local_webhooks_archiving_data',
'local_webhooks_unarchive_data',
];
foreach ($helpers as $helper) {
$this->assertFalse(function_exists($helper), $helper . ' is still callable.');
}
$context = \context_system::instance();
$events = [
event\backup_performed::create(['context' => $context, 'objectid' => 0]),
event\backup_restored::create(['context' => $context, 'objectid' => 0]),
event\response_answer::create([
'context' => $context,
'objectid' => 1,
'other' => ['status' => 'disabled'],
]),
event\service_added::create(['context' => $context, 'objectid' => 1]),
event\service_deleted::create(['context' => $context, 'objectid' => 1]),
event\service_updated::create(['context' => $context, 'objectid' => 1]),
];
foreach ($events as $event) {
$this->assertNull($event->get_url());
}
}
}