1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<?php
/**
* @group Database
* @covers SpecialMyLanguage
*/
class SpecialMyLanguageTest extends MediaWikiTestCase {
public function addDBData() {
$titles = array(
'Page/Another',
'Page/Another/ru',
);
foreach ( $titles as $title ) {
$page = WikiPage::factory( Title::newFromText( $title ) );
if ( $page->getId() == 0 ) {
$page->doEditContent(
new WikitextContent( 'UTContent' ),
'UTPageSummary',
EDIT_NEW,
false,
User::newFromName( 'UTSysop' ) );
}
}
}
/**
* @covers SpecialMyLanguage::findTitle
* @dataProvider provideFindTitle
* @param string $expected
* @param string $subpage
* @param string $langCode
* @param string $userLang
*/
public function testFindTitle( $expected, $subpage, $langCode, $userLang ) {
$this->setMwGlobals( 'wgLanguageCode', $langCode );
$special = new SpecialMyLanguage();
$special->getContext()->setLanguage( $userLang );
// Test with subpages both enabled and disabled
$this->mergeMwGlobalArrayValue( 'wgNamespacesWithSubpages', array( NS_MAIN => true ) );
$this->assertTitle( $expected, $special->findTitle( $subpage ) );
$this->mergeMwGlobalArrayValue( 'wgNamespacesWithSubpages', array( NS_MAIN => false ) );
$this->assertTitle( $expected, $special->findTitle( $subpage ) );
}
/**
* @param string $expected
* @param Title|null $title
*/
private function assertTitle( $expected, $title ) {
if ( $title ) {
$title = $title->getPrefixedText();
}
$this->assertEquals( $expected, $title );
}
public static function provideFindTitle() {
return array(
array( null, '::Fail', 'en', 'en' ),
array( 'Page/Another', 'Page/Another/en', 'en', 'en' ),
array( 'Page/Another', 'Page/Another', 'en', 'en' ),
array( 'Page/Another/ru', 'Page/Another', 'en', 'ru' ),
array( 'Page/Another', 'Page/Another', 'en', 'es' ),
);
}
}
|