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 dataIsSupportedFormat
66 public function testIsSupportedFormat( $format, $supported ) {
67 $this->assertEquals( $supported, $this->handler
->isSupportedFormat( $format ) );
70 public static function dataMerge3() {
90 array( "first paragraph
103 * @dataProvider dataMerge3
105 public function testMerge3( $old, $mine, $yours, $expected ) {
106 $this->checkHasDiff3();
109 $oldContent = new WikitextContent( $old );
110 $myContent = new WikitextContent( $mine );
111 $yourContent = new WikitextContent( $yours );
113 $merged = $this->handler
->merge3( $oldContent, $myContent, $yourContent );
115 $this->assertEquals( $expected, $merged ?
$merged->getNativeData() : $merged );
118 public static function dataGetAutosummary() {
121 'Hello there, world!',
124 '/^Redirected page .*Foo/'
131 '/^Created page .*Hello/'
135 'Hello there, world!',
142 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
143 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
144 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
147 '/^Replaced .*Hello/'
160 * @dataProvider dataGetAutosummary
162 public function testGetAutosummary( $old, $new, $flags, $expected ) {
163 $oldContent = is_null( $old ) ?
null : new WikitextContent( $old );
164 $newContent = is_null( $new ) ?
null : new WikitextContent( $new );
166 $summary = $this->handler
->getAutosummary( $oldContent, $newContent, $flags );
168 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
172 * @todo Text case requires database, should be done by a test class in the Database group
175 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {}
179 * @todo Text case requires database, should be done by a test class in the Database group
182 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {}