Merge "Log profiling data when tests have finished."
[lhc/web/wiklou.git] / tests / phpunit / includes / SampleTest.php
index 117ac1c..1324d50 100644 (file)
@@ -1,20 +1,29 @@
 <?php
 
-class TestSample extends PHPUnit_Framework_TestCase {
+class TestSample extends MediaWikiLangTestCase {
 
        /**
         * Anything that needs to happen before your tests should go here.
         */
-       function setUp() {
-               global $wgContLang;
-               /* For example, we need to set $wgContLang for creating a new Title */
-               $wgContLang = Language::factory( 'en' );
+       protected function setUp() {
+               // Be sure to do call the parent setup and teardown functions.
+               // This makes sure that all the various cleanup and restorations
+               // happen as they should (including the restoration for setMwGlobals).
+               parent::setUp();
+
+               // This sets the globals and will restore them automatically
+               // after each test.
+               $this->setMwGlobals( array(
+                       'wgContLang' => Language::factory( 'en' ),
+                       'wgLanguageCode' => 'en',
+               ) );
        }
 
        /**
         * Anything cleanup you need to do should go here.
         */
-       function tearDown() {
+       protected function tearDown() {
+               parent::tearDown();
        }
 
        /**
@@ -37,14 +46,16 @@ class TestSample extends PHPUnit_Framework_TestCase {
        /**
         * If you want to run a the same test with a variety of data. use a data provider.
         * see: http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html
+        *
+        * Note: Data providers are always called statically and outside setUp/tearDown!
         */
-       public function provideTitles() {
+       public static function provideTitles() {
                return array(
                        array( 'Text', NS_MEDIA, 'Media:Text' ),
                        array( 'Text', null, 'Text' ),
                        array( 'text', null, 'Text' ),
                        array( 'Text', NS_USER, 'User:Text' ),
-                       array( 'Photo.jpg', NS_IMAGE, 'File:Photo.jpg' )
+                       array( 'Photo.jpg', NS_FILE, 'File:Photo.jpg' )
                );
        }
 
@@ -75,6 +86,7 @@ class TestSample extends PHPUnit_Framework_TestCase {
         * example) as arguments to the next method (e.g. $title in
         * testTitleDepends is whatever testInitialCreatiion returned.)
         */
+
        /**
         * @depends testSetUpMainPageTitleForNextTest
         * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.depends
@@ -88,7 +100,7 @@ class TestSample extends PHPUnit_Framework_TestCase {
         * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.expectedException
         */
        function testTitleObjectFromObject() {
-               $title = Title::newFromText( new Title( "test" ) );
+               $title = Title::newFromText( Title::newFromText( "test" ) );
                $this->assertEquals( "Test", $title->isLocal() );
        }
 }