wiki.techinc.nl/tests/phpunit/includes/specials/SpecialMyLanguageTest.php
Timo Tijhof 96771e3a65 test: Clean up data providers that should be static
Follows-up b36d883.

By far most data providers are static (and PHPUnit expects them
to be static and calls them that way).

Most of these classes already had their data providers static
but additional commits sloppily introduced non-static ones.

* ResourceLoaderWikiModuleTest, 8968d8787f.
* TitleTest, 545f1d3a73.
  Odd unused method 'dataTestIsValidMoveOperation' was introduced
  in 550b878e63.
* GlobalVarConfigTest, a3e18c3670.

Change-Id: I5da99f7cd3da68c550ae507ffe1f725d31e7666f
2014-09-18 12:52:44 -07:00

65 lines
1.8 KiB
PHP

<?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' ),
);
}
}