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