Merge "(bug 24437) Add nofollow to image link"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / MagicVariableTest.php
index bd55001..3164531 100644 (file)
@@ -6,13 +6,13 @@
  * As of february 2011, it only tests some revisions and date related
  * magic variables.
  *
- * @author Ashar Voultoiz
- * @copyright Copyright © 2011, Ashar Voultoiz
+ * @author Antoine Musso
+ * @copyright Copyright © 2011, Antoine Musso
  * @file
  */
 
 /** */
-class MagicVariableTest extends PHPUnit_Framework_TestCase {
+class MagicVariableTest extends MediaWikiTestCase {
        /** Will contains a parser object*/
        private $testParser = null;
 
@@ -38,6 +38,12 @@ class MagicVariableTest extends PHPUnit_Framework_TestCase {
 
                # initialize parser output
                $this->testParser->clearState();
+
+               # Needs a title to do magic word stuff
+               $title = Title::newFromText( 'Tests' );
+               $title->mRedirect = false; # Else it needs a db connection just to check if it's a redirect (when deciding the page language)
+
+               $this->testParser->setTitle( $title );
        }
 
        /** destroy parser (TODO: is it really neded?)*/
@@ -46,44 +52,44 @@ class MagicVariableTest extends PHPUnit_Framework_TestCase {
        }
 
        ############### TESTS #############################################
-       # FIXME:
+       # @todo FIXME:
        #  - those got copy pasted, we can probably make them cleaner
        #  - tests are lacking useful messages
 
        # day
 
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testCurrentdayIsUnPadded( $day ) {
                $this->assertUnPadded( 'currentday', $day );
        }
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testCurrentdaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'currentday2', $day );
        }
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testLocaldayIsUnPadded( $day ) {
                $this->assertUnPadded( 'localday', $day );
        }
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testLocaldaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'localday2', $day );
        }
        
        # month
 
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testCurrentmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'currentmonth', $month );
        }
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testCurrentmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'currentmonth1', $month );
        }
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testLocalmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'localmonth', $month );
        }
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testLocalmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'localmonth1', $month );
        }
@@ -91,26 +97,44 @@ class MagicVariableTest extends PHPUnit_Framework_TestCase {
 
        # revision day
 
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testRevisiondayIsUnPadded( $day ) {
                $this->assertUnPadded( 'revisionday', $day );
        }
-       /** @dataProvider provideDays */
+       /** @dataProvider MediaWikiProvide::Days */
        function testRevisiondaytwoIsZeroPadded( $day ) {
                $this->assertZeroPadded( 'revisionday2', $day );
        }
        
        # revision month
 
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testRevisionmonthIsZeroPadded( $month ) {
                $this->assertZeroPadded( 'revisionmonth', $month );
        }
-       /** @dataProvider provideMonths */
+       /** @dataProvider MediaWikiProvide::Months */
        function testRevisionmonthoneIsUnPadded( $month ) {
                $this->assertUnPadded( 'revisionmonth1', $month );
        }
 
+       /**
+        * Rough tests for {{SERVERNAME}} magic word
+        * Bug 31176
+        */
+       function testServernameFromDifferentProtocols() {
+               global $wgServer;
+               $saved_wgServer= $wgServer;
+
+               $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;
+       }
+
        ############### HELPERS ############################################
 
        /** assertion helper expecting a magic output which is zero padded */
@@ -174,26 +198,4 @@ class MagicVariableTest extends PHPUnit_Framework_TestCase {
                        $msg
                );
        }
-
-
-       ############## PROVIDERS ##########################################
-
-       /* provide an array of numbers from 1 up to @param $num */
-       private function createProviderUpTo( $num ) {
-               $ret = array();
-               for( $i=1; $i<=$num;$i++ ) {
-                       $ret[] = array( $i );
-               }
-               return $ret;
-       }
-
-       /* array of months numbers (as an integer) */
-       public function provideMonths() {
-               return $this->createProviderUpTo( 12 );
-       }
-
-       /* array of days numbers (as an integer) */
-       public function provideDays() {
-               return $this->createProviderUpTo( 31 );
-       }
 }