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