"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/phpunit/includes/HooksTest.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

HooksTest.php  (mediawiki-1.31.1):HooksTest.php  (mediawiki-1.32.0)
skipping to change at line 36 skipping to change at line 36
'data', 'data',
'original' 'original'
], ],
[ 'Object and static method', [ $i, 'someStatic' ], 'chan ged-static', 'original' ], [ 'Object and static method', [ $i, 'someStatic' ], 'chan ged-static', 'original' ],
[ [
'Class::method static call', 'Class::method static call',
[ 'NothingClass::someStatic' ], [ 'NothingClass::someStatic' ],
'changed-static', 'changed-static',
'original' 'original'
], ],
[
'Class::method static call as array',
[ [ 'NothingClass::someStatic' ] ],
'changed-static',
'original'
],
[ 'Global function', [ 'NothingFunction' ], 'changed-func ', 'original' ], [ 'Global function', [ 'NothingFunction' ], 'changed-func ', 'original' ],
[ 'Global function with data', [ 'NothingFunctionData', ' data' ], 'data', 'original' ], [ 'Global function with data', [ 'NothingFunctionData', ' data' ], 'data', 'original' ],
[ 'Closure', [ function ( &$foo, $bar ) { [ 'Closure', [ function ( &$foo, $bar ) {
$foo = 'changed-closure'; $foo = 'changed-closure';
return true; return true;
} ], 'changed-closure', 'original' ], } ], 'changed-closure', 'original' ],
[ 'Closure with data', [ function ( $data, &$foo, $bar ) { [ 'Closure with data', [ function ( $data, &$foo, $bar ) {
$foo = $data; $foo = $data;
return true; return true;
}, 'data' ], 'data', 'original' ] }, 'data' ], 'data', 'original' ]
]; ];
} }
/** /**
* @dataProvider provideHooks * @dataProvider provideHooks
* @covers ::wfRunHooks
*/
public function testOldStyleHooks( $msg, array $hook, $expectedFoo, $expe
ctedBar ) {
global $wgHooks;
$this->hideDeprecated( 'wfRunHooks' );
$foo = $bar = 'original';
$wgHooks['MediaWikiHooksTest001'][] = $hook;
wfRunHooks( 'MediaWikiHooksTest001', [ &$foo, &$bar ] );
$this->assertSame( $expectedFoo, $foo, $msg );
$this->assertSame( $expectedBar, $bar, $msg );
}
/**
* @dataProvider provideHooks
* @covers Hooks::register * @covers Hooks::register
* @covers Hooks::run * @covers Hooks::run
* @covers Hooks::callHook * @covers Hooks::callHook
*/ */
public function testNewStyleHooks( $msg, $hook, $expectedFoo, $expectedBa r ) { public function testNewStyleHooks( $msg, $hook, $expectedFoo, $expectedBa r ) {
$foo = $bar = 'original'; $foo = $bar = 'original';
Hooks::register( 'MediaWikiHooksTest001', $hook ); Hooks::register( 'MediaWikiHooksTest001', $hook );
Hooks::run( 'MediaWikiHooksTest001', [ &$foo, &$bar ] ); Hooks::run( 'MediaWikiHooksTest001', [ &$foo, &$bar ] );
$this->assertSame( $expectedFoo, $foo, $msg ); $this->assertSame( $expectedFoo, $foo, $msg );
$this->assertSame( $expectedBar, $bar, $msg ); $this->assertSame( $expectedBar, $bar, $msg );
} }
/** /**
* @covers Hooks::getHandlers
*/
public function testGetHandlers() {
global $wgHooks;
$this->assertSame(
[],
Hooks::getHandlers( 'MediaWikiHooksTest001' ),
'No hooks registered'
);
$a = new NothingClass();
$b = new NothingClass();
$wgHooks['MediaWikiHooksTest001'][] = $a;
$this->assertSame(
[ $a ],
Hooks::getHandlers( 'MediaWikiHooksTest001' ),
'Hook registered by $wgHooks'
);
Hooks::register( 'MediaWikiHooksTest001', $b );
$this->assertSame(
[ $b, $a ],
Hooks::getHandlers( 'MediaWikiHooksTest001' ),
'Hooks::getHandlers() should return hooks registered via
wgHooks as well as Hooks::register'
);
Hooks::clear( 'MediaWikiHooksTest001' );
unset( $wgHooks['MediaWikiHooksTest001'] );
Hooks::register( 'MediaWikiHooksTest001', $b );
$this->assertSame(
[ $b ],
Hooks::getHandlers( 'MediaWikiHooksTest001' ),
'Hook registered by Hook::register'
);
}
/**
* @covers Hooks::isRegistered * @covers Hooks::isRegistered
* @covers Hooks::register * @covers Hooks::register
* @covers Hooks::getHandlers
* @covers Hooks::run * @covers Hooks::run
* @covers Hooks::callHook * @covers Hooks::callHook
*/ */
public function testNewStyleHookInteraction() { public function testNewStyleHookInteraction() {
global $wgHooks; global $wgHooks;
$a = new NothingClass(); $a = new NothingClass();
$b = new NothingClass(); $b = new NothingClass();
$wgHooks['MediaWikiHooksTest001'][] = $a; $wgHooks['MediaWikiHooksTest001'][] = $a;
skipping to change at line 155 skipping to change at line 184
$foo = 'test'; $foo = 'test';
return true; return true;
} ); } );
$foo = 'original'; $foo = 'original';
Hooks::run( 'MediaWikiHooksTest001', [ &$foo ] ); Hooks::run( 'MediaWikiHooksTest001', [ &$foo ] );
$this->assertSame( 'original', $foo, 'Hooks abort after a false r eturn.' ); $this->assertSame( 'original', $foo, 'Hooks abort after a false r eturn.' );
} }
/** /**
* @covers Hooks::run
*/
public function testNullReturn() {
Hooks::register( 'MediaWikiHooksTest001', function ( &$foo ) {
return;
} );
Hooks::register( 'MediaWikiHooksTest001', function ( &$foo ) {
$foo = 'test';
return true;
} );
$foo = 'original';
Hooks::run( 'MediaWikiHooksTest001', [ &$foo ] );
$this->assertSame( 'test', $foo, 'Hooks continue after a null ret
urn.' );
}
/**
* @covers Hooks::callHook
*/
public function testCallHook_FalseHook() {
Hooks::register( 'MediaWikiHooksTest001', false );
Hooks::register( 'MediaWikiHooksTest001', function ( &$foo ) {
$foo = 'test';
return true;
} );
$foo = 'original';
Hooks::run( 'MediaWikiHooksTest001', [ &$foo ] );
$this->assertSame( 'test', $foo, 'Hooks that are falsey are skipp
ed.' );
}
/**
* @covers Hooks::callHook
* @expectedException MWException
*/
public function testCallHook_UnknownDatatype() {
Hooks::register( 'MediaWikiHooksTest001', 12345 );
Hooks::run( 'MediaWikiHooksTest001' );
}
/**
* @covers Hooks::callHook
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testCallHook_Deprecated() {
Hooks::register( 'MediaWikiHooksTest001', 'NothingClass::someStat
ic' );
Hooks::run( 'MediaWikiHooksTest001', [], '1.31' );
}
/**
* @covers Hooks::runWithoutAbort * @covers Hooks::runWithoutAbort
* @covers Hooks::callHook * @covers Hooks::callHook
*/ */
public function testRunWithoutAbort() { public function testRunWithoutAbort() {
$list = []; $list = [];
Hooks::register( 'MediaWikiHooksTest001', function ( &$list ) { Hooks::register( 'MediaWikiHooksTest001', function ( &$list ) {
$list[] = 1; $list[] = 1;
return true; // Explicit true return true; // Explicit true
} ); } );
Hooks::register( 'MediaWikiHooksTest001', function ( &$list ) { Hooks::register( 'MediaWikiHooksTest001', function ( &$list ) {
 End of changes. 5 change blocks. 
19 lines changed or deleted 101 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)