Completed
Push — master ( f9239d...c22ee7 )
by mw
09:43
created

testTryPrependHtmlForNonViewAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 47
rs 9.0303
cc 1
eloc 33
nc 1
nop 0
1
<?php
2
3
namespace SBL\Tests;
4
5
use SBL\SkinTemplateOutputModifier;
6
7
use Title;
8
9
/**
10
 * @covers \SBL\SkinTemplateOutputModifier
11
 * @group semantic-breadcrumb-links
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.0
15
 *
16
 * @author mwjames
17
 */
18
class SkinTemplateOutputModifierTest extends \PHPUnit_Framework_TestCase {
19
20
	public function testCanConstruct() {
21
22
		$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' )
23
			->disableOriginalConstructor()
24
			->getMock();
25
26
		$this->assertInstanceOf(
27
			'\SBL\SkinTemplateOutputModifier',
28
			new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder )
29
		);
30
	}
31
32
	public function testForUnknownTitle() {
33
34
		$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' )
35
			->disableOriginalConstructor()
36
			->getMock();
37
38
		$title = $this->getMockBuilder( '\Title' )
39
			->disableOriginalConstructor()
40
			->getMock();
41
42
		$title->expects( $this->once() )
43
			->method( 'isKnown' )
44
			->will( $this->returnValue( false ) );
45
46
		$output = $this->getMockBuilder( '\OutputPage' )
47
			->disableOriginalConstructor()
48
			->getMock();
49
50
		$output->expects( $this->never() )
51
			->method( 'prependHTML' );
52
53
		$output->expects( $this->once() )
54
			->method( 'getTitle' )
55
			->will( $this->returnValue( $title ) );
56
57
		$instance = new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder );
58
59
		$this->assertTrue(
60
			$instance->modifyOutput( $output )
61
		);
62
	}
63
64
	public function testForIsSpecialPage() {
65
66
		$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' )
67
			->disableOriginalConstructor()
68
			->getMock();
69
70
		$title = $this->getMockBuilder( '\Title' )
71
			->disableOriginalConstructor()
72
			->getMock();
73
74
		$title->expects( $this->once() )
75
			->method( 'isKnown' )
76
			->will( $this->returnValue( true ) );
77
78
		$title->expects( $this->once() )
79
			->method( 'isSpecialPage' )
80
			->will( $this->returnValue( true ) );
81
82
		$output = $this->getMockBuilder( '\OutputPage' )
83
			->disableOriginalConstructor()
84
			->getMock();
85
86
		$output->expects( $this->never() )
87
			->method( 'prependHTML' );
88
89
		$output->expects( $this->atLeastOnce() )
90
			->method( 'getTitle' )
91
			->will( $this->returnValue( $title ) );
92
93
		$instance = new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder );
94
95
		$this->assertTrue(
96
			$instance->modifyOutput( $output )
97
		);
98
	}
99
100
	public function testTryPrependHtmlForNonViewAction() {
101
102
		$context = new \RequestContext();
103
		$context->setRequest( new \FauxRequest( array( 'action' => 'edit' ), true ) );
104
		$context->setTitle( Title::newFromText( __METHOD__ ) );
105
106
		$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' )
107
			->disableOriginalConstructor()
108
			->getMock();
109
110
		$title = $this->getMockBuilder( '\Title' )
111
			->disableOriginalConstructor()
112
			->getMock();
113
114
		$title->expects( $this->once() )
115
			->method( 'isKnown' )
116
			->will( $this->returnValue( true ) );
117
118
		$title->expects( $this->once() )
119
			->method( 'getNamespace' )
120
			->will( $this->returnValue( NS_MAIN ) );
121
122
		$title->expects( $this->once() )
123
			->method( 'isSpecialPage' )
124
			->will( $this->returnValue( false ) );
125
126
		$output = $this->getMockBuilder( '\OutputPage' )
127
			->disableOriginalConstructor()
128
			->getMock();
129
130
		$output->expects( $this->never() )
131
			->method( 'prependHTML' );
132
133
		$output->expects( $this->once() )
134
			->method( 'getContext' )
135
			->will( $this->returnValue( $context ) );
136
137
		$output->expects( $this->atLeastOnce() )
138
			->method( 'getTitle' )
139
			->will( $this->returnValue( $title ) );
140
141
		$instance = new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder );
142
143
		$this->assertTrue(
144
			$instance->modifyOutput( $output )
145
		);
146
	}
147
148
	public function testPrependHtmlForViewActionOnly() {
149
150
		$context = new \RequestContext();
151
		$context->setRequest( new \FauxRequest( array( 'action' => 'view'  ), true ) );
152
153
		$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' )
154
			->disableOriginalConstructor()
155
			->getMock();
156
157
		$htmlBreadcrumbLinksBuilder->expects( $this->once() )
158
			->method( 'buildBreadcrumbs' )
159
			->will( $this->returnSelf() );
160
161
		$language = $this->getMockBuilder( '\Language' )
162
			->disableOriginalConstructor()
163
			->getMock();
164
165
		$title = $this->getMockBuilder( '\Title' )
166
			->disableOriginalConstructor()
167
			->getMock();
168
169
		$title->expects( $this->once() )
170
			->method( 'isKnown' )
171
			->will( $this->returnValue( true ) );
172
173
		$title->expects( $this->once() )
174
			->method( 'getNamespace' )
175
			->will( $this->returnValue( NS_MAIN ) );
176
177
		$title->expects( $this->once() )
178
			->method( 'isSpecialPage' )
179
			->will( $this->returnValue( false ) );
180
181
		$title->expects( $this->once() )
182
			->method( 'getPageLanguage' )
183
			->will( $this->returnValue( $language ) );
184
185
		$output = $this->getMockBuilder( '\OutputPage' )
186
			->disableOriginalConstructor()
187
			->getMock();
188
189
		$output->expects( $this->once() )
190
			->method( 'prependHTML' );
191
192
		$output->expects( $this->once() )
193
			->method( 'getContext' )
194
			->will( $this->returnValue( $context ) );
195
196
		$output->expects( $this->atLeastOnce() )
197
			->method( 'getTitle' )
198
			->will( $this->returnValue( $title ) );
199
200
		$instance = new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder );
201
202
		$this->assertTrue(
203
			$instance->modifyOutput( $output )
204
		);
205
206
		$template = new \stdClass;
207
		$template->data = array();
208
209
		$instance->modifyTemplate( $template );
210
211
		$this->assertEmpty(
212
			$template->data['subtitle']
213
		);
214
	}
215
216
}
217