1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SIL\Tests\Category; |
4
|
|
|
|
5
|
|
|
use SIL\Category\LanguageFilterCategoryViewer; |
6
|
|
|
use Title; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SIL\Category\LanguageFilterCategoryViewer |
10
|
|
|
* @group semantic-interlanguage-links |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.0 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class LanguageFilterCategoryViewerTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $context; |
20
|
|
|
|
21
|
|
|
protected function setUp() { |
22
|
|
|
parent::setUp(); |
23
|
|
|
|
24
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
25
|
|
|
->disableOriginalConstructor() |
26
|
|
|
->getMock(); |
27
|
|
|
|
28
|
|
|
$this->context = $this->getMockBuilder( '\IContextSource' ) |
29
|
|
|
->disableOriginalConstructor() |
30
|
|
|
->getMock(); |
31
|
|
|
|
32
|
|
|
$this->context->expects( $this->any() ) |
33
|
|
|
->method( 'getConfig' ) |
34
|
|
|
->will( $this->returnValue( $this->getMock('\Config' ) ) ); |
35
|
|
|
|
36
|
|
|
$this->context->expects( $this->any() ) |
37
|
|
|
->method( 'getOutput' ) |
38
|
|
|
->will( $this->returnValue( $outputPage ) ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testCanConstruct() { |
42
|
|
|
|
43
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
44
|
|
|
|
45
|
|
|
$this->assertInstanceOf( |
46
|
|
|
'\SIL\Category\LanguageFilterCategoryViewer', |
47
|
|
|
new LanguageFilterCategoryViewer( $title, $this->context ) |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testAddPageForNoInterlanguageLinksLookup() { |
52
|
|
|
|
53
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
54
|
|
|
$target = Title::newFromText( 'Bar' ); |
55
|
|
|
|
56
|
|
|
$instance = new LanguageFilterCategoryViewer( |
57
|
|
|
$title, |
58
|
|
|
$this->context |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$instance->addPage( $target, 'B', '' ); |
62
|
|
|
|
63
|
|
|
$this->assertNotEmpty( |
64
|
|
|
$instance->articles |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testAddImageForNoInterlanguageLinksLookup() { |
69
|
|
|
|
70
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
71
|
|
|
$target = Title::newFromText( 'Bar', NS_FILE ); |
72
|
|
|
|
73
|
|
|
$instance = new LanguageFilterCategoryViewer( |
74
|
|
|
$title, |
75
|
|
|
$this->context |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$instance->addImage( $target, 'B', '' ); |
79
|
|
|
|
80
|
|
|
$this->assertNotEmpty( |
81
|
|
|
$instance->imgsNoGallery |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testTryAddImageForNoLanguageMatch() { |
86
|
|
|
|
87
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
88
|
|
|
$target = Title::newFromText( 'Bar', NS_FILE ); |
89
|
|
|
|
90
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
91
|
|
|
->disableOriginalConstructor() |
92
|
|
|
->getMock(); |
93
|
|
|
|
94
|
|
|
$interlanguageLinksLookup->expects( $this->atLeastOnce() ) |
95
|
|
|
->method( 'hasSilAnnotationFor' ) |
96
|
|
|
->will( $this->returnValue( true ) ); |
97
|
|
|
|
98
|
|
|
$interlanguageLinksLookup->expects( $this->at( 0 ) ) |
99
|
|
|
->method( 'findPageLanguageForTarget' ) |
100
|
|
|
->will( $this->returnValue( 'no' ) ); |
101
|
|
|
|
102
|
|
|
$interlanguageLinksLookup->expects( $this->at( 1 ) ) |
103
|
|
|
->method( 'findPageLanguageForTarget' ) |
104
|
|
|
->will( $this->returnValue( 'match' ) ); |
105
|
|
|
|
106
|
|
|
$title->interlanguageLinksLookup = $interlanguageLinksLookup; |
107
|
|
|
|
108
|
|
|
$instance = new LanguageFilterCategoryViewer( |
109
|
|
|
$title, |
110
|
|
|
$this->context |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
$instance->addImage( $target, 'B', '' ); |
114
|
|
|
|
115
|
|
|
$this->assertEmpty( |
116
|
|
|
$instance->imgsNoGallery |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testAddSubcategoryForNoInterlanguageLinksLookup() { |
121
|
|
|
|
122
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
123
|
|
|
|
124
|
|
|
$category = $this->getMockBuilder( '\Category' ) |
125
|
|
|
->disableOriginalConstructor() |
126
|
|
|
->getMock(); |
127
|
|
|
|
128
|
|
|
$category->expects( $this->any() ) |
129
|
|
|
->method( 'getTitle' ) |
130
|
|
|
->will( $this->returnValue( Title::newFromText( 'Bar' ) ) ); |
131
|
|
|
|
132
|
|
|
$instance = new LanguageFilterCategoryViewer( |
133
|
|
|
$title, |
134
|
|
|
$this->context |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
$instance->addSubcategoryObject( $category, 'B', '' ); |
138
|
|
|
|
139
|
|
|
$this->assertNotEmpty( |
140
|
|
|
$instance->children |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testTryAddSubcategoryForNoLanguageMatch() { |
145
|
|
|
|
146
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
147
|
|
|
|
148
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
149
|
|
|
->disableOriginalConstructor() |
150
|
|
|
->getMock(); |
151
|
|
|
|
152
|
|
|
$interlanguageLinksLookup->expects( $this->atLeastOnce() ) |
153
|
|
|
->method( 'hasSilAnnotationFor' ) |
154
|
|
|
->will( $this->returnValue( true ) ); |
155
|
|
|
|
156
|
|
|
$interlanguageLinksLookup->expects( $this->at( 0 ) ) |
157
|
|
|
->method( 'findPageLanguageForTarget' ) |
158
|
|
|
->will( $this->returnValue( 'no' ) ); |
159
|
|
|
|
160
|
|
|
$interlanguageLinksLookup->expects( $this->at( 1 ) ) |
161
|
|
|
->method( 'findPageLanguageForTarget' ) |
162
|
|
|
->will( $this->returnValue( 'match' ) ); |
163
|
|
|
|
164
|
|
|
$title->interlanguageLinksLookup = $interlanguageLinksLookup; |
165
|
|
|
|
166
|
|
|
$category = $this->getMockBuilder( '\Category' ) |
167
|
|
|
->disableOriginalConstructor() |
168
|
|
|
->getMock(); |
169
|
|
|
|
170
|
|
|
$category->expects( $this->once() ) |
171
|
|
|
->method( 'getTitle' ) |
172
|
|
|
->will( $this->returnValue( Title::newFromText( 'Bar' ) ) ); |
173
|
|
|
|
174
|
|
|
$instance = new LanguageFilterCategoryViewer( |
175
|
|
|
$title, |
176
|
|
|
$this->context |
177
|
|
|
); |
178
|
|
|
|
179
|
|
|
$instance->addSubcategoryObject( $category, 'B', '' ); |
180
|
|
|
|
181
|
|
|
$this->assertEmpty( |
182
|
|
|
$instance->children |
183
|
|
|
); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function testAddPageForEmptyLanguage() { |
187
|
|
|
|
188
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
189
|
|
|
$target = Title::newFromText( 'Bar' ); |
190
|
|
|
|
191
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
192
|
|
|
->disableOriginalConstructor() |
193
|
|
|
->getMock(); |
194
|
|
|
|
195
|
|
|
$interlanguageLinksLookup->expects( $this->atLeastOnce() ) |
196
|
|
|
->method( 'hasSilAnnotationFor' ) |
197
|
|
|
->will( $this->returnValue( true ) ); |
198
|
|
|
|
199
|
|
|
$interlanguageLinksLookup->expects( $this->atLeastOnce() ) |
200
|
|
|
->method( 'findPageLanguageForTarget' ) |
201
|
|
|
->with( $this->equalTo( $title ) ) |
202
|
|
|
->will( $this->returnValue( '' ) ); |
203
|
|
|
|
204
|
|
|
$title->interlanguageLinksLookup = $interlanguageLinksLookup; |
205
|
|
|
|
206
|
|
|
$instance = new LanguageFilterCategoryViewer( |
207
|
|
|
$title, |
208
|
|
|
$this->context |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
$instance->addPage( $target, 'B', '' ); |
212
|
|
|
|
213
|
|
|
$this->assertNotEmpty( |
214
|
|
|
$instance->articles |
215
|
|
|
); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function testAddPageForLanguageMatch() { |
219
|
|
|
|
220
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
221
|
|
|
$target = Title::newFromText( 'Bar' ); |
222
|
|
|
|
223
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
224
|
|
|
->disableOriginalConstructor() |
225
|
|
|
->getMock(); |
226
|
|
|
|
227
|
|
|
$interlanguageLinksLookup->expects( $this->atLeastOnce() ) |
228
|
|
|
->method( 'hasSilAnnotationFor' ) |
229
|
|
|
->will( $this->returnValue( true ) ); |
230
|
|
|
|
231
|
|
|
$interlanguageLinksLookup->expects( $this->at( 1 ) ) |
232
|
|
|
->method( 'findPageLanguageForTarget' ) |
233
|
|
|
->with( $this->equalTo( $title ) ) |
234
|
|
|
->will( $this->returnValue( 'vi' ) ); |
235
|
|
|
|
236
|
|
|
$interlanguageLinksLookup->expects( $this->at( 2 ) ) |
237
|
|
|
->method( 'findPageLanguageForTarget' ) |
238
|
|
|
->with( $this->equalTo( $target ) ) |
239
|
|
|
->will( $this->returnValue( 'vi' ) ); |
240
|
|
|
|
241
|
|
|
$title->interlanguageLinksLookup = $interlanguageLinksLookup; |
242
|
|
|
|
243
|
|
|
$instance = new LanguageFilterCategoryViewer( |
244
|
|
|
$title, |
245
|
|
|
$this->context |
246
|
|
|
); |
247
|
|
|
|
248
|
|
|
$instance->addPage( $target, 'B', '' ); |
249
|
|
|
|
250
|
|
|
$this->assertNotEmpty( |
251
|
|
|
$instance->articles |
252
|
|
|
); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
public function testTryAddPageForNoLanguageMatch() { |
256
|
|
|
|
257
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
258
|
|
|
$target = Title::newFromText( 'Bar' ); |
259
|
|
|
|
260
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
261
|
|
|
->disableOriginalConstructor() |
262
|
|
|
->getMock(); |
263
|
|
|
|
264
|
|
|
$interlanguageLinksLookup->expects( $this->atLeastOnce() ) |
265
|
|
|
->method( 'hasSilAnnotationFor' ) |
266
|
|
|
->will( $this->returnValue( true ) ); |
267
|
|
|
|
268
|
|
|
$interlanguageLinksLookup->expects( $this->at( 1 ) ) |
269
|
|
|
->method( 'findPageLanguageForTarget' ) |
270
|
|
|
->with( $this->equalTo( $title ) ) |
271
|
|
|
->will( $this->returnValue( 'vi' ) ); |
272
|
|
|
|
273
|
|
|
$interlanguageLinksLookup->expects( $this->at( 2 ) ) |
274
|
|
|
->method( 'findPageLanguageForTarget' ) |
275
|
|
|
->with( $this->equalTo( $target ) ) |
276
|
|
|
->will( $this->returnValue( 'en' ) ); |
277
|
|
|
|
278
|
|
|
$title->interlanguageLinksLookup = $interlanguageLinksLookup; |
279
|
|
|
|
280
|
|
|
$instance = new LanguageFilterCategoryViewer( |
281
|
|
|
$title, |
282
|
|
|
$this->context |
283
|
|
|
); |
284
|
|
|
|
285
|
|
|
$instance->addPage( $target, 'B', '' ); |
286
|
|
|
|
287
|
|
|
$this->assertEmpty( |
288
|
|
|
$instance->articles |
289
|
|
|
); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
public function testTryAddPageForNoAnnotationMatch() { |
293
|
|
|
|
294
|
|
|
$title = Title::newFromText( 'Foo', NS_CATEGORY ); |
295
|
|
|
$target = Title::newFromText( 'Bar' ); |
296
|
|
|
|
297
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
298
|
|
|
->disableOriginalConstructor() |
299
|
|
|
->getMock(); |
300
|
|
|
|
301
|
|
|
$interlanguageLinksLookup->expects( $this->atLeastOnce() ) |
302
|
|
|
->method( 'hasSilAnnotationFor' ) |
303
|
|
|
->will( $this->returnValue( false ) ); |
304
|
|
|
|
305
|
|
|
$title->interlanguageLinksLookup = $interlanguageLinksLookup; |
306
|
|
|
|
307
|
|
|
$instance = new LanguageFilterCategoryViewer( |
308
|
|
|
$title, |
309
|
|
|
$this->context |
310
|
|
|
); |
311
|
|
|
|
312
|
|
|
$instance->addPage( $target, 'B', '' ); |
313
|
|
|
|
314
|
|
|
$this->assertEmpty( |
315
|
|
|
$instance->articles |
316
|
|
|
); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
} |
320
|
|
|
|