1 | <?php |
||
16 | class InterlanguageLinkParserFunctionTest extends \PHPUnit_Framework_TestCase { |
||
17 | |||
18 | private $languageLinkAnnotator; |
||
19 | private $siteLanguageLinksParserOutputAppender; |
||
20 | private $pageContentLanguageOnTheFlyModifier; |
||
21 | private $pageContentLanguageDbModifier; |
||
22 | |||
23 | protected function setUp() { |
||
46 | |||
47 | public function testCanConstruct() { |
||
64 | |||
65 | public function testTryParseThatCausesErrorMessage() { |
||
103 | |||
104 | public function testParseToCreateErrorMessageForKnownTarget() { |
||
138 | |||
139 | public function testMultipleParseCalls() { |
||
140 | |||
141 | $title = \Title::newFromText( __METHOD__ ); |
||
142 | |||
143 | $this->siteLanguageLinksParserOutputAppender->expects( $this->any() ) |
||
144 | ->method( 'getRedirectTargetFor' ) |
||
145 | ->will( $this->returnValue( $title ) ); |
||
146 | |||
147 | $instance = new InterlanguageLinkParserFunction( |
||
148 | $title, |
||
149 | $this->languageLinkAnnotator, |
||
150 | $this->siteLanguageLinksParserOutputAppender, |
||
151 | $this->pageContentLanguageOnTheFlyModifier, |
||
152 | $this->pageContentLanguageDbModifier |
||
153 | ); |
||
154 | |||
155 | $this->assertContains( |
||
156 | 'div class="sil-interlanguagelink"', |
||
157 | $instance->parse( 'en', 'Foo' ) |
||
158 | ); |
||
159 | |||
160 | $this->assertContains( |
||
161 | 'div class="sil-interlanguagelink"', |
||
162 | $instance->parse( 'en', 'Foo' ) |
||
163 | ); |
||
164 | } |
||
165 | |||
166 | public function testMultipleParseCallsWithDifferentLanguagesTriggersErrorMessage() { |
||
193 | |||
194 | public function testParse() { |
||
195 | |||
196 | $title = $this->getMockBuilder( '\Title' ) |
||
197 | ->disableOriginalConstructor() |
||
198 | ->getMock(); |
||
199 | |||
200 | $this->languageLinkAnnotator->expects( $this->once() ) |
||
201 | ->method( 'addAnnotationForInterlanguageLink' ); |
||
202 | |||
203 | $this->siteLanguageLinksParserOutputAppender->expects( $this->any() ) |
||
204 | ->method( 'getRedirectTargetFor' ) |
||
205 | ->will( $this->returnValue( $title ) ); |
||
206 | |||
207 | $instance = new InterlanguageLinkParserFunction( |
||
208 | $title, |
||
209 | $this->languageLinkAnnotator, |
||
210 | $this->siteLanguageLinksParserOutputAppender, |
||
211 | $this->pageContentLanguageOnTheFlyModifier, |
||
212 | $this->pageContentLanguageDbModifier |
||
213 | ); |
||
214 | |||
215 | $instance->setInterlanguageLinksHideState( false ); |
||
216 | |||
217 | $this->assertContains( |
||
218 | 'div class="sil-interlanguagelink"', |
||
219 | $instance->parse( 'en', 'Foo' ) |
||
220 | ); |
||
221 | } |
||
222 | |||
223 | public function testValidLanguageCodeByLowerCaseComparison() { |
||
224 | |||
225 | $title = $this->getMockBuilder( '\Title' ) |
||
226 | ->disableOriginalConstructor() |
||
227 | ->getMock(); |
||
228 | |||
229 | $this->languageLinkAnnotator->expects( $this->once() ) |
||
230 | ->method( 'addAnnotationForInterlanguageLink' ); |
||
231 | |||
232 | $this->siteLanguageLinksParserOutputAppender->expects( $this->any() ) |
||
233 | ->method( 'getRedirectTargetFor' ) |
||
234 | ->will( $this->returnValue( $title ) ); |
||
235 | |||
236 | $instance = new InterlanguageLinkParserFunction( |
||
237 | $title, |
||
238 | $this->languageLinkAnnotator, |
||
239 | $this->siteLanguageLinksParserOutputAppender, |
||
240 | $this->pageContentLanguageOnTheFlyModifier, |
||
241 | $this->pageContentLanguageDbModifier |
||
242 | ); |
||
243 | |||
244 | $instance->setInterlanguageLinksHideState( false ); |
||
245 | |||
246 | $this->assertContains( |
||
247 | 'div class="sil-interlanguagelink"', |
||
248 | $instance->parse( 'zh-Hans', 'Foo' ) |
||
249 | ); |
||
250 | } |
||
251 | |||
252 | public function testRevisionMode() { |
||
253 | |||
254 | $title = $this->getMockBuilder( '\Title' ) |
||
255 | ->disableOriginalConstructor() |
||
256 | ->getMock(); |
||
257 | |||
258 | $this->siteLanguageLinksParserOutputAppender->expects( $this->any() ) |
||
259 | ->method( 'getRedirectTargetFor' ) |
||
260 | ->will( $this->returnValue( $title ) ); |
||
261 | |||
262 | $instance = new InterlanguageLinkParserFunction( |
||
263 | $title, |
||
264 | $this->languageLinkAnnotator, |
||
265 | $this->siteLanguageLinksParserOutputAppender, |
||
266 | $this->pageContentLanguageOnTheFlyModifier, |
||
267 | $this->pageContentLanguageDbModifier |
||
268 | ); |
||
269 | |||
270 | $instance->setRevisionModeState( true ); |
||
271 | |||
272 | $this->assertEmpty( |
||
273 | $instance->parse( 'en', 'Foo' ) |
||
274 | ); |
||
275 | } |
||
276 | |||
277 | public function testAnnotationModeIsDisabled() { |
||
303 | |||
304 | public function testAddLanguageCodeToPageContentLanguageIntermediaryCache() { |
||
328 | |||
329 | } |
||
330 |