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' ]
57 $foo = $bar =
'original';
59 $wgHooks[
'MediaWikiHooksTest001'][] = $hook;
60 wfRunHooks(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
62 $this->assertSame( $expectedFoo, $foo, $msg );
63 $this->assertSame( $expectedBar, $bar, $msg );
72 $foo = $bar =
'original';
74 Hooks::register(
'MediaWikiHooksTest001', $hook );
75 Hooks::run(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
77 $this->assertSame( $expectedFoo, $foo, $msg );
78 $this->assertSame( $expectedBar, $bar, $msg );
93 $wgHooks[
'MediaWikiHooksTest001'][] = $a;
95 Hooks::isRegistered(
'MediaWikiHooksTest001' ),
96 'Hook registered via $wgHooks should be noticed by Hooks::isRegistered'
99 Hooks::register(
'MediaWikiHooksTest001', $b );
102 count( Hooks::getHandlers(
'MediaWikiHooksTest001' ) ),
103 'Hooks::getHandlers() should return hooks registered via wgHooks as well as Hooks::register'
109 Hooks::run(
'MediaWikiHooksTest001', [ &$foo, &$bar ] );
113 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'
118 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register'
127 Hooks::register(
'MediaWikiHooksTest001',
'ThisFunctionDoesntExist' );
128 Hooks::run(
'MediaWikiHooksTest001', [] );
135 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
138 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
144 Hooks::run(
'MediaWikiHooksTest001', [ &$foo ] );
145 $this->assertSame(
'original', $foo,
'Hooks abort after a false return.' );
153 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
157 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
161 Hooks::register(
'MediaWikiHooksTest001',
function ( &$list ) {
166 Hooks::runWithoutAbort(
'MediaWikiHooksTest001', [ &$list ] );
167 $this->assertSame( [ 1, 2, 3 ], $list,
'All hooks ran.' );
174 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
177 Hooks::register(
'MediaWikiHooksTest001',
function ( &$foo ) {
183 $this->setExpectedException(
184 UnexpectedValueException::class,
185 'Invalid return from hook-MediaWikiHooksTest001-closure for ' .
186 'unabortable MediaWikiHooksTest001'
188 Hooks::runWithoutAbort(
'MediaWikiHooksTest001', [ &$foo ] );
196 Hooks::register(
'MediaWikiHooksTest001',
function () {
199 Hooks::run(
'MediaWikiHooksTest001', [] );
204 $foo =
'changed-func';
219 $foo =
'changed-static';
226 $foo =
'changed-nonstatic';
227 $bar =
'changed-nonstatic';
234 $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.
testOldStyleHooks( $msg, array $hook, $expectedFoo, $expectedBar)
provideHooks wfRunHooks
testFalseReturn()
Hooks::run.
testNewStyleHookInteraction()
Hooks::isRegistered Hooks::register Hooks::getHandlers Hooks::run.
testNewStyleHooks( $msg, $hook, $expectedFoo, $expectedBar)
provideHooks Hooks::register Hooks::run
testRunWithoutAbortWarning()
Hooks::runWithoutAbort.
testRunWithoutAbort()
Hooks::runWithoutAbort.
static someStatic(&$foo, &$bar)
someNonStaticWithData( $data, &$foo, &$bar)
someNonStatic(&$foo, &$bar)
onMediaWikiHooksTest001(&$foo, &$bar)
$wgHooks['ArticleShow'][]