From e5eb717d251a007882a1e2703f9354c90d1e70e5 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Thu, 21 Aug 2014 21:54:51 +0200 Subject: [PATCH] tests: avoid sql queries in TitleTest testIsAlwaysKnown was invoked on an interwiki link. To have the test pass, we used addDBData() to inject the interwiki in the database. This end up being execute on each test when it is only needed for a single assertion. Instead of creating a Title, use Title::makeTitle() to populate the interwiki, thus letting us avoid the database hits. Random timing: 1.20s -> 150ms. Change-Id: I63a4e7b9af5eacb7dc1de4b33b8e631e6c3f1fa6 --- tests/phpunit/includes/TitleTest.php | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 53e8dc230b..d0f418b292 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -1,9 +1,6 @@ db->replace( 'interwiki', 'iw_prefix', - array( - 'iw_prefix' => 'externalwiki', - 'iw_url' => '//example.com/$1', - 'iw_api' => '//example.com/api.php', - 'iw_wikiid' => '', - 'iw_local' => 0, - 'iw_trans' => 0, - ) - ); - } - /** * @covers Title::legalChars */ @@ -640,7 +624,14 @@ class TitleTest extends MediaWikiTestCase { array( 'Special:SomeNonexistentSpecialPage', false ), array( 'MediaWiki:Parentheses', true ), array( 'MediaWiki:Some nonexistent message', false ), - array( 'externalwiki:Interwiki link', true ), ); } + + /** + * @covers Title::isAlwaysKnown + */ + public function testIsAlwaysKnownOnInterwiki() { + $title = Title::makeTitle( NS_MAIN, 'Interwiki link', '', 'externalwiki' ); + $this->assertTrue( $title->isAlwaysKnown() ); + } } -- 2.20.1