From 388b14a15de6c531d876796dde02605f046fcf53 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 11 Jan 2013 16:22:25 +0100 Subject: [PATCH] Misc follow-ups to I2fc3966e (a161c5e) - Also add LinkCache::addLinkObj() calls to isRedirect(), getLength() and getContentModel() - Changed error messages when LinkCache returns null, since this really should not happen anymore - Removed incorrect comments - Only use the value of the member variable if GAID_FOR_UPDATE is not passed (for consistency between the three methods) - Mark tests that need database access as such due to the call to Title::getContentModel() (generally called through Parser::getFunctionLang()) Change-Id: I84e0c47cdf7412f2b7fa5f296d066b64b7bbfd42 --- includes/Title.php | 40 ++++++------ tests/phpunit/includes/ExtraParserTest.php | 18 +++++- .../includes/parser/MagicVariableTest.php | 61 +++++++++++++++---- .../phpunit/includes/parser/TagHooksTest.php | 2 + 4 files changed, 88 insertions(+), 33 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index b11d8c1ad4..c74b6844a3 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -681,6 +681,7 @@ class Title { public function getContentModel() { if ( !$this->mContentModel ) { $linkCache = LinkCache::singleton(); + $linkCache->addLinkObj( $this ); $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' ); } @@ -2935,22 +2936,21 @@ class Title { * @return Bool */ public function isRedirect( $flags = 0 ) { - if ( !is_null( $this->mRedirect ) ) { + if ( !( $flags & Title::GAID_FOR_UPDATE ) && !is_null( $this->mRedirect ) ) { return $this->mRedirect; } - # Calling getArticleID() loads the field from cache as needed + if ( !$this->getArticleID( $flags ) ) { return $this->mRedirect = false; } $linkCache = LinkCache::singleton(); + $linkCache->addLinkObj( $this ); $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' ); + if ( $cached === null ) { - // TODO: check the assumption that the cache actually knows about this title - // and handle this, such as get the title from the database. - // See https://bugzilla.wikimedia.org/show_bug.cgi?id=37209 - wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() ); - wfDebug( wfBacktrace() ); + // Should not happen + throw new MWException( "LinkCache doesn't know redirect status of this title: " . $this->getPrefixedDBkey() ); } $this->mRedirect = (bool)$cached; @@ -2966,20 +2966,21 @@ class Title { * @return Int */ public function getLength( $flags = 0 ) { - if ( $this->mLength != -1 ) { + if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLength != -1 ) { return $this->mLength; } - # Calling getArticleID() loads the field from cache as needed + if ( !$this->getArticleID( $flags ) ) { return $this->mLength = 0; } + $linkCache = LinkCache::singleton(); + $linkCache->addLinkObj( $this ); $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' ); - if ( $cached === null ) { # check the assumption that the cache actually knows about this title - # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209 - # as a stop gap, perhaps log this, but don't throw an exception? - wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() ); - wfDebug( wfBacktrace() ); + + if ( $cached === null ) { + // Should not happen + throw new MWException( "LinkCache doesn't know redirect status of this title: " . $this->getPrefixedDBkey() ); } $this->mLength = intval( $cached ); @@ -2998,17 +2999,18 @@ class Title { if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLatestID !== false ) { return intval( $this->mLatestID ); } - # Calling getArticleID() loads the field from cache as needed + if ( !$this->getArticleID( $flags ) ) { return $this->mLatestID = 0; } + $linkCache = LinkCache::singleton(); $linkCache->addLinkObj( $this ); $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' ); - if ( $cached === null ) { # check the assumption that the cache actually knows about this title - # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209 - # as a stop gap, perhaps log this, but don't throw an exception? - throw new MWException( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() ); + + if ( $cached === null ) { + // Should not happen + throw new MWException( "LinkCache doesn't know latest revision ID of this title: " . $this->getPrefixedDBkey() ); } $this->mLatestID = intval( $cached ); diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php index 067cfc4a73..e0e5535ac6 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -26,7 +26,11 @@ class ExtraParserTest extends MediaWikiTestCase { MagicWord::clearCache(); } - // Bug 8689 - Long numeric lines kill the parser + /** + * Bug 8689 - Long numeric lines kill the parser + * + * @group Database + */ function testBug8689() { global $wgUser; $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n"; @@ -37,13 +41,20 @@ class ExtraParserTest extends MediaWikiTestCase { $this->parser->parse( $longLine, $t, $options )->getText() ); } - /* Test the parser entry points */ + /** + * Test the parser entry points + * + * @group Database + */ function testParse() { $title = Title::newFromText( __FUNCTION__ ); $parserOutput = $this->parser->parse( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options ); $this->assertEquals( "

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

", $parserOutput->getText() ); } + /** + * @group Database + */ function testPreSaveTransform() { global $wgUser; $title = Title::newFromText( __FUNCTION__ ); @@ -52,6 +63,9 @@ class ExtraParserTest extends MediaWikiTestCase { $this->assertEquals( "Test\nContent of ''Template:Foo''\n{{Bar}}", $outputText ); } + /** + * @group Database + */ function testPreprocess() { $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->preprocess( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options ); diff --git a/tests/phpunit/includes/parser/MagicVariableTest.php b/tests/phpunit/includes/parser/MagicVariableTest.php index dfcdafde35..51643ce4e3 100644 --- a/tests/phpunit/includes/parser/MagicVariableTest.php +++ b/tests/phpunit/includes/parser/MagicVariableTest.php @@ -65,44 +65,68 @@ class MagicVariableTest extends MediaWikiTestCase { # day - /** @dataProvider MediaWikiProvide::Days */ + /** + * @dataProvider MediaWikiProvide::Days + * @group Database + */ function testCurrentdayIsUnPadded( $day ) { $this->assertUnPadded( 'currentday', $day ); } - /** @dataProvider MediaWikiProvide::Days */ + /** + * @dataProvider MediaWikiProvide::Days + * @group Database + */ function testCurrentdaytwoIsZeroPadded( $day ) { $this->assertZeroPadded( 'currentday2', $day ); } - /** @dataProvider MediaWikiProvide::Days */ + /** + * @dataProvider MediaWikiProvide::Days + * @group Database + */ function testLocaldayIsUnPadded( $day ) { $this->assertUnPadded( 'localday', $day ); } - /** @dataProvider MediaWikiProvide::Days */ + /** + * @dataProvider MediaWikiProvide::Days + * @group Database + */ function testLocaldaytwoIsZeroPadded( $day ) { $this->assertZeroPadded( 'localday2', $day ); } # month - /** @dataProvider MediaWikiProvide::Months */ + /** + * @dataProvider MediaWikiProvide::Months + * @group Database + */ function testCurrentmonthIsZeroPadded( $month ) { $this->assertZeroPadded( 'currentmonth', $month ); } - /** @dataProvider MediaWikiProvide::Months */ + /** + * @dataProvider MediaWikiProvide::Months + * @group Database + */ function testCurrentmonthoneIsUnPadded( $month ) { $this->assertUnPadded( 'currentmonth1', $month ); } - /** @dataProvider MediaWikiProvide::Months */ + /** + * @dataProvider MediaWikiProvide::Months + * @group Database + */ function testLocalmonthIsZeroPadded( $month ) { $this->assertZeroPadded( 'localmonth', $month ); } - /** @dataProvider MediaWikiProvide::Months */ + /** + * @dataProvider MediaWikiProvide::Months + * @group Database + */ function testLocalmonthoneIsUnPadded( $month ) { $this->assertUnPadded( 'localmonth1', $month ); } @@ -110,24 +134,36 @@ class MagicVariableTest extends MediaWikiTestCase { # revision day - /** @dataProvider MediaWikiProvide::Days */ + /** + * @dataProvider MediaWikiProvide::Days + * @group Database + */ function testRevisiondayIsUnPadded( $day ) { $this->assertUnPadded( 'revisionday', $day ); } - /** @dataProvider MediaWikiProvide::Days */ + /** + * @dataProvider MediaWikiProvide::Days + * @group Database + */ function testRevisiondaytwoIsZeroPadded( $day ) { $this->assertZeroPadded( 'revisionday2', $day ); } # revision month - /** @dataProvider MediaWikiProvide::Months */ + /** + * @dataProvider MediaWikiProvide::Months + * @group Database + */ function testRevisionmonthIsZeroPadded( $month ) { $this->assertZeroPadded( 'revisionmonth', $month ); } - /** @dataProvider MediaWikiProvide::Months */ + /** + * @dataProvider MediaWikiProvide::Months + * @group Database + */ function testRevisionmonthoneIsUnPadded( $month ) { $this->assertUnPadded( 'revisionmonth1', $month ); } @@ -135,6 +171,7 @@ class MagicVariableTest extends MediaWikiTestCase { /** * Rough tests for {{SERVERNAME}} magic word * Bug 31176 + * @group Database */ function testServernameFromDifferentProtocols() { global $wgServer; diff --git a/tests/phpunit/includes/parser/TagHooksTest.php b/tests/phpunit/includes/parser/TagHooksTest.php index ed600790e9..d643264fd0 100644 --- a/tests/phpunit/includes/parser/TagHooksTest.php +++ b/tests/phpunit/includes/parser/TagHooksTest.php @@ -20,6 +20,7 @@ class TagHookTest extends MediaWikiTestCase { /** * @dataProvider provideValidNames + * @group Database */ function testTagHooks( $tag ) { global $wgParserConf, $wgContLang; @@ -47,6 +48,7 @@ class TagHookTest extends MediaWikiTestCase { /** * @dataProvider provideValidNames + * @group Database */ function testFunctionTagHooks( $tag ) { global $wgParserConf, $wgContLang; -- 2.20.1