MediaWiki
REL1_20
|
00001 <?php 00008 class WikiPageTest extends MediaWikiLangTestCase { 00009 00010 var $pages_to_delete; 00011 00012 function __construct( $name = null, array $data = array(), $dataName = '' ) { 00013 parent::__construct( $name, $data, $dataName ); 00014 00015 $this->tablesUsed = array_merge ( $this->tablesUsed, 00016 array( 'page', 00017 'revision', 00018 'text', 00019 00020 'recentchanges', 00021 'logging', 00022 00023 'page_props', 00024 'pagelinks', 00025 'categorylinks', 00026 'langlinks', 00027 'externallinks', 00028 'imagelinks', 00029 'templatelinks', 00030 'iwlinks' ) ); 00031 } 00032 00033 public function setUp() { 00034 parent::setUp(); 00035 $this->pages_to_delete = array(); 00036 } 00037 00038 public function tearDown() { 00039 foreach ( $this->pages_to_delete as $p ) { 00040 /* @var $p WikiPage */ 00041 00042 try { 00043 if ( $p->exists() ) { 00044 $p->doDeleteArticle( "testing done." ); 00045 } 00046 } catch ( MWException $ex ) { 00047 // fail silently 00048 } 00049 } 00050 parent::tearDown(); 00051 } 00052 00053 protected function newPage( $title ) { 00054 if ( is_string( $title ) ) $title = Title::newFromText( $title ); 00055 00056 $p = new WikiPage( $title ); 00057 00058 $this->pages_to_delete[] = $p; 00059 00060 return $p; 00061 } 00062 00063 protected function createPage( $page, $text, $model = null ) { 00064 if ( is_string( $page ) ) $page = Title::newFromText( $page ); 00065 if ( $page instanceof Title ) $page = $this->newPage( $page ); 00066 00067 $page->doEdit( $text, "testing", EDIT_NEW ); 00068 00069 return $page; 00070 } 00071 00072 public function testDoEdit() { 00073 $title = Title::newFromText( "WikiPageTest_testDoEdit" ); 00074 00075 $page = $this->newPage( $title ); 00076 00077 $text = "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam " 00078 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat."; 00079 00080 $page->doEdit( $text, "testing 1" ); 00081 00082 $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" ); 00083 $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" ); 00084 00085 $id = $page->getId(); 00086 00087 # ------------------------ 00088 $page = new WikiPage( $title ); 00089 00090 $retrieved = $page->getText(); 00091 $this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' ); 00092 00093 # ------------------------ 00094 $text = "At vero eos et accusam et justo duo [[dolores]] et ea rebum. " 00095 . "Stet clita kasd [[gubergren]], no sea takimata sanctus est."; 00096 00097 $page->doEdit( $text, "testing 2" ); 00098 00099 # ------------------------ 00100 $page = new WikiPage( $title ); 00101 00102 $retrieved = $page->getText(); 00103 $this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' ); 00104 00105 # ------------------------ 00106 $dbr = wfGetDB( DB_SLAVE ); 00107 $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) ); 00108 $n = $res->numRows(); 00109 $res->free(); 00110 00111 $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' ); 00112 } 00113 00114 public function testDoQuickEdit() { 00115 global $wgUser; 00116 00117 $page = $this->createPage( "WikiPageTest_testDoQuickEdit", "original text" ); 00118 00119 $text = "quick text"; 00120 $page->doQuickEdit( $text, $wgUser, "testing q" ); 00121 00122 # --------------------- 00123 $page = new WikiPage( $page->getTitle() ); 00124 $this->assertEquals( $text, $page->getText() ); 00125 } 00126 00127 public function testDoDeleteArticle() { 00128 $page = $this->createPage( "WikiPageTest_testDoDeleteArticle", "[[original text]] foo" ); 00129 $id = $page->getId(); 00130 00131 $page->doDeleteArticle( "testing deletion" ); 00132 00133 $this->assertFalse( $page->exists(), "WikiPage::exists should return false after page was deleted" ); 00134 $this->assertFalse( $page->getText(), "WikiPage::getText should return false after page was deleted" ); 00135 00136 $t = Title::newFromText( $page->getTitle()->getPrefixedText() ); 00137 $this->assertFalse( $t->exists(), "Title::exists should return false after page was deleted" ); 00138 00139 # ------------------------ 00140 $dbr = wfGetDB( DB_SLAVE ); 00141 $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) ); 00142 $n = $res->numRows(); 00143 $res->free(); 00144 00145 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' ); 00146 } 00147 00148 public function testDoDeleteUpdates() { 00149 $page = $this->createPage( "WikiPageTest_testDoDeleteArticle", "[[original text]] foo" ); 00150 $id = $page->getId(); 00151 00152 $page->doDeleteUpdates( $id ); 00153 00154 # ------------------------ 00155 $dbr = wfGetDB( DB_SLAVE ); 00156 $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) ); 00157 $n = $res->numRows(); 00158 $res->free(); 00159 00160 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' ); 00161 } 00162 00163 public function testGetRevision() { 00164 $page = $this->newPage( "WikiPageTest_testGetRevision" ); 00165 00166 $rev = $page->getRevision(); 00167 $this->assertNull( $rev ); 00168 00169 # ----------------- 00170 $this->createPage( $page, "some text" ); 00171 00172 $rev = $page->getRevision(); 00173 00174 $this->assertEquals( $page->getLatest(), $rev->getId() ); 00175 $this->assertEquals( "some text", $rev->getText() ); 00176 } 00177 00178 public function testGetText() { 00179 $page = $this->newPage( "WikiPageTest_testGetText" ); 00180 00181 $text = $page->getText(); 00182 $this->assertFalse( $text ); 00183 00184 # ----------------- 00185 $this->createPage( $page, "some text" ); 00186 00187 $text = $page->getText(); 00188 $this->assertEquals( "some text", $text ); 00189 } 00190 00191 public function testGetRawText() { 00192 $page = $this->newPage( "WikiPageTest_testGetRawText" ); 00193 00194 $text = $page->getRawText(); 00195 $this->assertFalse( $text ); 00196 00197 # ----------------- 00198 $this->createPage( $page, "some text" ); 00199 00200 $text = $page->getRawText(); 00201 $this->assertEquals( "some text", $text ); 00202 } 00203 00204 00205 public function testExists() { 00206 $page = $this->newPage( "WikiPageTest_testExists" ); 00207 $this->assertFalse( $page->exists() ); 00208 00209 # ----------------- 00210 $this->createPage( $page, "some text" ); 00211 $this->assertTrue( $page->exists() ); 00212 00213 $page = new WikiPage( $page->getTitle() ); 00214 $this->assertTrue( $page->exists() ); 00215 00216 # ----------------- 00217 $page->doDeleteArticle( "done testing" ); 00218 $this->assertFalse( $page->exists() ); 00219 00220 $page = new WikiPage( $page->getTitle() ); 00221 $this->assertFalse( $page->exists() ); 00222 } 00223 00224 public function dataHasViewableContent() { 00225 return array( 00226 array( 'WikiPageTest_testHasViewableContent', false, true ), 00227 array( 'Special:WikiPageTest_testHasViewableContent', false ), 00228 array( 'MediaWiki:WikiPageTest_testHasViewableContent', false ), 00229 array( 'Special:Userlogin', true ), 00230 array( 'MediaWiki:help', true ), 00231 ); 00232 } 00233 00237 public function testHasViewableContent( $title, $viewable, $create = false ) { 00238 $page = $this->newPage( $title ); 00239 $this->assertEquals( $viewable, $page->hasViewableContent() ); 00240 00241 if ( $create ) { 00242 $this->createPage( $page, "some text" ); 00243 $this->assertTrue( $page->hasViewableContent() ); 00244 00245 $page = new WikiPage( $page->getTitle() ); 00246 $this->assertTrue( $page->hasViewableContent() ); 00247 } 00248 } 00249 00250 public function dataGetRedirectTarget() { 00251 return array( 00252 array( 'WikiPageTest_testGetRedirectTarget_1', "hello world", null ), 00253 array( 'WikiPageTest_testGetRedirectTarget_2', "#REDIRECT [[hello world]]", "Hello world" ), 00254 ); 00255 } 00256 00260 public function testGetRedirectTarget( $title, $text, $target ) { 00261 $page = $this->createPage( $title, $text ); 00262 00263 # now, test the actual redirect 00264 $t = $page->getRedirectTarget(); 00265 $this->assertEquals( $target, is_null( $t ) ? null : $t->getPrefixedText() ); 00266 } 00267 00271 public function testIsRedirect( $title, $text, $target ) { 00272 $page = $this->createPage( $title, $text ); 00273 $this->assertEquals( !is_null( $target ), $page->isRedirect() ); 00274 } 00275 00276 public function dataIsCountable() { 00277 return array( 00278 00279 // any 00280 array( 'WikiPageTest_testIsCountable', 00281 '', 00282 'any', 00283 true 00284 ), 00285 array( 'WikiPageTest_testIsCountable', 00286 'Foo', 00287 'any', 00288 true 00289 ), 00290 00291 // comma 00292 array( 'WikiPageTest_testIsCountable', 00293 'Foo', 00294 'comma', 00295 false 00296 ), 00297 array( 'WikiPageTest_testIsCountable', 00298 'Foo, bar', 00299 'comma', 00300 true 00301 ), 00302 00303 // link 00304 array( 'WikiPageTest_testIsCountable', 00305 'Foo', 00306 'link', 00307 false 00308 ), 00309 array( 'WikiPageTest_testIsCountable', 00310 'Foo [[bar]]', 00311 'link', 00312 true 00313 ), 00314 00315 // redirects 00316 array( 'WikiPageTest_testIsCountable', 00317 '#REDIRECT [[bar]]', 00318 'any', 00319 false 00320 ), 00321 array( 'WikiPageTest_testIsCountable', 00322 '#REDIRECT [[bar]]', 00323 'comma', 00324 false 00325 ), 00326 array( 'WikiPageTest_testIsCountable', 00327 '#REDIRECT [[bar]]', 00328 'link', 00329 false 00330 ), 00331 00332 // not a content namespace 00333 array( 'Talk:WikiPageTest_testIsCountable', 00334 'Foo', 00335 'any', 00336 false 00337 ), 00338 array( 'Talk:WikiPageTest_testIsCountable', 00339 'Foo, bar', 00340 'comma', 00341 false 00342 ), 00343 array( 'Talk:WikiPageTest_testIsCountable', 00344 'Foo [[bar]]', 00345 'link', 00346 false 00347 ), 00348 00349 // not a content namespace, different model 00350 array( 'MediaWiki:WikiPageTest_testIsCountable.js', 00351 'Foo', 00352 'any', 00353 false 00354 ), 00355 array( 'MediaWiki:WikiPageTest_testIsCountable.js', 00356 'Foo, bar', 00357 'comma', 00358 false 00359 ), 00360 array( 'MediaWiki:WikiPageTest_testIsCountable.js', 00361 'Foo [[bar]]', 00362 'link', 00363 false 00364 ), 00365 ); 00366 } 00367 00368 00372 public function testIsCountable( $title, $text, $mode, $expected ) { 00373 global $wgArticleCountMethod; 00374 00375 $old = $wgArticleCountMethod; 00376 $wgArticleCountMethod = $mode; 00377 00378 $page = $this->createPage( $title, $text ); 00379 $editInfo = $page->prepareTextForEdit( $page->getText() ); 00380 00381 $v = $page->isCountable(); 00382 $w = $page->isCountable( $editInfo ); 00383 $wgArticleCountMethod = $old; 00384 00385 $this->assertEquals( $expected, $v, "isCountable( null ) returned unexpected value " . var_export( $v, true ) 00386 . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" ); 00387 00388 $this->assertEquals( $expected, $w, "isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true ) 00389 . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" ); 00390 } 00391 00392 public function dataGetParserOutput() { 00393 return array( 00394 array("hello ''world''\n", "<p>hello <i>world</i></p>"), 00395 // @todo: more...? 00396 ); 00397 } 00398 00402 public function testGetParserOutput( $text, $expectedHtml ) { 00403 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text ); 00404 00405 $opt = new ParserOptions(); 00406 $po = $page->getParserOutput( $opt ); 00407 $text = $po->getText(); 00408 00409 $text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments 00410 $text = preg_replace( '!\s*(</p>)!sm', '\1', $text ); # don't let tidy confuse us 00411 00412 $this->assertEquals( $expectedHtml, $text ); 00413 return $po; 00414 } 00415 00416 static $sections = 00417 00418 "Intro 00419 00420 == stuff == 00421 hello world 00422 00423 == test == 00424 just a test 00425 00426 == foo == 00427 more stuff 00428 "; 00429 00430 00431 public function dataReplaceSection() { 00432 return array( 00433 array( 'WikiPageTest_testReplaceSection', 00434 WikiPageTest::$sections, 00435 "0", 00436 "No more", 00437 null, 00438 trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest::$sections ) ) 00439 ), 00440 array( 'WikiPageTest_testReplaceSection', 00441 WikiPageTest::$sections, 00442 "", 00443 "No more", 00444 null, 00445 "No more" 00446 ), 00447 array( 'WikiPageTest_testReplaceSection', 00448 WikiPageTest::$sections, 00449 "2", 00450 "== TEST ==\nmore fun", 00451 null, 00452 trim( preg_replace( '/^== test ==.*== foo ==/sm', "== TEST ==\nmore fun\n\n== foo ==", WikiPageTest::$sections ) ) 00453 ), 00454 array( 'WikiPageTest_testReplaceSection', 00455 WikiPageTest::$sections, 00456 "8", 00457 "No more", 00458 null, 00459 trim( WikiPageTest::$sections ) 00460 ), 00461 array( 'WikiPageTest_testReplaceSection', 00462 WikiPageTest::$sections, 00463 "new", 00464 "No more", 00465 "New", 00466 trim( WikiPageTest::$sections ) . "\n\n== New ==\n\nNo more" 00467 ), 00468 ); 00469 } 00470 00474 public function testReplaceSection( $title, $text, $section, $with, $sectionTitle, $expected ) { 00475 $page = $this->createPage( $title, $text ); 00476 $text = $page->replaceSection( $section, $with, $sectionTitle ); 00477 $text = trim( $text ); 00478 00479 $this->assertEquals( $expected, $text ); 00480 } 00481 00482 /* @todo FIXME: fix this! 00483 public function testGetUndoText() { 00484 global $wgDiff3; 00485 00486 wfSuppressWarnings(); 00487 $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 ); 00488 wfRestoreWarnings(); 00489 00490 if( !$haveDiff3 ) { 00491 $this->markTestSkipped( "diff3 not installed or not found" ); 00492 return; 00493 } 00494 00495 $text = "one"; 00496 $page = $this->createPage( "WikiPageTest_testGetUndoText", $text ); 00497 $rev1 = $page->getRevision(); 00498 00499 $text .= "\n\ntwo"; 00500 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section two"); 00501 $rev2 = $page->getRevision(); 00502 00503 $text .= "\n\nthree"; 00504 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section three"); 00505 $rev3 = $page->getRevision(); 00506 00507 $text .= "\n\nfour"; 00508 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section four"); 00509 $rev4 = $page->getRevision(); 00510 00511 $text .= "\n\nfive"; 00512 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section five"); 00513 $rev5 = $page->getRevision(); 00514 00515 $text .= "\n\nsix"; 00516 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section six"); 00517 $rev6 = $page->getRevision(); 00518 00519 $undo6 = $page->getUndoText( $rev6 ); 00520 if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" ); 00521 $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 ); 00522 00523 $undo3 = $page->getUndoText( $rev4, $rev2 ); 00524 if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" ); 00525 $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 ); 00526 00527 $undo2 = $page->getUndoText( $rev2 ); 00528 if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" ); 00529 $this->assertEquals( "one\n\nfive", $undo2 ); 00530 } 00531 */ 00532 00536 public function broken_testDoRollback() { 00537 $admin = new User(); 00538 $admin->setName("Admin"); 00539 00540 $text = "one"; 00541 $page = $this->newPage( "WikiPageTest_testDoRollback" ); 00542 $page->doEdit( $text, "section one", EDIT_NEW, false, $admin ); 00543 00544 $user1 = new User(); 00545 $user1->setName( "127.0.1.11" ); 00546 $text .= "\n\ntwo"; 00547 $page = new WikiPage( $page->getTitle() ); 00548 $page->doEdit( $text, "adding section two", 0, false, $user1 ); 00549 00550 $user2 = new User(); 00551 $user2->setName( "127.0.2.13" ); 00552 $text .= "\n\nthree"; 00553 $page = new WikiPage( $page->getTitle() ); 00554 $page->doEdit( $text, "adding section three", 0, false, $user2 ); 00555 00556 # we are having issues with doRollback spuriously failing. apparently the last revision somehow goes missing 00557 # or not committed under some circumstances. so, make sure the last revision has the right user name. 00558 $dbr = wfGetDB( DB_SLAVE ); 00559 $this->assertEquals( 3, Revision::countByPageId( $dbr, $page->getId() ) ); 00560 00561 $page = new WikiPage( $page->getTitle() ); 00562 $rev3 = $page->getRevision(); 00563 $this->assertEquals( '127.0.2.13', $rev3->getUserText() ); 00564 00565 $rev2 = $rev3->getPrevious(); 00566 $this->assertEquals( '127.0.1.11', $rev2->getUserText() ); 00567 00568 $rev1 = $rev2->getPrevious(); 00569 $this->assertEquals( 'Admin', $rev1->getUserText() ); 00570 00571 # now, try the actual rollback 00572 $admin->addGroup( "sysop" ); #XXX: make the test user a sysop... 00573 $token = $admin->getEditToken( array( $page->getTitle()->getPrefixedText(), $user2->getName() ), null ); 00574 $errors = $page->doRollback( $user2->getName(), "testing revert", $token, false, $details, $admin ); 00575 00576 if ( $errors ) { 00577 $this->fail( "Rollback failed:\n" . print_r( $errors, true ) . ";\n" . print_r( $details, true ) ); 00578 } 00579 00580 $page = new WikiPage( $page->getTitle() ); 00581 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(), "rollback did not revert to the correct revision" ); 00582 $this->assertEquals( "one\n\ntwo", $page->getText() ); 00583 } 00584 00588 public function testDoRollback() { 00589 $admin = new User(); 00590 $admin->setName("Admin"); 00591 00592 $text = "one"; 00593 $page = $this->newPage( "WikiPageTest_testDoRollback" ); 00594 $page->doEdit( $text, "section one", EDIT_NEW, false, $admin ); 00595 $rev1 = $page->getRevision(); 00596 00597 $user1 = new User(); 00598 $user1->setName( "127.0.1.11" ); 00599 $text .= "\n\ntwo"; 00600 $page = new WikiPage( $page->getTitle() ); 00601 $page->doEdit( $text, "adding section two", 0, false, $user1 ); 00602 00603 # now, try the rollback 00604 $admin->addGroup( "sysop" ); #XXX: make the test user a sysop... 00605 $token = $admin->getEditToken( array( $page->getTitle()->getPrefixedText(), $user1->getName() ), null ); 00606 $errors = $page->doRollback( $user1->getName(), "testing revert", $token, false, $details, $admin ); 00607 00608 if ( $errors ) { 00609 $this->fail( "Rollback failed:\n" . print_r( $errors, true ) . ";\n" . print_r( $details, true ) ); 00610 } 00611 00612 $page = new WikiPage( $page->getTitle() ); 00613 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(), "rollback did not revert to the correct revision" ); 00614 $this->assertEquals( "one", $page->getText() ); 00615 } 00616 00617 public function dataGetAutosummary( ) { 00618 return array( 00619 array( 00620 'Hello there, world!', 00621 '#REDIRECT [[Foo]]', 00622 0, 00623 '/^Redirected page .*Foo/' 00624 ), 00625 00626 array( 00627 null, 00628 'Hello world!', 00629 EDIT_NEW, 00630 '/^Created page .*Hello/' 00631 ), 00632 00633 array( 00634 'Hello there, world!', 00635 '', 00636 0, 00637 '/^Blanked/' 00638 ), 00639 00640 array( 00641 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut 00642 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et 00643 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', 00644 'Hello world!', 00645 0, 00646 '/^Replaced .*Hello/' 00647 ), 00648 00649 array( 00650 'foo', 00651 'bar', 00652 0, 00653 '/^$/' 00654 ), 00655 ); 00656 } 00657 00661 public function testGetAutosummary( $old, $new, $flags, $expected ) { 00662 $page = $this->newPage( "WikiPageTest_testGetAutosummary" ); 00663 00664 $summary = $page->getAutosummary( $old, $new, $flags ); 00665 00666 $this->assertTrue( (bool)preg_match( $expected, $summary ), "Autosummary didn't match expected pattern $expected: $summary" ); 00667 } 00668 00669 public function dataGetAutoDeleteReason( ) { 00670 return array( 00671 array( 00672 array(), 00673 false, 00674 false 00675 ), 00676 00677 array( 00678 array( 00679 array( "first edit", null ), 00680 ), 00681 "/first edit.*only contributor/", 00682 false 00683 ), 00684 00685 array( 00686 array( 00687 array( "first edit", null ), 00688 array( "second edit", null ), 00689 ), 00690 "/second edit.*only contributor/", 00691 true 00692 ), 00693 00694 array( 00695 array( 00696 array( "first edit", "127.0.2.22" ), 00697 array( "second edit", "127.0.3.33" ), 00698 ), 00699 "/second edit/", 00700 true 00701 ), 00702 00703 array( 00704 array( 00705 array( "first edit: " 00706 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam " 00707 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. " 00708 . "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea " 00709 . "takimata sanctus est Lorem ipsum dolor sit amet.'", null ), 00710 ), 00711 '/first edit:.*\.\.\."/', 00712 false 00713 ), 00714 00715 array( 00716 array( 00717 array( "first edit", "127.0.2.22" ), 00718 array( "", "127.0.3.33" ), 00719 ), 00720 "/before blanking.*first edit/", 00721 true 00722 ), 00723 00724 ); 00725 } 00726 00730 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) { 00731 global $wgUser; 00732 00733 $page = $this->newPage( "WikiPageTest_testGetAutoDeleteReason" ); 00734 00735 $c = 1; 00736 00737 foreach ( $edits as $edit ) { 00738 $user = new User(); 00739 00740 if ( !empty( $edit[1] ) ) $user->setName( $edit[1] ); 00741 else $user = $wgUser; 00742 00743 $page->doEdit( $edit[0], "test edit $c", $c < 2 ? EDIT_NEW : 0, false, $user ); 00744 00745 $c += 1; 00746 } 00747 00748 $reason = $page->getAutoDeleteReason( $hasHistory ); 00749 00750 if ( is_bool( $expectedResult ) || is_null( $expectedResult ) ) $this->assertEquals( $expectedResult, $reason ); 00751 else $this->assertTrue( (bool)preg_match( $expectedResult, $reason ), "Autosummary didn't match expected pattern $expectedResult: $reason" ); 00752 00753 $this->assertEquals( $expectedHistory, $hasHistory, "expected \$hasHistory to be " . var_export( $expectedHistory, true ) ); 00754 00755 $page->doDeleteArticle( "done" ); 00756 } 00757 00758 public function dataPreSaveTransform() { 00759 return array( 00760 array( 'hello this is ~~~', 00761 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]", 00762 ), 00763 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>', 00764 'hello \'\'this\'\' is <nowiki>~~~</nowiki>', 00765 ), 00766 ); 00767 } 00768 00772 public function testPreSaveTransform( $text, $expected ) { 00773 $this->hideDeprecated( 'WikiPage::preSaveTransform' ); 00774 $user = new User(); 00775 $user->setName("127.0.0.1"); 00776 00777 $page = $this->newPage( "WikiPageTest_testPreloadTransform" ); 00778 $text = $page->preSaveTransform( $text, $user ); 00779 00780 $this->assertEquals( $expected, $text ); 00781 } 00782 00783 } 00784