Index: trunk/phase3/tests/phpunit/includes/HooksTest.php |
— | — | @@ -0,0 +1,130 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | + |
| 5 | +class HooksTest extends MediaWikiTestCase { |
| 6 | + |
| 7 | + |
| 8 | + public function testOldStyleHooks() { |
| 9 | + |
| 10 | + $foo = 'Foo'; |
| 11 | + $bar = 'Bar'; |
| 12 | + |
| 13 | + $i = new NothingClass(); |
| 14 | + |
| 15 | + global $wgHooks; |
| 16 | + |
| 17 | + $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someNonStatic' ); |
| 18 | + |
| 19 | + wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); |
| 20 | + |
| 21 | + $this->assertEquals( 'fOO', $foo, 'Standard method' ); |
| 22 | + $foo = 'Foo'; |
| 23 | + |
| 24 | + |
| 25 | + $wgHooks['MediaWikiHooksTest001'][] = $i; |
| 26 | + |
| 27 | + wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); |
| 28 | + |
| 29 | + $this->assertEquals( 'foo', $foo, 'onEventName style' ); |
| 30 | + $foo = 'Foo'; |
| 31 | + |
| 32 | + |
| 33 | + $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someNonStaticWithData', 'baz' ); |
| 34 | + |
| 35 | + wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); |
| 36 | + |
| 37 | + $this->assertEquals( 'baz', $foo, 'Data included' ); |
| 38 | + $foo = 'Foo'; |
| 39 | + |
| 40 | + |
| 41 | + $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someStatic' ); |
| 42 | + |
| 43 | + wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); |
| 44 | + |
| 45 | + $this->assertEquals( 'bah', $foo, 'Standard static method' ); |
| 46 | + $foo = 'Foo'; |
| 47 | + |
| 48 | + |
| 49 | + unset( $wgHooks['MediaWikiHooksTest001'] ); |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | + public function testNewStyleHooks() { |
| 54 | + |
| 55 | + $foo = 'Foo'; |
| 56 | + $bar = 'Bar'; |
| 57 | + |
| 58 | + $i = new NothingClass(); |
| 59 | + |
| 60 | + |
| 61 | + Hooks::register( 'MediaWikiHooksTest001', array( $i, 'someNonStatic' ) ); |
| 62 | + |
| 63 | + Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); |
| 64 | + |
| 65 | + $this->assertEquals( 'fOO', $foo, 'Standard method' ); |
| 66 | + $foo = 'Foo'; |
| 67 | + |
| 68 | + |
| 69 | + Hooks::register( 'MediaWikiHooksTest001', $i ); |
| 70 | + |
| 71 | + Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); |
| 72 | + |
| 73 | + $this->assertEquals( 'foo', $foo, 'onEventName style' ); |
| 74 | + $foo = 'Foo'; |
| 75 | + |
| 76 | + |
| 77 | + Hooks::register( 'MediaWikiHooksTest001', array( $i, 'someNonStaticWithData', 'baz' ) ); |
| 78 | + |
| 79 | + Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); |
| 80 | + |
| 81 | + $this->assertEquals( 'baz', $foo, 'Data included' ); |
| 82 | + $foo = 'Foo'; |
| 83 | + |
| 84 | + |
| 85 | + Hooks::register( 'MediaWikiHooksTest001', array( $i, 'someStatic' ) ); |
| 86 | + |
| 87 | + Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); |
| 88 | + |
| 89 | + $this->assertEquals( 'bah', $foo, 'Standard static method' ); |
| 90 | + $foo = 'Foo'; |
| 91 | + |
| 92 | + } |
| 93 | + |
| 94 | +} |
| 95 | + |
| 96 | +class NothingClass { |
| 97 | + |
| 98 | + static public function someStatic( &$foo, &$bar ) { |
| 99 | + |
| 100 | + $foo = 'bah'; |
| 101 | + |
| 102 | + return true; |
| 103 | + |
| 104 | + } |
| 105 | + |
| 106 | + public function someNonStatic( &$foo, &$bar ) { |
| 107 | + |
| 108 | + $foo = 'fOO'; |
| 109 | + $bar = 'bAR'; |
| 110 | + |
| 111 | + return true; |
| 112 | + |
| 113 | + } |
| 114 | + |
| 115 | + public function onMediaWikiHooksTest001( &$foo, &$bar ) { |
| 116 | + |
| 117 | + $foo = 'foo'; |
| 118 | + |
| 119 | + return true; |
| 120 | + |
| 121 | + } |
| 122 | + |
| 123 | + public function someNonStaticWithData( $foo, &$bar ) { |
| 124 | + |
| 125 | + $bar = $foo; |
| 126 | + |
| 127 | + return true; |
| 128 | + |
| 129 | + } |
| 130 | + |
| 131 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/HooksTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 132 | + native |