MediaWiki
master
|
00001 <?php 00002 00006 class WikitextContentHandlerTest extends MediaWikiLangTestCase { 00007 00011 var $handler; 00012 00013 public function setUp() { 00014 parent::setUp(); 00015 00016 $this->handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT ); 00017 } 00018 00019 public function testSerializeContent( ) { 00020 $content = new WikitextContent( 'hello world' ); 00021 00022 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content ) ); 00023 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content, CONTENT_FORMAT_WIKITEXT ) ); 00024 00025 try { 00026 $this->handler->serializeContent( $content, 'dummy/foo' ); 00027 $this->fail( "serializeContent() should have failed on unknown format" ); 00028 } catch ( MWException $e ) { 00029 // ok, as expected 00030 } 00031 } 00032 00033 public function testUnserializeContent( ) { 00034 $content = $this->handler->unserializeContent( 'hello world' ); 00035 $this->assertEquals( 'hello world', $content->getNativeData() ); 00036 00037 $content = $this->handler->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT ); 00038 $this->assertEquals( 'hello world', $content->getNativeData() ); 00039 00040 try { 00041 $this->handler->unserializeContent( 'hello world', 'dummy/foo' ); 00042 $this->fail( "unserializeContent() should have failed on unknown format" ); 00043 } catch ( MWException $e ) { 00044 // ok, as expected 00045 } 00046 } 00047 00048 public function testMakeEmptyContent() { 00049 $content = $this->handler->makeEmptyContent(); 00050 00051 $this->assertTrue( $content->isEmpty() ); 00052 $this->assertEquals( '', $content->getNativeData() ); 00053 } 00054 00055 public static function dataIsSupportedFormat( ) { 00056 return array( 00057 array( null, true ), 00058 array( CONTENT_FORMAT_WIKITEXT, true ), 00059 array( 99887766, false ), 00060 ); 00061 } 00062 00066 public function testIsSupportedFormat( $format, $supported ) { 00067 $this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) ); 00068 } 00069 00070 public static function dataMerge3( ) { 00071 return array( 00072 array( "first paragraph 00073 00074 second paragraph\n", 00075 00076 "FIRST paragraph 00077 00078 second paragraph\n", 00079 00080 "first paragraph 00081 00082 SECOND paragraph\n", 00083 00084 "FIRST paragraph 00085 00086 SECOND paragraph\n", 00087 ), 00088 00089 array( "first paragraph 00090 second paragraph\n", 00091 00092 "Bla bla\n", 00093 00094 "Blubberdibla\n", 00095 00096 false, 00097 ), 00098 00099 ); 00100 } 00101 00105 public function testMerge3( $old, $mine, $yours, $expected ) { 00106 global $wgDiff3; 00107 00108 if ( !$wgDiff3 ) { 00109 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is not configured" ); 00110 } 00111 00112 if ( !file_exists( $wgDiff3 ) ) { 00113 #XXX: this sucks, since it uses arcane internal knowledge about TextContentHandler::merge3 and wfMerge. 00114 $this->markTestSkipped( "Can't test merge3(), since \$wgDiff3 is misconfigured: can't find $wgDiff3" ); 00115 } 00116 00117 // test merge 00118 $oldContent = new WikitextContent( $old ); 00119 $myContent = new WikitextContent( $mine ); 00120 $yourContent = new WikitextContent( $yours ); 00121 00122 $merged = $this->handler->merge3( $oldContent, $myContent, $yourContent ); 00123 00124 $this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged ); 00125 } 00126 00127 public static function dataGetAutosummary( ) { 00128 return array( 00129 array( 00130 'Hello there, world!', 00131 '#REDIRECT [[Foo]]', 00132 0, 00133 '/^Redirected page .*Foo/' 00134 ), 00135 00136 array( 00137 null, 00138 'Hello world!', 00139 EDIT_NEW, 00140 '/^Created page .*Hello/' 00141 ), 00142 00143 array( 00144 'Hello there, world!', 00145 '', 00146 0, 00147 '/^Blanked/' 00148 ), 00149 00150 array( 00151 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut 00152 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et 00153 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', 00154 'Hello world!', 00155 0, 00156 '/^Replaced .*Hello/' 00157 ), 00158 00159 array( 00160 'foo', 00161 'bar', 00162 0, 00163 '/^$/' 00164 ), 00165 ); 00166 } 00167 00171 public function testGetAutosummary( $old, $new, $flags, $expected ) { 00172 global $wgLanguageCode, $wgContLang; 00173 00174 $oldContent = is_null( $old ) ? null : new WikitextContent( $old ); 00175 $newContent = is_null( $new ) ? null : new WikitextContent( $new ); 00176 00177 $summary = $this->handler->getAutosummary( $oldContent, $newContent, $flags ); 00178 00179 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" ); 00180 } 00181 00185 /* 00186 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {} 00187 */ 00188 00192 /* 00193 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {} 00194 */ 00195 00196 }