From a4aef7d4952ce7b1887a4ba4f5c605e1c09cc770 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 20 Oct 2012 03:51:15 +0200 Subject: [PATCH] Fix warnings and enforce conventions in ContentHandler tests. Syntax: * Call parent setUp from setUp. * Set required globals for the test inside the test class instead of assuming the default settings. * Data providers are called statically and outside setUp/tearDown ("public static function") * Test function names should be prefixed with "test" ("testIsRedirect") * Marked 2 functions as unused. JavascriptContentTest has 2 data providers for tests that don't exist in it (nor in TextContentText) but do exist in WikitextContentTest. Style: * Single quotes * Remove odd comment "# =====" lines * Consistent tree wrapping with arrays. array( array( .. ) ); array( array( .. ) ); Some were closing on the previous line instead. Made it consistent now. * Remove odd indentation to make nested arrays line up: array( 'foo' => array( 'bar' => true, 'baz' => array() ) ) array( 'foo' => array( 'bar' => true, 'baz' => array() ) ) We don't do this kind of indentation because it is fragile and becomes outdates when any of the earlier keys ("foo") change. Converted to a regular tree instead. Also triggered git warnings for mixing spaces with tabs, which is almost always an detector for this style. * Not using @annotations in inline comments, reserved (and only parsed/meaningful) for block comments. Follows-up 8b568be5e2dfb889e1eeedbdca50b304864174f7 Change-Id: Ic55d539b9a58f448b550bcd98894d389764e0694 --- includes/AutoLoader.php | 10 +- includes/DefaultSettings.php | 12 +- tests/phpunit/MediaWikiTestCase.php | 2 +- tests/phpunit/includes/CssContentTest.php | 60 --------- .../{ => content}/ContentHandlerTest.php | 115 ++++++++++-------- .../includes/content/CssContentTest.php | 81 ++++++++++++ .../{ => content}/JavascriptContentTest.php | 71 +++++------ .../{ => content}/TextContentTest.php | 104 ++++++++-------- .../WikitextContentHandlerTest.php | 17 ++- .../{ => content}/WikitextContentTest.php | 85 +++++++------ 10 files changed, 308 insertions(+), 249 deletions(-) delete mode 100644 tests/phpunit/includes/CssContentTest.php rename tests/phpunit/includes/{ => content}/ContentHandlerTest.php (81%) create mode 100644 tests/phpunit/includes/content/CssContentTest.php rename tests/phpunit/includes/{ => content}/JavascriptContentTest.php (84%) rename tests/phpunit/includes/{ => content}/TextContentTest.php (78%) rename tests/phpunit/includes/{ => content}/WikitextContentHandlerTest.php (94%) rename tests/phpunit/includes/{ => content}/WikitextContentTest.php (89%) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index d98556ee34..c97c95a965 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -1095,13 +1095,15 @@ $wgAutoloadLocalClasses = array( 'TestRecorder' => 'tests/testHelpers.inc', # tests/phpunit - 'DummyContentHandlerForTesting' => 'tests/phpunit/includes/ContentHandlerTest.php', - 'DummyContentForTesting' => 'tests/phpunit/includes/ContentHandlerTest.php', - 'JavascriptContentTest' => 'tests/phpunit/includes/JavascriptContentTest.php', 'RevisionStorageTest' => 'tests/phpunit/includes/RevisionStorageTest.php', - 'TextContentTest' => 'tests/phpunit/includes/TextContentTest.php', 'WikiPageTest' => 'tests/phpunit/includes/WikiPageTest.php', + # tests/phpunit/content + 'DummyContentHandlerForTesting' => 'tests/phpunit/includes/content/ContentHandlerTest.php', + 'DummyContentForTesting' => 'tests/phpunit/includes/content/ContentHandlerTest.php', + 'JavascriptContentTest' => 'tests/phpunit/includes/content/JavascriptContentTest.php', + 'TextContentTest' => 'tests/phpunit/includes/content/TextContentTest.php', + # tests/phpunit/includes 'GenericArrayObjectTest' => 'tests/phpunit/includes/libs/GenericArrayObjectTest.php', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index cea63e07a3..c485b163a4 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -752,10 +752,14 @@ $wgMediaHandlers = array( * @since 1.21 */ $wgContentHandlers = array( - CONTENT_MODEL_WIKITEXT => 'WikitextContentHandler', // the usual case - CONTENT_MODEL_JAVASCRIPT => 'JavaScriptContentHandler', // dumb version, no syntax highlighting - CONTENT_MODEL_CSS => 'CssContentHandler', // dumb version, no syntax highlighting - CONTENT_MODEL_TEXT => 'TextContentHandler', // plain text, for use by extensions etc + // the usual case + CONTENT_MODEL_WIKITEXT => 'WikitextContentHandler', + // dumb version, no syntax highlighting + CONTENT_MODEL_JAVASCRIPT => 'JavaScriptContentHandler', + // dumb version, no syntax highlighting + CONTENT_MODEL_CSS => 'CssContentHandler', + // plain text, for use by extensions etc + CONTENT_MODEL_TEXT => 'TextContentHandler', ); /** diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 5bc36edea6..258dfec463 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -250,7 +250,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { throw new MWException( "MW global $name is not an array." ); } - //NOTE: do not use array_merge, it screws up for numeric keys. + // NOTE: do not use array_merge, it screws up for numeric keys. $merged = $GLOBALS[$name]; foreach ( $values as $k => $v ) { $merged[$k] = $v; diff --git a/tests/phpunit/includes/CssContentTest.php b/tests/phpunit/includes/CssContentTest.php deleted file mode 100644 index b6e8d293c5..0000000000 --- a/tests/phpunit/includes/CssContentTest.php +++ /dev/null @@ -1,60 +0,0 @@ -\n", - "
\nhello <world>\n\n
" ), - - array( - "MediaWiki:Test.css", - null, - "/* hello [[world]] */\n", - "
\n/* hello [[world]] */\n\n
", - array( 'Links' => array( // NOTE: assumes default settings for $wgTextModelsToParse - array( 'World' => 0 ) ) ) ), - - // @todo: more...? - ); - } - - - # ================================================================================================================= - - public function testGetModel() { - $content = $this->newContent( "hello world." ); - - $this->assertEquals( CONTENT_MODEL_CSS, $content->getModel() ); - } - - public function testGetContentHandler() { - $content = $this->newContent( "hello world." ); - - $this->assertEquals( CONTENT_MODEL_CSS, $content->getContentHandler()->getModelID() ); - } - - public function dataEquals( ) { - return array( - array( new CssContent( "hallo" ), null, false ), - array( new CssContent( "hallo" ), new CssContent( "hallo" ), true ), - array( new CssContent( "hallo" ), new WikitextContent( "hallo" ), false ), - array( new CssContent( "hallo" ), new CssContent( "HALLO" ), false ), - ); - } - -} diff --git a/tests/phpunit/includes/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php similarity index 81% rename from tests/phpunit/includes/ContentHandlerTest.php rename to tests/phpunit/includes/content/ContentHandlerTest.php index 797a3eedd8..60baedc614 100644 --- a/tests/phpunit/includes/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -2,46 +2,53 @@ /** * @group ContentHandler + * @group Database * - * @note: Declare that we are using the database, because otherwise we'll fail in the "databaseless" test run. + * @note Declare that we are using the database, because otherwise we'll fail in the "databaseless" test run. * This is because the LinkHolderArray used by the parser needs database access. * - * @group Database */ class ContentHandlerTest extends MediaWikiTestCase { public function setup() { + global $wgContLang; parent::setup(); - global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang; - - $wgExtraNamespaces[ 12312 ] = 'Dummy'; - $wgExtraNamespaces[ 12313 ] = 'Dummy_talk'; - - $wgNamespaceContentModels[ 12312 ] = "testing"; - $wgContentHandlers[ "testing" ] = 'DummyContentHandlerForTesting'; - - MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache - $wgContLang->resetNamespaces(); # reset namespace cache + $this->setMwGlobals( array( + 'wgExtraNamespaces' => array( + 12312 => 'Dummy', + 12313 => 'Dummy_talk', + ), + // The below tests assume that namespaces not mentioned here (Help, User, MediaWiki, ..) + // default to CONTENT_MODEL_WIKITEXT. + 'wgNamespaceContentModels' => array( + 12312 => 'testing', + ), + 'wgContentHandlers' => array( + CONTENT_MODEL_WIKITEXT => 'WikitextContentHandler', + CONTENT_MODEL_JAVASCRIPT => 'JavaScriptContentHandler', + CONTENT_MODEL_CSS => 'CssContentHandler', + CONTENT_MODEL_TEXT => 'TextContentHandler', + 'testing' => 'DummyContentHandlerForTesting', + ), + ) ); + + // Reset namespace cache + MWNamespace::getCanonicalNamespaces( true ); + $wgContLang->resetNamespaces(); } - public function teardown() { - global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang; - - unset( $wgExtraNamespaces[ 12312 ] ); - unset( $wgExtraNamespaces[ 12313 ] ); + public function tearDown() { + global $wgContLang; - unset( $wgNamespaceContentModels[ 12312 ] ); - unset( $wgContentHandlers[ "testing" ] ); + // Reset namespace cache + MWNamespace::getCanonicalNamespaces( true ); + $wgContLang->resetNamespaces(); - MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache - $wgContLang->resetNamespaces(); # reset namespace cache - - parent::teardown(); + parent::tearDown(); } - public function dataGetDefaultModelFor() { - //NOTE: assume that the Help namespace default to wikitext content + public static function dataGetDefaultModelFor() { return array( array( 'Help:Foo', CONTENT_MODEL_WIKITEXT ), array( 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ), @@ -68,6 +75,7 @@ class ContentHandlerTest extends MediaWikiTestCase { $title = Title::newFromText( $title ); $this->assertEquals( $expectedModelId, ContentHandler::getDefaultModelFor( $title ) ); } + /** * @dataProvider dataGetDefaultModelFor */ @@ -77,12 +85,13 @@ class ContentHandlerTest extends MediaWikiTestCase { $this->assertEquals( $expectedContentModel, $handler->getModelID() ); } - public function dataGetLocalizedName() { + public static function dataGetLocalizedName() { return array( array( null, null ), array( "xyzzy", null ), - array( CONTENT_MODEL_JAVASCRIPT, '/javascript/i' ), //XXX: depends on content language + // XXX: depends on content language + array( CONTENT_MODEL_JAVASCRIPT, '/javascript/i' ), ); } @@ -95,14 +104,16 @@ class ContentHandlerTest extends MediaWikiTestCase { if ( $expected ) { $this->assertNotNull( $name, "no name found for content model $id" ); $this->assertTrue( preg_match( $expected, $name ) > 0 , - "content model name for #$id did not match pattern $expected" ); + "content model name for #$id did not match pattern $expected" + ); } else { $this->assertEquals( $id, $name, "localization of unknown model $id should have " - . "fallen back to use the model id directly." ); + . "fallen back to use the model id directly." + ); } } - public function dataGetPageLanguage() { + public static function dataGetPageLanguage() { global $wgLanguageCode; return array( @@ -181,7 +192,7 @@ class ContentHandlerTest extends MediaWikiTestCase { $text = ContentHandler::getContentText( $content ); $this->fail( "ContentHandler::getContentText should have thrown an exception for non-text Content object" ); - } catch (MWException $ex) { + } catch ( MWException $ex ) { // as expected } @@ -194,10 +205,11 @@ class ContentHandlerTest extends MediaWikiTestCase { $this->assertNull( $text ); } - #public static function makeContent( $text, Title $title, $modelId = null, $format = null ) + /* + public static function makeContent( $text, Title $title, $modelId = null, $format = null ) {} + */ - public function dataMakeContent() { - //NOTE: assume the Help namespace defaults to wikitext content + public static function dataMakeContent() { return array( array( 'hallo', 'Help:Test', null, null, CONTENT_MODEL_WIKITEXT, 'hallo', false ), array( 'hallo', 'MediaWiki:Test.js', null, null, CONTENT_MODEL_JAVASCRIPT, 'hallo', false ), @@ -228,7 +240,9 @@ class ContentHandlerTest extends MediaWikiTestCase { try { $content = ContentHandler::makeContent( $data, $title, $modelId, $format ); - if ( $shouldFail ) $this->fail( "ContentHandler::makeContent should have failed!" ); + if ( $shouldFail ) { + $this->fail( "ContentHandler::makeContent should have failed!" ); + } $this->assertEquals( $expectedModelId, $content->getModel(), 'bad model id' ); $this->assertEquals( $expectedNativeData, $content->getNativeData(), 'bads native data' ); @@ -239,9 +253,11 @@ class ContentHandlerTest extends MediaWikiTestCase { } + /* public function testSupportsSections() { $this->markTestIncomplete( "not yet implemented" ); } + */ public function testRunLegacyHooks() { Hooks::register( 'testRunLegacyHooks', __CLASS__ . '::dummyHookHandler' ); @@ -277,8 +293,7 @@ class DummyContentHandlerForTesting extends ContentHandler { * @param null $format the desired serialization format * @return String serialized form of the content */ - public function serializeContent( Content $content, $format = null ) - { + public function serializeContent( Content $content, $format = null ) { return $content->serialize(); } @@ -289,8 +304,7 @@ class DummyContentHandlerForTesting extends ContentHandler { * @param null $format the format used for serialization * @return Content the Content object created by deserializing $blob */ - public function unserializeContent( $blob, $format = null ) - { + public function unserializeContent( $blob, $format = null ) { $d = unserialize( $blob ); return new DummyContentForTesting( $d ); } @@ -299,8 +313,7 @@ class DummyContentHandlerForTesting extends ContentHandler { * Creates an empty Content object of the type supported by this ContentHandler. * */ - public function makeEmptyContent() - { + public function makeEmptyContent() { return new DummyContentForTesting( '' ); } } @@ -327,7 +340,7 @@ class DummyContentForTesting extends AbstractContent { /** * @return String the wikitext to include when another page includes this content, or false if the content is not - * includable in a wikitext page. + * includable in a wikitext page. */ public function getWikitextForTransclusion() { return false; @@ -336,8 +349,8 @@ class DummyContentForTesting extends AbstractContent { /** * Returns a textual representation of the content suitable for use in edit summaries and log messages. * - * @param int $maxlength maximum length of the summary text - * @return String the summary text + * @param int $maxlength Maximum length of the summary text. + * @return string The summary text. */ public function getTextForSummary( $maxlength = 250 ) { return ''; @@ -348,7 +361,7 @@ class DummyContentForTesting extends AbstractContent { * as given by getDataModel(). * * @return mixed the native representation of the content. Could be a string, a nested array - * structure, an object, a binary blob... anything, really. + * structure, an object, a binary blob... anything, really. */ public function getNativeData() { @@ -376,7 +389,7 @@ class DummyContentForTesting extends AbstractContent { * return $this. That is, $copy === $original may be true, but only for imutable content * objects. * - * @return Content. A copy of this object + * @return Content. A copy of this object. */ public function copy() { return $this; @@ -386,8 +399,8 @@ class DummyContentForTesting extends AbstractContent { * Returns true if this content is countable as a "real" wiki page, provided * that it's also in a countable location (e.g. a current revision in the main namespace). * - * @param $hasLinks Bool: if it is known whether this content contains links, provide this information here, - * to avoid redundant parsing to find out. + * @param boolean $hasLinks if it is known whether this content contains links, provide this information here, + * to avoid redundant parsing to find out. * @return boolean */ public function isCountable( $hasLinks = null ) { @@ -398,9 +411,9 @@ class DummyContentForTesting extends AbstractContent { * @param Title $title * @param null $revId * @param null|ParserOptions $options - * @param Boolean $generateHtml whether to generate Html (default: true). If false, - * the result of calling getText() on the ParserOutput object returned by - * this method is undefined. + * @param boolean $generateHtml whether to generate Html (default: true). If false, + * the result of calling getText() on the ParserOutput object returned by + * this method is undefined. * * @return ParserOutput */ diff --git a/tests/phpunit/includes/content/CssContentTest.php b/tests/phpunit/includes/content/CssContentTest.php new file mode 100644 index 0000000000..b08a468b51 --- /dev/null +++ b/tests/phpunit/includes/content/CssContentTest.php @@ -0,0 +1,81 @@ +setName( '127.0.0.1' ); + + $this->setMwGlobals( array( + 'wgUser' => $user, + 'wgTextModelsToParse' => array( + CONTENT_MODEL_CSS, + ) + ) ); + } + + public function newContent( $text ) { + return new CssContent( $text ); + } + + public static function dataGetParserOutput() { + return array( + array( + 'MediaWiki:Test.css', + null, + "hello \n", + "
\nhello <world>\n\n
" + ), + array( + 'MediaWiki:Test.css', + null, + "/* hello [[world]] */\n", + "
\n/* hello [[world]] */\n\n
", + array( + 'Links' => array( + array( 'World' => 0 ) + ) + ) + ), + + // TODO: more...? + ); + } + + public function testGetModel() { + $content = $this->newContent( 'hello world.' ); + + $this->assertEquals( CONTENT_MODEL_CSS, $content->getModel() ); + } + + public function testGetContentHandler() { + $content = $this->newContent( 'hello world.' ); + + $this->assertEquals( CONTENT_MODEL_CSS, $content->getContentHandler()->getModelID() ); + } + + public static function dataEquals( ) { + return array( + array( new CssContent( 'hallo' ), null, false ), + array( new CssContent( 'hallo' ), new CssContent( 'hallo' ), true ), + array( new CssContent( 'hallo' ), new WikitextContent( 'hallo' ), false ), + array( new CssContent( 'hallo' ), new CssContent( 'HALLO' ), false ), + ); + } + + /** + * @dataProvider dataEquals + */ + public function testEquals( Content $a, Content $b = null, $equal = false ) { + $this->assertEquals( $equal, $a->equals( $b ) ); + } + +} diff --git a/tests/phpunit/includes/JavascriptContentTest.php b/tests/phpunit/includes/content/JavascriptContentTest.php similarity index 84% rename from tests/phpunit/includes/JavascriptContentTest.php rename to tests/phpunit/includes/content/JavascriptContentTest.php index d3810afd6d..e08252c5bd 100644 --- a/tests/phpunit/includes/JavascriptContentTest.php +++ b/tests/phpunit/includes/content/JavascriptContentTest.php @@ -2,7 +2,6 @@ /** * @group ContentHandler - * * @group Database * ^--- needed, because we do need the database to test link updates */ @@ -12,74 +11,79 @@ class JavascriptContentTest extends TextContentTest { return new JavascriptContent( $text ); } - - public function dataGetParserOutput() { + public static function dataGetParserOutput() { return array( array( - "MediaWiki:Test.js", + 'MediaWiki:Test.js', null, "hello \n", - "
\nhello <world>\n\n
" ), - + "
\nhello <world>\n\n
" + ), array( - "MediaWiki:Test.js", + 'MediaWiki:Test.js', null, "hello(); // [[world]]\n", "
\nhello(); // [[world]]\n\n
", - array( 'Links' => array( // NOTE: assumes default settings for $wgTextModelsToParse - array( 'World' => 0 ) ) ) ), + array( + 'Links' => array( + array( 'World' => 0 ) + ) + ) + ), - // @todo: more...? + // TODO: more...? ); } - public function dataGetSection() { + // XXX: Unused function + public static function dataGetSection() { return array( array( WikitextContentTest::$sections, - "0", + '0', null ), array( WikitextContentTest::$sections, - "2", + '2', null ), array( WikitextContentTest::$sections, - "8", + '8', null ), ); } - public function dataReplaceSection() { + // XXX: Unused function + public static function dataReplaceSection() { return array( array( WikitextContentTest::$sections, - "0", - "No more", + '0', + 'No more', null, null ), array( WikitextContentTest::$sections, - "", - "No more", + '', + 'No more', null, null ), array( WikitextContentTest::$sections, - "2", + '2', "== TEST ==\nmore fun", null, null ), array( WikitextContentTest::$sections, - "8", - "No more", + '8', + 'No more', null, null ), array( WikitextContentTest::$sections, - "new", - "No more", - "New", + 'new', + 'No more', + 'New', null ), ); @@ -93,7 +97,7 @@ class JavascriptContentTest extends TextContentTest { } // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional. - public function dataPreSaveTransform() { + public static function dataPreSaveTransform() { return array( array( 'hello this is ~~~', "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]", @@ -107,10 +111,10 @@ class JavascriptContentTest extends TextContentTest { ); } - public function dataPreloadTransform() { + public static function dataPreloadTransform() { return array( array( 'hello this is ~~~', - "hello this is ~~~", + 'hello this is ~~~', ), array( 'hello \'\'this\'\' is foobar', 'hello \'\'this\'\' is foobar', @@ -118,7 +122,7 @@ class JavascriptContentTest extends TextContentTest { ); } - public function dataGetRedirectTarget() { + public static function dataGetRedirectTarget() { return array( array( '#REDIRECT [[Test]]', null, @@ -152,8 +156,7 @@ class JavascriptContentTest extends TextContentTest { } */ - - public function dataIsCountable() { + public static function dataIsCountable() { return array( array( '', null, @@ -213,7 +216,7 @@ class JavascriptContentTest extends TextContentTest { ); } - public function dataGetTextForSummary() { + public static function dataGetTextForSummary() { return array( array( "hello\nworld.", 16, @@ -246,8 +249,6 @@ class JavascriptContentTest extends TextContentTest { $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" ); } - # ================================================================================================================= - public function testGetModel() { $content = $this->newContent( "hello world." ); @@ -260,7 +261,7 @@ class JavascriptContentTest extends TextContentTest { $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() ); } - public function dataEquals( ) { + public static function dataEquals( ) { return array( array( new JavascriptContent( "hallo" ), null, false ), array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ), diff --git a/tests/phpunit/includes/TextContentTest.php b/tests/phpunit/includes/content/TextContentTest.php similarity index 78% rename from tests/phpunit/includes/TextContentTest.php rename to tests/phpunit/includes/content/TextContentTest.php index b80af298d6..c867a83e2e 100644 --- a/tests/phpunit/includes/TextContentTest.php +++ b/tests/phpunit/includes/content/TextContentTest.php @@ -2,39 +2,48 @@ /** * @group ContentHandler - * * @group Database * ^--- needed, because we do need the database to test link updates */ class TextContentTest extends MediaWikiTestCase { + protected $context; - public function setup() { - global $wgUser; - + protected function setUp() { parent::setUp(); - // anon user - $wgUser = new User(); - $wgUser->setName( '127.0.0.1' ); + // Anon user + $user = new User(); + $user->setName( '127.0.0.1' ); + + $this->setMwGlobals( array( + 'wgUser' => $user, + 'wgTextModelsToParse' => array( + CONTENT_MODEL_WIKITEXT, + CONTENT_MODEL_CSS, + CONTENT_MODEL_JAVASCRIPT, + ) + ) ); $this->context = new RequestContext( new FauxRequest() ); - $this->context->setTitle( Title::newFromText( "Test" ) ); - $this->context->setUser( $wgUser ); + $this->context->setTitle( Title::newFromText( 'Test' ) ); + $this->context->setUser( $user ); } public function newContent( $text ) { return new TextContent( $text ); } - - public function dataGetParserOutput() { + public static function dataGetParserOutput() { return array( array( - "TextContentTest_testGetParserOutput", + 'TextContentTest_testGetParserOutput', CONTENT_MODEL_TEXT, "hello ''world'' & [[stuff]]\n", "hello ''world'' & [[stuff]]", - array( 'Links' => array() ) ), - // @todo: more...? + array( + 'Links' => array() + ) + ), + // TODO: more...? ); } @@ -65,18 +74,20 @@ class TextContentTest extends MediaWikiTestCase { } } - // @todo: assert more properties + // TODO: assert more properties } - public function dataPreSaveTransform() { + public static function dataPreSaveTransform() { return array( - array( #0: no signature resolution - "hello this is ~~~", - "hello this is ~~~", + array( + #0: no signature resolution + 'hello this is ~~~', + 'hello this is ~~~', ), - array( #1: rtrim + array( + #1: rtrim " Foo \n ", - " Foo", + ' Foo', ), ); } @@ -95,10 +106,11 @@ class TextContentTest extends MediaWikiTestCase { $this->assertEquals( $expected, $content->getNativeData() ); } - public function dataPreloadTransform() { + public static function dataPreloadTransform() { return array( - array( 'hello this is ~~~', - "hello this is ~~~", + array( + 'hello this is ~~~', + 'hello this is ~~~', ), ); } @@ -116,7 +128,7 @@ class TextContentTest extends MediaWikiTestCase { $this->assertEquals( $expected, $content->getNativeData() ); } - public function dataGetRedirectTarget() { + public static function dataGetRedirectTarget() { return array( array( '#REDIRECT [[Test]]', null, @@ -141,13 +153,12 @@ class TextContentTest extends MediaWikiTestCase { /** * @dataProvider dataGetRedirectTarget */ - public function isRedirect( $text, $expected ) { + public function testIsRedirect( $text, $expected ) { $content = $this->newContent( $text ); $this->assertEquals( !is_null($expected), $content->isRedirect() ); } - /** * @todo: test needs database! Should be done by a test class in the Database group. */ @@ -168,8 +179,7 @@ class TextContentTest extends MediaWikiTestCase { } */ - - public function dataIsCountable() { + public static function dataIsCountable() { return array( array( '', null, @@ -210,11 +220,11 @@ class TextContentTest extends MediaWikiTestCase { $v = $content->isCountable( $hasLinks, $this->context->getTitle() ); $wgArticleCountMethod = $old; - $this->assertEquals( $expected, $v, "isCountable() returned unexpected value " . var_export( $v, true ) - . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" ); + $this->assertEquals( $expected, $v, 'isCountable() returned unexpected value ' . var_export( $v, true ) + . ' instead of ' . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" ); } - public function dataGetTextForSummary() { + public static function dataGetTextForSummary() { return array( array( "hello\nworld.", 16, @@ -242,39 +252,37 @@ class TextContentTest extends MediaWikiTestCase { public function testGetTextForSearchIndex( ) { - $content = $this->newContent( "hello world." ); + $content = $this->newContent( 'hello world.' ); - $this->assertEquals( "hello world.", $content->getTextForSearchIndex() ); + $this->assertEquals( 'hello world.', $content->getTextForSearchIndex() ); } public function testCopy() { - $content = $this->newContent( "hello world." ); + $content = $this->newContent( 'hello world.' ); $copy = $content->copy(); - $this->assertTrue( $content->equals( $copy ), "copy must be equal to original" ); - $this->assertEquals( "hello world.", $copy->getNativeData() ); + $this->assertTrue( $content->equals( $copy ), 'copy must be equal to original' ); + $this->assertEquals( 'hello world.', $copy->getNativeData() ); } public function testGetSize( ) { - $content = $this->newContent( "hello world." ); + $content = $this->newContent( 'hello world.' ); $this->assertEquals( 12, $content->getSize() ); } public function testGetNativeData( ) { - $content = $this->newContent( "hello world." ); + $content = $this->newContent( 'hello world.' ); - $this->assertEquals( "hello world.", $content->getNativeData() ); + $this->assertEquals( 'hello world.', $content->getNativeData() ); } public function testGetWikitextForTransclusion( ) { - $content = $this->newContent( "hello world." ); + $content = $this->newContent( 'hello world.' ); - $this->assertEquals( "hello world.", $content->getWikitextForTransclusion() ); + $this->assertEquals( 'hello world.', $content->getWikitextForTransclusion() ); } - # ================================================================================================================= - public function testGetModel() { $content = $this->newContent( "hello world." ); @@ -287,7 +295,7 @@ class TextContentTest extends MediaWikiTestCase { $this->assertEquals( CONTENT_MODEL_TEXT, $content->getContentHandler()->getModelID() ); } - public function dataIsEmpty( ) { + public static function dataIsEmpty( ) { return array( array( '', true ), array( ' ', false ), @@ -305,7 +313,7 @@ class TextContentTest extends MediaWikiTestCase { $this->assertEquals( $empty, $content->isEmpty() ); } - public function dataEquals( ) { + public static function dataEquals( ) { return array( array( new TextContent( "hallo" ), null, false ), array( new TextContent( "hallo" ), new TextContent( "hallo" ), true ), @@ -322,7 +330,7 @@ class TextContentTest extends MediaWikiTestCase { $this->assertEquals( $equal, $a->equals( $b ) ); } - public function dataGetDeletionUpdates() { + public static function dataGetDeletionUpdates() { return array( array("TextContentTest_testGetSecondaryDataUpdates_1", CONTENT_MODEL_TEXT, "hello ''world''\n", @@ -332,7 +340,7 @@ class TextContentTest extends MediaWikiTestCase { CONTENT_MODEL_TEXT, "hello [[world test 21344]]\n", array( ) ), - // @todo: more...? + // TODO: more...? ); } diff --git a/tests/phpunit/includes/WikitextContentHandlerTest.php b/tests/phpunit/includes/content/WikitextContentHandlerTest.php similarity index 94% rename from tests/phpunit/includes/WikitextContentHandlerTest.php rename to tests/phpunit/includes/content/WikitextContentHandlerTest.php index 8db96d1b56..1ba85a91f2 100644 --- a/tests/phpunit/includes/WikitextContentHandlerTest.php +++ b/tests/phpunit/includes/content/WikitextContentHandlerTest.php @@ -10,8 +10,9 @@ class WikitextContentHandlerTest extends MediaWikiTestCase { */ var $handler; - public function setup() { + public function setUp() { parent::setUp(); + $this->handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT ); } @@ -51,7 +52,7 @@ class WikitextContentHandlerTest extends MediaWikiTestCase { $this->assertEquals( '', $content->getNativeData() ); } - public function dataIsSupportedFormat( ) { + public static function dataIsSupportedFormat( ) { return array( array( null, true ), array( CONTENT_FORMAT_WIKITEXT, true ), @@ -66,7 +67,7 @@ class WikitextContentHandlerTest extends MediaWikiTestCase { $this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) ); } - public function dataMerge3( ) { + public static function dataMerge3( ) { return array( array( "first paragraph @@ -123,7 +124,7 @@ class WikitextContentHandlerTest extends MediaWikiTestCase { $this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged ); } - public function dataGetAutosummary( ) { + public static function dataGetAutosummary( ) { return array( array( 'Hello there, world!', @@ -165,7 +166,7 @@ class WikitextContentHandlerTest extends MediaWikiTestCase { } /** - * @dataProvider dataGetAutoSummary + * @dataProvider dataGetAutosummary */ public function testGetAutosummary( $old, $new, $flags, $expected ) { global $wgLanguageCode, $wgContLang; @@ -182,16 +183,14 @@ class WikitextContentHandlerTest extends MediaWikiTestCase { * @todo Text case requires database, should be done by a test class in the Database group */ /* - public function testGetAutoDeleteReason( Title $title, &$hasHistory ) { - } + public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {} */ /** * @todo Text case requires database, should be done by a test class in the Database group */ /* - public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) { - } + public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {} */ } diff --git a/tests/phpunit/includes/WikitextContentTest.php b/tests/phpunit/includes/content/WikitextContentTest.php similarity index 89% rename from tests/phpunit/includes/WikitextContentTest.php rename to tests/phpunit/includes/content/WikitextContentTest.php index c1332a6052..ceb6d485f9 100644 --- a/tests/phpunit/includes/WikitextContentTest.php +++ b/tests/phpunit/includes/content/WikitextContentTest.php @@ -8,30 +8,59 @@ */ class WikitextContentTest extends TextContentTest { + static $sections = + +"Intro + +== stuff == +hello world + +== test == +just a test + +== foo == +more stuff +"; + public function newContent( $text ) { return new WikitextContent( $text ); } - public function dataGetParserOutput() { + public static function dataGetParserOutput() { return array( - array("WikitextContentTest_testGetParserOutput", CONTENT_MODEL_WIKITEXT, "hello ''world''\n", "

hello world\n

"), - // @todo: more...? + array( + "WikitextContentTest_testGetParserOutput", + CONTENT_MODEL_WIKITEXT, + "hello ''world''\n", + "

hello world\n

" + ), + // TODO: more...? ); } - public function dataGetSecondaryDataUpdates() { + public static function dataGetSecondaryDataUpdates() { return array( array( "WikitextContentTest_testGetSecondaryDataUpdates_1", CONTENT_MODEL_WIKITEXT, "hello ''world''\n", - array( 'LinksUpdate' => array( 'mRecursive' => true, - 'mLinks' => array() ) ) + array( + 'LinksUpdate' => array( + 'mRecursive' => true, + 'mLinks' => array() + ) + ) ), array( "WikitextContentTest_testGetSecondaryDataUpdates_2", CONTENT_MODEL_WIKITEXT, "hello [[world test 21344]]\n", - array( 'LinksUpdate' => array( 'mRecursive' => true, - 'mLinks' => array( array( 'World_test_21344' => 0 ) ) ) ) - ), - // @todo: more...? + array( + 'LinksUpdate' => array( + 'mRecursive' => true, + 'mLinks' => array( + array( 'World_test_21344' => 0 ) + ) + ) + ) + ), + // TODO: more...? ); } @@ -65,22 +94,7 @@ class WikitextContentTest extends TextContentTest { } } - - static $sections = - -"Intro - -== stuff == -hello world - -== test == -just a test - -== foo == -more stuff -"; - - public function dataGetSection() { + public static function dataGetSection() { return array( array( WikitextContentTest::$sections, "0", @@ -114,7 +128,7 @@ just a test" $this->assertEquals( $expectedText, $sectionText ); } - public function dataReplaceSection() { + public static function dataReplaceSection() { return array( array( WikitextContentTest::$sections, "0", @@ -166,7 +180,7 @@ just a test" $this->assertEquals( "== test ==\n\nhello world", $content->getNativeData() ); } - public function dataPreSaveTransform() { + public static function dataPreSaveTransform() { return array( array( 'hello this is ~~~', "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]", @@ -181,7 +195,7 @@ just a test" ); } - public function dataPreloadTransform() { + public static function dataPreloadTransform() { return array( array( 'hello this is ~~~', "hello this is ~~~", @@ -192,7 +206,7 @@ just a test" ); } - public function dataGetRedirectTarget() { + public static function dataGetRedirectTarget() { return array( array( '#REDIRECT [[Test]]', 'Test', @@ -206,7 +220,7 @@ just a test" ); } - public function dataGetTextForSummary() { + public static function dataGetTextForSummary() { return array( array( "hello\nworld.", 16, @@ -243,8 +257,7 @@ just a test" } */ - - public function dataIsCountable() { + public static function dataIsCountable() { return array( array( '', null, @@ -333,8 +346,6 @@ just a test" $this->assertEquals( $target->getFullText(), $newContent->getRedirectTarget()->getFullText() ); } - # ================================================================================================================= - public function testGetModel() { $content = $this->newContent( "hello world." ); @@ -347,7 +358,7 @@ just a test" $this->assertEquals( CONTENT_MODEL_WIKITEXT, $content->getContentHandler()->getModelID() ); } - public function dataEquals( ) { + public static function dataEquals( ) { return array( array( new WikitextContent( "hallo" ), null, false ), array( new WikitextContent( "hallo" ), new WikitextContent( "hallo" ), true ), @@ -357,7 +368,7 @@ just a test" ); } - public function dataGetDeletionUpdates() { + public static function dataGetDeletionUpdates() { return array( array("WikitextContentTest_testGetSecondaryDataUpdates_1", CONTENT_MODEL_WIKITEXT, "hello ''world''\n", -- 2.20.1