MediaWiki  REL1_21
WikitextContentHandlerTest.php
Go to the documentation of this file.
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(
00073                                 "first paragraph
00074 
00075                                         second paragraph\n",
00076 
00077                                 "FIRST paragraph
00078 
00079                                         second paragraph\n",
00080 
00081                                 "first paragraph
00082 
00083                                         SECOND paragraph\n",
00084 
00085                                 "FIRST paragraph
00086 
00087                                         SECOND paragraph\n",
00088                         ),
00089 
00090                         array( "first paragraph
00091                                         second paragraph\n",
00092 
00093                                 "Bla bla\n",
00094 
00095                                 "Blubberdibla\n",
00096 
00097                                 false,
00098                         ),
00099                 );
00100         }
00101 
00105         public function testMerge3( $old, $mine, $yours, $expected ) {
00106                 $this->checkHasDiff3();
00107 
00108                 // test merge
00109                 $oldContent = new WikitextContent( $old );
00110                 $myContent = new WikitextContent( $mine );
00111                 $yourContent = new WikitextContent( $yours );
00112 
00113                 $merged = $this->handler->merge3( $oldContent, $myContent, $yourContent );
00114 
00115                 $this->assertEquals( $expected, $merged ? $merged->getNativeData() : $merged );
00116         }
00117 
00118         public static function dataGetAutosummary() {
00119                 return array(
00120                         array(
00121                                 'Hello there, world!',
00122                                 '#REDIRECT [[Foo]]',
00123                                 0,
00124                                 '/^Redirected page .*Foo/'
00125                         ),
00126 
00127                         array(
00128                                 null,
00129                                 'Hello world!',
00130                                 EDIT_NEW,
00131                                 '/^Created page .*Hello/'
00132                         ),
00133 
00134                         array(
00135                                 'Hello there, world!',
00136                                 '',
00137                                 0,
00138                                 '/^Blanked/'
00139                         ),
00140 
00141                         array(
00142                                 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
00143                                 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
00144                                 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
00145                                 'Hello world!',
00146                                 0,
00147                                 '/^Replaced .*Hello/'
00148                         ),
00149 
00150                         array(
00151                                 'foo',
00152                                 'bar',
00153                                 0,
00154                                 '/^$/'
00155                         ),
00156                 );
00157         }
00158 
00162         public function testGetAutosummary( $old, $new, $flags, $expected ) {
00163                 $oldContent = is_null( $old ) ? null : new WikitextContent( $old );
00164                 $newContent = is_null( $new ) ? null : new WikitextContent( $new );
00165 
00166                 $summary = $this->handler->getAutosummary( $oldContent, $newContent, $flags );
00167 
00168                 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" );
00169         }
00170 
00174         /*
00175         public function testGetAutoDeleteReason( Title $title, &$hasHistory ) {}
00176         */
00177 
00181         /*
00182         public function testGetUndoContent( Revision $current, Revision $undo, Revision $undoafter = null ) {}
00183         */
00184 
00185 }