78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?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/>.
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Event handler 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;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Event handler tests.
|
||
|
|
*/
|
||
|
|
#[\PHPUnit\Framework\Attributes\CoversClass(handler::class)]
|
||
|
|
final class handler_test extends \advanced_testcase {
|
||
|
|
/**
|
||
|
|
* The legacy observer does not inspect or deliver events.
|
||
|
|
*/
|
||
|
|
public function test_legacy_delivery_is_disabled(): void {
|
||
|
|
global $CFG;
|
||
|
|
|
||
|
|
$this->resetAfterTest();
|
||
|
|
|
||
|
|
$event = new class {
|
||
|
|
/** @var bool Whether event data was requested. */
|
||
|
|
public bool $accessed = false;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Fails if the disabled handler reads the event.
|
||
|
|
*
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function get_data(): array {
|
||
|
|
$this->accessed = true;
|
||
|
|
throw new \LogicException('The disabled handler must not read event data.');
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
handler::events($event);
|
||
|
|
$this->assertFalse($event->accessed);
|
||
|
|
|
||
|
|
$user = $this->getDataGenerator()->create_user();
|
||
|
|
$coreevent = \core\event\user_created::create([
|
||
|
|
'objectid' => $user->id,
|
||
|
|
'context' => \context_user::instance($user->id),
|
||
|
|
]);
|
||
|
|
$sink = $this->redirectEvents();
|
||
|
|
$debug = $CFG->debug;
|
||
|
|
|
||
|
|
try {
|
||
|
|
$CFG->debug = DEBUG_DEVELOPER;
|
||
|
|
handler::events($coreevent);
|
||
|
|
} finally {
|
||
|
|
$CFG->debug = $debug;
|
||
|
|
}
|
||
|
|
|
||
|
|
$events = $sink->get_events();
|
||
|
|
$sink->close();
|
||
|
|
$this->assertEmpty($events);
|
||
|
|
}
|
||
|
|
}
|