Fix WikitextContent::getSection() for missing sections
authorTim Starling <tstarling@wikimedia.org>
Mon, 15 Oct 2012 00:49:28 +0000 (11:49 +1100)
committerTim Starling <tstarling@wikimedia.org>
Mon, 15 Oct 2012 00:49:28 +0000 (11:49 +1100)
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
tests/phpunit/includes/WikitextContentTest.php

index b660fc0..a17bf31 100644 (file)
@@ -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
+}
index e6118ea..b2d3bdf 100644 (file)
@@ -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() {