8 Hooks::clear(
'MediaWikiHooksTest001' );
9 unset(
$wgHooks[
'MediaWikiHooksTest001'] );
18 [ $i,
'someNonStatic' ],
22 [
'Object and no method', [ $i ],
'changed-onevent',
'original' ],
24 'Object and method with data',
25 [ $i,
'someNonStaticWithData',
'data' ],
29 [
'Object and static method', [ $i,
'someStatic' ],
'changed-static',
'original' ],
31 'Class::method static call',
32 [
'NothingClass::someStatic' ],
36 [
'Global function', [
'NothingFunction' ],
'changed-func',
'original' ],
37 [
'Global function with data', [
'NothingFunctionData',
'data' ],
'data',
'original' ],
38 [
'Closure', [
function ( &$foo, $bar ) {
39 $foo =
'changed-closure';
42 } ],
'changed-closure',
'original' ],
43 [
'Closure with data', [
function ( $data, &$foo, $bar ) {
47 },
'data' ],
'data',
'original' ]
59 $foo = $bar =
'original';
61 $wgHooks[
'MediaWikiHooksTest001'][] = $hook;
62 wfRunHooks(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
64 $this->assertSame( $expectedFoo, $foo, $msg );
65 $this->assertSame( $expectedBar, $bar, $msg );
75 $foo = $bar =
'original';
77 Hooks::register(
'MediaWikiHooksTest001', $hook );
78 Hooks::run(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
80 $this->assertSame( $expectedFoo, $foo, $msg );
81 $this->assertSame( $expectedBar, $bar, $msg );
97 $wgHooks[
'MediaWikiHooksTest001'][] = $a;
99 Hooks::isRegistered(
'MediaWikiHooksTest001' ),
100 'Hook registered via $wgHooks should be noticed by Hooks::isRegistered'
103 Hooks::register(
'MediaWikiHooksTest001', $b );
106 count( Hooks::getHandlers(
'MediaWikiHooksTest001' ) ),
107 'Hooks::getHandlers() should return hooks registered via wgHooks as well as Hooks::register'
113 Hooks::run(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
117 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'
122 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'
132 Hooks::register(
'MediaWikiHooksTest001',
'ThisFunctionDoesntExist' );
133 Hooks::run(
'MediaWikiHooksTest001', [] );
141 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
144 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
150 Hooks::run(
'MediaWikiHooksTest001', [ &$foo ] );
151 $this->assertSame(
'original', $foo,
'Hooks abort after a false return.' );
160 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
164 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
168 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
173 Hooks::runWithoutAbort(
'MediaWikiHooksTest001', [ &$list ] );
174 $this->assertSame( [ 1, 2, 3 ], $list,
'All hooks ran.' );
182 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
185 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
191 $this->setExpectedException(
192 UnexpectedValueException::class,
193 'Invalid return from hook-MediaWikiHooksTest001-closure for ' .
194 'unabortable MediaWikiHooksTest001'
196 Hooks::runWithoutAbort(
'MediaWikiHooksTest001', [ &$foo ] );
204 Hooks::register(
'MediaWikiHooksTest001',
function () {
207 Hooks::run(
'MediaWikiHooksTest001', [] );
212 $foo =
'changed-func';
227 $foo =
'changed-static';
234 $foo =
'changed-nonstatic';
235 $bar =
'changed-nonstatic';
242 $foo =
'changed-onevent';
wfRunHooks( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
NothingFunction(&$foo, &$bar)
NothingFunctionData( $data, &$foo, &$bar)
testFatalError()
FatalError Hooks::run.
testUncallableFunction()
MWException Hooks::run Hooks::callHook.
testOldStyleHooks( $msg, array $hook, $expectedFoo, $expectedBar)
provideHooks wfRunHooks
testFalseReturn()
Hooks::run Hooks::callHook.
testNewStyleHookInteraction()
Hooks::isRegistered Hooks::register Hooks::getHandlers Hooks::run Hooks::callHook.
testNewStyleHooks( $msg, $hook, $expectedFoo, $expectedBar)
provideHooks Hooks::register Hooks::run Hooks::callHook
testRunWithoutAbortWarning()
Hooks::runWithoutAbort Hooks::callHook.
testRunWithoutAbort()
Hooks::runWithoutAbort Hooks::callHook.
static someStatic(&$foo, &$bar)
someNonStaticWithData( $data, &$foo, &$bar)
someNonStatic(&$foo, &$bar)
onMediaWikiHooksTest001(&$foo, &$bar)
$wgHooks['ArticleShow'][]