Completed
Pull Request — master (#8)
by mw
04:04
created

HookRegistryTest::doTestOutputPageParserOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 13
nc 1
nop 1
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
		$outputPage = $this->getMockBuilder( '\OutputPage' )
93
			->disableOriginalConstructor()
94
			->getMock();
95
96
		$handler = 'OutputPageParserOutput';
97
98
		$this->assertTrue(
99
			$instance->isRegistered( $handler )
100
		);
101
102
		$this->assertThatHookIsExcutable(
103
			$instance->getHandlerFor( $handler ),
104
			array( $outputPage, $parserOutput )
105
		);
106
	}
107
108
	private function assertThatHookIsExcutable( \Closure $handler, $arguments ) {
109
		$this->assertInternalType(
110
			'boolean',
111
			call_user_func_array( $handler, $arguments )
112
		);
113
	}
114
115
}
116