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 ) {
110 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is not configured" );
113 if ( !file_exists( $wgDiff3 ) ) {
114 #XXX: this sucks, since it uses arcane internal knowledge about TextContentHandler::merge3 and wfMerge.
115 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is misconfigured: can't find $wgDiff3" );
119 $oldContent = new WikitextContent( $old );
120 $myContent = new WikitextContent( $mine );
121 $yourContent = new WikitextContent( $yours );
123 $merged = $this->handler
->merge3( $oldContent, $myContent, $yourContent );
125 $this->assertEquals( $expected, $merged ?
$merged->getNativeData() : $merged );
128 public function dataGetAutosummary( ) {
131 'Hello there, world!',
134 '/^Redirected page .*Foo/'
141 '/^Created page .*Hello/'
145 'Hello there, world!',
152 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
153 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
154 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
157 '/^Replaced .*Hello/'
170 * @dataProvider dataGetAutoSummary
172 public function testGetAutosummary( $old, $new, $flags, $expected ) {
173 global $wgLanguageCode, $wgContLang;
175 $oldContent = is_null( $old ) ?
null : new WikitextContent( $old );
176 $newContent = is_null( $new ) ?
null : new WikitextContent( $new );
178 $summary = $this->handler
->getAutosummary( $oldContent, $newContent, $flags );
180 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
184 * @todo Text case required database!
187 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {
192 * @todo Text case required database!
195 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {