jenkins-bot has submitted this change and it was merged. Change subject: Cleanup a bunch of tests and add todos ......................................................................
Cleanup a bunch of tests and add todos Change-Id: Iae44427edee3ed2a62abdb5a8f5d9f1ed2e7d660 --- M tests/phpunit/includes/ArticleTablesTest.php M tests/phpunit/includes/ExtraParserTest.php M tests/phpunit/includes/TitleTest.php M tests/phpunit/includes/api/ApiQueryAllPagesTest.php M tests/phpunit/includes/libs/JavaScriptMinifierTest.php M tests/phpunit/includes/search/SearchUpdateTest.php M tests/phpunit/includes/specials/SpecialPreferencesTest.php M tests/phpunit/includes/upload/UploadStashTest.php 8 files changed, 103 insertions(+), 43 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/phpunit/includes/ArticleTablesTest.php b/tests/phpunit/includes/ArticleTablesTest.php index 7f9a023..8e78da3 100644 --- a/tests/phpunit/includes/ArticleTablesTest.php +++ b/tests/phpunit/includes/ArticleTablesTest.php @@ -8,28 +8,43 @@ /** * @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 dc19154..3cf7abd 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -32,17 +32,16 @@ } /** - * 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 @@ 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 @@ $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 @@ $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(); diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 078dfef..b8a7a45 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -213,6 +213,7 @@ /** * @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 bc08afe..124988f 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 62ee45a..01c330a 100644 --- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php +++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php @@ -154,6 +154,7 @@ /** * @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 b913af8..c627537 100644 --- a/tests/phpunit/includes/search/SearchUpdateTest.php +++ b/tests/phpunit/includes/search/SearchUpdateTest.php @@ -26,7 +26,7 @@ $this->setMwGlobals( 'wgSearchType', 'MockSearch' ); } - function updateText( $text ) { + public function updateText( $text ) { return trim( SearchUpdate::updateText( $text ) ); } @@ -67,6 +67,7 @@ /** * @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 8a92daf..ea2d28c 100644 --- a/tests/phpunit/includes/specials/SpecialPreferencesTest.php +++ b/tests/phpunit/includes/specials/SpecialPreferencesTest.php @@ -17,6 +17,7 @@ * 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() { @@ -40,13 +41,6 @@ array( 'nickname', null, false, 'superlongnickname' ), ) ) ); - - # 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(); diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php index 1c89377..da72a9d 100644 --- a/tests/phpunit/includes/upload/UploadStashTest.php +++ b/tests/phpunit/includes/upload/UploadStashTest.php @@ -1,4 +1,5 @@ <?php + /** * @group Database * @@ -9,6 +10,11 @@ * @var Array of UploadStashTestUser */ public static $users; + + /** + * @var string + */ + private $bug29408File; protected function setUp() { parent::setUp(); @@ -45,6 +51,9 @@ 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 @@ $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' ); - - $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test' ) ); - $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check good wpSessionKey' ); - - $request = new FauxRequest( array( 'wpFileKey' => 'testkey-test.test', 'wpSessionKey' => 'foo' ) ); - $this->assertTrue( UploadFromStash::isValidRequest( $request ), 'Check key precedence' ); + 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' ) ) ), + ); } + + /** + * @dataProvider provideInvalidRequests + */ + public function testValidRequestWithInvalidRequests( $request ) { + $this->assertFalse( UploadFromStash::isValidRequest( $request ) ); + } + + 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 ) ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/117464 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iae44427edee3ed2a62abdb5a8f5d9f1ed2e7d660 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Mwalker <mwal...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits