3 * @group ContentHandler
5 * ^--- important, causes temporary tables to be used instead of the real database
9 class WikiPageTest
extends MediaWikiLangTestCase
{
13 function __construct( $name = null, array $data = array(), $dataName = '' ) {
14 parent
::__construct( $name, $data, $dataName );
16 $this->tablesUsed
= array_merge(
35 protected function setUp() {
37 $this->pages_to_delete
= array();
39 LinkCache
::singleton()->clear(); # avoid cached redirect status, etc
42 protected function tearDown() {
43 foreach ( $this->pages_to_delete
as $p ) {
44 /* @var $p WikiPage */
48 $p->doDeleteArticle( "testing done." );
50 } catch ( MWException
$ex ) {
59 * @param String $model
62 protected function newPage( $title, $model = null ) {
63 if ( is_string( $title ) ) {
64 $ns = $this->getDefaultWikitextNS();
65 $title = Title
::newFromText( $title, $ns );
68 $p = new WikiPage( $title );
70 $this->pages_to_delete
[] = $p;
76 * @param String|Title|WikiPage $page
82 protected function createPage( $page, $text, $model = null ) {
83 if ( is_string( $page ) ||
$page instanceof Title
) {
84 $page = $this->newPage( $page, $model );
87 $content = ContentHandler
::makeContent( $text, $page->getTitle(), $model );
88 $page->doEditContent( $content, "testing", EDIT_NEW
);
93 public function testDoEditContent() {
94 $page = $this->newPage( "WikiPageTest_testDoEditContent" );
95 $title = $page->getTitle();
97 $content = ContentHandler
::makeContent( "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
98 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
99 $title, CONTENT_MODEL_WIKITEXT
);
101 $page->doEditContent( $content, "[[testing]] 1" );
103 $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
104 $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" );
105 $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
106 $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
108 $id = $page->getId();
110 # ------------------------
111 $dbr = wfGetDB( DB_SLAVE
);
112 $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
113 $n = $res->numRows();
116 $this->assertEquals( 1, $n, 'pagelinks should contain one link from the page' );
118 # ------------------------
119 $page = new WikiPage( $title );
121 $retrieved = $page->getContent();
122 $this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
124 # ------------------------
125 $content = ContentHandler
::makeContent( "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
126 . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.",
127 $title, CONTENT_MODEL_WIKITEXT
);
129 $page->doEditContent( $content, "testing 2" );
131 # ------------------------
132 $page = new WikiPage( $title );
134 $retrieved = $page->getContent();
135 $this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
137 # ------------------------
138 $dbr = wfGetDB( DB_SLAVE
);
139 $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
140 $n = $res->numRows();
143 $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
146 public function testDoEdit() {
147 $this->hideDeprecated( "WikiPage::doEdit" );
148 $this->hideDeprecated( "WikiPage::getText" );
149 $this->hideDeprecated( "Revision::getText" );
151 //NOTE: assume help namespace will default to wikitext
152 $title = Title
::newFromText( "Help:WikiPageTest_testDoEdit" );
154 $page = $this->newPage( $title );
156 $text = "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
157 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";
159 $page->doEdit( $text, "[[testing]] 1" );
161 $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
162 $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" );
163 $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
164 $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
166 $id = $page->getId();
168 # ------------------------
169 $dbr = wfGetDB( DB_SLAVE
);
170 $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
171 $n = $res->numRows();
174 $this->assertEquals( 1, $n, 'pagelinks should contain one link from the page' );
176 # ------------------------
177 $page = new WikiPage( $title );
179 $retrieved = $page->getText();
180 $this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' );
182 # ------------------------
183 $text = "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
184 . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.";
186 $page->doEdit( $text, "testing 2" );
188 # ------------------------
189 $page = new WikiPage( $title );
191 $retrieved = $page->getText();
192 $this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' );
194 # ------------------------
195 $dbr = wfGetDB( DB_SLAVE
);
196 $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
197 $n = $res->numRows();
200 $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
203 public function testDoQuickEdit() {
206 $this->hideDeprecated( "WikiPage::doQuickEdit" );
208 //NOTE: assume help namespace will default to wikitext
209 $page = $this->createPage( "Help:WikiPageTest_testDoQuickEdit", "original text" );
211 $text = "quick text";
212 $page->doQuickEdit( $text, $wgUser, "testing q" );
214 # ---------------------
215 $page = new WikiPage( $page->getTitle() );
216 $this->assertEquals( $text, $page->getText() );
219 public function testDoQuickEditContent() {
222 $page = $this->createPage( "WikiPageTest_testDoQuickEditContent", "original text", CONTENT_MODEL_WIKITEXT
);
224 $content = ContentHandler
::makeContent( "quick text", $page->getTitle(), CONTENT_MODEL_WIKITEXT
);
225 $page->doQuickEditContent( $content, $wgUser, "testing q" );
227 # ---------------------
228 $page = new WikiPage( $page->getTitle() );
229 $this->assertTrue( $content->equals( $page->getContent() ) );
232 public function testDoDeleteArticle() {
233 $page = $this->createPage( "WikiPageTest_testDoDeleteArticle", "[[original text]] foo", CONTENT_MODEL_WIKITEXT
);
234 $id = $page->getId();
236 $page->doDeleteArticle( "testing deletion" );
238 $this->assertFalse( $page->getTitle()->getArticleID() > 0, "Title object should now have page id 0" );
239 $this->assertFalse( $page->getId() > 0, "WikiPage should now have page id 0" );
240 $this->assertFalse( $page->exists(), "WikiPage::exists should return false after page was deleted" );
241 $this->assertNull( $page->getContent(), "WikiPage::getContent should return null after page was deleted" );
242 $this->assertFalse( $page->getText(), "WikiPage::getText should return false after page was deleted" );
244 $t = Title
::newFromText( $page->getTitle()->getPrefixedText() );
245 $this->assertFalse( $t->exists(), "Title::exists should return false after page was deleted" );
247 # ------------------------
248 $dbr = wfGetDB( DB_SLAVE
);
249 $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
250 $n = $res->numRows();
253 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
256 public function testDoDeleteUpdates() {
257 $page = $this->createPage( "WikiPageTest_testDoDeleteArticle", "[[original text]] foo", CONTENT_MODEL_WIKITEXT
);
258 $id = $page->getId();
260 $page->doDeleteUpdates( $id );
262 # ------------------------
263 $dbr = wfGetDB( DB_SLAVE
);
264 $res = $dbr->select( 'pagelinks', '*', array( 'pl_from' => $id ) );
265 $n = $res->numRows();
268 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
271 public function testGetRevision() {
272 $page = $this->newPage( "WikiPageTest_testGetRevision" );
274 $rev = $page->getRevision();
275 $this->assertNull( $rev );
278 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
280 $rev = $page->getRevision();
282 $this->assertEquals( $page->getLatest(), $rev->getId() );
283 $this->assertEquals( "some text", $rev->getContent()->getNativeData() );
286 public function testGetContent() {
287 $page = $this->newPage( "WikiPageTest_testGetContent" );
289 $content = $page->getContent();
290 $this->assertNull( $content );
293 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
295 $content = $page->getContent();
296 $this->assertEquals( "some text", $content->getNativeData() );
299 public function testGetText() {
300 $this->hideDeprecated( "WikiPage::getText" );
302 $page = $this->newPage( "WikiPageTest_testGetText" );
304 $text = $page->getText();
305 $this->assertFalse( $text );
308 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
310 $text = $page->getText();
311 $this->assertEquals( "some text", $text );
314 public function testGetRawText() {
315 $this->hideDeprecated( "WikiPage::getRawText" );
317 $page = $this->newPage( "WikiPageTest_testGetRawText" );
319 $text = $page->getRawText();
320 $this->assertFalse( $text );
323 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
325 $text = $page->getRawText();
326 $this->assertEquals( "some text", $text );
329 public function testGetContentModel() {
330 global $wgContentHandlerUseDB;
332 if ( !$wgContentHandlerUseDB ) {
333 $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
336 $page = $this->createPage( "WikiPageTest_testGetContentModel", "some text", CONTENT_MODEL_JAVASCRIPT
);
338 $page = new WikiPage( $page->getTitle() );
339 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $page->getContentModel() );
342 public function testGetContentHandler() {
343 global $wgContentHandlerUseDB;
345 if ( !$wgContentHandlerUseDB ) {
346 $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
349 $page = $this->createPage( "WikiPageTest_testGetContentHandler", "some text", CONTENT_MODEL_JAVASCRIPT
);
351 $page = new WikiPage( $page->getTitle() );
352 $this->assertEquals( 'JavaScriptContentHandler', get_class( $page->getContentHandler() ) );
355 public function testExists() {
356 $page = $this->newPage( "WikiPageTest_testExists" );
357 $this->assertFalse( $page->exists() );
360 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
361 $this->assertTrue( $page->exists() );
363 $page = new WikiPage( $page->getTitle() );
364 $this->assertTrue( $page->exists() );
367 $page->doDeleteArticle( "done testing" );
368 $this->assertFalse( $page->exists() );
370 $page = new WikiPage( $page->getTitle() );
371 $this->assertFalse( $page->exists() );
374 public static function provideHasViewableContent() {
376 array( 'WikiPageTest_testHasViewableContent', false, true ),
377 array( 'Special:WikiPageTest_testHasViewableContent', false ),
378 array( 'MediaWiki:WikiPageTest_testHasViewableContent', false ),
379 array( 'Special:Userlogin', true ),
380 array( 'MediaWiki:help', true ),
385 * @dataProvider provideHasViewableContent
387 public function testHasViewableContent( $title, $viewable, $create = false ) {
388 $page = $this->newPage( $title );
389 $this->assertEquals( $viewable, $page->hasViewableContent() );
392 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
393 $this->assertTrue( $page->hasViewableContent() );
395 $page = new WikiPage( $page->getTitle() );
396 $this->assertTrue( $page->hasViewableContent() );
400 public static function provideGetRedirectTarget() {
402 array( 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT
, "hello world", null ),
403 array( 'WikiPageTest_testGetRedirectTarget_2', CONTENT_MODEL_WIKITEXT
, "#REDIRECT [[hello world]]", "Hello world" ),
408 * @dataProvider provideGetRedirectTarget
410 public function testGetRedirectTarget( $title, $model, $text, $target ) {
411 $page = $this->createPage( $title, $text, $model );
413 # sanity check, because this test seems to fail for no reason for some people.
414 $c = $page->getContent();
415 $this->assertEquals( 'WikitextContent', get_class( $c ) );
417 # now, test the actual redirect
418 $t = $page->getRedirectTarget();
419 $this->assertEquals( $target, is_null( $t ) ?
null : $t->getPrefixedText() );
423 * @dataProvider provideGetRedirectTarget
425 public function testIsRedirect( $title, $model, $text, $target ) {
426 $page = $this->createPage( $title, $text, $model );
427 $this->assertEquals( !is_null( $target ), $page->isRedirect() );
430 public static function provideIsCountable() {
434 array( 'WikiPageTest_testIsCountable',
435 CONTENT_MODEL_WIKITEXT
,
440 array( 'WikiPageTest_testIsCountable',
441 CONTENT_MODEL_WIKITEXT
,
448 array( 'WikiPageTest_testIsCountable',
449 CONTENT_MODEL_WIKITEXT
,
454 array( 'WikiPageTest_testIsCountable',
455 CONTENT_MODEL_WIKITEXT
,
462 array( 'WikiPageTest_testIsCountable',
463 CONTENT_MODEL_WIKITEXT
,
468 array( 'WikiPageTest_testIsCountable',
469 CONTENT_MODEL_WIKITEXT
,
476 array( 'WikiPageTest_testIsCountable',
477 CONTENT_MODEL_WIKITEXT
,
482 array( 'WikiPageTest_testIsCountable',
483 CONTENT_MODEL_WIKITEXT
,
488 array( 'WikiPageTest_testIsCountable',
489 CONTENT_MODEL_WIKITEXT
,
495 // not a content namespace
496 array( 'Talk:WikiPageTest_testIsCountable',
497 CONTENT_MODEL_WIKITEXT
,
502 array( 'Talk:WikiPageTest_testIsCountable',
503 CONTENT_MODEL_WIKITEXT
,
508 array( 'Talk:WikiPageTest_testIsCountable',
509 CONTENT_MODEL_WIKITEXT
,
515 // not a content namespace, different model
516 array( 'MediaWiki:WikiPageTest_testIsCountable.js',
522 array( 'MediaWiki:WikiPageTest_testIsCountable.js',
528 array( 'MediaWiki:WikiPageTest_testIsCountable.js',
539 * @dataProvider provideIsCountable
541 public function testIsCountable( $title, $model, $text, $mode, $expected ) {
542 global $wgContentHandlerUseDB;
544 $this->setMwGlobals( 'wgArticleCountMethod', $mode );
546 $title = Title
::newFromText( $title );
548 if ( !$wgContentHandlerUseDB && $model && ContentHandler
::getDefaultModelFor( $title ) != $model ) {
549 $this->markTestSkipped( "Can not use non-default content model $model for "
550 . $title->getPrefixedDBkey() . " with \$wgContentHandlerUseDB disabled." );
553 $page = $this->createPage( $title, $text, $model );
554 $hasLinks = wfGetDB( DB_SLAVE
)->selectField( 'pagelinks', 1,
555 array( 'pl_from' => $page->getId() ), __METHOD__
);
557 $editInfo = $page->prepareContentForEdit( $page->getContent() );
559 $v = $page->isCountable();
560 $w = $page->isCountable( $editInfo );
562 $this->assertEquals( $expected, $v, "isCountable( null ) returned unexpected value " . var_export( $v, true )
563 . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
565 $this->assertEquals( $expected, $w, "isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true )
566 . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );
569 public static function provideGetParserOutput() {
571 array( CONTENT_MODEL_WIKITEXT
, "hello ''world''\n", "<p>hello <i>world</i></p>" ),
577 * @dataProvider provideGetParserOutput
579 public function testGetParserOutput( $model, $text, $expectedHtml ) {
580 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text, $model );
582 $opt = $page->makeParserOptions( 'canonical' );
583 $po = $page->getParserOutput( $opt );
584 $text = $po->getText();
586 $text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments
587 $text = preg_replace( '!\s*(</p>)!sm', '\1', $text ); # don't let tidy confuse us
589 $this->assertEquals( $expectedHtml, $text );
593 public function testGetParserOutput_nonexisting() {
597 $page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
599 $opt = new ParserOptions();
600 $po = $page->getParserOutput( $opt );
602 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
605 public function testGetParserOutput_badrev() {
606 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT
);
608 $opt = new ParserOptions();
609 $po = $page->getParserOutput( $opt, $page->getLatest() +
1234 );
611 //@todo: would be neat to also test deleted revision
613 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
631 public function dataReplaceSection() {
632 //NOTE: assume the Help namespace to contain wikitext
634 array( 'Help:WikiPageTest_testReplaceSection',
635 CONTENT_MODEL_WIKITEXT
,
636 WikiPageTest
::$sections,
640 trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest
::$sections ) )
642 array( 'Help:WikiPageTest_testReplaceSection',
643 CONTENT_MODEL_WIKITEXT
,
644 WikiPageTest
::$sections,
650 array( 'Help:WikiPageTest_testReplaceSection',
651 CONTENT_MODEL_WIKITEXT
,
652 WikiPageTest
::$sections,
654 "== TEST ==\nmore fun",
656 trim( preg_replace( '/^== test ==.*== foo ==/sm',
657 "== TEST ==\nmore fun\n\n== foo ==",
658 WikiPageTest
::$sections ) )
660 array( 'Help:WikiPageTest_testReplaceSection',
661 CONTENT_MODEL_WIKITEXT
,
662 WikiPageTest
::$sections,
666 trim( WikiPageTest
::$sections )
668 array( 'Help:WikiPageTest_testReplaceSection',
669 CONTENT_MODEL_WIKITEXT
,
670 WikiPageTest
::$sections,
674 trim( WikiPageTest
::$sections ) . "\n\n== New ==\n\nNo more"
680 * @dataProvider dataReplaceSection
682 public function testReplaceSection( $title, $model, $text, $section, $with, $sectionTitle, $expected ) {
683 $this->hideDeprecated( "WikiPage::replaceSection" );
685 $page = $this->createPage( $title, $text, $model );
686 $text = $page->replaceSection( $section, $with, $sectionTitle );
687 $text = trim( $text );
689 $this->assertEquals( $expected, $text );
693 * @dataProvider dataReplaceSection
695 public function testReplaceSectionContent( $title, $model, $text, $section, $with, $sectionTitle, $expected ) {
696 $page = $this->createPage( $title, $text, $model );
698 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
699 $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
701 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
704 /* @todo FIXME: fix this!
705 public function testGetUndoText() {
706 $this->checkHasDiff3();
709 $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
710 $rev1 = $page->getRevision();
713 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section two");
714 $rev2 = $page->getRevision();
716 $text .= "\n\nthree";
717 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section three");
718 $rev3 = $page->getRevision();
721 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section four");
722 $rev4 = $page->getRevision();
725 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section five");
726 $rev5 = $page->getRevision();
729 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section six");
730 $rev6 = $page->getRevision();
732 $undo6 = $page->getUndoText( $rev6 );
733 if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
734 $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
736 $undo3 = $page->getUndoText( $rev4, $rev2 );
737 if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
738 $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
740 $undo2 = $page->getUndoText( $rev2 );
741 if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
742 $this->assertEquals( "one\n\nfive", $undo2 );
747 * @todo FIXME: this is a better rollback test than the one below, but it keeps failing in jenkins for some reason.
749 public function broken_testDoRollback() {
751 $admin->setName( "Admin" );
754 $page = $this->newPage( "WikiPageTest_testDoRollback" );
755 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
756 "section one", EDIT_NEW
, false, $admin );
759 $user1->setName( "127.0.1.11" );
761 $page = new WikiPage( $page->getTitle() );
762 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
763 "adding section two", 0, false, $user1 );
766 $user2->setName( "127.0.2.13" );
767 $text .= "\n\nthree";
768 $page = new WikiPage( $page->getTitle() );
769 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
770 "adding section three", 0, false, $user2 );
772 # we are having issues with doRollback spuriously failing. apparently the last revision somehow goes missing
773 # or not committed under some circumstances. so, make sure the last revision has the right user name.
774 $dbr = wfGetDB( DB_SLAVE
);
775 $this->assertEquals( 3, Revision
::countByPageId( $dbr, $page->getId() ) );
777 $page = new WikiPage( $page->getTitle() );
778 $rev3 = $page->getRevision();
779 $this->assertEquals( '127.0.2.13', $rev3->getUserText() );
781 $rev2 = $rev3->getPrevious();
782 $this->assertEquals( '127.0.1.11', $rev2->getUserText() );
784 $rev1 = $rev2->getPrevious();
785 $this->assertEquals( 'Admin', $rev1->getUserText() );
787 # now, try the actual rollback
788 $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
789 $token = $admin->getEditToken( array( $page->getTitle()->getPrefixedText(), $user2->getName() ), null );
790 $errors = $page->doRollback( $user2->getName(), "testing revert", $token, false, $details, $admin );
793 $this->fail( "Rollback failed:\n" . print_r( $errors, true ) . ";\n" . print_r( $details, true ) );
796 $page = new WikiPage( $page->getTitle() );
797 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
798 "rollback did not revert to the correct revision" );
799 $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
803 * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason.
805 public function testDoRollback() {
807 $admin->setName( "Admin" );
810 $page = $this->newPage( "WikiPageTest_testDoRollback" );
811 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
812 "section one", EDIT_NEW
, false, $admin );
813 $rev1 = $page->getRevision();
816 $user1->setName( "127.0.1.11" );
818 $page = new WikiPage( $page->getTitle() );
819 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
820 "adding section two", 0, false, $user1 );
822 # now, try the rollback
823 $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
824 $token = $admin->getEditToken( array( $page->getTitle()->getPrefixedText(), $user1->getName() ), null );
825 $errors = $page->doRollback( $user1->getName(), "testing revert", $token, false, $details, $admin );
828 $this->fail( "Rollback failed:\n" . print_r( $errors, true ) . ";\n" . print_r( $details, true ) );
831 $page = new WikiPage( $page->getTitle() );
832 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
833 "rollback did not revert to the correct revision" );
834 $this->assertEquals( "one", $page->getContent()->getNativeData() );
837 public static function provideGetAutosummary() {
840 'Hello there, world!',
843 '/^Redirected page .*Foo/'
850 '/^Created page .*Hello/'
854 'Hello there, world!',
861 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
862 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
863 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
866 '/^Replaced .*Hello/'
879 * @dataProvider provideGetAutoSummary
881 public function testGetAutosummary( $old, $new, $flags, $expected ) {
882 $this->hideDeprecated( "WikiPage::getAutosummary" );
884 $page = $this->newPage( "WikiPageTest_testGetAutosummary" );
886 $summary = $page->getAutosummary( $old, $new, $flags );
888 $this->assertTrue( (bool)preg_match( $expected, $summary ),
889 "Autosummary didn't match expected pattern $expected: $summary" );
892 public static function provideGetAutoDeleteReason() {
902 array( "first edit", null ),
904 "/first edit.*only contributor/",
910 array( "first edit", null ),
911 array( "second edit", null ),
913 "/second edit.*only contributor/",
919 array( "first edit", "127.0.2.22" ),
920 array( "second edit", "127.0.3.33" ),
928 array( "first edit: "
929 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
930 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. "
931 . "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea "
932 . "takimata sanctus est Lorem ipsum dolor sit amet.'", null ),
934 '/first edit:.*\.\.\."/',
940 array( "first edit", "127.0.2.22" ),
941 array( "", "127.0.3.33" ),
943 "/before blanking.*first edit/",
951 * @dataProvider provideGetAutoDeleteReason
953 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
956 //NOTE: assume Help namespace to contain wikitext
957 $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
961 foreach ( $edits as $edit ) {
964 if ( !empty( $edit[1] ) ) {
965 $user->setName( $edit[1] );
970 $content = ContentHandler
::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
972 $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW
: 0, false, $user );
977 $reason = $page->getAutoDeleteReason( $hasHistory );
979 if ( is_bool( $expectedResult ) ||
is_null( $expectedResult ) ) {
980 $this->assertEquals( $expectedResult, $reason );
982 $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
983 "Autosummary didn't match expected pattern $expectedResult: $reason" );
986 $this->assertEquals( $expectedHistory, $hasHistory,
987 "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
989 $page->doDeleteArticle( "done" );
992 public static function providePreSaveTransform() {
994 array( 'hello this is ~~~',
995 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
997 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
998 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1004 * @dataProvider providePreSaveTransform
1006 public function testPreSaveTransform( $text, $expected ) {
1007 $this->hideDeprecated( 'WikiPage::preSaveTransform' );
1009 $user->setName( "127.0.0.1" );
1011 //NOTE: assume Help namespace to contain wikitext
1012 $page = $this->newPage( "Help:WikiPageTest_testPreloadTransform" );
1013 $text = $page->preSaveTransform( $text, $user );
1015 $this->assertEquals( $expected, $text );