1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SIL\Tests\Category; |
4
|
|
|
|
5
|
|
|
use SIL\Category\LanguageFilterCategoryPage; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \SIL\Category\LanguageFilterCategoryPage |
9
|
|
|
* @group semantic-interlanguage-links |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 1.0 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class LanguageFilterCategoryPageTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
public function testCanConstruct() { |
19
|
|
|
|
20
|
|
|
$LanguageFilterCategoryPage = $this->getMockBuilder( '\SIL\Category\LanguageFilterCategoryPage' ) |
21
|
|
|
->disableOriginalConstructor() |
22
|
|
|
->getMock(); |
23
|
|
|
|
24
|
|
|
$this->assertInstanceOf( |
25
|
|
|
'\SIL\Category\LanguageFilterCategoryPage', |
26
|
|
|
$LanguageFilterCategoryPage |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testDisabledCategoryFilter() { |
31
|
|
|
|
32
|
|
|
$instance = new LanguageFilterCategoryPage( \Title::newFromText( 'Foo', NS_CATEGORY ) ); |
33
|
|
|
|
34
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMock(); |
37
|
|
|
|
38
|
|
|
$instance->isCategoryFilterByLanguage( false ); |
39
|
|
|
|
40
|
|
|
$article = ''; |
41
|
|
|
|
42
|
|
|
$instance->modifyCategoryView( $article, $interlanguageLinksLookup ); |
43
|
|
|
|
44
|
|
|
$this->assertEmpty( |
45
|
|
|
$article |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testDisabledForNonCategoryNamespace() { |
50
|
|
|
|
51
|
|
|
$instance = new LanguageFilterCategoryPage( \Title::newFromText( 'Foo', NS_MAIN ) ); |
52
|
|
|
|
53
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->getMock(); |
56
|
|
|
|
57
|
|
|
$instance->isCategoryFilterByLanguage( true ); |
58
|
|
|
|
59
|
|
|
$article = ''; |
60
|
|
|
|
61
|
|
|
$instance->modifyCategoryView( $article, $interlanguageLinksLookup ); |
62
|
|
|
|
63
|
|
|
$this->assertEmpty( |
64
|
|
|
$article |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testEnabledCategoryFilter() { |
69
|
|
|
|
70
|
|
|
$title = \Title::newFromText( 'Foo', NS_CATEGORY ); |
71
|
|
|
|
72
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
73
|
|
|
->disableOriginalConstructor() |
74
|
|
|
->getMock(); |
75
|
|
|
|
76
|
|
|
$interlanguageLinksLookup->expects( $this->once() ) |
77
|
|
|
->method( 'hasSilAnnotationFor' ) |
78
|
|
|
->will( $this->returnValue( true ) ); |
79
|
|
|
|
80
|
|
|
$context = $this->getMockBuilder( '\IContextSource' ) |
81
|
|
|
->disableOriginalConstructor() |
82
|
|
|
->getMock(); |
83
|
|
|
|
84
|
|
|
$instance = new LanguageFilterCategoryPage( $title ); |
85
|
|
|
|
86
|
|
|
$instance->setContext( $context ); |
87
|
|
|
$instance->isCategoryFilterByLanguage( true ); |
88
|
|
|
|
89
|
|
|
$article = ''; |
90
|
|
|
|
91
|
|
|
$instance->modifyCategoryView( $article, $interlanguageLinksLookup ); |
92
|
|
|
|
93
|
|
|
$this->assertInstanceOf( |
94
|
|
|
'\SIL\Category\LanguageFilterCategoryPage', |
95
|
|
|
$article |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$this->assertSame( |
99
|
|
|
$title->interlanguageLinksLookup, |
100
|
|
|
$interlanguageLinksLookup |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testInfoMessageByOpenShowCategoryForEnabledLanguageFilter() { |
105
|
|
|
|
106
|
|
|
$title = \Title::newFromText( 'Foo', NS_CATEGORY ); |
107
|
|
|
|
108
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
109
|
|
|
->disableOriginalConstructor() |
110
|
|
|
->getMock(); |
111
|
|
|
|
112
|
|
|
$interlanguageLinksLookup->expects( $this->atLeastOnce() ) |
113
|
|
|
->method( 'hasSilAnnotationFor' ) |
114
|
|
|
->will( $this->returnValue( true ) ); |
115
|
|
|
|
116
|
|
|
$interlanguageLinksLookup->expects( $this->exactly( 1 ) ) |
117
|
|
|
->method( 'findPageLanguageForTarget' ) |
118
|
|
|
->will( $this->returnValue( 'foo' ) ); |
119
|
|
|
|
120
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
121
|
|
|
->disableOriginalConstructor() |
122
|
|
|
->getMock(); |
123
|
|
|
|
124
|
|
|
$context = $this->getMockBuilder( '\IContextSource' ) |
125
|
|
|
->disableOriginalConstructor() |
126
|
|
|
->getMock(); |
127
|
|
|
|
128
|
|
|
$context->expects( $this->once() ) |
129
|
|
|
->method( 'getOutput' ) |
130
|
|
|
->will( $this->returnValue( $outputPage ) ); |
131
|
|
|
|
132
|
|
|
$instance = new LanguageFilterCategoryPage( $title ); |
133
|
|
|
|
134
|
|
|
$instance->setContext( $context ); |
135
|
|
|
$instance->isCategoryFilterByLanguage( true ); |
136
|
|
|
|
137
|
|
|
$article = ''; |
138
|
|
|
|
139
|
|
|
$instance->modifyCategoryView( $article, $interlanguageLinksLookup ); |
140
|
|
|
|
141
|
|
|
$instance->openShowCategory(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testNoInfoMessageByOpenShowCategoryForNonAvailableLanguage() { |
145
|
|
|
|
146
|
|
|
$title = \Title::newFromText( 'Foo', NS_CATEGORY ); |
147
|
|
|
|
148
|
|
|
$interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
149
|
|
|
->disableOriginalConstructor() |
150
|
|
|
->getMock(); |
151
|
|
|
|
152
|
|
|
$interlanguageLinksLookup->expects( $this->never() ) |
153
|
|
|
->method( 'findPageLanguageForTarget' ) |
154
|
|
|
->will( $this->returnValue( false ) ); |
155
|
|
|
|
156
|
|
|
$context = $this->getMockBuilder( '\IContextSource' ) |
157
|
|
|
->disableOriginalConstructor() |
158
|
|
|
->getMock(); |
159
|
|
|
|
160
|
|
|
$context->expects( $this->never() ) |
161
|
|
|
->method( 'getOutput' ); |
162
|
|
|
|
163
|
|
|
$instance = new LanguageFilterCategoryPage( $title ); |
164
|
|
|
|
165
|
|
|
$instance->setContext( $context ); |
166
|
|
|
$instance->isCategoryFilterByLanguage( true ); |
167
|
|
|
|
168
|
|
|
$instance->openShowCategory(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testNoInfoMessageByOpenShowCategory() { |
172
|
|
|
|
173
|
|
|
$title = \Title::newFromText( 'Foo', NS_CATEGORY ); |
174
|
|
|
|
175
|
|
|
$context = $this->getMockBuilder( '\IContextSource' ) |
176
|
|
|
->disableOriginalConstructor() |
177
|
|
|
->getMock(); |
178
|
|
|
|
179
|
|
|
$context->expects( $this->never() ) |
180
|
|
|
->method( 'getOutput' ); |
181
|
|
|
|
182
|
|
|
$instance = new LanguageFilterCategoryPage( $title ); |
183
|
|
|
|
184
|
|
|
$instance->setContext( $context ); |
185
|
|
|
$instance->openShowCategory(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
} |
189
|
|
|
|