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
|
|
|
private $namespaceExaminer; |
21
|
|
|
|
22
|
|
|
protected function setUp() { |
23
|
|
|
|
24
|
|
|
$this->namespaceExaminer = $this->getMockBuilder( '\SMW\NamespaceExaminer' ) |
25
|
|
|
->disableOriginalConstructor() |
26
|
|
|
->getMock(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testCanConstruct() { |
30
|
|
|
|
31
|
|
|
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' ) |
32
|
|
|
->disableOriginalConstructor() |
33
|
|
|
->getMock(); |
34
|
|
|
|
35
|
|
|
$this->assertInstanceOf( |
36
|
|
|
SkinTemplateOutputModifier::class, |
37
|
|
|
new SkinTemplateOutputModifier( $htmlBreadcrumbLinksBuilder, $this->namespaceExaminer ) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testTryPrependHtmlOnUnknownTitle() { |
42
|
|
|
|
43
|
|
|
$this->namespaceExaminer->expects( $this->never() ) |
44
|
|
|
->method( 'isSemanticEnabled' ) |
45
|
|
|
->will( $this->returnValue( true ) ); |
46
|
|
|
|
47
|
|
|
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' ) |
48
|
|
|
->disableOriginalConstructor() |
49
|
|
|
->getMock(); |
50
|
|
|
|
51
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
52
|
|
|
->disableOriginalConstructor() |
53
|
|
|
->getMock(); |
54
|
|
|
|
55
|
|
|
$title->expects( $this->once() ) |
56
|
|
|
->method( 'isKnown' ) |
57
|
|
|
->will( $this->returnValue( false ) ); |
58
|
|
|
|
59
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
60
|
|
|
->disableOriginalConstructor() |
61
|
|
|
->getMock(); |
62
|
|
|
|
63
|
|
|
$output->expects( $this->never() ) |
64
|
|
|
->method( 'prependHTML' ); |
65
|
|
|
|
66
|
|
|
$output->expects( $this->atLeastOnce() ) |
67
|
|
|
->method( 'getTitle' ) |
68
|
|
|
->will( $this->returnValue( $title ) ); |
69
|
|
|
|
70
|
|
|
$instance = new SkinTemplateOutputModifier( |
71
|
|
|
$htmlBreadcrumbLinksBuilder, |
72
|
|
|
$this->namespaceExaminer |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$template = new \stdClass; |
76
|
|
|
$template->data = []; |
77
|
|
|
|
78
|
|
|
$instance->modify( $output, $template ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testTryPrependHtmlOnSpecialPage() { |
82
|
|
|
|
83
|
|
|
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' ) |
84
|
|
|
->disableOriginalConstructor() |
85
|
|
|
->getMock(); |
86
|
|
|
|
87
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
88
|
|
|
->disableOriginalConstructor() |
89
|
|
|
->getMock(); |
90
|
|
|
|
91
|
|
|
$title->expects( $this->once() ) |
92
|
|
|
->method( 'isKnown' ) |
93
|
|
|
->will( $this->returnValue( true ) ); |
94
|
|
|
|
95
|
|
|
$title->expects( $this->once() ) |
96
|
|
|
->method( 'isSpecialPage' ) |
97
|
|
|
->will( $this->returnValue( true ) ); |
98
|
|
|
|
99
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
100
|
|
|
->disableOriginalConstructor() |
101
|
|
|
->getMock(); |
102
|
|
|
|
103
|
|
|
$output->expects( $this->atLeastOnce() ) |
104
|
|
|
->method( 'getTitle' ) |
105
|
|
|
->will( $this->returnValue( $title ) ); |
106
|
|
|
|
107
|
|
|
$instance = new SkinTemplateOutputModifier( |
108
|
|
|
$htmlBreadcrumbLinksBuilder, |
109
|
|
|
$this->namespaceExaminer |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$template = new \stdClass; |
113
|
|
|
$template->data = []; |
114
|
|
|
|
115
|
|
|
$instance->modify( $output, $template ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function PrependHtmlOnNonViewAction() { |
119
|
|
|
|
120
|
|
|
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' ) |
121
|
|
|
->disableOriginalConstructor() |
122
|
|
|
->getMock(); |
123
|
|
|
|
124
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
125
|
|
|
->disableOriginalConstructor() |
126
|
|
|
->getMock(); |
127
|
|
|
|
128
|
|
|
$title->expects( $this->once() ) |
129
|
|
|
->method( 'isKnown' ) |
130
|
|
|
->will( $this->returnValue( true ) ); |
131
|
|
|
|
132
|
|
|
$title->expects( $this->once() ) |
133
|
|
|
->method( 'getNamespace' ) |
134
|
|
|
->will( $this->returnValue( NS_MAIN ) ); |
135
|
|
|
|
136
|
|
|
$title->expects( $this->once() ) |
137
|
|
|
->method( 'isSpecialPage' ) |
138
|
|
|
->will( $this->returnValue( false ) ); |
139
|
|
|
|
140
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
141
|
|
|
->disableOriginalConstructor() |
142
|
|
|
->getMock(); |
143
|
|
|
|
144
|
|
|
$output->expects( $this->atLeastOnce() ) |
145
|
|
|
->method( 'getTitle' ) |
146
|
|
|
->will( $this->returnValue( $title ) ); |
147
|
|
|
|
148
|
|
|
$instance = new SkinTemplateOutputModifier( |
149
|
|
|
$htmlBreadcrumbLinksBuilder, |
150
|
|
|
$this->namespaceExaminer |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
$template = new \stdClass; |
154
|
|
|
$template->data = []; |
155
|
|
|
|
156
|
|
|
$instance->modify( $output, $template ); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testTryPrependHtmlOnNOBREADCRUMBLINKS() { |
160
|
|
|
|
161
|
|
|
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder( '\SBL\HtmlBreadcrumbLinksBuilder' ) |
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
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
182
|
|
|
->disableOriginalConstructor() |
183
|
|
|
->getMock(); |
184
|
|
|
|
185
|
|
|
$output->expects( $this->atLeastOnce() ) |
186
|
|
|
->method( 'getTitle' ) |
187
|
|
|
->will( $this->returnValue( $title ) ); |
188
|
|
|
|
189
|
|
|
$instance = new SkinTemplateOutputModifier( |
190
|
|
|
$htmlBreadcrumbLinksBuilder, |
191
|
|
|
$this->namespaceExaminer |
192
|
|
|
); |
193
|
|
|
|
194
|
|
|
$output->smwmagicwords = [ 'SBL_NOBREADCRUMBLINKS' ]; |
195
|
|
|
|
196
|
|
|
$template = new \stdClass; |
197
|
|
|
$template->data = []; |
198
|
|
|
|
199
|
|
|
$instance->modify( $output, $template ); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function testAppendHtml() { |
203
|
|
|
|
204
|
|
|
$this->namespaceExaminer->expects( $this->once() ) |
205
|
|
|
->method( 'isSemanticEnabled' ) |
206
|
|
|
->will( $this->returnValue( 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
|
|
|
$htmlBreadcrumbLinksBuilder->expects( $this->once() ) |
217
|
|
|
->method( 'getHtml' ) |
218
|
|
|
->will( $this->returnValue( 'bar' ) ); |
219
|
|
|
|
220
|
|
|
$language = $this->getMockBuilder( '\Language' ) |
221
|
|
|
->disableOriginalConstructor() |
222
|
|
|
->getMock(); |
223
|
|
|
|
224
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
225
|
|
|
->disableOriginalConstructor() |
226
|
|
|
->getMock(); |
227
|
|
|
|
228
|
|
|
$title->expects( $this->once() ) |
229
|
|
|
->method( 'isKnown' ) |
230
|
|
|
->will( $this->returnValue( true ) ); |
231
|
|
|
|
232
|
|
|
$title->expects( $this->once() ) |
233
|
|
|
->method( 'getNamespace' ) |
234
|
|
|
->will( $this->returnValue( NS_MAIN ) ); |
235
|
|
|
|
236
|
|
|
$title->expects( $this->once() ) |
237
|
|
|
->method( 'isSpecialPage' ) |
238
|
|
|
->will( $this->returnValue( false ) ); |
239
|
|
|
|
240
|
|
|
$title->expects( $this->once() ) |
241
|
|
|
->method( 'getPageLanguage' ) |
242
|
|
|
->will( $this->returnValue( $language ) ); |
243
|
|
|
|
244
|
|
|
$output = $this->getMockBuilder( '\OutputPage' ) |
245
|
|
|
->disableOriginalConstructor() |
246
|
|
|
->getMock(); |
247
|
|
|
|
248
|
|
|
$output->expects( $this->atLeastOnce() ) |
249
|
|
|
->method( 'getTitle' ) |
250
|
|
|
->will( $this->returnValue( $title ) ); |
251
|
|
|
|
252
|
|
|
$instance = new SkinTemplateOutputModifier( |
253
|
|
|
$htmlBreadcrumbLinksBuilder, |
254
|
|
|
$this->namespaceExaminer |
255
|
|
|
); |
256
|
|
|
|
257
|
|
|
$template = new \stdClass; |
258
|
|
|
|
259
|
|
|
$template->data = [ |
260
|
|
|
'subtitle' => 'Foo' |
261
|
|
|
]; |
262
|
|
|
|
263
|
|
|
$instance->modify( $output, $template ); |
264
|
|
|
|
265
|
|
|
$this->assertEquals( |
266
|
|
|
'Foobar', |
267
|
|
|
$template->data['subtitle'] |
268
|
|
|
); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
} |
272
|
|
|
|