4 * @group ContentHandler
6 class WikitextContentHandlerTest
extends MediaWikiTestCase
{
13 public function setup() {
14 $this->handler
= ContentHandler
::getForModelID( CONTENT_MODEL_WIKITEXT
);
17 public function teardown() {
20 public function testSerializeContent( ) {
21 $content = new WikitextContent( 'hello world' );
23 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content ) );
24 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content, CONTENT_FORMAT_WIKITEXT
) );
27 $this->handler
->serializeContent( $content, 'dummy/foo' );
28 $this->fail( "serializeContent() should have failed on unknown format" );
29 } catch ( MWException
$e ) {
34 public function testUnserializeContent( ) {
35 $content = $this->handler
->unserializeContent( 'hello world' );
36 $this->assertEquals( 'hello world', $content->getNativeData() );
38 $content = $this->handler
->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT
);
39 $this->assertEquals( 'hello world', $content->getNativeData() );
42 $this->handler
->unserializeContent( 'hello world', 'dummy/foo' );
43 $this->fail( "unserializeContent() should have failed on unknown format" );
44 } catch ( MWException
$e ) {
49 public function testMakeEmptyContent() {
50 $content = $this->handler
->makeEmptyContent();
52 $this->assertTrue( $content->isEmpty() );
53 $this->assertEquals( '', $content->getNativeData() );
56 public function dataIsSupportedFormat( ) {
59 array( CONTENT_FORMAT_WIKITEXT
, true ),
60 array( 99887766, false ),
65 * @dataProvider dataIsSupportedFormat
67 public function testIsSupportedFormat( $format, $supported ) {
68 $this->assertEquals( $supported, $this->handler
->isSupportedFormat( $format ) );
71 public function dataMerge3( ) {
73 array( "first paragraph
90 array( "first paragraph
104 * @dataProvider dataMerge3
106 public function testMerge3( $old, $mine, $yours, $expected ) {
107 $oldContent = new WikitextContent( $old );
108 $myContent = new WikitextContent( $mine );
109 $yourContent = new WikitextContent( $yours );
111 $merged = $this->handler
->merge3( $oldContent, $myContent, $yourContent );
113 $this->assertEquals( $expected, $merged ?
$merged->getNativeData() : $merged );
116 public function dataGetAutosummary( ) {
119 'Hello there, world!',
122 '/^Redirected page .*Foo/'
129 '/^Created page .*Hello/'
133 'Hello there, world!',
140 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
141 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
142 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
145 '/^Replaced .*Hello/'
158 * @dataProvider dataGetAutoSummary
160 public function testGetAutosummary( $old, $new, $flags, $expected ) {
161 global $wgLanguageCode, $wgContLang;
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 required database!
175 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {
180 * @todo Text case required database!
183 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {