From: daniel Date: Fri, 20 Apr 2012 10:42:59 +0000 (+0200) Subject: more tests for ContentHandler::getContentText X-Git-Tag: 1.31.0-rc.0~22097^2^2~232 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/bilan.php?a=commitdiff_plain;h=df3e1645058367fa959ce103c570324d65f8aed6;p=lhc%2Fweb%2Fwiklou.git more tests for ContentHandler::getContentText --- diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index c6daeff5ce..e4413b33ac 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -23,19 +23,20 @@ class MWContentSerializationException extends MWException { abstract class ContentHandler { /** - * Conveniance function for getting flat text from a Content object. This shleould only + * Conveniance function for getting flat text from a Content object. This should only * be used in the context of backwards compatibility with code that is not yet able * to handle Content objects! * - * If $content is equal to null or false, this method returns the empty string. + * If $content is null, this method returns the empty string. * - * If $content is an instance of TextContent, this method returns the flat text as returned by $content->getnativeData(). + * If $content is an instance of TextContent, this method returns the flat text as returned by $content->getNativeData(). * * If $content is not a TextContent object, the bahaviour of this method depends on the global $wgContentHandlerTextFallback: - * If $wgContentHandlerTextFallback is 'fail' and $content is not a TextContent object, an MWException is thrown. - * If $wgContentHandlerTextFallback is 'serialize' and $content is not a TextContent object, $content->serialize() + * * If $wgContentHandlerTextFallback is 'fail' and $content is not a TextContent object, an MWException is thrown. + * * If $wgContentHandlerTextFallback is 'serialize' and $content is not a TextContent object, $content->serialize() * is called to get a string form of the content. - * Otherwise, this method returns null. + * * If $wgContentHandlerTextFallback is 'ignore' and $content is not a TextContent object, this method returns null. + * * otherwise, the behaviour is undefined. * * @static * @param Content|null $content @@ -77,6 +78,7 @@ abstract class ContentHandler { * @param null|String $format the format to use for deserialization. If not given, the model's default format is used. * * @return Content a Content object representing $text + * @throw MWException if $model or $format is not supported or if $text can not be unserialized using $format. */ public static function makeContent( $text, Title $title, $modelName = null, $format = null ) { diff --git a/tests/phpunit/includes/ContentHandlerTest.php b/tests/phpunit/includes/ContentHandlerTest.php index 0484116115..0114c43899 100644 --- a/tests/phpunit/includes/ContentHandlerTest.php +++ b/tests/phpunit/includes/ContentHandlerTest.php @@ -30,6 +30,24 @@ class ContentHandlerTest extends MediaWikiTestCase { $this->assertEquals( $expectedModelName, ContentHandler::getDefaultModelFor( $title ) ); } + public function testGetContentText_Null( ) { + global $wgContentHandlerTextFallback; + + $content = null; + + $wgContentHandlerTextFallback = 'fail'; + $text = ContentHandler::getContentText( $content ); + $this->assertEquals( '', $text ); + + $wgContentHandlerTextFallback = 'serialize'; + $text = ContentHandler::getContentText( $content ); + $this->assertEquals( '', $text ); + + $wgContentHandlerTextFallback = 'ignore'; + $text = ContentHandler::getContentText( $content ); + $this->assertEquals( '', $text ); + } + public function testGetContentText_TextContent( ) { global $wgContentHandlerTextFallback;