MediaWiki
REL1_23
|
00001 <?php 00002 00006 class WikitextContentHandlerTest extends MediaWikiLangTestCase { 00007 00011 var $handler; 00012 00013 protected function setUp() { 00014 parent::setUp(); 00015 00016 $this->handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT ); 00017 } 00018 00022 public function testSerializeContent() { 00023 $content = new WikitextContent( 'hello world' ); 00024 00025 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content ) ); 00026 $this->assertEquals( 'hello world', $this->handler->serializeContent( $content, CONTENT_FORMAT_WIKITEXT ) ); 00027 00028 try { 00029 $this->handler->serializeContent( $content, 'dummy/foo' ); 00030 $this->fail( "serializeContent() should have failed on unknown format" ); 00031 } catch ( MWException $e ) { 00032 // ok, as expected 00033 } 00034 } 00035 00039 public function testUnserializeContent() { 00040 $content = $this->handler->unserializeContent( 'hello world' ); 00041 $this->assertEquals( 'hello world', $content->getNativeData() ); 00042 00043 $content = $this->handler->unserializeContent( 'hello world', CONTENT_FORMAT_WIKITEXT ); 00044 $this->assertEquals( 'hello world', $content->getNativeData() ); 00045 00046 try { 00047 $this->handler->unserializeContent( 'hello world', 'dummy/foo' ); 00048 $this->fail( "unserializeContent() should have failed on unknown format" ); 00049 } catch ( MWException $e ) { 00050 // ok, as expected 00051 } 00052 } 00053 00057 public function testMakeEmptyContent() { 00058 $content = $this->handler->makeEmptyContent(); 00059 00060 $this->assertTrue( $content->isEmpty() ); 00061 $this->assertEquals( '', $content->getNativeData() ); 00062 } 00063 00064 public static function dataIsSupportedFormat() { 00065 return array( 00066 array( null, true ), 00067 array( CONTENT_FORMAT_WIKITEXT, true ), 00068 array( 99887766, false ), 00069 ); 00070 } 00071 00078 public function testMakeRedirectContent( $title, $expected ) { 00079 global $wgContLang; 00080 $wgContLang->resetNamespaces(); 00081 00082 MagicWord::clearCache(); 00083 00084 if ( is_string( $title ) ) { 00085 $title = Title::newFromText( $title ); 00086 } 00087 $content = $this->handler->makeRedirectContent( $title ); 00088 $this->assertEquals( $expected, $content->serialize() ); 00089 } 00090 00091 public static function provideMakeRedirectContent() { 00092 return array( 00093 array( 'Hello', '#REDIRECT [[Hello]]' ), 00094 array( 'Template:Hello', '#REDIRECT [[Template:Hello]]' ), 00095 array( 'Hello#section', '#REDIRECT [[Hello#section]]' ), 00096 array( 'user:john_doe#section', '#REDIRECT [[User:John doe#section]]' ), 00097 array( 'MEDIAWIKI:FOOBAR', '#REDIRECT [[MediaWiki:FOOBAR]]' ), 00098 array( 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ), 00099 array( Title::makeTitle( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ), 00100 array( Title::makeTitle( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ), 00101 array( Title::makeTitle( NS_MAIN, 'Bar', 'fragment', 'google' ), '#REDIRECT [[google:Bar#fragment]]' ), 00102 ); 00103 } 00104 00109 public function testIsSupportedFormat( $format, $supported ) { 00110 $this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) ); 00111 } 00112 00113 public static function dataMerge3() { 00114 return array( 00115 array( 00116 "first paragraph 00117 00118 second paragraph\n", 00119 00120 "FIRST paragraph 00121 00122 second paragraph\n", 00123 00124 "first paragraph 00125 00126 SECOND paragraph\n", 00127 00128 "FIRST paragraph 00129 00130 SECOND paragraph\n", 00131 ), 00132 00133 array( "first paragraph 00134 second paragraph\n", 00135 00136 "Bla bla\n", 00137 00138 "Blubberdibla\n", 00139 00140 false, 00141 ), 00142 ); 00143 } 00144 00149 public function testMerge3( $old, $mine, $yours, $expected ) { 00150 $this->checkHasDiff3(); 00151 00152 // test merge 00153 $oldContent = new WikitextContent( $old ); 00154 $myContent = new WikitextContent( $mine ); 00155 $yourContent = new WikitextContent( $yours ); 00156 00157 $merged = $this->handler->merge3( $oldContent, $myContent, $yourContent ); 00158 00159 $this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged ); 00160 } 00161 00162 public static function dataGetAutosummary() { 00163 return array( 00164 array( 00165 'Hello there, world!', 00166 '#REDIRECT [[Foo]]', 00167 0, 00168 '/^Redirected page .*Foo/' 00169 ), 00170 00171 array( 00172 null, 00173 'Hello world!', 00174 EDIT_NEW, 00175 '/^Created page .*Hello/' 00176 ), 00177 00178 array( 00179 'Hello there, world!', 00180 '', 00181 0, 00182 '/^Blanked/' 00183 ), 00184 00185 array( 00186 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut 00187 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et 00188 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', 00189 'Hello world!', 00190 0, 00191 '/^Replaced .*Hello/' 00192 ), 00193 00194 array( 00195 'foo', 00196 'bar', 00197 0, 00198 '/^$/' 00199 ), 00200 ); 00201 } 00202 00207 public function testGetAutosummary( $old, $new, $flags, $expected ) { 00208 $oldContent = is_null( $old ) ? null : new WikitextContent( $old ); 00209 $newContent = is_null( $new ) ? null : new WikitextContent( $new ); 00210 00211 $summary = $this->handler->getAutosummary( $oldContent, $newContent, $flags ); 00212 00213 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" ); 00214 } 00215 00219 /* 00220 public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {} 00221 */ 00222 00226 /* 00227 public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {} 00228 */ 00229 }