4 * @group ContentHandler
6 class WikitextContentHandlerTest
extends MediaWikiLangTestCase
{
13 public function setUp() {
16 $this->handler
= ContentHandler
::getForModelID( CONTENT_MODEL_WIKITEXT
);
19 public function testSerializeContent() {
20 $content = new WikitextContent( 'hello world' );
22 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content ) );
23 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content, CONTENT_FORMAT_WIKITEXT
) );
26 $this->handler
->serializeContent( $content, 'dummy/foo' );
27 $this->fail( "serializeContent() should have failed on unknown format" );
28 } catch ( MWException
$e ) {
33 public function testUnserializeContent() {
34 $content = $this->handler
->unserializeContent( 'hello world' );
35 $this->assertEquals( 'hello world', $content->getNativeData() );
37 $content = $this->handler
->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT
);
38 $this->assertEquals( 'hello world', $content->getNativeData() );
41 $this->handler
->unserializeContent( 'hello world', 'dummy/foo' );
42 $this->fail( "unserializeContent() should have failed on unknown format" );
43 } catch ( MWException
$e ) {
48 public function testMakeEmptyContent() {
49 $content = $this->handler
->makeEmptyContent();
51 $this->assertTrue( $content->isEmpty() );
52 $this->assertEquals( '', $content->getNativeData() );
55 public static function dataIsSupportedFormat() {
58 array( CONTENT_FORMAT_WIKITEXT
, true ),
59 array( 99887766, false ),
64 * @dataProvider provideMakeRedirectContent
65 * @param Title|string $title Title object or string for Title::newFromText()
66 * @param string $expected Serialized form of the content object built
68 public function testMakeRedirectContent( $title, $expected ) {
70 $wgContLang->resetNamespaces();
72 if ( is_string( $title ) ) {
73 $title = Title
::newFromText( $title );
75 $content = $this->handler
->makeRedirectContent( $title );
76 $this->assertEquals( $expected, $content->serialize() );
79 public static function provideMakeRedirectContent() {
81 array( 'Hello', '#REDIRECT [[Hello]]' ),
82 array( 'Template:Hello', '#REDIRECT [[Template:Hello]]' ),
83 array( 'Hello#section', '#REDIRECT [[Hello#section]]' ),
84 array( 'user:john_doe#section', '#REDIRECT [[User:John doe#section]]' ),
85 array( 'MEDIAWIKI:FOOBAR', '#REDIRECT [[MediaWiki:FOOBAR]]' ),
86 array( 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ),
87 array( Title
::makeTitle( NS_MAIN
, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ),
88 array( Title
::makeTitle( NS_MAIN
, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ),
89 array( Title
::makeTitle( NS_MAIN
, 'Bar', 'fragment', 'google' ), '#REDIRECT [[google:Bar#fragment]]' ),
94 * @dataProvider dataIsSupportedFormat
96 public function testIsSupportedFormat( $format, $supported ) {
97 $this->assertEquals( $supported, $this->handler
->isSupportedFormat( $format ) );
100 public static function dataMerge3() {
120 array( "first paragraph
133 * @dataProvider dataMerge3
135 public function testMerge3( $old, $mine, $yours, $expected ) {
136 $this->checkHasDiff3();
139 $oldContent = new WikitextContent( $old );
140 $myContent = new WikitextContent( $mine );
141 $yourContent = new WikitextContent( $yours );
143 $merged = $this->handler
->merge3( $oldContent, $myContent, $yourContent );
145 $this->assertEquals( $expected, $merged ?
$merged->getNativeData() : $merged );
148 public static function dataGetAutosummary() {
151 'Hello there, world!',
154 '/^Redirected page .*Foo/'
161 '/^Created page .*Hello/'
165 'Hello there, world!',
172 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
173 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
174 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
177 '/^Replaced .*Hello/'
190 * @dataProvider dataGetAutosummary
192 public function testGetAutosummary( $old, $new, $flags, $expected ) {
193 $oldContent = is_null( $old ) ?
null : new WikitextContent( $old );
194 $newContent = is_null( $new ) ?
null : new WikitextContent( $new );
196 $summary = $this->handler
->getAutosummary( $oldContent, $newContent, $flags );
198 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
202 * @todo Text case requires database, should be done by a test class in the Database group
205 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {}
209 * @todo Text case requires database, should be done by a test class in the Database group
212 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {}