04841161153a3e873340f84ab1082aedf69cd815
3 class ContentHandlerTest
extends MediaWikiTestCase
{
5 public function dataGetDefaultModelFor() {
7 array( 'Foo', CONTENT_MODEL_WIKITEXT
),
8 array( 'Foo.js', CONTENT_MODEL_WIKITEXT
),
9 array( 'Foo/bar.js', CONTENT_MODEL_WIKITEXT
),
10 array( 'User:Foo', CONTENT_MODEL_WIKITEXT
),
11 array( 'User:Foo.js', CONTENT_MODEL_WIKITEXT
),
12 array( 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT
),
13 array( 'User:Foo/bar.css', CONTENT_MODEL_CSS
),
14 array( 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT
),
15 array( 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT
),
16 array( 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT
),
17 array( 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT
),
18 array( 'MediaWiki:Foo.css', CONTENT_MODEL_CSS
),
19 array( 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT
),
20 array( 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT
),
21 array( 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT
),
26 * @dataProvider dataGetDefaultModelFor
28 public function testGetDefaultModelFor( $title, $expectedModelName ) {
29 $title = Title
::newFromText( $title );
30 $this->assertEquals( $expectedModelName, ContentHandler
::getDefaultModelFor( $title ) );
33 public function testGetContentText_TextContent( ) {
34 global $wgContentHandlerTextFallback;
36 $content = new WikitextContent( "hello world" );
38 $wgContentHandlerTextFallback = 'fail';
39 $text = ContentHandler
::getContentText( $content );
40 $this->assertEquals( $content->getNativeData(), $text );
42 $wgContentHandlerTextFallback = 'serialize';
43 $text = ContentHandler
::getContentText( $content );
44 $this->assertEquals( $content->serialize(), $text );
46 $wgContentHandlerTextFallback = 'ignore';
47 $text = ContentHandler
::getContentText( $content );
48 $this->assertEquals( $content->getNativeData(), $text );
51 public function testGetContentText_NonTextContent( ) {
52 global $wgContentHandlerTextFallback;
54 $content = new DummyContentForTesting( "hello world" );
56 $wgContentHandlerTextFallback = 'fail';
59 $text = ContentHandler
::getContentText( $content );
61 $this->fail( "ContentHandler::getContentText should have thrown an exception for non-text Content object" );
62 } catch (MWException
$ex) {
66 $wgContentHandlerTextFallback = 'serialize';
67 $text = ContentHandler
::getContentText( $content );
68 $this->assertEquals( $content->serialize(), $text );
70 $wgContentHandlerTextFallback = 'ignore';
71 $text = ContentHandler
::getContentText( $content );
72 $this->assertNull( $text );
77 class DummyContentForTesting
extends Content
{
79 public function __construct( $data ) {
80 parent
::__construct( "DUMMY" );
85 public function serialize() {
86 return serialize( $this->data
);
90 * @return String a string representing the content in a way useful for building a full text search index.
91 * If no useful representation exists, this method returns an empty string.
93 public function getTextForSearchIndex()
99 * @return String the wikitext to include when another page includes this content, or false if the content is not
100 * includable in a wikitext page.
102 public function getWikitextForTransclusion()
108 * Returns a textual representation of the content suitable for use in edit summaries and log messages.
110 * @param int $maxlength maximum length of the summary text
111 * @return String the summary text
113 public function getTextForSummary($maxlength = 250)
119 * Returns native represenation of the data. Interpretation depends on the data model used,
120 * as given by getDataModel().
122 * @return mixed the native representation of the content. Could be a string, a nested array
123 * structure, an object, a binary blob... anything, really.
125 public function getNativeData()
131 * returns the content's nominal size in bogo-bytes.
135 public function getSize()
141 * Return a copy of this Content object. The following must be true for the object returned
142 * if $copy = $original->copy()
144 * * get_class($original) === get_class($copy)
145 * * $original->getModelName() === $copy->getModelName()
146 * * $original->equals( $copy )
148 * If and only if the Content object is imutable, the copy() method can and should
149 * return $this. That is, $copy === $original may be true, but only for imutable content
152 * @return Content. A copy of this object
154 public function copy()
160 * Returns true if this content is countable as a "real" wiki page, provided
161 * that it's also in a countable location (e.g. a current revision in the main namespace).
163 * @param $hasLinks Bool: if it is known whether this content contains links, provide this information here,
164 * to avoid redundant parsing to find out.
167 public function isCountable($hasLinks = null)
173 * @param IContextSource $context
175 * @param null|ParserOptions $options
176 * @param Boolean $generateHtml whether to generate Html (default: true). If false,
177 * the result of calling getText() on the ParserOutput object returned by
178 * this method is undefined.
180 * @return ParserOutput
182 public function getParserOutput(IContextSource
$context, $revId = null, ParserOptions
$options = NULL, $generateHtml = true)
184 return new ParserOutput( $this->data
);