wiki.techinc.nl/tests/phpunit/includes/specials/SpecialMyLanguageTest.php
daniel a8995619c1 Avoid rebuilding database fixtures for every test run
This reduces the runtime of database-bound tests by about 40%
(on my system, from 4:55 to 2:47; results from Jenkins are
inconclusive).

The basic idea is to call addCoreDBData() only once, and have
a addDBDataOnce() that is called once per test class, not for
every test method lie addDBData() is. Most tests could be
trivially be changed to implement addDBDataOnce() instead of
addDBData(). The ones for which this did not work immediately
were left out for now. A closer look at the tests that still
implement addDBData() may reveal additional potential for
improvement.

TODO: Once this is merged, try to change addDBData() to
addDBDataOnce() where possible in extensions.

Change-Id: Iec4ed4c8419fb4ad87e6710de808863ede9998b7
2016-03-10 23:44:34 +00:00

65 lines
1.8 KiB
PHP

<?php
/**
* @group Database
* @covers SpecialMyLanguage
*/
class SpecialMyLanguageTest extends MediaWikiTestCase {
public function addDBDataOnce() {
$titles = [
'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', [ NS_MAIN => true ] );
$this->assertTitle( $expected, $special->findTitle( $subpage ) );
$this->mergeMwGlobalArrayValue( 'wgNamespacesWithSubpages', [ 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 [
[ 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' ],
];
}
}