Index: trunk/phase3/maintenance/tests/parser/parserTest.inc |
— | — | @@ -49,6 +49,11 @@ |
50 | 50 | private $databaseSetupDone = false; |
51 | 51 | |
52 | 52 | /** |
| 53 | + * Our connection to the database |
| 54 | + */ |
| 55 | + private $db; |
| 56 | + |
| 57 | + /** |
53 | 58 | * string $oldTablePrefix Original table prefix |
54 | 59 | */ |
55 | 60 | private $oldTablePrefix; |
— | — | @@ -64,7 +69,7 @@ |
65 | 70 | * Sets terminal colorization and diff/quick modes depending on OS and |
66 | 71 | * command-line options (--color and --quick). |
67 | 72 | */ |
68 | | - public function ParserTest( $options = array() ) { |
| 73 | + public function __construct( $options = array() ) { |
69 | 74 | # Only colorize output if stdout is a terminal. |
70 | 75 | $this->color = !wfIsWindows() && posix_isatty( 1 ); |
71 | 76 | |
— | — | @@ -584,8 +589,6 @@ |
585 | 590 | * Ideally this should replace the global configuration entirely. |
586 | 591 | */ |
587 | 592 | private function setupGlobals( $opts = '', $config = '' ) { |
588 | | - global $wgDBtype; |
589 | | - |
590 | 593 | # Find out values for some special options. |
591 | 594 | $lang = |
592 | 595 | self::getOptionValue( 'language', $opts, 'en' ); |
— | — | @@ -615,7 +618,7 @@ |
616 | 619 | 'wgStyleSheetPath' => '/skins', |
617 | 620 | 'wgSitename' => 'MediaWiki', |
618 | 621 | 'wgLanguageCode' => $lang, |
619 | | - 'wgDBprefix' => $wgDBtype != 'oracle' ? 'parsertest_' : 'pt_', |
| 622 | + 'wgDBprefix' => $this->db->getType() != 'oracle' ? 'parsertest_' : 'pt_', |
620 | 623 | 'wgRawHtml' => isset( $opts['rawhtml'] ), |
621 | 624 | 'wgLang' => null, |
622 | 625 | 'wgContLang' => null, |
— | — | @@ -695,8 +698,6 @@ |
696 | 699 | * Some of these probably aren't necessary. |
697 | 700 | */ |
698 | 701 | private function listTables() { |
699 | | - global $wgDBtype; |
700 | | - |
701 | 702 | $tables = array( 'user', 'user_properties', 'page', 'page_restrictions', |
702 | 703 | 'protected_titles', 'revision', 'text', 'pagelinks', 'imagelinks', |
703 | 704 | 'categorylinks', 'templatelinks', 'externallinks', 'langlinks', 'iwlinks', |
— | — | @@ -706,7 +707,7 @@ |
707 | 708 | 'archive', 'user_groups', 'page_props', 'category', 'msg_resource', 'msg_resource_links' |
708 | 709 | ); |
709 | 710 | |
710 | | - if ( in_array( $wgDBtype, array( 'mysql', 'sqlite', 'oracle' ) ) ) |
| 711 | + if ( in_array( $this->db->getType(), array( 'mysql', 'sqlite', 'oracle' ) ) ) |
711 | 712 | array_push( $tables, 'searchindex' ); |
712 | 713 | |
713 | 714 | // Allow extensions to add to the list of tables to duplicate; |
— | — | @@ -729,8 +730,8 @@ |
730 | 731 | return; |
731 | 732 | } |
732 | 733 | |
733 | | - $db = wfGetDB( DB_MASTER ); |
734 | | - $dbType = $db->getType(); |
| 734 | + $this->db = wfGetDB( DB_MASTER ); |
| 735 | + $dbType = $this->db->getType(); |
735 | 736 | |
736 | 737 | if ( $wgDBprefix === 'parsertest_' || ( $dbType == 'oracle' && $wgDBprefix === 'pt_' ) ) { |
737 | 738 | throw new MWException( 'setupDatabase should be called before setupGlobals' ); |
— | — | @@ -756,27 +757,27 @@ |
757 | 758 | # works correctly across DB engines, we need to change the pre- |
758 | 759 | # fix back and forth so tableName() works right. |
759 | 760 | $this->changePrefix( $this->oldTablePrefix ); |
760 | | - $oldTableName = $db->tableName( $tbl ); |
| 761 | + $oldTableName = $this->db->tableName( $tbl ); |
761 | 762 | $this->changePrefix( $dbType != 'oracle' ? 'parsertest_' : 'pt_' ); |
762 | | - $newTableName = $db->tableName( $tbl ); |
| 763 | + $newTableName = $this->db->tableName( $tbl ); |
763 | 764 | |
764 | 765 | if ( $dbType == 'mysql' ) { |
765 | | - $db->query( "DROP TABLE IF EXISTS $newTableName" ); |
| 766 | + $this->db->query( "DROP TABLE IF EXISTS $newTableName" ); |
766 | 767 | } elseif ( in_array( $dbType, array( 'postgres', 'oracle' ) ) ) { |
767 | 768 | /* DROPs wouldn't work due to Foreign Key Constraints (bug 14990, r58669) |
768 | 769 | * Use "DROP TABLE IF EXISTS $newTableName CASCADE" for postgres? That |
769 | 770 | * syntax would also work for mysql. |
770 | 771 | */ |
771 | | - } elseif ( $db->tableExists( $tbl ) ) { |
772 | | - $db->query( "DROP TABLE $newTableName" ); |
| 772 | + } elseif ( $this->db->tableExists( $tbl ) ) { |
| 773 | + $this->db->query( "DROP TABLE $newTableName" ); |
773 | 774 | } |
774 | 775 | |
775 | 776 | # Create new table |
776 | | - $db->duplicateTableStructure( $oldTableName, $newTableName, $temporary ); |
| 777 | + $this->db->duplicateTableStructure( $oldTableName, $newTableName, $temporary ); |
777 | 778 | } |
778 | 779 | |
779 | 780 | if ( $dbType == 'oracle' ) |
780 | | - $db->query( 'BEGIN FILL_WIKI_INFO; END;' ); |
| 781 | + $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' ); |
781 | 782 | |
782 | 783 | $this->changePrefix( $dbType != 'oracle' ? 'parsertest_' : 'pt_' ); |
783 | 784 | |
— | — | @@ -784,14 +785,14 @@ |
785 | 786 | # Insert 0 user to prevent FK violations |
786 | 787 | |
787 | 788 | # Anonymous user |
788 | | - $db->insert( 'user', array( |
| 789 | + $this->db->insert( 'user', array( |
789 | 790 | 'user_id' => 0, |
790 | 791 | 'user_name' => 'Anonymous' ) ); |
791 | 792 | } |
792 | 793 | |
793 | 794 | # Hack: insert a few Wikipedia in-project interwiki prefixes, |
794 | 795 | # for testing inter-language links |
795 | | - $db->insert( 'interwiki', array( |
| 796 | + $this->db->insert( 'interwiki', array( |
796 | 797 | array( 'iw_prefix' => 'wikipedia', |
797 | 798 | 'iw_url' => 'http://en.wikipedia.org/wiki/$1', |
798 | 799 | 'iw_api' => '', |
— | — | @@ -826,7 +827,7 @@ |
827 | 828 | |
828 | 829 | |
829 | 830 | # Update certain things in site_stats |
830 | | - $db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) ); |
| 831 | + $this->db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) ); |
831 | 832 | |
832 | 833 | # Reinitialise the LocalisationCache to match the database state |
833 | 834 | Language::getLocalisationCache()->unloadAll(); |
— | — | @@ -848,7 +849,7 @@ |
849 | 850 | 'metadata' => serialize( array() ), |
850 | 851 | 'sha1' => wfBaseConvert( '', 16, 36, 31 ), |
851 | 852 | 'fileExists' => true |
852 | | - ), $db->timestamp( '20010115123500' ), $user ); |
| 853 | + ), $this->db->timestamp( '20010115123500' ), $user ); |
853 | 854 | |
854 | 855 | # This image will be blacklisted in [[MediaWiki:Bad image list]] |
855 | 856 | $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) ); |
— | — | @@ -862,7 +863,7 @@ |
863 | 864 | 'metadata' => serialize( array() ), |
864 | 865 | 'sha1' => wfBaseConvert( '', 16, 36, 31 ), |
865 | 866 | 'fileExists' => true |
866 | | - ), $db->timestamp( '20010115123500' ), $user ); |
| 867 | + ), $this->db->timestamp( '20010115123500' ), $user ); |
867 | 868 | } |
868 | 869 | |
869 | 870 | /** |
— | — | @@ -899,15 +900,14 @@ |
900 | 901 | } |
901 | 902 | |
902 | 903 | $tables = $this->listTables(); |
903 | | - $db = wfGetDB( DB_MASTER ); |
904 | 904 | |
905 | 905 | foreach ( $tables as $table ) { |
906 | | - $sql = $db->getType() == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`"; |
907 | | - $db->query( $sql ); |
| 906 | + $sql = $this->db->getType() == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`"; |
| 907 | + $this->db->query( $sql ); |
908 | 908 | } |
909 | 909 | |
910 | | - if ( $db->getType() == 'oracle' ) |
911 | | - $db->query( 'BEGIN FILL_WIKI_INFO; END;' ); |
| 910 | + if ( $this->db->getType() == 'oracle' ) |
| 911 | + $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' ); |
912 | 912 | |
913 | 913 | $this->teardownGlobals(); |
914 | 914 | } |