MagicVariableTest.php: Use dataProvider
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / MagicVariableTest.php
index 611a45a..75e1fd1 100644 (file)
@@ -33,7 +33,10 @@ class MagicVariableTest extends MediaWikiTestCase {
                parent::setUp();
 
                $contLang = Language::factory( 'en' );
-               $this->setMwGlobals( 'wgContLang', $contLang );
+               $this->setMwGlobals( array(
+                       'wgLanguageCode' => 'en',
+                       'wgContLang' => $contLang,
+               ) );
 
                $this->testParser = new Parser();
                $this->testParser->Options( ParserOptions::newFromUserAndLang( new User, $contLang ) );
@@ -62,38 +65,68 @@ class MagicVariableTest extends MediaWikiTestCase {
 
        # day
 
-       /** @dataProvider MediaWikiProvide::Days */
+       /**
+        * @dataProvider MediaWikiProvide::Days
+        * @group Database
+        */
        function testCurrentdayIsUnPadded( $day ) {
                $this->assertUnPadded( 'currentday', $day );
        }
-       /** @dataProvider MediaWikiProvide::Days */
+
+       /**
+        * @dataProvider MediaWikiProvide::Days
+        * @group Database
+        */
        function testCurrentdaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'currentday2', $day );
        }
-       /** @dataProvider MediaWikiProvide::Days */
+
+       /**
+        * @dataProvider MediaWikiProvide::Days
+        * @group Database
+        */
        function testLocaldayIsUnPadded( $day ) {
                $this->assertUnPadded( 'localday', $day );
        }
-       /** @dataProvider MediaWikiProvide::Days */
+
+       /**
+        * @dataProvider MediaWikiProvide::Days
+        * @group Database
+        */
        function testLocaldaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'localday2', $day );
        }
-       
+
        # month
 
-       /** @dataProvider MediaWikiProvide::Months */
+       /**
+        * @dataProvider MediaWikiProvide::Months
+        * @group Database
+        */
        function testCurrentmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'currentmonth', $month );
        }
-       /** @dataProvider MediaWikiProvide::Months */
+
+       /**
+        * @dataProvider MediaWikiProvide::Months
+        * @group Database
+        */
        function testCurrentmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'currentmonth1', $month );
        }
-       /** @dataProvider MediaWikiProvide::Months */
+
+       /**
+        * @dataProvider MediaWikiProvide::Months
+        * @group Database
+        */
        function testLocalmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'localmonth', $month );
        }
-       /** @dataProvider MediaWikiProvide::Months */
+
+       /**
+        * @dataProvider MediaWikiProvide::Months
+        * @group Database
+        */
        function testLocalmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'localmonth1', $month );
        }
@@ -101,22 +134,36 @@ class MagicVariableTest extends MediaWikiTestCase {
 
        # revision day
 
-       /** @dataProvider MediaWikiProvide::Days */
+       /**
+        * @dataProvider MediaWikiProvide::Days
+        * @group Database
+        */
        function testRevisiondayIsUnPadded( $day ) {
                $this->assertUnPadded( 'revisionday', $day );
        }
-       /** @dataProvider MediaWikiProvide::Days */
+
+       /**
+        * @dataProvider MediaWikiProvide::Days
+        * @group Database
+        */
        function testRevisiondaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'revisionday2', $day );
        }
-       
+
        # revision month
 
-       /** @dataProvider MediaWikiProvide::Months */
+       /**
+        * @dataProvider MediaWikiProvide::Months
+        * @group Database
+        */
        function testRevisionmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'revisionmonth', $month );
        }
-       /** @dataProvider MediaWikiProvide::Months */
+
+       /**
+        * @dataProvider MediaWikiProvide::Months
+        * @group Database
+        */
        function testRevisionmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'revisionmonth1', $month );
        }
@@ -124,19 +171,21 @@ class MagicVariableTest extends MediaWikiTestCase {
        /**
         * Rough tests for {{SERVERNAME}} magic word
         * Bug 31176
+        * @group Database
+        * @dataProvider dataServernameFromDifferentProtocols
         */
-       function testServernameFromDifferentProtocols() {
-               global $wgServer;
-               $saved_wgServer= $wgServer;
+       function testServernameFromDifferentProtocols( $server ) {
+               $this->setMwGlobals( 'wgServer', $server );
 
-               $wgServer = 'http://localhost/';
-               $this->assertMagic( 'localhost', 'servername' );
-               $wgServer = 'https://localhost/';
-               $this->assertMagic( 'localhost', 'servername' );
-               $wgServer = '//localhost/';  # bug 31176
                $this->assertMagic( 'localhost', 'servername' );
+       }
 
-               $wgServer = $saved_wgServer;
+       function dataServernameFromDifferentProtocols() {
+               return array(
+                       array( 'http://localhost/' ),
+                       array( 'https://localhost/' ),
+                       array( '//localhost/' ), # bug 31176
+               );
        }
 
        ############### HELPERS ############################################
@@ -153,26 +202,29 @@ class MagicVariableTest extends MediaWikiTestCase {
 
        /**
         * Main assertion helper for magic variables padding
-        * @param $magic string Magic variable name 
+        * @param $magic string Magic variable name
         * @param $value mixed Month or day
-        * @param $format string sprintf format for $value 
+        * @param $format string sprintf format for $value
         */
        private function assertMagicPadding( $magic, $value, $format ) {
                # Initialize parser timestamp as year 2010 at 12h34 56s.
                # month and day are given by the caller ($value). Month < 12!
-               if( $value > 12 ) { $month = $value % 12; }
-               else { $month = $value; }
-       
+               if ( $value > 12 ) {
+                       $month = $value % 12;
+               } else {
+                       $month = $value;
+               }
+
                $this->setParserTS(
                        sprintf( '2010%02d%02d123456', $month, $value )
                );
 
-               # please keep the following commented line of code. It helps debugging. 
+               # please keep the following commented line of code. It helps debugging.
                //print "\nDEBUG (value $value):" . sprintf( '2010%02d%02d123456', $value, $value ) . "\n";
 
                # format expectation and test it
                $expected = sprintf( $format, $value );
-               $this->assertMagic( $expected, $magic ); 
+               $this->assertMagic( $expected, $magic );
        }
 
        /** helper to set the parser timestamp and revision timestamp */
@@ -185,8 +237,8 @@ class MagicVariableTest extends MediaWikiTestCase {
         * Assertion helper to test a magic variable output
         */
        private function assertMagic( $expected, $magic ) {
-               if( in_array( $magic, $this->expectedAsInteger ) ) {
-                       $expected = (int) $expected;
+               if ( in_array( $magic, $this->expectedAsInteger ) ) {
+                       $expected = (int)$expected;
                }
 
                # Generate a message for the assertion