4 * @group ContentHandler
6 class WikitextContentHandlerTest
extends MediaWikiTestCase
{
13 public function setup() {
15 $this->handler
= ContentHandler
::getForModelID( CONTENT_MODEL_WIKITEXT
);
18 public function testSerializeContent( ) {
19 $content = new WikitextContent( 'hello world' );
21 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content ) );
22 $this->assertEquals( 'hello world', $this->handler
->serializeContent( $content, CONTENT_FORMAT_WIKITEXT
) );
25 $this->handler
->serializeContent( $content, 'dummy/foo' );
26 $this->fail( "serializeContent() should have failed on unknown format" );
27 } catch ( MWException
$e ) {
32 public function testUnserializeContent( ) {
33 $content = $this->handler
->unserializeContent( 'hello world' );
34 $this->assertEquals( 'hello world', $content->getNativeData() );
36 $content = $this->handler
->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT
);
37 $this->assertEquals( 'hello world', $content->getNativeData() );
40 $this->handler
->unserializeContent( 'hello world', 'dummy/foo' );
41 $this->fail( "unserializeContent() should have failed on unknown format" );
42 } catch ( MWException
$e ) {
47 public function testMakeEmptyContent() {
48 $content = $this->handler
->makeEmptyContent();
50 $this->assertTrue( $content->isEmpty() );
51 $this->assertEquals( '', $content->getNativeData() );
54 public function dataIsSupportedFormat( ) {
57 array( CONTENT_FORMAT_WIKITEXT
, true ),
58 array( 99887766, false ),
63 * @dataProvider dataIsSupportedFormat
65 public function testIsSupportedFormat( $format, $supported ) {
66 $this->assertEquals( $supported, $this->handler
->isSupportedFormat( $format ) );
69 public function dataMerge3( ) {
71 array( "first paragraph
88 array( "first paragraph
102 * @dataProvider dataMerge3
104 public function testMerge3( $old, $mine, $yours, $expected ) {
108 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is not configured" );
111 if ( !file_exists( $wgDiff3 ) ) {
112 #XXX: this sucks, since it uses arcane internal knowledge about TextContentHandler::merge3 and wfMerge.
113 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is misconfigured: can't find $wgDiff3" );
117 $oldContent = new WikitextContent( $old );
118 $myContent = new WikitextContent( $mine );
119 $yourContent = new WikitextContent( $yours );
121 $merged = $this->handler
->merge3( $oldContent, $myContent, $yourContent );
123 $this->assertEquals( $expected, $merged ?
$merged->getNativeData() : $merged );
126 public function dataGetAutosummary( ) {
129 'Hello there, world!',
132 '/^Redirected page .*Foo/'
139 '/^Created page .*Hello/'
143 'Hello there, world!',
150 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
151 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
152 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
155 '/^Replaced .*Hello/'
168 * @dataProvider dataGetAutoSummary
170 public function testGetAutosummary( $old, $new, $flags, $expected ) {
171 global $wgLanguageCode, $wgContLang;
173 $oldContent = is_null( $old ) ?
null : new WikitextContent( $old );
174 $newContent = is_null( $new ) ?
null : new WikitextContent( $new );
176 $summary = $this->handler
->getAutosummary( $oldContent, $newContent, $flags );
178 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
182 * @todo Text case requires database, should be done by a test class in the Database group
185 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 ) {