Cleanup a bunch of tests and add todos
authoraddshore <addshorewiki@gmail.com>
Fri, 7 Mar 2014 20:22:13 +0000 (21:22 +0100)
committeraddshore <addshorewiki@gmail.com>
Sun, 9 Mar 2014 14:12:45 +0000 (15:12 +0100)
Change-Id: Iae44427edee3ed2a62abdb5a8f5d9f1ed2e7d660

tests/phpunit/includes/ArticleTablesTest.php
tests/phpunit/includes/ExtraParserTest.php
tests/phpunit/includes/TitleTest.php
tests/phpunit/includes/api/ApiQueryAllPagesTest.php
tests/phpunit/includes/libs/JavaScriptMinifierTest.php
tests/phpunit/includes/search/SearchUpdateTest.php
tests/phpunit/includes/specials/SpecialPreferencesTest.php
tests/phpunit/includes/upload/UploadStashTest.php

index 7f9a023..8e78da3 100644 (file)
@@ -8,28 +8,43 @@ class ArticleTablesTest extends MediaWikiLangTestCase {
        /**
         * @covers Title::getTemplateLinksFrom
         * @covers Title::getLinksFrom
+        * @todo give this test a real name explaining what is being tested here
         */
        public function testbug14404() {
-               global $wgContLang, $wgLanguageCode, $wgLang;
-
                $title = Title::newFromText( 'Bug 14404' );
                $page = WikiPage::factory( $title );
                $user = new User();
                $user->mRights = array( 'createpage', 'edit', 'purge' );
-               $wgLanguageCode = 'es';
-               $wgContLang = Language::factory( 'es' );
+               $this->setMwGlobals( 'wgLanguageCode', 'es' );
+               $this->setMwGlobals( 'wgContLang', Language::factory( 'es' ) );
+               $this->setMwGlobals( 'wgLang', Language::factory( 'fr' ) );
 
-               $wgLang = Language::factory( 'fr' );
-               $page->doEditContent( new WikitextContent( '{{:{{int:history}}}}' ), 'Test code for bug 14404', 0, false, $user );
+               $page->doEditContent(
+                       new WikitextContent( '{{:{{int:history}}}}' ),
+                       'Test code for bug 14404',
+                       0,
+                       false,
+                       $user
+               );
                $templates1 = $title->getTemplateLinksFrom();
 
-               $wgLang = Language::factory( 'de' );
-               $page = WikiPage::factory( $title ); // In order to force the rerendering of the same wikitext
+               $this->setMwGlobals( 'wgLang', Language::factory( 'de' ) );
+               $page = WikiPage::factory( $title ); // In order to force the re-rendering of the same wikitext
 
                // We need an edit, a purge is not enough to regenerate the tables
-               $page->doEditContent( new WikitextContent( '{{:{{int:history}}}}' ), 'Test code for bug 14404', EDIT_UPDATE, false, $user );
+               $page->doEditContent(
+                       new WikitextContent( '{{:{{int:history}}}}' ),
+                       'Test code for bug 14404',
+                       EDIT_UPDATE,
+                       false,
+                       $user
+               );
                $templates2 = $title->getTemplateLinksFrom();
 
+               /**
+                * @var Title[] $templates1
+                * @var Title[] $templates2
+                */
                $this->assertEquals( $templates1, $templates2 );
                $this->assertEquals( $templates1[0]->getFullText(), 'Historial' );
        }
index dc19154..3cf7abd 100644 (file)
@@ -32,17 +32,16 @@ class ExtraParserTest extends MediaWikiTestCase {
        }
 
        /**
-        * Bug 8689 - Long numeric lines kill the parser
+        * @see Bug 8689
         * @covers Parser::parse
         */
-       public function testBug8689() {
-               global $wgUser;
+       public function testLongNumericLinesDontKillTheParser() {
                $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n";
 
-               $t = Title::newFromText( 'Unit test' );
-               $options = ParserOptions::newFromUser( $wgUser );
+               $title = Title::newFromText( 'Unit test' );
+               $options = ParserOptions::newFromUser( new User() );
                $this->assertEquals( "<p>$longLine</p>",
-                       $this->parser->parse( $longLine, $t, $options )->getText() );
+                       $this->parser->parse( $longLine, $title, $options )->getText() );
        }
 
        /**
@@ -52,16 +51,23 @@ class ExtraParserTest extends MediaWikiTestCase {
        public function testParse() {
                $title = Title::newFromText( __FUNCTION__ );
                $parserOutput = $this->parser->parse( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options );
-               $this->assertEquals( "<p>Test\nContent of <i>Template:Foo</i>\nContent of <i>Template:Bar</i>\n</p>", $parserOutput->getText() );
+               $this->assertEquals(
+                       "<p>Test\nContent of <i>Template:Foo</i>\nContent of <i>Template:Bar</i>\n</p>",
+                       $parserOutput->getText()
+               );
        }
 
        /**
         * @covers Parser::preSaveTransform
         */
        public function testPreSaveTransform() {
-               global $wgUser;
                $title = Title::newFromText( __FUNCTION__ );
-               $outputText = $this->parser->preSaveTransform( "Test\r\n{{subst:Foo}}\n{{Bar}}", $title, $wgUser, $this->options );
+               $outputText = $this->parser->preSaveTransform(
+                       "Test\r\n{{subst:Foo}}\n{{Bar}}",
+                       $title,
+                       new User(),
+                       $this->options
+               );
 
                $this->assertEquals( "Test\nContent of ''Template:Foo''\n{{Bar}}", $outputText );
        }
@@ -73,7 +79,10 @@ class ExtraParserTest extends MediaWikiTestCase {
                $title = Title::newFromText( __FUNCTION__ );
                $outputText = $this->parser->preprocess( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options );
 
-               $this->assertEquals( "Test\nContent of ''Template:Foo''\nContent of ''Template:Bar''", $outputText );
+               $this->assertEquals(
+                       "Test\nContent of ''Template:Foo''\nContent of ''Template:Bar''",
+                       $outputText
+               );
        }
 
        /**
@@ -148,6 +157,12 @@ class ExtraParserTest extends MediaWikiTestCase {
                $this->assertEquals( "{{Foo}} information <!-- is very secret -->", $outputText );
        }
 
+       /**
+        * @param Title $title
+        * @param bool $parser
+        *
+        * @return array
+        */
        static function statelessFetchTemplate( $title, $parser = false ) {
                $text = "Content of ''" . $title->getFullText() . "''";
                $deps = array();
index 078dfef..b8a7a45 100644 (file)
@@ -213,6 +213,7 @@ class TitleTest extends MediaWikiTestCase {
        /**
         * @dataProvider provideBug31100
         * @covers Title::fixSpecialName
+        * @todo give this test a real name explaining what is being tested here
         */
        public function testBug31100FixSpecialName( $text, $expectedParam ) {
                $title = Title::newFromText( $text );
index bc08afe..124988f 100644 (file)
@@ -6,12 +6,16 @@
  * @group medium
  */
 class ApiQueryAllPagesTest extends ApiTestCase {
+
        protected function setUp() {
                parent::setUp();
                $this->doLogin();
        }
 
-       function testBug25702() {
+       /**
+        * @todo give this test a real name explaining what is being tested here
+        */
+       public function testBug25702() {
                $title = Title::newFromText( 'Category:Template:xyz' );
                $page = WikiPage::factory( $title );
                $page->doEdit( 'Some text', 'inserting content' );
index 62ee45a..01c330a 100644 (file)
@@ -154,6 +154,7 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
        /**
         * @dataProvider provideBug32548
         * @covers JavaScriptMinifier::minify
+        * @todo give this test a real name explaining what is being tested here
         */
        public function testBug32548Exponent( $num ) {
                // Long line breaking was being incorrectly done between the base and
index b913af8..c627537 100644 (file)
@@ -26,7 +26,7 @@ class SearchUpdateTest extends MediaWikiTestCase {
                $this->setMwGlobals( 'wgSearchType', 'MockSearch' );
        }
 
-       function updateText( $text ) {
+       public function updateText( $text ) {
                return trim( SearchUpdate::updateText( $text ) );
        }
 
@@ -67,6 +67,7 @@ EOT
 
        /**
         * @covers SearchUpdate::updateText
+        * @todo give this test a real name explaining what is being tested here
         */
        public function testBug32712() {
                $text = "text „http://example.com“ text";
index 8a92daf..ea2d28c 100644 (file)
@@ -17,6 +17,7 @@ class SpecialPreferencesTest extends MediaWikiTestCase {
         * is not throwing a fatal error.
         *
         * Test specifications by Alexandre "ialex" Emsenhuber.
+        * @todo give this test a real name explaining what is being tested here
         */
        public function testBug41337() {
 
@@ -41,13 +42,6 @@ class SpecialPreferencesTest extends MediaWikiTestCase {
                        )
                        ) );
 
-               # Validate the mock (FIXME should probably be removed)
-               $this->assertFalse( $user->isAnon() );
-               $this->assertEquals( array(),
-                       $user->getEffectiveGroups() );
-               $this->assertEquals( 'superlongnickname',
-                       $user->getOption( 'nickname' ) );
-
                # Forge a request to call the special page
                $context = new RequestContext();
                $context->setRequest( new FauxRequest() );
index 1c89377..da72a9d 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * @group Database
  *
@@ -10,6 +11,11 @@ class UploadStashTest extends MediaWikiTestCase {
         */
        public static $users;
 
+       /**
+        * @var string
+        */
+       private $bug29408File;
+
        protected function setUp() {
                parent::setUp();
 
@@ -45,6 +51,9 @@ class UploadStashTest extends MediaWikiTestCase {
                parent::tearDown();
        }
 
+       /**
+        * @todo give this test a real name explaining what is being tested here
+        */
        public function testBug29408() {
                $this->setMwGlobals( 'wgUser', self::$users['uploader']->user );
 
@@ -59,20 +68,40 @@ class UploadStashTest extends MediaWikiTestCase {
                $stash->removeFile( $file->getFileKey() );
        }
 
-       public function testValidRequest() {
-               $request = new FauxRequest( array( 'wpFileKey' => 'foo' ) );
-               $this->assertFalse( UploadFromStash::isValidRequest( $request ), 'Check failure on bad wpFileKey' );
-
-               $request = new FauxRequest( array( 'wpSessionKey' => 'foo' ) );
-               $this->assertFalse( UploadFromStash::isValidRequest( $request ), 'Check failure on bad wpSessionKey' );
-
-               $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
-               $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check good wpFileKey' );
+       public function provideInvalidRequests() {
+               return array(
+                       'Check failure on bad wpFileKey' =>
+                               array( new FauxRequest( array( 'wpFileKey' => 'foo' ) ) ),
+                       'Check failure on bad wpSessionKey' =>
+                               array( new FauxRequest( array( 'wpSessionKey' => 'foo' ) ) ),
+               );
+       }
 
-               $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) );
-               $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check good wpSessionKey' );
+       /**
+        * @dataProvider provideInvalidRequests
+        */
+       public function testValidRequestWithInvalidRequests( $request ) {
+               $this->assertFalse( UploadFromStash::isValidRequest( $request ) );
+       }
 
-               $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo' ) );
-               $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check key precedence' );
+       public function provideValidRequests() {
+               return array(
+                       'Check good wpFileKey' =>
+                               array( new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) ) ),
+                       'Check good wpSessionKey' =>
+                               array( new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) ) ),
+                       'Check key precedence' =>
+                               array( new FauxRequest( array(
+                                       'wpFileKey' => 'testkey-test.test',
+                                       'wpSessionKey' => 'foo'
+                               ) ) ),
+               );
        }
+       /**
+        * @dataProvider provideValidRequests
+        */
+       public function testValidRequestWithValidRequests( $request ) {
+               $this->assertTrue( UploadFromStash::isValidRequest( $request ) );
+       }
+
 }