From fb16eb2abed5476b582685cc5a508cd132b194b1 Mon Sep 17 00:00:00 2001 From: addshore Date: Mon, 21 Oct 2013 23:09:13 +0200 Subject: [PATCH] Add more @covers tags and test cleanup Other cleanup includes - Adding method scopes - Fixing php comments - Adding todos Change-Id: I0a231008e6a59110ffcab6af1bd8c4d3ee13f21d --- tests/phpunit/includes/HttpTest.php | 6 +- tests/phpunit/includes/IPTest.php | 7 +- tests/phpunit/includes/PathRouterTest.php | 9 ++- tests/phpunit/includes/PreferencesTest.php | 17 +++-- tests/phpunit/includes/RecentChangeTest.php | 27 +++---- tests/phpunit/includes/RequestContextTest.php | 5 ++ tests/phpunit/includes/ResourceLoaderTest.php | 2 + .../phpunit/includes/RevisionStorageTest.php | 10 +-- ...evisionStorageTest_ContentHandlerUseDB.php | 2 +- tests/phpunit/includes/RevisionTest.php | 72 ++++++++++++++----- tests/phpunit/includes/SanitizerTest.php | 53 ++++++++++---- .../includes/SanitizerValidateEmailTest.php | 35 +++++---- .../includes/SiteConfigurationTest.php | 36 ++++++++-- .../includes/TemplateCategoriesTest.php | 21 +++++- tests/phpunit/includes/TestUser.php | 6 +- tests/phpunit/includes/TimeAdjustTest.php | 3 +- tests/phpunit/includes/TimestampTest.php | 16 +++-- tests/phpunit/includes/TitleMethodsTest.php | 15 +++- .../phpunit/includes/TitlePermissionTest.php | 45 ++++++++---- tests/phpunit/includes/TitleTest.php | 47 +++++++----- tests/phpunit/includes/UIDGeneratorTest.php | 22 ++++++ tests/phpunit/includes/UserTest.php | 15 ++++ tests/phpunit/includes/WebRequestTest.php | 4 ++ tests/phpunit/includes/WikiPageTest.php | 60 +++++++++++++++- .../WikiPageTest_ContentHandlerUseDB.php | 8 ++- tests/phpunit/includes/XmlJsTest.php | 25 +++++-- tests/phpunit/includes/XmlSelectTest.php | 38 ++++++++-- tests/phpunit/includes/XmlTest.php | 3 + tests/phpunit/includes/XmlTypeCheckTest.php | 2 +- .../includes/ZipDirectoryReaderTest.php | 3 +- 30 files changed, 475 insertions(+), 139 deletions(-) diff --git a/tests/phpunit/includes/HttpTest.php b/tests/phpunit/includes/HttpTest.php index d8a0f74f7c..6e0aa88223 100644 --- a/tests/phpunit/includes/HttpTest.php +++ b/tests/phpunit/includes/HttpTest.php @@ -5,8 +5,9 @@ class HttpTest extends MediaWikiTestCase { /** * @dataProvider cookieDomains + * @covers Cookie::validateCookieDomain */ - function testValidateCookieDomain( $expected, $domain, $origin = null ) { + public function testValidateCookieDomain( $expected, $domain, $origin = null ) { if ( $origin ) { $ok = Cookie::validateCookieDomain( $domain, $origin ); $msg = "$domain against origin $origin"; @@ -50,6 +51,7 @@ class HttpTest extends MediaWikiTestCase { * Test Http::isValidURI() * @bug 27854 : Http::isValidURI is too lax * @dataProvider provideURI + * @covers Http::isValidURI */ function testIsValidUri( $expect, $URI, $message = '' ) { $this->assertEquals( @@ -132,7 +134,7 @@ class HttpTest extends MediaWikiTestCase { * rewritten when bug 29232 is taken care of (high-level handling of * HTTP redirects). */ - function testRelativeRedirections() { + public function testRelativeRedirections() { $h = MWHttpRequestTester::factory( 'http://oldsite/file.ext' ); # Forge a Location header diff --git a/tests/phpunit/includes/IPTest.php b/tests/phpunit/includes/IPTest.php index e18295fccf..22bf0c0cd3 100644 --- a/tests/phpunit/includes/IPTest.php +++ b/tests/phpunit/includes/IPTest.php @@ -1,7 +1,12 @@ prefUsers['noemail'] = new User; @@ -40,7 +45,7 @@ class PreferencesTest extends MediaWikiTestCase { * Placeholder to verify bug 34302 * @covers Preferences::profilePreferences */ - function testEmailFieldsWhenUserHasNoEmail() { + public function testEmailFieldsWhenUserHasNoEmail() { $prefs = $this->prefsFor( 'noemail' ); $this->assertArrayHasKey( 'cssclass', $prefs['emailaddress'] @@ -52,7 +57,7 @@ class PreferencesTest extends MediaWikiTestCase { * Placeholder to verify bug 34302 * @covers Preferences::profilePreferences */ - function testEmailFieldsWhenUserEmailNotAuthenticated() { + public function testEmailFieldsWhenUserEmailNotAuthenticated() { $prefs = $this->prefsFor( 'notauth' ); $this->assertArrayHasKey( 'cssclass', $prefs['emailaddress'] @@ -64,7 +69,7 @@ class PreferencesTest extends MediaWikiTestCase { * Placeholder to verify bug 34302 * @covers Preferences::profilePreferences */ - function testEmailFieldsWhenUserEmailIsAuthenticated() { + public function testEmailFieldsWhenUserEmailIsAuthenticated() { $prefs = $this->prefsFor( 'auth' ); $this->assertArrayHasKey( 'cssclass', $prefs['emailaddress'] @@ -73,7 +78,7 @@ class PreferencesTest extends MediaWikiTestCase { } /** Helper */ - function prefsFor( $user_key ) { + protected function prefsFor( $user_key ) { $preferences = array(); Preferences::profilePreferences( $this->prefUsers[$user_key] diff --git a/tests/phpunit/includes/RecentChangeTest.php b/tests/phpunit/includes/RecentChangeTest.php index f01fb23578..cfa3e777df 100644 --- a/tests/phpunit/includes/RecentChangeTest.php +++ b/tests/phpunit/includes/RecentChangeTest.php @@ -9,7 +9,7 @@ class RecentChangeTest extends MediaWikiTestCase { protected $user_comment; protected $context; - function __construct() { + public function __construct() { parent::__construct(); $this->title = Title::newFromText( 'SomeTitle' ); @@ -56,7 +56,7 @@ class RecentChangeTest extends MediaWikiTestCase { /** * @covers LogFormatter::getIRCActionText */ - function testIrcMsgForLogTypeBlock() { + public function testIrcMsgForLogTypeBlock() { $sep = $this->context->msg( 'colon-separator' )->text(); # block/block @@ -78,7 +78,7 @@ class RecentChangeTest extends MediaWikiTestCase { /** * @covers LogFormatter::getIRCActionText */ - function testIrcMsgForLogTypeDelete() { + public function testIrcMsgForLogTypeDelete() { $sep = $this->context->msg( 'colon-separator' )->text(); # delete/delete @@ -101,7 +101,7 @@ class RecentChangeTest extends MediaWikiTestCase { /** * @covers LogFormatter::getIRCActionText */ - function testIrcMsgForLogTypeNewusers() { + public function testIrcMsgForLogTypeNewusers() { $this->assertIRCComment( 'New user account', 'newusers', 'newusers', @@ -127,7 +127,7 @@ class RecentChangeTest extends MediaWikiTestCase { /** * @covers LogFormatter::getIRCActionText */ - function testIrcMsgForLogTypeMove() { + public function testIrcMsgForLogTypeMove() { $move_params = array( '4::target' => $this->target->getPrefixedText(), '5::noredir' => 0, @@ -154,7 +154,7 @@ class RecentChangeTest extends MediaWikiTestCase { /** * @covers LogFormatter::getIRCActionText */ - function testIrcMsgForLogTypePatrol() { + public function testIrcMsgForLogTypePatrol() { # patrol/patrol $this->assertIRCComment( $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(), @@ -170,7 +170,7 @@ class RecentChangeTest extends MediaWikiTestCase { /** * @covers LogFormatter::getIRCActionText */ - function testIrcMsgForLogTypeProtect() { + public function testIrcMsgForLogTypeProtect() { $protectParams = array( '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)' ); @@ -204,7 +204,7 @@ class RecentChangeTest extends MediaWikiTestCase { /** * @covers LogFormatter::getIRCActionText */ - function testIrcMsgForLogTypeUpload() { + public function testIrcMsgForLogTypeUpload() { $sep = $this->context->msg( 'colon-separator' )->text(); # upload/upload @@ -230,19 +230,19 @@ class RecentChangeTest extends MediaWikiTestCase { * -- */ /* - function testIrcMsgForBlankingAES() { + public function testIrcMsgForBlankingAES() { // $this->context->msg( 'autosumm-blank', .. ); } - function testIrcMsgForReplaceAES() { + public function testIrcMsgForReplaceAES() { // $this->context->msg( 'autosumm-replace', .. ); } - function testIrcMsgForRollbackAES() { + public function testIrcMsgForRollbackAES() { // $this->context->msg( 'revertpage', .. ); } - function testIrcMsgForUndoAES() { + public function testIrcMsgForUndoAES() { // $this->context->msg( 'undo-summary', .. ); } */ @@ -251,10 +251,11 @@ class RecentChangeTest extends MediaWikiTestCase { * @param $expected String Expected IRC text without colors codes * @param $type String Log type (move, delete, suppress, patrol ...) * @param $action String A log type action + * @param $params * @param $comment String (optional) A comment for the log action * @param $msg String (optional) A message for PHPUnit :-) */ - function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) { + protected function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) { $logEntry = new ManualLogEntry( $type, $action ); $logEntry->setPerformer( $this->user ); diff --git a/tests/phpunit/includes/RequestContextTest.php b/tests/phpunit/includes/RequestContextTest.php index e3a9cfb1af..1776b5d5ef 100644 --- a/tests/phpunit/includes/RequestContextTest.php +++ b/tests/phpunit/includes/RequestContextTest.php @@ -7,6 +7,8 @@ class RequestContextTest extends MediaWikiTestCase { /** * Test the relationship between title and wikipage in RequestContext + * @covers RequestContext::getWikiPage + * @covers RequestContext::getTitle */ public function testWikiPageTitle() { $context = new RequestContext(); @@ -27,6 +29,9 @@ class RequestContextTest extends MediaWikiTestCase { "When a title is updated the WikiPage should be purged and recreated on-demand with the new title." ); } + /** + * @covers RequestContext::importScopedSession + */ public function testImportScopedSession() { $context = RequestContext::getMain(); diff --git a/tests/phpunit/includes/ResourceLoaderTest.php b/tests/phpunit/includes/ResourceLoaderTest.php index c30c441ba2..ca8b2b6efe 100644 --- a/tests/phpunit/includes/ResourceLoaderTest.php +++ b/tests/phpunit/includes/ResourceLoaderTest.php @@ -99,6 +99,7 @@ class ResourceLoaderTest extends MediaWikiTestCase { /** * @dataProvider providePackedModules + * @covers ResourceLoader::makePackedModulesString */ public function testMakePackedModulesString( $desc, $modules, $packed ) { $this->assertEquals( $packed, ResourceLoader::makePackedModulesString( $modules ), $desc ); @@ -106,6 +107,7 @@ class ResourceLoaderTest extends MediaWikiTestCase { /** * @dataProvider providePackedModules + * @covers ResourceLoaderContext::expandModuleNames */ public function testexpandModuleNames( $desc, $modules, $packed ) { $this->assertEquals( $modules, ResourceLoaderContext::expandModuleNames( $packed ), $desc ); diff --git a/tests/phpunit/includes/RevisionStorageTest.php b/tests/phpunit/includes/RevisionStorageTest.php index 00b1f29b87..e17c7b0f5b 100644 --- a/tests/phpunit/includes/RevisionStorageTest.php +++ b/tests/phpunit/includes/RevisionStorageTest.php @@ -38,7 +38,7 @@ class RevisionStorageTest extends MediaWikiTestCase { 'iwlinks' ) ); } - public function setUp() { + protected function setUp() { global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang; parent::setUp(); @@ -456,15 +456,15 @@ class RevisionStorageTest extends MediaWikiTestCase { * @dataProvider provideUserWasLastToEdit */ public function testUserWasLastToEdit( $sinceIdx, $expectedLast ) { - $userA = \User::newFromName( "RevisionStorageTest_userA" ); - $userB = \User::newFromName( "RevisionStorageTest_userB" ); + $userA = User::newFromName( "RevisionStorageTest_userA" ); + $userB = User::newFromName( "RevisionStorageTest_userB" ); if ( $userA->getId() === 0 ) { - $userA = \User::createNew( $userA->getName() ); + $userA = User::createNew( $userA->getName() ); } if ( $userB->getId() === 0 ) { - $userB = \User::createNew( $userB->getName() ); + $userB = User::createNew( $userB->getName() ); } $ns = $this->getDefaultWikitextNS(); diff --git a/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php b/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php index f35a05f71c..4e83e3555e 100644 --- a/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php +++ b/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php @@ -7,7 +7,7 @@ */ class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest { - function setUp() { + protected function setUp() { $this->setMwGlobals( 'wgContentHandlerUseDB', false ); $dbw = wfGetDB( DB_MASTER ); diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index e3b0844ebf..b5819ff689 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -54,7 +54,10 @@ class RevisionTest extends MediaWikiTestCase { parent::tearDown(); } - function testGetRevisionText() { + /** + * @covers Revision::getRevisionText + */ + public function testGetRevisionText() { $row = new stdClass; $row->old_flags = ''; $row->old_text = 'This is a bunch of revision text.'; @@ -63,7 +66,10 @@ class RevisionTest extends MediaWikiTestCase { Revision::getRevisionText( $row ) ); } - function testGetRevisionTextGzip() { + /** + * @covers Revision::getRevisionText + */ + public function testGetRevisionTextGzip() { $this->checkPHPExtension( 'zlib' ); $row = new stdClass; @@ -74,7 +80,10 @@ class RevisionTest extends MediaWikiTestCase { Revision::getRevisionText( $row ) ); } - function testGetRevisionTextUtf8Native() { + /** + * @covers Revision::getRevisionText + */ + public function testGetRevisionTextUtf8Native() { $row = new stdClass; $row->old_flags = 'utf-8'; $row->old_text = "Wiki est l'\xc3\xa9cole superieur !"; @@ -84,7 +93,10 @@ class RevisionTest extends MediaWikiTestCase { Revision::getRevisionText( $row ) ); } - function testGetRevisionTextUtf8Legacy() { + /** + * @covers Revision::getRevisionText + */ + public function testGetRevisionTextUtf8Legacy() { $row = new stdClass; $row->old_flags = ''; $row->old_text = "Wiki est l'\xe9cole superieur !"; @@ -94,7 +106,10 @@ class RevisionTest extends MediaWikiTestCase { Revision::getRevisionText( $row ) ); } - function testGetRevisionTextUtf8NativeGzip() { + /** + * @covers Revision::getRevisionText + */ + public function testGetRevisionTextUtf8NativeGzip() { $this->checkPHPExtension( 'zlib' ); $row = new stdClass; @@ -106,7 +121,10 @@ class RevisionTest extends MediaWikiTestCase { Revision::getRevisionText( $row ) ); } - function testGetRevisionTextUtf8LegacyGzip() { + /** + * @covers Revision::getRevisionText + */ + public function testGetRevisionTextUtf8LegacyGzip() { $this->checkPHPExtension( 'zlib' ); $row = new stdClass; @@ -118,7 +136,10 @@ class RevisionTest extends MediaWikiTestCase { Revision::getRevisionText( $row ) ); } - function testCompressRevisionTextUtf8() { + /** + * @covers Revision::compressRevisionText + */ + public function testCompressRevisionTextUtf8() { $row = new stdClass; $row->old_text = "Wiki est l'\xc3\xa9cole superieur !"; $row->old_flags = Revision::compressRevisionText( $row->old_text ); @@ -132,7 +153,10 @@ class RevisionTest extends MediaWikiTestCase { Revision::getRevisionText( $row ), "getRevisionText" ); } - function testCompressRevisionTextUtf8Gzip() { + /** + * @covers Revision::compressRevisionText + */ + public function testCompressRevisionTextUtf8Gzip() { $this->checkPHPExtension( 'zlib' ); $this->setMwGlobals( 'wgCompressRevisions', true ); @@ -155,6 +179,8 @@ class RevisionTest extends MediaWikiTestCase { * @param string $text * @param string $title * @param string $model + * @param null $format + * * @return Revision */ function newTestRevision( $text, $title = "Test", $model = CONTENT_MODEL_WIKITEXT, $format = null ) { @@ -194,8 +220,9 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database * @dataProvider dataGetContentModel + * @covers Revision::getContentModel */ - function testGetContentModel( $text, $title, $model, $format, $expectedModel ) { + public function testGetContentModel( $text, $title, $model, $format, $expectedModel ) { $rev = $this->newTestRevision( $text, $title, $model, $format ); $this->assertEquals( $expectedModel, $rev->getContentModel() ); @@ -214,8 +241,9 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database * @dataProvider dataGetContentFormat + * @covers Revision::getContentFormat */ - function testGetContentFormat( $text, $title, $model, $format, $expectedFormat ) { + public function testGetContentFormat( $text, $title, $model, $format, $expectedFormat ) { $rev = $this->newTestRevision( $text, $title, $model, $format ); $this->assertEquals( $expectedFormat, $rev->getContentFormat() ); @@ -233,8 +261,9 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database * @dataProvider dataGetContentHandler + * @covers Revision::getContentHandler */ - function testGetContentHandler( $text, $title, $model, $format, $expectedClass ) { + public function testGetContentHandler( $text, $title, $model, $format, $expectedClass ) { $rev = $this->newTestRevision( $text, $title, $model, $format ); $this->assertEquals( $expectedClass, get_class( $rev->getContentHandler() ) ); @@ -252,8 +281,9 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database * @dataProvider dataGetContent + * @covers Revision::getContent */ - function testGetContent( $text, $title, $model, $format, $audience, $expectedSerialization ) { + public function testGetContent( $text, $title, $model, $format, $audience, $expectedSerialization ) { $rev = $this->newTestRevision( $text, $title, $model, $format ); $content = $rev->getContent( $audience ); @@ -272,8 +302,9 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database * @dataProvider dataGetText + * @covers Revision::getText */ - function testGetText( $text, $title, $model, $format, $audience, $expectedText ) { + public function testGetText( $text, $title, $model, $format, $audience, $expectedText ) { $this->hideDeprecated( 'Revision::getText' ); $rev = $this->newTestRevision( $text, $title, $model, $format ); @@ -284,8 +315,9 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database * @dataProvider dataGetText + * @covers Revision::getRawText */ - function testGetRawText( $text, $title, $model, $format, $audience, $expectedText ) { + public function testGetRawText( $text, $title, $model, $format, $audience, $expectedText ) { $this->hideDeprecated( 'Revision::getRawText' ); $rev = $this->newTestRevision( $text, $title, $model, $format ); @@ -328,6 +360,9 @@ class RevisionTest extends MediaWikiTestCase { $this->assertEquals( $expected_hash, $rev->getSha1() ); } + /** + * @covers Revision::__construct + */ public function testConstructWithText() { $this->hideDeprecated( "Revision::getText" ); @@ -342,6 +377,9 @@ class RevisionTest extends MediaWikiTestCase { $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() ); } + /** + * @covers Revision::__construct + */ public function testConstructWithContent() { $this->hideDeprecated( "Revision::getText" ); @@ -361,8 +399,9 @@ class RevisionTest extends MediaWikiTestCase { * Tests whether $rev->getContent() returns a clone when needed. * * @group Database + * @covers Revision::getContent */ - function testGetContentClone() { + public function testGetContentClone() { $content = new RevisionTestModifyableContent( "foo" ); $rev = new Revision( @@ -394,8 +433,9 @@ class RevisionTest extends MediaWikiTestCase { * Tests whether $rev->getContent() returns the same object repeatedly if appropriate. * * @group Database + * @covers Revision::getContent */ - function testGetContentUncloned() { + public function testGetContentUncloned() { $rev = $this->newTestRevision( "hello", "testGetContentUncloned_dummy", CONTENT_MODEL_WIKITEXT ); $content = $rev->getContent( Revision::RAW ); $content2 = $rev->getContent( Revision::RAW ); diff --git a/tests/phpunit/includes/SanitizerTest.php b/tests/phpunit/includes/SanitizerTest.php index 38c15eef07..81246d335b 100644 --- a/tests/phpunit/includes/SanitizerTest.php +++ b/tests/phpunit/includes/SanitizerTest.php @@ -1,5 +1,9 @@ assertEquals( "\xc3\xa9cole", Sanitizer::decodeCharReferences( 'école' ), @@ -16,7 +23,10 @@ class SanitizerTest extends MediaWikiTestCase { ); } - function testDecodeNumericEntities() { + /** + * @covers Sanitizer::decodeCharReferences + */ + public function testDecodeNumericEntities() { $this->assertEquals( "\xc4\x88io bonas dans l'\xc3\xa9cole!", Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ), @@ -24,7 +34,10 @@ class SanitizerTest extends MediaWikiTestCase { ); } - function testDecodeMixedEntities() { + /** + * @covers Sanitizer::decodeCharReferences + */ + public function testDecodeMixedEntities() { $this->assertEquals( "\xc4\x88io bonas dans l'\xc3\xa9cole!", Sanitizer::decodeCharReferences( "Ĉio bonas dans l'école!" ), @@ -32,7 +45,10 @@ class SanitizerTest extends MediaWikiTestCase { ); } - function testDecodeMixedComplexEntities() { + /** + * @covers Sanitizer::decodeCharReferences + */ + public function testDecodeMixedComplexEntities() { $this->assertEquals( "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas Ĉio dans l'école)", Sanitizer::decodeCharReferences( @@ -42,7 +58,10 @@ class SanitizerTest extends MediaWikiTestCase { ); } - function testInvalidAmpersand() { + /** + * @covers Sanitizer::decodeCharReferences + */ + public function testInvalidAmpersand() { $this->assertEquals( 'a & b', Sanitizer::decodeCharReferences( 'a & b' ), @@ -50,7 +69,10 @@ class SanitizerTest extends MediaWikiTestCase { ); } - function testInvalidEntities() { + /** + * @covers Sanitizer::decodeCharReferences + */ + public function testInvalidEntities() { $this->assertEquals( '&foo;', Sanitizer::decodeCharReferences( '&foo;' ), @@ -58,7 +80,10 @@ class SanitizerTest extends MediaWikiTestCase { ); } - function testInvalidNumberedEntities() { + /** + * @covers Sanitizer::decodeCharReferences + */ + public function testInvalidNumberedEntities() { $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "�" ), 'Invalid numbered entity' ); } @@ -69,7 +94,7 @@ class SanitizerTest extends MediaWikiTestCase { * @param String $tag Name of an HTML5 element (ie: 'video') * @param Boolean $escaped Wheter sanitizer let the tag in or escape it (ie: '<video>') */ - function testRemovehtmltagsOnHtml5Tags( $tag, $escaped ) { + public function testRemovehtmltagsOnHtml5Tags( $tag, $escaped ) { $this->setMwGlobals( array( 'wgUseTidy' => false ) ); @@ -131,8 +156,9 @@ class SanitizerTest extends MediaWikiTestCase { /** * @dataProvider dataRemoveHTMLtags + * @covers Sanitizer::removeHTMLtags */ - function testRemoveHTMLtags( $input, $output, $msg = null ) { + public function testRemoveHTMLtags( $input, $output, $msg = null ) { $GLOBALS['wgUseTidy'] = false; $this->assertEquals( $output, Sanitizer::removeHTMLtags( $input ), $msg ); } @@ -141,7 +167,7 @@ class SanitizerTest extends MediaWikiTestCase { * @dataProvider provideTagAttributesToDecode * @covers Sanitizer::decodeTagAttributes */ - function testDecodeTagAttributes( $expected, $attributes, $message = '' ) { + public function testDecodeTagAttributes( $expected, $attributes, $message = '' ) { $this->assertEquals( $expected, Sanitizer::decodeTagAttributes( $attributes ), $message @@ -189,7 +215,7 @@ class SanitizerTest extends MediaWikiTestCase { * @dataProvider provideDeprecatedAttributes * @covers Sanitizer::fixTagAttributes */ - function testDeprecatedAttributesUnaltered( $inputAttr, $inputEl, $message = '' ) { + public function testDeprecatedAttributesUnaltered( $inputAttr, $inputEl, $message = '' ) { $this->assertEquals( " $inputAttr", Sanitizer::fixTagAttributes( $inputAttr, $inputEl ), $message @@ -217,7 +243,7 @@ class SanitizerTest extends MediaWikiTestCase { * @dataProvider provideCssCommentsFixtures * @covers Sanitizer::checkCss */ - function testCssCommentsChecking( $expected, $css, $message = '' ) { + public function testCssCommentsChecking( $expected, $css, $message = '' ) { $this->assertEquals( $expected, Sanitizer::checkCss( $css ), $message @@ -265,8 +291,9 @@ class SanitizerTest extends MediaWikiTestCase { /** * @dataProvider provideAttributeSupport + * @covers Sanitizer::fixTagAttributes */ - function testAttributeSupport( $tag, $attributes, $expected, $message ) { + public function testAttributeSupport( $tag, $attributes, $expected, $message ) { $this->assertEquals( $expected, Sanitizer::fixTagAttributes( $attributes, $tag ), $message diff --git a/tests/phpunit/includes/SanitizerValidateEmailTest.php b/tests/phpunit/includes/SanitizerValidateEmailTest.php index fe0bc64e2f..f13e838288 100644 --- a/tests/phpunit/includes/SanitizerValidateEmailTest.php +++ b/tests/phpunit/includes/SanitizerValidateEmailTest.php @@ -1,5 +1,10 @@ checkEmail( $addr, false, $msg ); } - function testEmailWellKnownUserAtHostDotTldAreValid() { + public function testEmailWellKnownUserAtHostDotTldAreValid() { $this->valid( 'user@example.com' ); $this->valid( 'user@example.museum' ); } - function testEmailWithUpperCaseCharactersAreValid() { + public function testEmailWithUpperCaseCharactersAreValid() { $this->valid( 'USER@example.com' ); $this->valid( 'user@EXAMPLE.COM' ); $this->valid( 'user@Example.com' ); $this->valid( 'USER@eXAMPLE.com' ); } - function testEmailWithAPlusInUserName() { + public function testEmailWithAPlusInUserName() { $this->valid( 'user+sub@example.com' ); $this->valid( 'user+@example.com' ); } - function testEmailDoesNotNeedATopLevelDomain() { + public function testEmailDoesNotNeedATopLevelDomain() { $this->valid( "user@localhost" ); $this->valid( "FooBar@localdomain" ); $this->valid( "nobody@mycompany" ); } - function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() { + public function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() { $this->invalid( " user@host.com" ); $this->invalid( "user@host.com " ); $this->invalid( "\tuser@host.com" ); $this->invalid( "user@host.com\t" ); } - function testEmailWithWhiteSpacesAreInvalids() { + public function testEmailWithWhiteSpacesAreInvalids() { $this->invalid( "User user@host" ); $this->invalid( "first last@mycompany" ); $this->invalid( "firstlast@my company" ); } - // bug 26948 : comma were matched by an incorrect regexp range - function testEmailWithCommasAreInvalids() { + /** + * bug 26948 : comma were matched by an incorrect regexp range + */ + public function testEmailWithCommasAreInvalids() { $this->invalid( "user,foo@example.org" ); $this->invalid( "userfoo@ex,ample.org" ); } - function testEmailWithHyphens() { + public function testEmailWithHyphens() { $this->valid( "user-foo@example.org" ); $this->valid( "userfoo@ex-ample.org" ); } - function testEmailDomainCanNotBeginWithDot() { + public function testEmailDomainCanNotBeginWithDot() { $this->invalid( "user@." ); $this->invalid( "user@.localdomain" ); $this->invalid( "user@localdomain." ); @@ -78,19 +85,19 @@ class SanitizerValidateEmailTest extends MediaWikiTestCase { $this->invalid( ".@a............" ); } - function testEmailWithFunnyCharacters() { + public function testEmailWithFunnyCharacters() { $this->valid( "\$user!ex{this}@123.com" ); } - function testEmailTopLevelDomainCanBeNumerical() { + public function testEmailTopLevelDomainCanBeNumerical() { $this->valid( "user@example.1234" ); } - function testEmailWithoutAtSignIsInvalid() { + public function testEmailWithoutAtSignIsInvalid() { $this->invalid( 'useràexample.com' ); } - function testEmailWithOneCharacterDomainIsValid() { + public function testEmailWithOneCharacterDomainIsValid() { $this->valid( 'user@a' ); } } diff --git a/tests/phpunit/includes/SiteConfigurationTest.php b/tests/phpunit/includes/SiteConfigurationTest.php index 181a9132e6..053d8a7d26 100644 --- a/tests/phpunit/includes/SiteConfigurationTest.php +++ b/tests/phpunit/includes/SiteConfigurationTest.php @@ -24,7 +24,11 @@ function getSiteParams( $conf, $wiki ) { } class SiteConfigurationTest extends MediaWikiTestCase { - var $mConf; + + /** + * @var SiteConfiguration + */ + protected $mConf; protected function setUp() { parent::setUp(); @@ -95,7 +99,10 @@ class SiteConfigurationTest extends MediaWikiTestCase { $GLOBALS['global'] = array( 'global' => 'global' ); } - function testSiteFromDb() { + /** + * @covers SiteConfiguration::siteFromDB + */ + public function testSiteFromDb() { $this->assertEquals( array( 'wikipedia', 'en' ), $this->mConf->siteFromDB( 'enwiki' ), @@ -120,7 +127,10 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - function testGetLocalDatabases() { + /** + * @covers SiteConfiguration::getLocalDatabases + */ + public function testGetLocalDatabases() { $this->assertEquals( array( 'enwiki', 'dewiki', 'frwiki' ), $this->mConf->getLocalDatabases(), @@ -128,7 +138,10 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - function testGetConfVariables() { + /** + * @covers SiteConfiguration::get + */ + public function testGetConfVariables() { $this->assertEquals( 'enwiki', $this->mConf->get( 'simple', 'enwiki', 'wiki' ), @@ -240,7 +253,10 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - function testSiteFromDbWithCallback() { + /** + * @covers SiteConfiguration::siteFromDB + */ + public function testSiteFromDbWithCallback() { $this->mConf->siteParamsCallback = 'getSiteParams'; $this->assertEquals( @@ -260,7 +276,10 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - function testParameterReplacement() { + /** + * @covers SiteConfiguration::get + */ + public function testParameterReplacement() { $this->mConf->siteParamsCallback = 'getSiteParams'; $this->assertEquals( @@ -290,7 +309,10 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - function testGetAllGlobals() { + /** + * @covers SiteConfiguration::getAll + */ + public function testGetAllGlobals() { $this->mConf->siteParamsCallback = 'getSiteParams'; $getall = array( diff --git a/tests/phpunit/includes/TemplateCategoriesTest.php b/tests/phpunit/includes/TemplateCategoriesTest.php index ffa8c428b3..906aebd9d2 100644 --- a/tests/phpunit/includes/TemplateCategoriesTest.php +++ b/tests/phpunit/includes/TemplateCategoriesTest.php @@ -7,20 +7,37 @@ require __DIR__ . "/../../../maintenance/runJobs.php"; class TemplateCategoriesTest extends MediaWikiLangTestCase { + /** + * @covers Title::getParentCategories + */ function testTemplateCategories() { $title = Title::newFromText( "Categorized from template" ); $page = WikiPage::factory( $title ); $user = new User(); $user->mRights = array( 'createpage', 'edit', 'purge' ); - $page->doEditContent( new WikitextContent( '{{Categorising template}}' ), 'Create a page with a template', 0, false, $user ); + $page->doEditContent( + new WikitextContent( '{{Categorising template}}' ), + 'Create a page with a template', + 0, + false, + $user + ); + $this->assertEquals( array() , $title->getParentCategories() ); $template = WikiPage::factory( Title::newFromText( 'Template:Categorising template' ) ); - $template->doEditContent( new WikitextContent( '[[Category:Solved bugs]]' ), 'Add a category through a template', 0, false, $user ); + + $template->doEditContent( + new WikitextContent( '[[Category:Solved bugs]]' ), + 'Add a category through a template', + 0, + false, + $user + ); // Run the job queue JobQueueGroup::destroySingletons(); diff --git a/tests/phpunit/includes/TestUser.php b/tests/phpunit/includes/TestUser.php index 2fb0f499c5..23e65031e0 100644 --- a/tests/phpunit/includes/TestUser.php +++ b/tests/phpunit/includes/TestUser.php @@ -1,6 +1,8 @@ username = $username; $this->realname = $realname; $this->email = $email; diff --git a/tests/phpunit/includes/TimeAdjustTest.php b/tests/phpunit/includes/TimeAdjustTest.php index 3a2c62a41b..0b368c251d 100644 --- a/tests/phpunit/includes/TimeAdjustTest.php +++ b/tests/phpunit/includes/TimeAdjustTest.php @@ -8,8 +8,9 @@ class TimeAdjustTest extends MediaWikiLangTestCase { } /** - * Test offset usage for a given language::userAdjust + * Test offset usage for a given Language::userAdjust * @dataProvider dataUserAdjust + * @covers Language::userAdjust */ public function testUserAdjust( $date, $localTZoffset, $expected ) { global $wgContLang; diff --git a/tests/phpunit/includes/TimestampTest.php b/tests/phpunit/includes/TimestampTest.php index 3668046200..5338839261 100644 --- a/tests/phpunit/includes/TimestampTest.php +++ b/tests/phpunit/includes/TimestampTest.php @@ -14,8 +14,9 @@ class TimestampTest extends MediaWikiLangTestCase { /** * Test parsing of valid timestamps and outputing to MW format. * @dataProvider provideValidTimestamps + * @covers MWTimestamp::getTimestamp */ - function testValidParse( $format, $original, $expected ) { + public function testValidParse( $format, $original, $expected ) { $timestamp = new MWTimestamp( $original ); $this->assertEquals( $expected, $timestamp->getTimestamp( TS_MW ) ); } @@ -23,8 +24,9 @@ class TimestampTest extends MediaWikiLangTestCase { /** * Test outputting valid timestamps to different formats. * @dataProvider provideValidTimestamps + * @covers MWTimestamp::getTimestamp */ - function testValidOutput( $format, $expected, $original ) { + public function testValidOutput( $format, $expected, $original ) { $timestamp = new MWTimestamp( $original ); $this->assertEquals( $expected, (string)$timestamp->getTimestamp( $format ) ); } @@ -32,16 +34,18 @@ class TimestampTest extends MediaWikiLangTestCase { /** * Test an invalid timestamp. * @expectedException TimestampException + * @covers MWTimestamp */ - function testInvalidParse() { + public function testInvalidParse() { new MWTimestamp( "This is not a timestamp." ); } /** * Test requesting an invalid output format. * @expectedException TimestampException + * @covers MWTimestamp::getTimestamp */ - function testInvalidOutput() { + public function testInvalidOutput() { $timestamp = new MWTimestamp( '1343761268' ); $timestamp->getTimestamp( 98 ); } @@ -69,8 +73,8 @@ class TimestampTest extends MediaWikiLangTestCase { } /** - * @test * @dataProvider provideHumanTimestampTests + * @covers MWTimestamp::getHumanTimestamp */ public function testHumanTimestamp( $tsTime, // The timestamp to format @@ -202,8 +206,8 @@ class TimestampTest extends MediaWikiLangTestCase { } /** - * @test * @dataProvider provideRelativeTimestampTests + * @covers MWTimestamp::getRelativeTimestamp */ public function testRelativeTimestamp( $tsTime, // The timestamp to format diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index a11c3d9802..3079d73a37 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -6,7 +6,6 @@ * * @note: We don't make assumptions about the main namespace. * But we do expect the Help namespace to contain Wikitext. - * */ class TitleMethodsTest extends MediaWikiTestCase { @@ -57,6 +56,7 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider provideEquals + * @covers Title::equals */ public function testEquals( $titleA, $titleB, $expectedBool ) { $titleA = Title::newFromText( $titleA ); @@ -81,12 +81,16 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider provideInNamespace + * @covers Title::inNamespace */ public function testInNamespace( $title, $ns, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) ); } + /** + * @covers Title::inNamespaces + */ public function testInNamespaces() { $mainpage = Title::newFromText( 'Main Page' ); $this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) ); @@ -110,6 +114,7 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider provideHasSubjectNamespace + * @covers Title::hasSubjectNamespace */ public function testHasSubjectNamespace( $title, $ns, $expectedBool ) { $title = Title::newFromText( $title ); @@ -143,6 +148,7 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider dataGetContentModel + * @covers Title::getContentModel */ public function testGetContentModel( $title, $expectedModelId ) { $title = Title::newFromText( $title ); @@ -151,6 +157,7 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider dataGetContentModel + * @covers Title::hasContentModel */ public function testHasContentModel( $title, $expectedModelId ) { $title = Title::newFromText( $title ); @@ -181,13 +188,13 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider provideIsCssOrJsPage + * @covers Title::isCssOrJsPage */ public function testIsCssOrJsPage( $title, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isCssOrJsPage() ); } - public static function provideIsCssJsSubpage() { return array( array( 'Help:Foo', false ), @@ -210,6 +217,7 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider provideIsCssJsSubpage + * @covers Title::isCssJsSubpage */ public function testIsCssJsSubpage( $title, $expectedBool ) { $title = Title::newFromText( $title ); @@ -230,6 +238,7 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider provideIsCssSubpage + * @covers Title::isCssSubpage */ public function testIsCssSubpage( $title, $expectedBool ) { $title = Title::newFromText( $title ); @@ -250,6 +259,7 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider provideIsJsSubpage + * @covers Title::isJsSubpage */ public function testIsJsSubpage( $title, $expectedBool ) { $title = Title::newFromText( $title ); @@ -281,6 +291,7 @@ class TitleMethodsTest extends MediaWikiTestCase { /** * @dataProvider provideIsWikitextPage + * @covers Title::isWikitextPage */ public function testIsWikitextPage( $title, $expectedBool ) { $title = Title::newFromText( $title ); diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 9144d0c34b..f15c177226 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -2,6 +2,7 @@ /** * @group Database + * @todo covers tags */ class TitlePermissionTest extends MediaWikiLangTestCase { @@ -68,7 +69,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { } } - function setUserPerm( $perm ) { + protected function setUserPerm( $perm ) { // Setting member variables is evil!!! if ( is_array( $perm ) ) { @@ -78,11 +79,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase { } } - function setTitle( $ns, $title = "Main_Page" ) { + protected function setTitle( $ns, $title = "Main_Page" ) { $this->title = Title::makeTitle( $ns, $title ); } - function setUser( $userName = null ) { + protected function setUser( $userName = null ) { if ( $userName === 'anon' ) { $this->user = $this->anonUser; } elseif ( $userName === null || $userName === $this->userName ) { @@ -92,7 +93,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase { } } - function testQuickPermissions() { + /** + * @todo This test method should be split up into separate test methods and + * data providers + */ + public function testQuickPermissions() { global $wgContLang; $prefix = $wgContLang->getFormattedNsText( NS_PROJECT ); @@ -320,7 +325,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { } } - function runGroupPermissions( $action, $result, $result2 = null ) { + protected function runGroupPermissions( $action, $result, $result2 = null ) { global $wgGroupPermissions; if ( $result2 === null ) { @@ -348,7 +353,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->assertEquals( $result2, $res ); } - function testSpecialsAndNSPermissions() { + /** + * @todo This test method should be split up into separate test methods and + * data providers + */ + public function testSpecialsAndNSPermissions() { global $wgNamespaceProtection; $this->setUser( $this->userName ); @@ -399,7 +408,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->title->userCan( 'bogus', $this->user ) ); } - function testCssAndJavascriptPermissions() { + /** + * @todo This test method should be split up into separate test methods and + * data providers + */ + public function testCssAndJavascriptPermissions() { $this->setUser( $this->userName ); $this->setTitle( NS_USER, $this->userName . '/test.js' ); @@ -448,7 +461,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { ); } - function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) { + protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) { $this->setUserPerm( '' ); $this->assertEquals( $result0, $this->title->getUserPermissionsErrors( 'bogus', @@ -485,7 +498,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->user ) ); } - function testPageRestrictions() { + /** + * @todo This test method should be split up into separate test methods and + * data providers + */ + public function testPageRestrictions() { global $wgContLang; $prefix = $wgContLang->getFormattedNsText( NS_PROJECT ); @@ -576,7 +593,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->user ) ); } - function testCascadingSourcesRestrictions() { + public function testCascadingSourcesRestrictions() { $this->setTitle( NS_MAIN, "test page" ); $this->setUserPerm( array( "edit", "bogus" ) ); @@ -596,7 +613,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); } - function testActionPermissions() { + /** + * @todo This test method should be split up into separate test methods and + * data providers + */ + public function testActionPermissions() { $this->setUserPerm( array( "createpage" ) ); $this->setTitle( NS_MAIN, "test page" ); $this->title->mTitleProtection['pt_create_perm'] = ''; @@ -667,7 +688,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->title->userCan( 'move-target', $this->user ) ); } - function testUserBlock() { + public function testUserBlock() { global $wgEmailConfirmToEdit, $wgEmailAuthentication; $wgEmailConfirmToEdit = true; $wgEmailAuthentication = true; diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index da663c4b01..6bfe545301 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -1,7 +1,6 @@ assertEquals( $unicodeClass, Title::convertByteClassToUnicodeClass( $byteClass ) ); } /** * @dataProvider provideBug31100 + * @covers Title::fixSpecialName */ - function testBug31100FixSpecialName( $text, $expectedParam ) { + public function testBug31100FixSpecialName( $text, $expectedParam ) { $title = Title::newFromText( $text ); $fixed = $title->fixSpecialName(); $stuff = explode( '/', $fixed->getDBkey(), 2 ); @@ -205,10 +211,11 @@ class TitleTest extends MediaWikiTestCase { * @group Database * @param string $source * @param string $target - * @param array|string|true $expected Required error + * @param array|string|bool $expected Required error * @dataProvider provideTestIsValidMoveOperation + * @covers Title::isValidMoveOperation */ - function testIsValidMoveOperation( $source, $target, $expected ) { + public function testIsValidMoveOperation( $source, $target, $expected ) { $title = Title::newFromText( $source ); $nt = Title::newFromText( $target ); $errors = $title->isValidMoveOperation( $nt, false ); @@ -225,7 +232,7 @@ class TitleTest extends MediaWikiTestCase { /** * Provides test parameter values for testIsValidMoveOperation() */ - function dataTestIsValidMoveOperation() { + public function dataTestIsValidMoveOperation() { return array( array( 'Test', 'Test', 'selfmove' ), array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' ) @@ -238,12 +245,12 @@ class TitleTest extends MediaWikiTestCase { * @param array $whitelistRegexp * @param string $source * @param string $action - * @param array|string|true $expected Required error + * @param array|string|bool $expected Required error * * @covers Title::checkReadPermissions * @dataProvider dataWgWhitelistReadRegexp */ - function testWgWhitelistReadRegexp( $whitelistRegexp, $source, $action, $expected ) { + public function testWgWhitelistReadRegexp( $whitelistRegexp, $source, $action, $expected ) { // $wgWhitelistReadRegexp must be an array. Since the provided test cases // usually have only one regex, it is more concise to write the lonely regex // as a string. Thus we cast to an array() to honor $wgWhitelistReadRegexp @@ -300,7 +307,7 @@ class TitleTest extends MediaWikiTestCase { /** * Provides test parameter values for testWgWhitelistReadRegexp() */ - function dataWgWhitelistReadRegexp() { + public function dataWgWhitelistReadRegexp() { $ALLOWED = true; $DISALLOWED = false; @@ -336,7 +343,7 @@ class TitleTest extends MediaWikiTestCase { ); } - function flattenErrorsArray( $errors ) { + public function flattenErrorsArray( $errors ) { $result = array(); foreach ( $errors as $error ) { $result[] = $error[0]; @@ -353,9 +360,10 @@ class TitleTest extends MediaWikiTestCase { } /** - * @dataProvider provideCasesForGetpageviewlanguage + * @dataProvider provideGetPageViewLanguage + * @covers Title::getPageViewLanguage */ - function testGetpageviewlanguage( $expected, $titleText, $contLang, $lang, $variant, $msg = '' ) { + public function testGetPageViewLanguage( $expected, $titleText, $contLang, $lang, $variant, $msg = '' ) { global $wgLanguageCode, $wgContLang, $wgLang, $wgDefaultLanguageVariant, $wgAllowUserJs; // Setup environnement for this test @@ -375,7 +383,7 @@ class TitleTest extends MediaWikiTestCase { ); } - public static function provideCasesForGetpageviewlanguage() { + public static function provideGetPageViewLanguage() { # Format: # - expected # - Title name @@ -416,8 +424,9 @@ class TitleTest extends MediaWikiTestCase { /** * @dataProvider provideBaseTitleCases + * @covers Title::getBaseText */ - function testExtractingBaseTextFromTitle( $title, $expected, $msg = '' ) { + public function testGetBaseText( $title, $expected, $msg = '' ) { $title = Title::newFromText( $title ); $this->assertEquals( $expected, $title->getBaseText(), @@ -435,8 +444,9 @@ class TitleTest extends MediaWikiTestCase { /** * @dataProvider provideRootTitleCases + * @covers Title::getRootText */ - function testExtractingRootTextFromTitle( $title, $expected, $msg = '' ) { + public function testGetRootText( $title, $expected, $msg = '' ) { $title = Title::newFromText( $title ); $this->assertEquals( $expected, $title->getRootText(), @@ -455,8 +465,9 @@ class TitleTest extends MediaWikiTestCase { /** * @todo Handle $wgNamespacesWithSubpages cases * @dataProvider provideSubpageTitleCases + * @covers Title::getSubpageText */ - function testExtractingSubpageTextFromTitle( $title, $expected, $msg = '' ) { + public function testGetSubpageText( $title, $expected, $msg = '' ) { $title = Title::newFromText( $title ); $this->assertEquals( $expected, $title->getSubpageText(), diff --git a/tests/phpunit/includes/UIDGeneratorTest.php b/tests/phpunit/includes/UIDGeneratorTest.php index 23553ca710..8f78ae5126 100644 --- a/tests/phpunit/includes/UIDGeneratorTest.php +++ b/tests/phpunit/includes/UIDGeneratorTest.php @@ -1,8 +1,11 @@ assertEquals( true, preg_match( '!^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$!', $id ), "UID $id has the right format" ); + } + } + /** + * @covers UIDGenerator::newRawUUIDv4 + */ + public function testRawUUIDv4() { + for ( $i = 0; $i < 100; $i++ ) { $id = UIDGenerator::newRawUUIDv4(); $this->assertEquals( true, preg_match( '!^[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}$!', $id ), "UID $id has the right format" ); + } + } + /** + * @covers UIDGenerator::newRawUUIDv4 + */ + public function testRawUUIDv4QuickRand() { + for ( $i = 0; $i < 100; $i++ ) { $id = UIDGenerator::newRawUUIDv4( UIDGenerator::QUICK_RAND ); $this->assertEquals( true, preg_match( '!^[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}$!', $id ), "UID $id has the right format" ); } } + } diff --git a/tests/phpunit/includes/UserTest.php b/tests/phpunit/includes/UserTest.php index 0113cab8de..ff33e825ee 100644 --- a/tests/phpunit/includes/UserTest.php +++ b/tests/phpunit/includes/UserTest.php @@ -53,6 +53,9 @@ class UserTest extends MediaWikiTestCase { ); } + /** + * @covers User::getGroupPermissions + */ public function testGroupPermissions() { $rights = User::getGroupPermissions( array( 'unittesters' ) ); $this->assertContains( 'runtest', $rights ); @@ -67,6 +70,9 @@ class UserTest extends MediaWikiTestCase { $this->assertNotContains( 'nukeworld', $rights ); } + /** + * @covers User::getGroupPermissions + */ public function testRevokePermissions() { $rights = User::getGroupPermissions( array( 'unittesters', 'formertesters' ) ); $this->assertNotContains( 'runtest', $rights ); @@ -75,6 +81,9 @@ class UserTest extends MediaWikiTestCase { $this->assertNotContains( 'nukeworld', $rights ); } + /** + * @covers User::getRights + */ public function testUserPermissions() { $rights = $this->user->getRights(); $this->assertContains( 'runtest', $rights ); @@ -85,6 +94,7 @@ class UserTest extends MediaWikiTestCase { /** * @dataProvider provideGetGroupsWithPermission + * @covers User::getGroupsWithPermission */ public function testGetGroupsWithPermission( $expected, $right ) { $result = User::getGroupsWithPermission( $right ); @@ -117,6 +127,7 @@ class UserTest extends MediaWikiTestCase { /** * @dataProvider provideUserNames + * @covers User::isValidUserName */ public function testIsValidUserName( $username, $result, $message ) { $this->assertEquals( $this->user->isValidUserName( $username ), $result, $message ); @@ -171,6 +182,7 @@ class UserTest extends MediaWikiTestCase { /** * Test User::editCount * @group medium + * @covers User::getEditCount */ public function testEditCount() { $user = User::newFromName( 'UnitTestUser' ); @@ -195,6 +207,8 @@ class UserTest extends MediaWikiTestCase { /** * Test changing user options. + * @covers User::setOption + * @covers User::getOption */ public function testOptions() { $user = User::newFromName( 'UnitTestUser' ); @@ -212,6 +226,7 @@ class UserTest extends MediaWikiTestCase { /** * Bug 37963 * Make sure defaults are loaded when setOption is called. + * @covers User::loadOptions */ public function testAnonOptions() { global $wgDefaultUserOptions; diff --git a/tests/phpunit/includes/WebRequestTest.php b/tests/phpunit/includes/WebRequestTest.php index 4f5322e8a7..a600188b9f 100644 --- a/tests/phpunit/includes/WebRequestTest.php +++ b/tests/phpunit/includes/WebRequestTest.php @@ -20,6 +20,7 @@ class WebRequestTest extends MediaWikiTestCase { /** * @dataProvider provideDetectServer + * @covers WebRequest::detectServer */ function testDetectServer( $expected, $input, $description ) { $_SERVER = $input; @@ -103,6 +104,7 @@ class WebRequestTest extends MediaWikiTestCase { /** * @dataProvider provideGetIP + * @covers WebRequest::getIP */ function testGetIP( $expected, $input, $squid, $xffList, $private, $description ) { $_SERVER = $input; @@ -272,6 +274,7 @@ class WebRequestTest extends MediaWikiTestCase { /** * @expectedException MWException + * @covers WebRequest::getIP */ function testGetIpLackOfRemoteAddrThrowAnException() { $request = new WebRequest(); @@ -297,6 +300,7 @@ class WebRequestTest extends MediaWikiTestCase { /** * @dataProvider provideLanguageData + * @covers WebRequest::getAcceptLang */ function testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description ) { $_SERVER = array( 'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader ); diff --git a/tests/phpunit/includes/WikiPageTest.php b/tests/phpunit/includes/WikiPageTest.php index bf8cd37e93..e0d786b9d4 100644 --- a/tests/phpunit/includes/WikiPageTest.php +++ b/tests/phpunit/includes/WikiPageTest.php @@ -1,14 +1,14 @@ newPage( "WikiPageTest_testDoEditContent" ); $title = $page->getTitle(); @@ -143,6 +146,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' ); } + /** + * @covers WikiPage::doEdit + */ public function testDoEdit() { $this->hideDeprecated( "WikiPage::doEdit" ); $this->hideDeprecated( "WikiPage::getText" ); @@ -200,6 +206,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' ); } + /** + * @covers WikiPage::doQuickEdit + */ public function testDoQuickEdit() { global $wgUser; @@ -216,6 +225,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( $text, $page->getText() ); } + /** + * @covers WikiPage::doQuickEditContent + */ public function testDoQuickEditContent() { global $wgUser; @@ -229,6 +241,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertTrue( $content->equals( $page->getContent() ) ); } + /** + * @covers WikiPage::doDeleteArticle + */ public function testDoDeleteArticle() { $page = $this->createPage( "WikiPageTest_testDoDeleteArticle", "[[original text]] foo", CONTENT_MODEL_WIKITEXT ); $id = $page->getId(); @@ -253,6 +268,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' ); } + /** + * @covers WikiPage::doDeleteUpdates + */ public function testDoDeleteUpdates() { $page = $this->createPage( "WikiPageTest_testDoDeleteArticle", "[[original text]] foo", CONTENT_MODEL_WIKITEXT ); $id = $page->getId(); @@ -268,6 +286,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' ); } + /** + * @covers WikiPage::getRevision + */ public function testGetRevision() { $page = $this->newPage( "WikiPageTest_testGetRevision" ); @@ -283,6 +304,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( "some text", $rev->getContent()->getNativeData() ); } + /** + * @covers WikiPage::getContent + */ public function testGetContent() { $page = $this->newPage( "WikiPageTest_testGetContent" ); @@ -296,6 +320,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( "some text", $content->getNativeData() ); } + /** + * @covers WikiPage::getText + */ public function testGetText() { $this->hideDeprecated( "WikiPage::getText" ); @@ -311,6 +338,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( "some text", $text ); } + /** + * @covers WikiPage::getRawText + */ public function testGetRawText() { $this->hideDeprecated( "WikiPage::getRawText" ); @@ -326,6 +356,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( "some text", $text ); } + /** + * @covers WikiPage::getContentModel + */ public function testGetContentModel() { global $wgContentHandlerUseDB; @@ -339,6 +372,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $page->getContentModel() ); } + /** + * @covers WikiPage::getContentHandler + */ public function testGetContentHandler() { global $wgContentHandlerUseDB; @@ -352,6 +388,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertEquals( 'JavaScriptContentHandler', get_class( $page->getContentHandler() ) ); } + /** + * @covers WikiPage::exists + */ public function testExists() { $page = $this->newPage( "WikiPageTest_testExists" ); $this->assertFalse( $page->exists() ); @@ -383,6 +422,7 @@ class WikiPageTest extends MediaWikiLangTestCase { /** * @dataProvider provideHasViewableContent + * @covers WikiPage::hasViewableContent */ public function testHasViewableContent( $title, $viewable, $create = false ) { $page = $this->newPage( $title ); @@ -406,6 +446,7 @@ class WikiPageTest extends MediaWikiLangTestCase { /** * @dataProvider provideGetRedirectTarget + * @covers WikiPage::getRedirectTarget */ public function testGetRedirectTarget( $title, $model, $text, $target ) { $page = $this->createPage( $title, $text, $model ); @@ -421,6 +462,7 @@ class WikiPageTest extends MediaWikiLangTestCase { /** * @dataProvider provideGetRedirectTarget + * @covers WikiPage::isRedirect */ public function testIsRedirect( $title, $model, $text, $target ) { $page = $this->createPage( $title, $text, $model ); @@ -537,6 +579,7 @@ class WikiPageTest extends MediaWikiLangTestCase { /** * @dataProvider provideIsCountable + * @covers WikiPage::isCountable */ public function testIsCountable( $title, $model, $text, $mode, $expected ) { global $wgContentHandlerUseDB; @@ -575,6 +618,7 @@ class WikiPageTest extends MediaWikiLangTestCase { /** * @dataProvider provideGetParserOutput + * @covers WikiPage::getParserOutput */ public function testGetParserOutput( $model, $text, $expectedHtml ) { $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text, $model ); @@ -591,6 +635,9 @@ class WikiPageTest extends MediaWikiLangTestCase { return $po; } + /** + * @covers WikiPage::getParserOutput + */ public function testGetParserOutput_nonexisting() { static $count = 0; $count++; @@ -603,6 +650,9 @@ class WikiPageTest extends MediaWikiLangTestCase { $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." ); } + /** + * @covers WikiPage::getParserOutput + */ public function testGetParserOutput_badrev() { $page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT ); @@ -679,6 +729,7 @@ more stuff /** * @dataProvider dataReplaceSection + * @covers WikiPage::replaceSection */ public function testReplaceSection( $title, $model, $text, $section, $with, $sectionTitle, $expected ) { $this->hideDeprecated( "WikiPage::replaceSection" ); @@ -692,6 +743,7 @@ more stuff /** * @dataProvider dataReplaceSection + * @covers WikiPage::replaceSectionContent */ public function testReplaceSectionContent( $title, $model, $text, $section, $with, $sectionTitle, $expected ) { $page = $this->createPage( $title, $text, $model ); @@ -802,6 +854,7 @@ more stuff /** * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason. + * @covers WikiPage::doRollback */ public function testDoRollback() { $admin = new User(); @@ -878,6 +931,7 @@ more stuff /** * @dataProvider provideGetAutoSummary + * @covers WikiPage::getAutosummary */ public function testGetAutosummary( $old, $new, $flags, $expected ) { $this->hideDeprecated( "WikiPage::getAutosummary" ); @@ -950,6 +1004,7 @@ more stuff /** * @dataProvider provideGetAutoDeleteReason + * @covers WikiPage::getAutoDeleteReason */ public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) { global $wgUser; @@ -1003,6 +1058,7 @@ more stuff /** * @dataProvider providePreSaveTransform + * @covers WikiPage::preSaveTransform */ public function testPreSaveTransform( $text, $expected ) { $this->hideDeprecated( 'WikiPage::preSaveTransform' ); diff --git a/tests/phpunit/includes/WikiPageTest_ContentHandlerUseDB.php b/tests/phpunit/includes/WikiPageTest_ContentHandlerUseDB.php index 41f3572efd..2a723e8503 100644 --- a/tests/phpunit/includes/WikiPageTest_ContentHandlerUseDB.php +++ b/tests/phpunit/includes/WikiPageTest_ContentHandlerUseDB.php @@ -7,7 +7,7 @@ */ class WikiPageTest_ContentHandlerUseDB extends WikiPageTest { - function setUp() { + protected function setUp() { parent::setUp(); $this->setMwGlobals( 'wgContentHandlerUseDB', false ); @@ -26,6 +26,9 @@ class WikiPageTest_ContentHandlerUseDB extends WikiPageTest { } } + /** + * @covers WikiPage::getContentModel + */ public function testGetContentModel() { $page = $this->createPage( "WikiPageTest_testGetContentModel", "some text", CONTENT_MODEL_JAVASCRIPT ); @@ -36,6 +39,9 @@ class WikiPageTest_ContentHandlerUseDB extends WikiPageTest { $this->assertEquals( CONTENT_MODEL_WIKITEXT, $page->getContentModel() ); } + /** + * @covers WikiPage::getContentHandler + */ public function testGetContentHandler() { $page = $this->createPage( "WikiPageTest_testGetContentHandler", "some text", CONTENT_MODEL_JAVASCRIPT ); diff --git a/tests/phpunit/includes/XmlJsTest.php b/tests/phpunit/includes/XmlJsTest.php index c5b411fb47..161468e29e 100644 --- a/tests/phpunit/includes/XmlJsTest.php +++ b/tests/phpunit/includes/XmlJsTest.php @@ -1,9 +1,24 @@ assertNull( $obj->value ); - $obj = new XmlJsCode( '' ); - $this->assertSame( $obj->value, '' ); + + /** + * @covers XmlJsCode::__construct + * @dataProvider provideConstruction + */ + public function testConstruction( $value ) { + $obj = new XmlJsCode( $value ); + $this->assertEquals( $value, $obj->value ); } + + public function provideConstruction(){ + return array( + array( null ), + array( '' ), + ); + } + } diff --git a/tests/phpunit/includes/XmlSelectTest.php b/tests/phpunit/includes/XmlSelectTest.php index 08c031f8d7..56d28b5411 100644 --- a/tests/phpunit/includes/XmlSelectTest.php +++ b/tests/phpunit/includes/XmlSelectTest.php @@ -1,7 +1,13 @@ select = null; } - ### START OF TESTS ### - + /** + * @covers XmlSelect::__construct + */ public function testConstructWithoutParameters() { $this->assertEquals( '', $this->select->getHTML() ); } @@ -26,6 +33,7 @@ class XmlSelectTest extends MediaWikiTestCase { /** * Parameters are $name (false), $id (false), $default (false) * @dataProvider provideConstructionParameters + * @covers XmlSelect::__construct */ public function testConstructParameters( $name, $id, $default, $expected ) { $this->select = new XmlSelect( $name, $id, $default ); @@ -39,7 +47,6 @@ class XmlSelectTest extends MediaWikiTestCase { * - $id (default: false) * - $default (default: false) * Provides a fourth parameters representing the expected HTML output - * */ public static function provideConstructionParameters() { return array( @@ -60,29 +67,41 @@ class XmlSelectTest extends MediaWikiTestCase { ); } - # Begin XmlSelect::addOption() similar to Xml::option + /** + * @covers XmlSelect::addOption + */ public function testAddOption() { $this->select->addOption( 'foo' ); $this->assertEquals( '', $this->select->getHTML() ); } + /** + * @covers XmlSelect::addOption + */ public function testAddOptionWithDefault() { $this->select->addOption( 'foo', true ); $this->assertEquals( '', $this->select->getHTML() ); } + /** + * @covers XmlSelect::addOption + */ public function testAddOptionWithFalse() { $this->select->addOption( 'foo', false ); $this->assertEquals( '', $this->select->getHTML() ); } + /** + * @covers XmlSelect::addOption + */ public function testAddOptionWithValueZero() { $this->select->addOption( 'foo', 0 ); $this->assertEquals( '', $this->select->getHTML() ); } - # End XmlSelect::addOption() similar to Xml::option - + /** + * @covers XmlSelect::setDefault + */ public function testSetDefault() { $this->select->setDefault( 'bar1' ); $this->select->addOption( 'foo1' ); @@ -98,6 +117,7 @@ class XmlSelectTest extends MediaWikiTestCase { * Adding default later on should set the correct selection or * raise an exception. * To handle this, we need to render the options in getHtml() + * @covers XmlSelect::setDefault */ public function testSetDefaultAfterAddingOptions() { $this->select->addOption( 'foo1' ); @@ -110,6 +130,10 @@ class XmlSelectTest extends MediaWikiTestCase { '', $this->select->getHTML() ); } + /** + * @covers XmlSelect::setAttribute + * @covers XmlSelect::getAttribute + */ public function testGetAttributes() { # create some attributes $this->select->setAttribute( 'dummy', 0x777 ); diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index a19883257f..a0b33ee801 100644 --- a/tests/phpunit/includes/XmlTest.php +++ b/tests/phpunit/includes/XmlTest.php @@ -1,5 +1,8 @@