tests: avoid sql queries in TitleTest
authorAntoine Musso <hashar@free.fr>
Thu, 21 Aug 2014 19:54:51 +0000 (21:54 +0200)
committerLegoktm <legoktm.wikipedia@gmail.com>
Fri, 22 Aug 2014 23:16:01 +0000 (23:16 +0000)
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

index 53e8dc2..d0f418b 100644 (file)
@@ -1,9 +1,6 @@
 <?php
 
 /**
- * @group Database
- *        ^--- needed for language cache stuff
- *
  * @group Title
  */
 class TitleTest extends MediaWikiTestCase {
@@ -20,19 +17,6 @@ class TitleTest extends MediaWikiTestCase {
                ) );
        }
 
-       public function addDBData() {
-               $this->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() );
+       }
 }