MediaWiki  REL1_19
HooksTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class HooksTest extends MediaWikiTestCase {
00004 
00005         public function testOldStyleHooks() {
00006                 $foo = 'Foo';
00007                 $bar = 'Bar';
00008 
00009                 $i = new NothingClass();
00010 
00011                 global $wgHooks;
00012 
00013                 $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someNonStatic' );
00014 
00015                 wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
00016 
00017                 $this->assertEquals( 'fOO', $foo, 'Standard method' );
00018                 $foo = 'Foo';
00019 
00020                 $wgHooks['MediaWikiHooksTest001'][] = $i;
00021 
00022                 wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
00023 
00024                 $this->assertEquals( 'foo', $foo, 'onEventName style' );
00025                 $foo = 'Foo';
00026 
00027                 $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someNonStaticWithData', 'baz' );
00028 
00029                 wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
00030 
00031                 $this->assertEquals( 'baz', $foo, 'Data included' );
00032                 $foo = 'Foo';
00033 
00034                 $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someStatic' );
00035 
00036                 wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
00037 
00038                 $this->assertEquals( 'bah', $foo, 'Standard static method' );
00039                 //$foo = 'Foo';
00040 
00041                 unset( $wgHooks['MediaWikiHooksTest001'] );
00042 
00043         }
00044 
00045         public function testNewStyleHooks() {
00046                 $foo = 'Foo';
00047                 $bar = 'Bar';
00048 
00049                 $i = new NothingClass();
00050 
00051                 Hooks::register( 'MediaWikiHooksTest001', array( $i, 'someNonStatic' ) );
00052 
00053                 Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
00054 
00055                 $this->assertEquals( 'fOO', $foo, 'Standard method' );
00056                 $foo = 'Foo';
00057 
00058                 Hooks::register( 'MediaWikiHooksTest001', $i );
00059 
00060                 Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
00061 
00062                 $this->assertEquals( 'foo', $foo, 'onEventName style' );
00063                 $foo = 'Foo';
00064 
00065                 Hooks::register( 'MediaWikiHooksTest001', array( $i, 'someNonStaticWithData', 'baz' ) );
00066 
00067                 Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
00068 
00069                 $this->assertEquals( 'baz', $foo, 'Data included' );
00070                 $foo = 'Foo';
00071 
00072                 Hooks::register( 'MediaWikiHooksTest001', array( $i, 'someStatic' ) );
00073 
00074                 Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) );
00075 
00076                 $this->assertEquals( 'bah', $foo, 'Standard static method' );
00077                 $foo = 'Foo';
00078         }
00079 }
00080 
00081 class NothingClass {
00082         static public function someStatic( &$foo, &$bar ) {
00083                 $foo = 'bah';
00084                 return true;
00085         }
00086 
00087         public function someNonStatic( &$foo, &$bar ) {
00088                 $foo = 'fOO';
00089                 $bar = 'bAR';
00090                 return true;
00091         }
00092 
00093         public function onMediaWikiHooksTest001( &$foo, &$bar ) {
00094                 $foo = 'foo';
00095                 return true;
00096         }
00097 
00098         public function someNonStaticWithData( $foo, &$bar ) {
00099                 $bar = $foo;
00100                 return true;
00101         }
00102 }