2014-06-19 18:36:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
* @covers SpecialMyLanguage
|
|
|
|
|
*/
|
|
|
|
|
class SpecialMyLanguageTest extends MediaWikiTestCase {
|
2016-03-07 17:26:25 +00:00
|
|
|
public function addDBDataOnce() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$titles = [
|
2014-06-19 18:36:56 +00:00
|
|
|
'Page/Another',
|
2016-01-27 17:26:42 +00:00
|
|
|
'Page/Another/ar',
|
|
|
|
|
'Page/Another/en',
|
2014-06-19 18:36:56 +00:00
|
|
|
'Page/Another/ru',
|
2016-01-27 17:26:42 +00:00
|
|
|
'Page/Another/zh-hans',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-06-19 18:36:56 +00:00
|
|
|
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
|
2014-07-24 12:55:43 +00:00
|
|
|
* @param string $expected
|
|
|
|
|
* @param string $subpage
|
|
|
|
|
* @param string $langCode
|
|
|
|
|
* @param string $userLang
|
2014-06-19 18:36:56 +00:00
|
|
|
*/
|
|
|
|
|
public function testFindTitle( $expected, $subpage, $langCode, $userLang ) {
|
2018-08-03 16:14:10 +00:00
|
|
|
$this->setContentLang( $langCode );
|
2014-06-19 18:36:56 +00:00
|
|
|
$special = new SpecialMyLanguage();
|
|
|
|
|
$special->getContext()->setLanguage( $userLang );
|
|
|
|
|
// Test with subpages both enabled and disabled
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->mergeMwGlobalArrayValue( 'wgNamespacesWithSubpages', [ NS_MAIN => true ] );
|
2014-06-19 18:36:56 +00:00
|
|
|
$this->assertTitle( $expected, $special->findTitle( $subpage ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->mergeMwGlobalArrayValue( 'wgNamespacesWithSubpages', [ NS_MAIN => false ] );
|
2014-06-19 18:36:56 +00:00
|
|
|
$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 );
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 01:28:26 +00:00
|
|
|
public static function provideFindTitle() {
|
2016-01-27 17:26:42 +00:00
|
|
|
// See addDBDataOnce() for page declarations
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2016-01-27 17:26:42 +00:00
|
|
|
// [ $expected, $subpage, $langCode, $userLang ]
|
2016-02-17 09:09:32 +00:00
|
|
|
[ null, '::Fail', 'en', 'en' ],
|
|
|
|
|
[ 'Page/Another', 'Page/Another/en', 'en', 'en' ],
|
|
|
|
|
[ 'Page/Another', 'Page/Another', 'en', 'en' ],
|
|
|
|
|
[ 'Page/Another/ru', 'Page/Another', 'en', 'ru' ],
|
|
|
|
|
[ 'Page/Another', 'Page/Another', 'en', 'es' ],
|
2016-01-27 17:26:42 +00:00
|
|
|
[ 'Page/Another/zh-hans', 'Page/Another', 'en', 'zh-hans' ],
|
|
|
|
|
[ 'Page/Another/zh-hans', 'Page/Another', 'en', 'zh-mo' ],
|
|
|
|
|
[ 'Page/Another/en', 'Page/Another', 'de', 'es' ],
|
|
|
|
|
[ 'Page/Another/ar', 'Page/Another', 'en', 'ar' ],
|
|
|
|
|
[ 'Page/Another/ar', 'Page/Another', 'en', 'arz' ],
|
|
|
|
|
[ 'Page/Another/ar', 'Page/Another/de', 'en', 'arz' ],
|
|
|
|
|
[ 'Page/Another/ru', 'Page/Another/ru', 'en', 'arz' ],
|
|
|
|
|
[ 'Page/Another/ar', 'Page/Another/ru', 'en', 'ar' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-06-19 18:36:56 +00:00
|
|
|
}
|
2014-07-21 12:47:42 +00:00
|
|
|
}
|