X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FHooksTest.php;h=666051666b0c4b36f01656774b0446201e3716ce;hb=9f3bc1fe5978c24230d0b6a92a83560f9d638a18;hp=527e12927ab1516e363684b26026b64d771396b4;hpb=d716155c8b2d6e4a51a4110195cee7a1794846e8;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/HooksTest.php b/tests/phpunit/includes/HooksTest.php index 527e12927a..666051666b 100644 --- a/tests/phpunit/includes/HooksTest.php +++ b/tests/phpunit/includes/HooksTest.php @@ -54,6 +54,8 @@ class HooksTest extends MediaWikiTestCase { */ public function testOldStyleHooks( $msg, array $hook, $expectedFoo, $expectedBar ) { global $wgHooks; + + $this->hideDeprecated( 'wfRunHooks' ); $foo = $bar = 'original'; $wgHooks['MediaWikiHooksTest001'][] = $hook; @@ -142,7 +144,50 @@ class HooksTest extends MediaWikiTestCase { } ); $foo = 'original'; Hooks::run( 'MediaWikiHooksTest001', [ &$foo ] ); - $this->assertSame( 'original', $foo, 'Hooks continued processing after a false return.' ); + $this->assertSame( 'original', $foo, 'Hooks abort after a false return.' ); + } + + /** + * @covers Hooks::runWithoutAbort + */ + public function testRunWithoutAbort() { + $list = []; + Hooks::register( 'MediaWikiHooksTest001', function ( &$list ) { + $list[] = 1; + return true; // Explicit true + } ); + Hooks::register( 'MediaWikiHooksTest001', function ( &$list ) { + $list[] = 2; + return; // Implicit null + } ); + Hooks::register( 'MediaWikiHooksTest001', function ( &$list ) { + $list[] = 3; + // No return + } ); + + Hooks::runWithoutAbort( 'MediaWikiHooksTest001', [ &$list ] ); + $this->assertSame( [ 1, 2, 3 ], $list, 'All hooks ran.' ); + } + + /** + * @covers Hooks::runWithoutAbort + */ + public function testRunWithoutAbortWarning() { + Hooks::register( 'MediaWikiHooksTest001', function ( &$foo ) { + return false; + } ); + Hooks::register( 'MediaWikiHooksTest001', function ( &$foo ) { + $foo = 'test'; + return true; + } ); + $foo = 'original'; + + $this->setExpectedException( + UnexpectedValueException::class, + 'Invalid return from hook-MediaWikiHooksTest001-closure for ' . + 'unabortable MediaWikiHooksTest001' + ); + Hooks::runWithoutAbort( 'MediaWikiHooksTest001', [ &$foo ] ); } /**