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 testTryPrependHtmlOnUnknownTitle() { |
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( |
58
|
|
|
$htmlBreadcrumbLinksBuilder |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$this->assertTrue( |
62
|
|
|
$instance->modifyOutput( $output ) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testTryPrependHtmlOnSpecialPage() { |
67
|
|
|
|
68
|
|
|
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' ) |
69
|
|
|
->disableOriginalConstructor() |
70
|
|
|
->getMock(); |
71
|
|
|
|
72
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
73
|
|
|
->disableOriginalConstructor() |
74
|
|
|
->getMock(); |
75
|
|
|
|
76
|
|
|
$title->expects( $this->once() ) |
77
|
|
|
->method( 'isKnown' ) |
78
|
|
|
->will( $this->returnValue( true ) ); |
79
|
|
|
|
80
|
|
|
$title->expects( $this->once() ) |
81
|
|
|
->method( 'isSpecialPage' ) |
82
|
|
|
->will( $this->returnValue( true ) ); |
83
|
|
|
|
84
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
85
|
|
|
->disableOriginalConstructor() |
86
|
|
|
->getMock(); |
87
|
|
|
|
88
|
|
|
$output->expects( $this->never() ) |
89
|
|
|
->method( 'prependHTML' ); |
90
|
|
|
|
91
|
|
|
$output->expects( $this->atLeastOnce() ) |
92
|
|
|
->method( 'getTitle' ) |
93
|
|
|
->will( $this->returnValue( $title ) ); |
94
|
|
|
|
95
|
|
|
$instance = new SkinTemplateOutputModifier( |
96
|
|
|
$htmlBreadcrumbLinksBuilder |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$this->assertTrue( |
100
|
|
|
$instance->modifyOutput( $output ) |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testTryPrependHtmlOnNonViewAction() { |
105
|
|
|
|
106
|
|
|
$context = new \RequestContext(); |
107
|
|
|
$context->setRequest( new \FauxRequest( array( 'action' => 'edit' ), true ) ); |
108
|
|
|
$context->setTitle( Title::newFromText( __METHOD__ ) ); |
109
|
|
|
|
110
|
|
|
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' ) |
111
|
|
|
->disableOriginalConstructor() |
112
|
|
|
->getMock(); |
113
|
|
|
|
114
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
115
|
|
|
->disableOriginalConstructor() |
116
|
|
|
->getMock(); |
117
|
|
|
|
118
|
|
|
$title->expects( $this->once() ) |
119
|
|
|
->method( 'isKnown' ) |
120
|
|
|
->will( $this->returnValue( true ) ); |
121
|
|
|
|
122
|
|
|
$title->expects( $this->once() ) |
123
|
|
|
->method( 'getNamespace' ) |
124
|
|
|
->will( $this->returnValue( NS_MAIN ) ); |
125
|
|
|
|
126
|
|
|
$title->expects( $this->once() ) |
127
|
|
|
->method( 'isSpecialPage' ) |
128
|
|
|
->will( $this->returnValue( false ) ); |
129
|
|
|
|
130
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
131
|
|
|
->disableOriginalConstructor() |
132
|
|
|
->getMock(); |
133
|
|
|
|
134
|
|
|
$output->expects( $this->never() ) |
135
|
|
|
->method( 'prependHTML' ); |
136
|
|
|
|
137
|
|
|
$output->expects( $this->once() ) |
138
|
|
|
->method( 'getContext' ) |
139
|
|
|
->will( $this->returnValue( $context ) ); |
140
|
|
|
|
141
|
|
|
$output->expects( $this->atLeastOnce() ) |
142
|
|
|
->method( 'getTitle' ) |
143
|
|
|
->will( $this->returnValue( $title ) ); |
144
|
|
|
|
145
|
|
|
$instance = new SkinTemplateOutputModifier( |
146
|
|
|
$htmlBreadcrumbLinksBuilder |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
$this->assertTrue( |
150
|
|
|
$instance->modifyOutput( $output ) |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testTryPrependHtmlOnNOBREADCRUMBLINKS() { |
155
|
|
|
|
156
|
|
|
$context = new \RequestContext(); |
157
|
|
|
$context->setRequest( new \FauxRequest( array( 'action' => 'view' ), true ) ); |
158
|
|
|
|
159
|
|
|
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' ) |
160
|
|
|
->disableOriginalConstructor() |
161
|
|
|
->getMock(); |
162
|
|
|
|
163
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
164
|
|
|
->disableOriginalConstructor() |
165
|
|
|
->getMock(); |
166
|
|
|
|
167
|
|
|
$title->expects( $this->once() ) |
168
|
|
|
->method( 'isKnown' ) |
169
|
|
|
->will( $this->returnValue( true ) ); |
170
|
|
|
|
171
|
|
|
$title->expects( $this->once() ) |
172
|
|
|
->method( 'getNamespace' ) |
173
|
|
|
->will( $this->returnValue( NS_MAIN ) ); |
174
|
|
|
|
175
|
|
|
$title->expects( $this->once() ) |
176
|
|
|
->method( 'isSpecialPage' ) |
177
|
|
|
->will( $this->returnValue( false ) ); |
178
|
|
|
|
179
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
180
|
|
|
->disableOriginalConstructor() |
181
|
|
|
->getMock(); |
182
|
|
|
|
183
|
|
|
$output->expects( $this->never() ) |
184
|
|
|
->method( 'prependHTML' ); |
185
|
|
|
|
186
|
|
|
$output->expects( $this->once() ) |
187
|
|
|
->method( 'getContext' ) |
188
|
|
|
->will( $this->returnValue( $context ) ); |
189
|
|
|
|
190
|
|
|
$output->expects( $this->atLeastOnce() ) |
191
|
|
|
->method( 'getTitle' ) |
192
|
|
|
->will( $this->returnValue( $title ) ); |
193
|
|
|
|
194
|
|
|
$instance = new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder ); |
195
|
|
|
|
196
|
|
|
$output->smwmagicwords = array( 'SBL_NOBREADCRUMBLINKS' ); |
197
|
|
|
|
198
|
|
|
$this->assertTrue( |
199
|
|
|
$instance->modifyOutput( $output ) |
200
|
|
|
); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function testPrependHtmlForViewActionOnly() { |
204
|
|
|
|
205
|
|
|
$context = new \RequestContext(); |
206
|
|
|
$context->setRequest( new \FauxRequest( array( 'action' => 'view' ), true ) ); |
207
|
|
|
|
208
|
|
|
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' ) |
209
|
|
|
->disableOriginalConstructor() |
210
|
|
|
->getMock(); |
211
|
|
|
|
212
|
|
|
$htmlBreadcrumbLinksBuilder->expects( $this->once() ) |
213
|
|
|
->method( 'buildBreadcrumbs' ) |
214
|
|
|
->will( $this->returnSelf() ); |
215
|
|
|
|
216
|
|
|
$language = $this->getMockBuilder( '\Language' ) |
217
|
|
|
->disableOriginalConstructor() |
218
|
|
|
->getMock(); |
219
|
|
|
|
220
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
221
|
|
|
->disableOriginalConstructor() |
222
|
|
|
->getMock(); |
223
|
|
|
|
224
|
|
|
$title->expects( $this->once() ) |
225
|
|
|
->method( 'isKnown' ) |
226
|
|
|
->will( $this->returnValue( true ) ); |
227
|
|
|
|
228
|
|
|
$title->expects( $this->once() ) |
229
|
|
|
->method( 'getNamespace' ) |
230
|
|
|
->will( $this->returnValue( NS_MAIN ) ); |
231
|
|
|
|
232
|
|
|
$title->expects( $this->once() ) |
233
|
|
|
->method( 'isSpecialPage' ) |
234
|
|
|
->will( $this->returnValue( false ) ); |
235
|
|
|
|
236
|
|
|
$title->expects( $this->once() ) |
237
|
|
|
->method( 'getPageLanguage' ) |
238
|
|
|
->will( $this->returnValue( $language ) ); |
239
|
|
|
|
240
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
241
|
|
|
->disableOriginalConstructor() |
242
|
|
|
->getMock(); |
243
|
|
|
|
244
|
|
|
$output->expects( $this->once() ) |
245
|
|
|
->method( 'prependHTML' ); |
246
|
|
|
|
247
|
|
|
$output->expects( $this->once() ) |
248
|
|
|
->method( 'getContext' ) |
249
|
|
|
->will( $this->returnValue( $context ) ); |
250
|
|
|
|
251
|
|
|
$output->expects( $this->atLeastOnce() ) |
252
|
|
|
->method( 'getTitle' ) |
253
|
|
|
->will( $this->returnValue( $title ) ); |
254
|
|
|
|
255
|
|
|
$instance = new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder ); |
256
|
|
|
|
257
|
|
|
$this->assertTrue( |
258
|
|
|
$instance->modifyOutput( $output ) |
259
|
|
|
); |
260
|
|
|
|
261
|
|
|
$template = new \stdClass; |
262
|
|
|
$template->data = array(); |
263
|
|
|
|
264
|
|
|
$instance->modifyTemplate( $template ); |
265
|
|
|
|
266
|
|
|
$this->assertEmpty( |
267
|
|
|
$template->data['subtitle'] |
268
|
|
|
); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
} |
272
|
|
|
|