fd8e3ba58542bdccfc3cdf6c6b914ac3f3b52507
4 * @group ContentHandler
6 class UnknownContentTest
extends MediaWikiLangTestCase
{
10 * @return UnknownContent
12 public function newContent( $data, $type = 'xyzzy' ) {
13 return new UnknownContent( $data, $type );
17 * @covers UnknownContent::getParserOutput
19 public function testGetParserOutput() {
20 $this->setUserLang( 'en' );
21 $this->setContentLang( 'qqx' );
23 $title = Title
::newFromText( 'Test' );
24 $content = $this->newContent( 'Horkyporky' );
26 $po = $content->getParserOutput( $title );
27 $html = $po->getText();
28 $html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
30 $this->assertNotContains( 'Horkyporky', $html );
31 $this->assertNotContains( '(unsupported-content-model)', $html );
35 * @covers UnknownContent::preSaveTransform
37 public function testPreSaveTransform() {
38 $title = Title
::newFromText( 'Test' );
39 $user = $this->getTestUser()->getUser();
40 $content = $this->newContent( 'Horkyporky ~~~' );
42 $options = new ParserOptions();
44 $this->assertSame( $content, $content->preSaveTransform( $title, $user, $options ) );
48 * @covers UnknownContent::preloadTransform
50 public function testPreloadTransform() {
51 $title = Title
::newFromText( 'Test' );
52 $content = $this->newContent( 'Horkyporky ~~~' );
54 $options = new ParserOptions();
56 $this->assertSame( $content, $content->preloadTransform( $title, $options ) );
60 * @covers UnknownContent::getRedirectTarget
62 public function testGetRedirectTarget() {
63 $content = $this->newContent( '#REDIRECT [[Horkyporky]]' );
64 $this->assertNull( $content->getRedirectTarget() );
68 * @covers UnknownContent::isRedirect
70 public function testIsRedirect() {
71 $content = $this->newContent( '#REDIRECT [[Horkyporky]]' );
72 $this->assertFalse( $content->isRedirect() );
76 * @covers UnknownContent::isCountable
78 public function testIsCountable() {
79 $content = $this->newContent( '[[Horkyporky]]' );
80 $this->assertFalse( $content->isCountable( true ) );
84 * @covers UnknownContent::getTextForSummary
86 public function testGetTextForSummary() {
87 $content = $this->newContent( 'Horkyporky' );
88 $this->assertSame( '', $content->getTextForSummary() );
92 * @covers UnknownContent::getTextForSearchIndex
94 public function testGetTextForSearchIndex() {
95 $content = $this->newContent( 'Horkyporky' );
96 $this->assertSame( '', $content->getTextForSearchIndex() );
100 * @covers UnknownContent::copy
102 public function testCopy() {
103 $content = $this->newContent( 'hello world.' );
104 $copy = $content->copy();
106 $this->assertSame( $content, $copy );
110 * @covers UnknownContent::getSize
112 public function testGetSize() {
113 $content = $this->newContent( 'hello world.' );
115 $this->assertEquals( 12, $content->getSize() );
119 * @covers UnknownContent::getData
121 public function testGetData() {
122 $content = $this->newContent( 'hello world.' );
124 $this->assertEquals( 'hello world.', $content->getData() );
128 * @covers UnknownContent::getNativeData
130 public function testGetNativeData() {
131 $content = $this->newContent( 'hello world.' );
133 $this->assertEquals( 'hello world.', $content->getNativeData() );
137 * @covers UnknownContent::getWikitextForTransclusion
139 public function testGetWikitextForTransclusion() {
140 $content = $this->newContent( 'hello world.' );
142 $this->assertEquals( '', $content->getWikitextForTransclusion() );
146 * @covers UnknownContent::getModel
148 public function testGetModel() {
149 $content = $this->newContent( "hello world.", 'horkyporky' );
151 $this->assertEquals( 'horkyporky', $content->getModel() );
155 * @covers UnknownContent::getContentHandler
157 public function testGetContentHandler() {
158 $this->mergeMwGlobalArrayValue(
160 [ 'horkyporky' => 'UnknownContentHandler' ]
163 $content = $this->newContent( "hello world.", 'horkyporky' );
165 $this->assertInstanceOf( UnknownContentHandler
::class, $content->getContentHandler() );
166 $this->assertEquals( 'horkyporky', $content->getContentHandler()->getModelID() );
169 public static function dataIsEmpty() {
174 [ 'hallo welt.', false ],
179 * @dataProvider dataIsEmpty
180 * @covers UnknownContent::isEmpty
182 public function testIsEmpty( $text, $empty ) {
183 $content = $this->newContent( $text );
185 $this->assertEquals( $empty, $content->isEmpty() );
188 public function provideEquals() {
190 [ new UnknownContent( "hallo", 'horky' ), null, false ],
191 [ new UnknownContent( "hallo", 'horky' ), new UnknownContent( "hallo", 'horky' ), true ],
192 [ new UnknownContent( "hallo", 'horky' ), new UnknownContent( "hallo", 'xyzzy' ), false ],
193 [ new UnknownContent( "hallo", 'horky' ), new JavaScriptContent( "hallo" ), false ],
194 [ new UnknownContent( "hallo", 'horky' ), new WikitextContent( "hallo" ), false ],
199 * @dataProvider provideEquals
200 * @covers UnknownContent::equals
202 public function testEquals( Content
$a, Content
$b = null, $equal = false ) {
203 $this->assertEquals( $equal, $a->equals( $b ) );
206 public static function provideConvert() {
210 CONTENT_MODEL_WIKITEXT
,
216 CONTENT_MODEL_WIKITEXT
,
228 CONTENT_MODEL_JAVASCRIPT
,
236 * @covers UnknownContent::convert
238 public function testConvert() {
239 $content = $this->newContent( 'More horkyporky?' );
241 $this->assertFalse( $content->convert( CONTENT_MODEL_TEXT
) );
245 * @covers UnknownContent::__construct
246 * @covers UnknownContentHandler::serializeContent
248 public function testSerialize() {
249 $this->mergeMwGlobalArrayValue(
251 [ 'horkyporky' => 'UnknownContentHandler' ]
254 $content = $this->newContent( 'Hörkypörky', 'horkyporky' );
256 $this->assertSame( 'Hörkypörky', $content->serialize() );