From: addshore Date: Fri, 7 Mar 2014 20:22:13 +0000 (+0100) Subject: Cleanup a bunch of tests and add todos X-Git-Tag: 1.31.0-rc.0~16597^2 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=9e85aabe52d37b9106cc89050abd7ff68b0e405f;p=lhc%2Fweb%2Fwiklou.git Cleanup a bunch of tests and add todos Change-Id: Iae44427edee3ed2a62abdb5a8f5d9f1ed2e7d660 --- diff --git a/tests/phpunit/includes/ArticleTablesTest.php b/tests/phpunit/includes/ArticleTablesTest.php index 7f9a023765..8e78da34e5 100644 --- a/tests/phpunit/includes/ArticleTablesTest.php +++ b/tests/phpunit/includes/ArticleTablesTest.php @@ -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' ); } diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php index dc1915441f..3cf7abdcf7 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -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( "

$longLine

", - $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( "

Test\nContent of Template:Foo\nContent of Template:Bar\n

", $parserOutput->getText() ); + $this->assertEquals( + "

Test\nContent of Template:Foo\nContent of Template:Bar\n

", + $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 ", $outputText ); } + /** + * @param Title $title + * @param bool $parser + * + * @return array + */ static function statelessFetchTemplate( $title, $parser = false ) { $text = "Content of ''" . $title->getFullText() . "''"; $deps = array(); diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 078dfefdf4..b8a7a45d3e 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -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 ); diff --git a/tests/phpunit/includes/api/ApiQueryAllPagesTest.php b/tests/phpunit/includes/api/ApiQueryAllPagesTest.php index bc08afe066..124988f32f 100644 --- a/tests/phpunit/includes/api/ApiQueryAllPagesTest.php +++ b/tests/phpunit/includes/api/ApiQueryAllPagesTest.php @@ -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' ); diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php index 62ee45a6cc..01c330ab71 100644 --- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php +++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php @@ -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 diff --git a/tests/phpunit/includes/search/SearchUpdateTest.php b/tests/phpunit/includes/search/SearchUpdateTest.php index b913af80ec..c62753713a 100644 --- a/tests/phpunit/includes/search/SearchUpdateTest.php +++ b/tests/phpunit/includes/search/SearchUpdateTest.php @@ -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"; diff --git a/tests/phpunit/includes/specials/SpecialPreferencesTest.php b/tests/phpunit/includes/specials/SpecialPreferencesTest.php index 8a92dafe93..ea2d28cc01 100644 --- a/tests/phpunit/includes/specials/SpecialPreferencesTest.php +++ b/tests/phpunit/includes/specials/SpecialPreferencesTest.php @@ -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() ); diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php index 1c89377d95..da72a9d0c6 100644 --- a/tests/phpunit/includes/upload/UploadStashTest.php +++ b/tests/phpunit/includes/upload/UploadStashTest.php @@ -1,4 +1,5 @@ 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 ) ); + } + }