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( ) {
72 array( "first paragraph
89 array( "first paragraph
103 * @dataProvider dataMerge3
105 public function testMerge3( $old, $mine, $yours, $expected ) {
109 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is not configured" );
112 if ( !file_exists( $wgDiff3 ) ) {
113 #XXX: this sucks, since it uses arcane internal knowledge about TextContentHandler::merge3 and wfMerge.
114 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is misconfigured: can't find $wgDiff3" );
118 $oldContent = new WikitextContent( $old );
119 $myContent = new WikitextContent( $mine );
120 $yourContent = new WikitextContent( $yours );
122 $merged = $this->handler
->merge3( $oldContent, $myContent, $yourContent );
124 $this->assertEquals( $expected, $merged ?
$merged->getNativeData() : $merged );
127 public static function dataGetAutosummary( ) {
130 'Hello there, world!',
133 '/^Redirected page .*Foo/'
140 '/^Created page .*Hello/'
144 'Hello there, world!',
151 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
152 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
153 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
156 '/^Replaced .*Hello/'
169 * @dataProvider dataGetAutosummary
171 public function testGetAutosummary( $old, $new, $flags, $expected ) {
172 global $wgLanguageCode, $wgContLang;
174 $oldContent = is_null( $old ) ?
null : new WikitextContent( $old );
175 $newContent = is_null( $new ) ?
null : new WikitextContent( $new );
177 $summary = $this->handler
->getAutosummary( $oldContent, $newContent, $flags );
179 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
183 * @todo Text case requires database, should be done by a test class in the Database group
186 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {}
190 * @todo Text case requires database, should be done by a test class in the Database group
193 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {}