Merge "database: Add extra sanity check to selectFieldValues()"
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialMyLanguageTest.php
1 <?php
2
3 /**
4 * @group Database
5 * @covers SpecialMyLanguage
6 */
7 class SpecialMyLanguageTest extends MediaWikiTestCase {
8 public function addDBData() {
9 $titles = [
10 'Page/Another',
11 'Page/Another/ru',
12 ];
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' ) );
22 }
23 }
24 }
25
26 /**
27 * @covers SpecialMyLanguage::findTitle
28 * @dataProvider provideFindTitle
29 * @param string $expected
30 * @param string $subpage
31 * @param string $langCode
32 * @param string $userLang
33 */
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', [ NS_MAIN => true ] );
40 $this->assertTitle( $expected, $special->findTitle( $subpage ) );
41 $this->mergeMwGlobalArrayValue( 'wgNamespacesWithSubpages', [ NS_MAIN => false ] );
42 $this->assertTitle( $expected, $special->findTitle( $subpage ) );
43 }
44
45 /**
46 * @param string $expected
47 * @param Title|null $title
48 */
49 private function assertTitle( $expected, $title ) {
50 if ( $title ) {
51 $title = $title->getPrefixedText();
52 }
53 $this->assertEquals( $expected, $title );
54 }
55
56 public static function provideFindTitle() {
57 return [
58 [ null, '::Fail', 'en', 'en' ],
59 [ 'Page/Another', 'Page/Another/en', 'en', 'en' ],
60 [ 'Page/Another', 'Page/Another', 'en', 'en' ],
61 [ 'Page/Another/ru', 'Page/Another', 'en', 'ru' ],
62 [ 'Page/Another', 'Page/Another', 'en', 'es' ],
63 ];
64 }
65 }