3 class HooksTest
extends MediaWikiTestCase
{
5 public function testOldStyleHooks() {
9 $i = new NothingClass();
13 $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someNonStatic' );
15 wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
17 $this->assertEquals( 'fOO', $foo, 'Standard method' );
20 $wgHooks['MediaWikiHooksTest001'][] = $i;
22 wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
24 $this->assertEquals( 'foo', $foo, 'onEventName style' );
27 $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someNonStaticWithData', 'baz' );
29 wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
31 $this->assertEquals( 'baz', $foo, 'Data included' );
34 $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someStatic' );
36 wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
38 $this->assertEquals( 'bah', $foo, 'Standard static method' );
41 unset( $wgHooks['MediaWikiHooksTest001'] );
45 public function testNewStyleHooks() {
49 $i = new NothingClass();
51 Hooks
::register( 'MediaWikiHooksTest001', array( $i, 'someNonStatic' ) );
53 Hooks
::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
55 $this->assertEquals( 'fOO', $foo, 'Standard method' );
58 Hooks
::register( 'MediaWikiHooksTest001', $i );
60 Hooks
::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
62 $this->assertEquals( 'foo', $foo, 'onEventName style' );
65 Hooks
::register( 'MediaWikiHooksTest001', array( $i, 'someNonStaticWithData', 'baz' ) );
67 Hooks
::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
69 $this->assertEquals( 'baz', $foo, 'Data included' );
72 Hooks
::register( 'MediaWikiHooksTest001', array( $i, 'someStatic' ) );
74 Hooks
::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
76 $this->assertEquals( 'bah', $foo, 'Standard static method' );
82 static public function someStatic( &$foo, &$bar ) {
87 public function someNonStatic( &$foo, &$bar ) {
93 public function onMediaWikiHooksTest001( &$foo, &$bar ) {
98 public function someNonStaticWithData( $foo, &$bar ) {