Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / specials / SpecialMyLanguageTest.php
blob4dbfc412c94ffad20d929f14fc223622cbdc6706
1 <?php
3 /**
4 * @group Database
5 * @covers SpecialMyLanguage
6 */
7 class SpecialMyLanguageTest extends MediaWikiTestCase {
8 public function addDBData() {
9 $titles = array(
10 'Page/Another',
11 'Page/Another/ru',
13 foreach ( $titles as $title ) {
14 $page = WikiPage::factory( Title::newFromText( $title ) );
15 if ( $page->getId() == 0 ) {
16 $page->doEditContent(
17 new WikitextContent( 'UTContent' ),
18 'UTPageSummary',
19 EDIT_NEW,
20 false,
21 User::newFromName( 'UTSysop' ) );
26 /**
27 * @covers SpecialMyLanguage::findTitle
28 * @dataProvider provideFindTitle
29 * @param string $expected
30 * @param string $subpage
31 * @param string $langCode
32 * @param string $userLang
34 public function testFindTitle( $expected, $subpage, $langCode, $userLang ) {
35 $this->setMwGlobals( 'wgLanguageCode', $langCode );
36 $special = new SpecialMyLanguage();
37 $special->getContext()->setLanguage( $userLang );
38 // Test with subpages both enabled and disabled
39 $this->mergeMwGlobalArrayValue( 'wgNamespacesWithSubpages', array( NS_MAIN => true ) );
40 $this->assertTitle( $expected, $special->findTitle( $subpage ) );
41 $this->mergeMwGlobalArrayValue( 'wgNamespacesWithSubpages', array( NS_MAIN => false ) );
42 $this->assertTitle( $expected, $special->findTitle( $subpage ) );
45 /**
46 * @param string $expected
47 * @param Title|null $title
49 private function assertTitle( $expected, $title ) {
50 if ( $title ) {
51 $title = $title->getPrefixedText();
53 $this->assertEquals( $expected, $title );
56 public static function provideFindTitle() {
57 return array(
58 array( null, '::Fail', 'en', 'en' ),
59 array( 'Page/Another', 'Page/Another/en', 'en', 'en' ),
60 array( 'Page/Another', 'Page/Another', 'en', 'en' ),
61 array( 'Page/Another/ru', 'Page/Another', 'en', 'ru' ),
62 array( 'Page/Another', 'Page/Another', 'en', 'es' ),