test: Clean up data providers that should be static
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleTest.php
index b2b0d34..53c22b4 100644 (file)
@@ -39,84 +39,61 @@ class TitleTest extends MediaWikiTestCase {
                }
        }
 
-       /**
-        * See also mediawiki.Title.test.js
-        * @covers Title::secureAndSplit
-        * @todo This method should be split into 2 separate tests each with a provider
-        * @note This mainly tests MediaWikiTitleCodec::parseTitle().
-        */
-       public function testSecureAndSplit() {
-               $this->setMwGlobals( array(
-                       'wgLocalInterwikis' => array( 'localtestiw' ),
-                       'wgHooks' => array(
-                               'InterwikiLoadPrefix' => array(
-                                       function ( $prefix, &$data ) {
-                                               if ( $prefix === 'localtestiw' ) {
-                                                       $data = array( 'iw_url' => 'localtestiw' );
-                                               } elseif ( $prefix === 'remotetestiw' ) {
-                                                       $data = array( 'iw_url' => 'remotetestiw' );
-                                               }
-                                               return false;
-                                       }
-                               )
-                       )
-               ));
-               // Valid
-               foreach ( array(
-                       'Sandbox',
-                       'A "B"',
-                       'A \'B\'',
-                       '.com',
-                       '~',
-                       '#',
-                       '"',
-                       '\'',
-                       'Talk:Sandbox',
-                       'Talk:Foo:Sandbox',
-                       'File:Example.svg',
-                       'File_talk:Example.svg',
-                       'Foo/.../Sandbox',
-                       'Sandbox/...',
-                       'A~~',
-                       ':A',
+       public static function provideValidSecureAndSplit() {
+               return array(
+                       array( 'Sandbox' ),
+                       array( 'A "B"' ),
+                       array( 'A \'B\'' ),
+                       array( '.com' ),
+                       array( '~' ),
+                       array( '#' ),
+                       array( '"' ),
+                       array( '\'' ),
+                       array( 'Talk:Sandbox' ),
+                       array( 'Talk:Foo:Sandbox' ),
+                       array( 'File:Example.svg' ),
+                       array( 'File_talk:Example.svg' ),
+                       array( 'Foo/.../Sandbox' ),
+                       array( 'Sandbox/...' ),
+                       array( 'A~~' ),
+                       array( ':A' ),
                        // Length is 256 total, but only title part matters
-                       'Category:' . str_repeat( 'x', 248 ),
-                       str_repeat( 'x', 252 ),
+                       array( 'Category:' . str_repeat( 'x', 248 ) ),
+                       array( str_repeat( 'x', 252 ) ),
                        // interwiki prefix
-                       'localtestiw: #anchor',
-                       'localtestiw:',
-                       'localtestiw:foo',
-                       'localtestiw: foo # anchor',
-                       'localtestiw: Talk: Sandbox # anchor',
-                       'remotetestiw:',
-                       'remotetestiw: Talk: # anchor',
-                       'remotetestiw: #bar',
-                       'remotetestiw: Talk:',
-                       'remotetestiw: Talk: Foo',
-                       'localtestiw:remotetestiw:',
-                       'localtestiw:remotetestiw:foo'
-               ) as $text ) {
-                       $this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" );
-               }
+                       array( 'localtestiw: #anchor' ),
+                       array( 'localtestiw:' ),
+                       array( 'localtestiw:foo' ),
+                       array( 'localtestiw: foo # anchor' ),
+                       array( 'localtestiw: Talk: Sandbox # anchor' ),
+                       array( 'remotetestiw:' ),
+                       array( 'remotetestiw: Talk: # anchor' ),
+                       array( 'remotetestiw: #bar' ),
+                       array( 'remotetestiw: Talk:' ),
+                       array( 'remotetestiw: Talk: Foo' ),
+                       array( 'localtestiw:remotetestiw:' ),
+                       array( 'localtestiw:remotetestiw:foo' )
+               );
+       }
 
-               // Invalid
-               foreach ( array(
-                       '',
-                       ':',
-                       '__  __',
-                       '  __  ',
+       public static function provideInvalidSecureAndSplit() {
+               return array(
+                       array( '' ),
+                       array( ':' ),
+                       array( '__  __' ),
+                       array( '  __  ' ),
                        // Bad characters forbidden regardless of wgLegalTitleChars
-                       'A [ B',
-                       'A ] B',
-                       'A { B',
-                       'A } B',
-                       'A < B',
-                       'A > B',
-                       'A | B',
+                       array( 'A [ B' ),
+                       array( 'A ] B' ),
+                       array( 'A { B' ),
+                       array( 'A } B' ),
+                       array( 'A < B' ),
+                       array( 'A > B' ),
+                       array( 'A | B' ),
                        // URL encoding
-                       'A%20B',
-                       'A%23B',
-                       'A%2523B',
+                       array( 'A%20B' ),
+                       array( 'A%23B' ),
+                       array( 'A%2523B' ),
                        // XML/HTML character entity references
                        // Note: Commented out because they are not marked invalid by the PHP test as
                        // Title::newFromText runs Sanitizer::decodeCharReferencesAndNormalize first.
@@ -124,32 +101,70 @@ class TitleTest extends MediaWikiTestCase {
                        //'A &#233; B',
                        //'A &#x00E9; B',
                        // Subject of NS_TALK does not roundtrip to NS_MAIN
-                       'Talk:File:Example.svg',
+                       array( 'Talk:File:Example.svg' ),
                        // Directory navigation
-                       '.',
-                       '..',
-                       './Sandbox',
-                       '../Sandbox',
-                       'Foo/./Sandbox',
-                       'Foo/../Sandbox',
-                       'Sandbox/.',
-                       'Sandbox/..',
+                       array( '.' ),
+                       array( '..' ),
+                       array( './Sandbox' ),
+                       array( '../Sandbox' ),
+                       array( 'Foo/./Sandbox' ),
+                       array( 'Foo/../Sandbox' ),
+                       array( 'Sandbox/.' ),
+                       array( 'Sandbox/..' ),
                        // Tilde
-                       'A ~~~ Name',
-                       'A ~~~~ Signature',
-                       'A ~~~~~ Timestamp',
-                       str_repeat( 'x', 256 ),
+                       array( 'A ~~~ Name' ),
+                       array( 'A ~~~~ Signature' ),
+                       array( 'A ~~~~~ Timestamp' ),
+                       array( str_repeat( 'x', 256 ) ),
                        // Namespace prefix without actual title
-                       'Talk:',
-                       'Talk:#',
-                       'Category: ',
-                       'Category: #bar',
+                       array( 'Talk:' ),
+                       array( 'Talk:#' ),
+                       array( 'Category: ' ),
+                       array( 'Category: #bar' ),
                        // interwiki prefix
-                       'localtestiw: Talk: # anchor',
-                       'localtestiw: Talk:'
-               ) as $text ) {
-                       $this->assertNull( Title::newFromText( $text ), "Invalid: $text" );
-               }
+                       array( 'localtestiw: Talk: # anchor' ),
+                       array( 'localtestiw: Talk:' )
+               );
+       }
+
+       private function secureAndSplitGlobals() {
+               $this->setMwGlobals( array(
+                       'wgLocalInterwikis' => array( 'localtestiw' ),
+                       'wgHooks' => array(
+                               'InterwikiLoadPrefix' => array(
+                                       function ( $prefix, &$data ) {
+                                               if ( $prefix === 'localtestiw' ) {
+                                                       $data = array( 'iw_url' => 'localtestiw' );
+                                               } elseif ( $prefix === 'remotetestiw' ) {
+                                                       $data = array( 'iw_url' => 'remotetestiw' );
+                                               }
+                                               return false;
+                                       }
+                               )
+                       )
+               ));
+       }
+
+       /**
+        * See also mediawiki.Title.test.js
+        * @covers Title::secureAndSplit
+        * @dataProvider provideValidSecureAndSplit
+        * @note This mainly tests MediaWikiTitleCodec::parseTitle().
+        */
+       public function testSecureAndSplitValid( $text ) {
+               $this->secureAndSplitGlobals();
+               $this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" );
+       }
+
+       /**
+        * See also mediawiki.Title.test.js
+        * @covers Title::secureAndSplit
+        * @dataProvider provideInvalidSecureAndSplit
+        * @note This mainly tests MediaWikiTitleCodec::parseTitle().
+        */
+       public function testSecureAndSplitInvalid( $text ) {
+               $this->secureAndSplitGlobals();
+               $this->assertNull( Title::newFromText( $text ), "Invalid: $text" );
        }
 
        public static function provideConvertByteClassToUnicodeClass() {
@@ -273,10 +288,7 @@ class TitleTest extends MediaWikiTestCase {
                }
        }
 
-       /**
-        * Provides test parameter values for testIsValidMoveOperation()
-        */
-       public function dataTestIsValidMoveOperation() {
+       public static function provideTestIsValidMoveOperation() {
                return array(
                        array( 'Test', 'Test', 'selfmove' ),
                        array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' )
@@ -400,13 +412,6 @@ class TitleTest extends MediaWikiTestCase {
                return $result;
        }
 
-       public static function provideTestIsValidMoveOperation() {
-               return array(
-                       array( 'Test', 'Test', 'selfmove' ),
-                       array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' )
-               );
-       }
-
        /**
         * @dataProvider provideGetPageViewLanguage
         * @covers Title::getPageViewLanguage
@@ -533,7 +538,7 @@ class TitleTest extends MediaWikiTestCase {
                );
        }
 
-       public function provideNewFromTitleValue() {
+       public static function provideNewFromTitleValue() {
                return array(
                        array( new TitleValue( NS_MAIN, 'Foo' ) ),
                        array( new TitleValue( NS_MAIN, 'Foo', 'bar' ) ),
@@ -553,7 +558,7 @@ class TitleTest extends MediaWikiTestCase {
                $this->assertEquals( $value->getFragment(), $title->getFragment() );
        }
 
-       public function provideGetTitleValue() {
+       public static function provideGetTitleValue() {
                return array(
                        array( 'Foo' ),
                        array( 'Foo#bar' ),
@@ -574,7 +579,7 @@ class TitleTest extends MediaWikiTestCase {
                $this->assertEquals( $title->getFragment(), $value->getFragment() );
        }
 
-       public function provideGetFragment() {
+       public static function provideGetFragment() {
                return array(
                        array( 'Foo', '' ),
                        array( 'Foo#bar', 'bar' ),
@@ -614,7 +619,7 @@ class TitleTest extends MediaWikiTestCase {
                $this->assertEquals( $isKnown, $title->isAlwaysKnown() );
        }
 
-       public function provideIsAlwaysKnown() {
+       public static function provideIsAlwaysKnown() {
                return array(
                        array( 'Some nonexistent page', false ),
                        array( 'UTPage', false ),