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 );
594 public function testGetParserOutput_nonexisting() {
598 $page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
600 $opt = new ParserOptions();
601 $po = $page->getParserOutput( $opt );
603 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
606 public function testGetParserOutput_badrev() {
607 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT
);
609 $opt = new ParserOptions();
610 $po = $page->getParserOutput( $opt, $page->getLatest() +
1234 );
612 // @todo would be neat to also test deleted revision
614 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
632 public function dataReplaceSection() {
633 //NOTE: assume the Help namespace to contain wikitext
635 array( 'Help:WikiPageTest_testReplaceSection',
636 CONTENT_MODEL_WIKITEXT
,
637 WikiPageTest
::$sections,
641 trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest
::$sections ) )
643 array( 'Help:WikiPageTest_testReplaceSection',
644 CONTENT_MODEL_WIKITEXT
,
645 WikiPageTest
::$sections,
651 array( 'Help:WikiPageTest_testReplaceSection',
652 CONTENT_MODEL_WIKITEXT
,
653 WikiPageTest
::$sections,
655 "== TEST ==\nmore fun",
657 trim( preg_replace( '/^== test ==.*== foo ==/sm',
658 "== TEST ==\nmore fun\n\n== foo ==",
659 WikiPageTest
::$sections ) )
661 array( 'Help:WikiPageTest_testReplaceSection',
662 CONTENT_MODEL_WIKITEXT
,
663 WikiPageTest
::$sections,
667 trim( WikiPageTest
::$sections )
669 array( 'Help:WikiPageTest_testReplaceSection',
670 CONTENT_MODEL_WIKITEXT
,
671 WikiPageTest
::$sections,
675 trim( WikiPageTest
::$sections ) . "\n\n== New ==\n\nNo more"
681 * @dataProvider dataReplaceSection
683 public function testReplaceSection( $title, $model, $text, $section, $with, $sectionTitle, $expected ) {
684 $this->hideDeprecated( "WikiPage::replaceSection" );
686 $page = $this->createPage( $title, $text, $model );
687 $text = $page->replaceSection( $section, $with, $sectionTitle );
688 $text = trim( $text );
690 $this->assertEquals( $expected, $text );
694 * @dataProvider dataReplaceSection
696 public function testReplaceSectionContent( $title, $model, $text, $section, $with, $sectionTitle, $expected ) {
697 $page = $this->createPage( $title, $text, $model );
699 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
700 $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
702 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
705 /* @todo FIXME: fix this!
706 public function testGetUndoText() {
707 $this->checkHasDiff3();
710 $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
711 $rev1 = $page->getRevision();
714 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section two");
715 $rev2 = $page->getRevision();
717 $text .= "\n\nthree";
718 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section three");
719 $rev3 = $page->getRevision();
722 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section four");
723 $rev4 = $page->getRevision();
726 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section five");
727 $rev5 = $page->getRevision();
730 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), "adding section six");
731 $rev6 = $page->getRevision();
733 $undo6 = $page->getUndoText( $rev6 );
734 if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
735 $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
737 $undo3 = $page->getUndoText( $rev4, $rev2 );
738 if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
739 $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
741 $undo2 = $page->getUndoText( $rev2 );
742 if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
743 $this->assertEquals( "one\n\nfive", $undo2 );
748 * @todo FIXME: this is a better rollback test than the one below, but it keeps failing in jenkins for some reason.
750 public function broken_testDoRollback() {
752 $admin->setName( "Admin" );
755 $page = $this->newPage( "WikiPageTest_testDoRollback" );
756 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
757 "section one", EDIT_NEW
, false, $admin );
760 $user1->setName( "127.0.1.11" );
762 $page = new WikiPage( $page->getTitle() );
763 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
764 "adding section two", 0, false, $user1 );
767 $user2->setName( "127.0.2.13" );
768 $text .= "\n\nthree";
769 $page = new WikiPage( $page->getTitle() );
770 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
771 "adding section three", 0, false, $user2 );
773 # we are having issues with doRollback spuriously failing. apparently the last revision somehow goes missing
774 # or not committed under some circumstances. so, make sure the last revision has the right user name.
775 $dbr = wfGetDB( DB_SLAVE
);
776 $this->assertEquals( 3, Revision
::countByPageId( $dbr, $page->getId() ) );
778 $page = new WikiPage( $page->getTitle() );
779 $rev3 = $page->getRevision();
780 $this->assertEquals( '127.0.2.13', $rev3->getUserText() );
782 $rev2 = $rev3->getPrevious();
783 $this->assertEquals( '127.0.1.11', $rev2->getUserText() );
785 $rev1 = $rev2->getPrevious();
786 $this->assertEquals( 'Admin', $rev1->getUserText() );
788 # now, try the actual rollback
789 $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
790 $token = $admin->getEditToken( array( $page->getTitle()->getPrefixedText(), $user2->getName() ), null );
791 $errors = $page->doRollback( $user2->getName(), "testing revert", $token, false, $details, $admin );
794 $this->fail( "Rollback failed:\n" . print_r( $errors, true ) . ";\n" . print_r( $details, true ) );
797 $page = new WikiPage( $page->getTitle() );
798 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
799 "rollback did not revert to the correct revision" );
800 $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
804 * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason.
806 public function testDoRollback() {
808 $admin->setName( "Admin" );
811 $page = $this->newPage( "WikiPageTest_testDoRollback" );
812 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
813 "section one", EDIT_NEW
, false, $admin );
814 $rev1 = $page->getRevision();
817 $user1->setName( "127.0.1.11" );
819 $page = new WikiPage( $page->getTitle() );
820 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
821 "adding section two", 0, false, $user1 );
823 # now, try the rollback
824 $admin->addGroup( "sysop" ); #XXX: make the test user a sysop...
825 $token = $admin->getEditToken( array( $page->getTitle()->getPrefixedText(), $user1->getName() ), null );
826 $errors = $page->doRollback( $user1->getName(), "testing revert", $token, false, $details, $admin );
829 $this->fail( "Rollback failed:\n" . print_r( $errors, true ) . ";\n" . print_r( $details, true ) );
832 $page = new WikiPage( $page->getTitle() );
833 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
834 "rollback did not revert to the correct revision" );
835 $this->assertEquals( "one", $page->getContent()->getNativeData() );
838 public static function provideGetAutosummary() {
841 'Hello there, world!',
844 '/^Redirected page .*Foo/'
851 '/^Created page .*Hello/'
855 'Hello there, world!',
862 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
863 labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
864 ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
867 '/^Replaced .*Hello/'
880 * @dataProvider provideGetAutoSummary
882 public function testGetAutosummary( $old, $new, $flags, $expected ) {
883 $this->hideDeprecated( "WikiPage::getAutosummary" );
885 $page = $this->newPage( "WikiPageTest_testGetAutosummary" );
887 $summary = $page->getAutosummary( $old, $new, $flags );
889 $this->assertTrue( (bool)preg_match( $expected, $summary ),
890 "Autosummary didn't match expected pattern $expected: $summary" );
893 public static function provideGetAutoDeleteReason() {
903 array( "first edit", null ),
905 "/first edit.*only contributor/",
911 array( "first edit", null ),
912 array( "second edit", null ),
914 "/second edit.*only contributor/",
920 array( "first edit", "127.0.2.22" ),
921 array( "second edit", "127.0.3.33" ),
929 array( "first edit: "
930 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
931 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. "
932 . "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea "
933 . "takimata sanctus est Lorem ipsum dolor sit amet.'", null ),
935 '/first edit:.*\.\.\."/',
941 array( "first edit", "127.0.2.22" ),
942 array( "", "127.0.3.33" ),
944 "/before blanking.*first edit/",
952 * @dataProvider provideGetAutoDeleteReason
954 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
957 //NOTE: assume Help namespace to contain wikitext
958 $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
962 foreach ( $edits as $edit ) {
965 if ( !empty( $edit[1] ) ) {
966 $user->setName( $edit[1] );
971 $content = ContentHandler
::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
973 $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW
: 0, false, $user );
978 $reason = $page->getAutoDeleteReason( $hasHistory );
980 if ( is_bool( $expectedResult ) ||
is_null( $expectedResult ) ) {
981 $this->assertEquals( $expectedResult, $reason );
983 $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
984 "Autosummary didn't match expected pattern $expectedResult: $reason" );
987 $this->assertEquals( $expectedHistory, $hasHistory,
988 "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
990 $page->doDeleteArticle( "done" );
993 public static function providePreSaveTransform() {
995 array( 'hello this is ~~~',
996 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
998 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
999 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1005 * @dataProvider providePreSaveTransform
1007 public function testPreSaveTransform( $text, $expected ) {
1008 $this->hideDeprecated( 'WikiPage::preSaveTransform' );
1010 $user->setName( "127.0.0.1" );
1012 //NOTE: assume Help namespace to contain wikitext
1013 $page = $this->newPage( "Help:WikiPageTest_testPreloadTransform" );
1014 $text = $page->preSaveTransform( $text, $user );
1016 $this->assertEquals( $expected, $text );