jenkins-bot has submitted this change and it was merged.
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(-)
Approvals:
Hashar: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc
index 1c3ba1d..4efd708 100644
--- a/tests/parser/parserTest.inc
+++ b/tests/parser/parserTest.inc
@@ -212,6 +212,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 ) {
@@ -828,41 +883,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 6975939..93923fd 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;
@@ -155,49 +160,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: merged
Gerrit-Change-Id: I36865e3890e08a05b8a6aaafa309a87556e235b9
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: IAlex <[email protected]>
Gerrit-Reviewer: Platonides <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-Reviewer: ใในใ <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits