Merge "Clarify userrights-conflict"
[lhc/web/wiklou.git] / tests / parser / parserTest.inc
index 1c3ba1d..e7c36db 100644 (file)
@@ -212,6 +212,61 @@ class ParserTest {
                        $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 ) {
@@ -379,7 +434,12 @@ class ParserTest {
         */
        public function runTestsFromFiles( $filenames ) {
                $ok = false;
+
+               // be sure, ParserTest::addArticle has correct language set,
+               // so that system messages gets into the right language cache
+               $GLOBALS['wgLanguageCode'] = 'en';
                $GLOBALS['wgContLang'] = Language::factory( 'en' );
+
                $this->recorder->start();
                try {
                        $this->setupDatabase();
@@ -673,7 +733,7 @@ class ParserTest {
                        'wgSitename' => 'MediaWiki',
                        'wgLanguageCode' => $lang,
                        'wgDBprefix' => $this->db->getType() != 'oracle' ? 'parsertest_' : 'pt_',
-                       'wgRawHtml' => isset( $opts['rawhtml'] ),
+                       'wgRawHtml' => self::getOptionValue( 'wgRawHtml', $opts, false ),
                        'wgLang' => null,
                        'wgContLang' => null,
                        'wgNamespacesWithSubpages' => array( 0 => isset( $opts['subpage'] ) ),
@@ -686,7 +746,7 @@ class ParserTest {
                        'wgSVGConverter' => 'null',
                        'wgSVGConverters' => array( 'null' => 'echo "1">$output' ),
                        'wgLocaltimezone' => 'UTC',
-                       'wgAllowExternalImages' => true,
+                       'wgAllowExternalImages' => self::getOptionValue( 'wgAllowExternalImages', $opts, true ),
                        'wgUseTidy' => false,
                        'wgDefaultLanguageVariant' => $variant,
                        'wgVariantArticlePath' => false,
@@ -829,43 +889,9 @@ class ParserTest {
                                '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 ) );
+               $this->db->insert( 'site_stats',
+                       array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) );
 
                # Reinitialise the LocalisationCache to match the database state
                Language::getLocalisationCache()->unloadAll();
@@ -962,8 +988,11 @@ class ParserTest {
                $tables = $this->listTables();
 
                foreach ( $tables as $table ) {
-                       $sql = $this->db->getType() == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`";
-                       $this->db->query( $sql );
+                       if ( $this->db->getType() == 'oracle' ) {
+                               $this->db->query( "DROP TABLE pt_$table DROP CONSTRAINTS" );
+                       } else {
+                               $this->db->query( "DROP TABLE `parsertest_$table`" );
+                       }
                }
 
                if ( $this->db->getType() == 'oracle' ) {
@@ -1190,7 +1219,9 @@ class ParserTest {
         * @param $outFileTail String: tailing for the output file name
         * @return String
         */
-       protected function quickDiff( $input, $output, $inFileTail = 'expected', $outFileTail = 'actual' ) {
+       protected function quickDiff( $input, $output,
+               $inFileTail = 'expected', $outFileTail = 'actual'
+       ) {
                # Windows, or at least the fc utility, is retarded
                $slash = wfIsWindows() ? '\\' : '/';
                $prefix = wfTempDir() . "{$slash}mwParser-" . mt_rand();
@@ -1409,7 +1440,7 @@ class ParserTest {
        }
 
        static function getFakeTimestamp( &$parser, &$ts ) {
-               $ts = 123;
+               $ts = 123; //parsed as '1970-01-01T00:02:03Z'
                return true;
        }
 }