merged master
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index 1cc45e0..d3dd389 100644 (file)
@@ -19,6 +19,16 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        protected $reuseDB = false;
        protected $tablesUsed = array(); // tables with data
 
+       protected $restoreGlobals = array( // global variables to restore for each test
+               'wgLang',
+               'wgContLang',
+               'wgLanguageCode',
+               'wgUser',
+               'wgTitle',
+       );
+
+       private $savedGlobals = array();
+
        private static $dbSetup = false;
 
        /**
@@ -119,7 +129,21 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                return $fname;
        }
 
-       protected function tearDown() {
+       protected function setup() {
+               parent::setup();
+
+               foreach ( $this->restoreGlobals as $var ) {
+                       $v = $GLOBALS[ $var ];
+
+                       if ( is_object( $v ) || is_array( $v ) ) {
+                               $v = clone $v;
+                       }
+
+                       $this->savedGlobals[ $var ] = $v;
+               }
+       }
+
+       protected function teardown() {
                // Cleaning up temporary files
                foreach ( $this->tmpfiles as $fname ) {
                        if ( is_file( $fname ) || ( is_link( $fname ) ) ) {
@@ -136,7 +160,12 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        }
                }
 
-               parent::tearDown();
+               // restore saved globals
+               foreach ( $this->savedGlobals as $k => $v ) {
+                       $GLOBALS[ $k ] = $v;
+               }
+
+               parent::teardown();
        }
 
        function dbPrefix() {
@@ -212,11 +241,12 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                //Make 1 page with 1 revision
                $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
                if ( !$page->getId() == 0 ) {
-                       $page->doEdit( 'UTContent',
-                                                       'UTPageSummary',
-                                                       EDIT_NEW,
-                                                       false,
-                                                       User::newFromName( 'UTSysop' ) );
+                       $page->doEditContent(
+                               new WikitextContent( 'UTContent' ),
+                               'UTPageSummary',
+                               EDIT_NEW,
+                               false,
+                               User::newFromName( 'UTSysop' ) );
                }
        }