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