Hashar has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/64574


Change subject: test: rework interwiki lookup in parser tests
......................................................................

test: rework interwiki lookup in parser tests

Some of our parser tests lookup interwikis.  This was originally done
(parser/parserTest.inc) by inserting a set of interwikis in the database
and was later lamely copy pasted in the PHPUnit wrapped test suite
(phpunit/includes/parser/NewParserTest.php).

Since that time, we had duplicate code and had the test hitting the
database to fetch interwiki.  Nowadays, we can trick the Interwiki
lookup class by using the InterwikiLoadPrefix hook, that let us skip
database lookup entirely (by having the hook returning false) and get
rid of the duplicate code.

The good old parserTests.php still pass the tests :-]

Change-Id: I36865e3890e08a05b8a6aaafa309a87556e235b9
---
M tests/parser/parserTest.inc
M tests/phpunit/includes/parser/NewParserTest.php
2 files changed, 60 insertions(+), 76 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/74/64574/1

diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc
index 972ad8f..a66980b 100644
--- a/tests/parser/parserTest.inc
+++ b/tests/parser/parserTest.inc
@@ -210,6 +210,61 @@
                        $wgStyleDirectory = "$IP/skins";
                }
 
+               self::setupInterwikis();
+       }
+
+       /**
+        * Insert hardcoded interwiki in the lookup table.
+        *
+        * This function insert a set of well known interwikis that are used in
+        * the parser tests. They can be considered has fixtures are injected in
+        * the interwiki cache by using the 'InterwikiLoadPrefix' hook.
+        * Since we are not interested in looking up interwikis in the database,
+        * the hook completely replace the existing mechanism (hook returns 
false).
+        */
+       public static function setupInterwikis() {
+               # Hack: insert a few Wikipedia in-project interwiki prefixes,
+               # for testing inter-language links
+               Hooks::register( 'InterwikiLoadPrefix', function ( $prefix, 
&$iwData ) {
+                       static $testInterwikis = array(
+                               'wikipedia' => array(
+                                       'iw_url' => 
'http://en.wikipedia.org/wiki/$1',
+                                       'iw_api' => '',
+                                       'iw_wikiid' => '',
+                                       'iw_local' => 0 ),
+                               'meatball' => array(
+                                       'iw_url' => 
'http://www.usemod.com/cgi-bin/mb.pl?$1',
+                                       'iw_api' => '',
+                                       'iw_wikiid' => '',
+                                       'iw_local' => 0 ),
+                               'zh' => array(
+                                       'iw_url' => 
'http://zh.wikipedia.org/wiki/$1',
+                                       'iw_api' => '',
+                                       'iw_wikiid' => '',
+                                       'iw_local' => 1 ),
+                               'es' => array(
+                                       'iw_url' => 
'http://es.wikipedia.org/wiki/$1',
+                                       'iw_api' => '',
+                                       'iw_wikiid' => '',
+                                       'iw_local' => 1 ),
+                               'fr' => array(
+                                       'iw_url' => 
'http://fr.wikipedia.org/wiki/$1',
+                                       'iw_api' => '',
+                                       'iw_wikiid' => '',
+                                       'iw_local' => 1 ),
+                               'ru' => array(
+                                       'iw_url' => 
'http://ru.wikipedia.org/wiki/$1',
+                                       'iw_api' => '',
+                                       'iw_wikiid' => '',
+                                       'iw_local' => 1 ),
+                       );
+                       if( array_key_exists( $prefix, $testInterwikis ) ) {
+                               $iwData = $testInterwikis[$prefix];
+                       }
+
+                       // We only want to rely on the above fixtures
+                       return false;
+               } );// hooks::register
        }
 
        public function setupRecorder( $options ) {
@@ -824,41 +879,6 @@
                                'user_id' => 0,
                                'user_name' => 'Anonymous' ) );
                }
-
-               # Hack: insert a few Wikipedia in-project interwiki prefixes,
-               # for testing inter-language links
-               $this->db->insert( 'interwiki', array(
-                       array( 'iw_prefix' => 'wikipedia',
-                               'iw_url' => 'http://en.wikipedia.org/wiki/$1',
-                               'iw_api' => '',
-                               'iw_wikiid' => '',
-                               'iw_local' => 0 ),
-                       array( 'iw_prefix' => 'meatball',
-                               'iw_url' => 
'http://www.usemod.com/cgi-bin/mb.pl?$1',
-                               'iw_api' => '',
-                               'iw_wikiid' => '',
-                               'iw_local' => 0 ),
-                       array( 'iw_prefix' => 'zh',
-                               'iw_url' => 'http://zh.wikipedia.org/wiki/$1',
-                               'iw_api' => '',
-                               'iw_wikiid' => '',
-                               'iw_local' => 1 ),
-                       array( 'iw_prefix' => 'es',
-                               'iw_url' => 'http://es.wikipedia.org/wiki/$1',
-                               'iw_api' => '',
-                               'iw_wikiid' => '',
-                               'iw_local' => 1 ),
-                       array( 'iw_prefix' => 'fr',
-                               'iw_url' => 'http://fr.wikipedia.org/wiki/$1',
-                               'iw_api' => '',
-                               'iw_wikiid' => '',
-                               'iw_local' => 1 ),
-                       array( 'iw_prefix' => 'ru',
-                               'iw_url' => 'http://ru.wikipedia.org/wiki/$1',
-                               'iw_api' => '',
-                               'iw_wikiid' => '',
-                               'iw_local' => 1 ),
-               ) );
 
                # Update certain things in site_stats
                $this->db->insert( 'site_stats', array( 'ss_row_id' => 1, 
'ss_images' => 2, 'ss_good_articles' => 1 ) );
diff --git a/tests/phpunit/includes/parser/NewParserTest.php 
b/tests/phpunit/includes/parser/NewParserTest.php
index 8cee07b..90e2958 100644
--- a/tests/phpunit/includes/parser/NewParserTest.php
+++ b/tests/phpunit/includes/parser/NewParserTest.php
@@ -31,6 +31,11 @@
 
        protected $file = false;
 
+       public static function setUpBeforeClass() {
+               // Inject ParserTest well-known interwikis
+               ParserTest::setupInterwikis();
+       }
+
        protected function setUp() {
                global $wgNamespaceAliases;
                global $wgHooks, $IP;
@@ -149,49 +154,8 @@
 
        function addDBData() {
                $this->tablesUsed[] = 'site_stats';
-               $this->tablesUsed[] = 'interwiki';
                # disabled for performance
                #$this->tablesUsed[] = 'image';
-
-               # Hack: insert a few Wikipedia in-project interwiki prefixes,
-               # for testing inter-language links
-               $this->db->insert( 'interwiki', array(
-                               array( 'iw_prefix' => 'wikipedia',
-                                       'iw_url' => 
'http://en.wikipedia.org/wiki/$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 0 ),
-                               array( 'iw_prefix' => 'meatball',
-                                       'iw_url' => 
'http://www.usemod.com/cgi-bin/mb.pl?$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 0 ),
-                               array( 'iw_prefix' => 'zh',
-                                       'iw_url' => 
'http://zh.wikipedia.org/wiki/$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 1 ),
-                               array( 'iw_prefix' => 'es',
-                                       'iw_url' => 
'http://es.wikipedia.org/wiki/$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 1 ),
-                               array( 'iw_prefix' => 'fr',
-                                       'iw_url' => 
'http://fr.wikipedia.org/wiki/$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 1 ),
-                               array( 'iw_prefix' => 'ru',
-                                       'iw_url' => 
'http://ru.wikipedia.org/wiki/$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 1 ),
-                               /**
-                                * @todo Fixme! Why are we inserting duplicate 
data here? Shouldn't
-                                * need this IGNORE or shouldn't need the 
insert at all.
-                                */
-                       ), __METHOD__, array( 'IGNORE' )
-               );
 
                # Update certain things in site_stats
                $this->db->insert( 'site_stats',

-- 
To view, visit https://gerrit.wikimedia.org/r/64574
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I36865e3890e08a05b8a6aaafa309a87556e235b9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to