|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WNBY\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use WNBY\HookRegistry; |
|
6
|
|
|
use Title; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers \WNBY\HookRegistry |
|
10
|
|
|
* @group whats-nearby |
|
11
|
|
|
* |
|
12
|
|
|
* @license GNU GPL v2+ |
|
13
|
|
|
* @since 1.0 |
|
14
|
|
|
* |
|
15
|
|
|
* @author mwjames |
|
16
|
|
|
*/ |
|
17
|
|
|
class HookRegistryTest extends \PHPUnit_Framework_TestCase { |
|
18
|
|
|
|
|
19
|
|
|
public function testCanConstruct() { |
|
20
|
|
|
|
|
21
|
|
|
$this->assertInstanceOf( |
|
22
|
|
|
'\WNBY\HookRegistry', |
|
23
|
|
|
new HookRegistry() |
|
24
|
|
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testRegister() { |
|
28
|
|
|
|
|
29
|
|
|
$title = Title::newFromText( __METHOD__ ); |
|
30
|
|
|
|
|
31
|
|
|
$parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
|
32
|
|
|
->disableOriginalConstructor() |
|
33
|
|
|
->getMock(); |
|
34
|
|
|
|
|
35
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
|
36
|
|
|
->disableOriginalConstructor() |
|
37
|
|
|
->getMock(); |
|
38
|
|
|
|
|
39
|
|
|
$parser->expects( $this->any() ) |
|
40
|
|
|
->method( 'getTitle' ) |
|
41
|
|
|
->will( $this->returnValue( $title ) ); |
|
42
|
|
|
|
|
43
|
|
|
$parser->expects( $this->any() ) |
|
44
|
|
|
->method( 'getOutput' ) |
|
45
|
|
|
->will( $this->returnValue( $parserOutput ) ); |
|
46
|
|
|
|
|
47
|
|
|
$instance = new HookRegistry(); |
|
48
|
|
|
$instance->deregister(); |
|
49
|
|
|
$instance->register(); |
|
50
|
|
|
|
|
51
|
|
|
$this->doTestParserFirstCallInit( $instance, $parser ); |
|
52
|
|
|
$this->doTestResourceLoaderGetConfigVars( $instance ); |
|
53
|
|
|
$this->doTestOutputPageParserOutput( $instance ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function doTestParserFirstCallInit( $instance, $parser ) { |
|
57
|
|
|
|
|
58
|
|
|
$handler = 'ParserFirstCallInit'; |
|
59
|
|
|
|
|
60
|
|
|
$this->assertTrue( |
|
61
|
|
|
$instance->isRegistered( $handler ) |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertThatHookIsExcutable( |
|
65
|
|
|
$instance->getHandlerFor( $handler ), |
|
66
|
|
|
array( &$parser ) |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function doTestResourceLoaderGetConfigVars( $instance ) { |
|
71
|
|
|
|
|
72
|
|
|
$handler = 'ResourceLoaderGetConfigVars'; |
|
73
|
|
|
|
|
74
|
|
|
$this->assertTrue( |
|
75
|
|
|
$instance->isRegistered( $handler ) |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
$vars = array(); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertThatHookIsExcutable( |
|
81
|
|
|
$instance->getHandlerFor( $handler ), |
|
82
|
|
|
array( &$vars ) |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function doTestOutputPageParserOutput( $instance ) { |
|
87
|
|
|
|
|
88
|
|
|
$parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
|
89
|
|
|
->disableOriginalConstructor() |
|
90
|
|
|
->getMock(); |
|
91
|
|
|
|
|
92
|
|
|
$parserOutput->expects( $this->any() ) |
|
93
|
|
|
->method( 'getExtensionData' ) |
|
94
|
|
|
->will( $this->returnValue( true ) ); |
|
95
|
|
|
|
|
96
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
|
97
|
|
|
->disableOriginalConstructor() |
|
98
|
|
|
->getMock(); |
|
99
|
|
|
|
|
100
|
|
|
$handler = 'OutputPageParserOutput'; |
|
101
|
|
|
|
|
102
|
|
|
$this->assertTrue( |
|
103
|
|
|
$instance->isRegistered( $handler ) |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertThatHookIsExcutable( |
|
107
|
|
|
$instance->getHandlerFor( $handler ), |
|
108
|
|
|
array( $outputPage, $parserOutput ) |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
private function assertThatHookIsExcutable( \Closure $handler, $arguments ) { |
|
113
|
|
|
$this->assertInternalType( |
|
114
|
|
|
'boolean', |
|
115
|
|
|
call_user_func_array( $handler, $arguments ) |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|