From 16f25691ea5382eb333bcd6801e714727e68704e Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 15 Oct 2012 11:49:28 +1100 Subject: [PATCH] Fix WikitextContent::getSection() for missing sections Make WikitextContent::getSection() return false when the section is missing, as per the documented behaviour for Content::getSection(). Fix a test so that it doesn't generate a PHP fatal error if getSection() returns false. Should fix the current Jenkins build failure: https://integration.mediawiki.org/ci/job/MediaWiki-Tests-Misc/6989/testReport/junit/%28root%29/WikitextContentTest__testGetSection/testGetSection_with_data_set__2/ Change-Id: Ifa85f8eed50943d8ece32555d06b3e989077da46 --- includes/content/WikitextContent.php | 8 ++++++-- tests/phpunit/includes/WikitextContentTest.php | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/includes/content/WikitextContent.php b/includes/content/WikitextContent.php index b660fc092d..a17bf319a7 100644 --- a/includes/content/WikitextContent.php +++ b/includes/content/WikitextContent.php @@ -17,7 +17,11 @@ class WikitextContent extends TextContent { $text = $this->getNativeData(); $sect = $wgParser->getSection( $text, $section, false ); - return new WikitextContent( $sect ); + if ( $sect === false ) { + return false; + } else { + return new WikitextContent( $sect ); + } } /** @@ -286,4 +290,4 @@ class WikitextContent extends TextContent { public function matchMagicWord( MagicWord $word ) { return $word->match( $this->getNativeData() ); } -} \ No newline at end of file +} diff --git a/tests/phpunit/includes/WikitextContentTest.php b/tests/phpunit/includes/WikitextContentTest.php index e6118ea0bb..b2d3bdff0e 100644 --- a/tests/phpunit/includes/WikitextContentTest.php +++ b/tests/phpunit/includes/WikitextContentTest.php @@ -105,8 +105,13 @@ just a test" $content = $this->newContent( $text ); $sectionContent = $content->getSection( $sectionId ); + if ( is_object( $sectionContent ) ) { + $sectionText = $sectionContent->getNativeData(); + } else { + $sectionText = $sectionContent; + } - $this->assertEquals( $expectedText, is_null( $sectionContent ) ? null : $sectionContent->getNativeData() ); + $this->assertEquals( $expectedText, $sectionText ); } public function dataReplaceSection() { -- 2.20.1