4 * @group ContentHandler
6 * ^--- important, causes temporary tables to be used instead of the real database
9 class WikiPageTest
extends MediaWikiLangTestCase
{
11 protected $pages_to_delete;
13 function __construct( $name = null, array $data = [], $dataName = '' ) {
14 parent
::__construct( $name, $data, $dataName );
16 $this->tablesUsed
= array_merge(
35 protected function setUp() {
37 $this->pages_to_delete
= [];
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 ) {
58 * @param Title|string $title
59 * @param string|null $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
);
94 * @covers WikiPage::doEditContent
95 * @covers WikiPage::doModify
96 * @covers WikiPage::doCreate
97 * @covers WikiPage::doEditUpdates
99 public function testDoEditContent() {
100 $page = $this->newPage( "WikiPageTest_testDoEditContent" );
101 $title = $page->getTitle();
103 $content = ContentHandler
::makeContent(
104 "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
105 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
107 CONTENT_MODEL_WIKITEXT
110 $page->doEditContent( $content, "[[testing]] 1" );
112 $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
113 $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" );
114 $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
115 $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
117 $id = $page->getId();
119 # ------------------------
120 $dbr = wfGetDB( DB_REPLICA
);
121 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
122 $n = $res->numRows();
125 $this->assertEquals( 1, $n, 'pagelinks should contain one link from the page' );
127 # ------------------------
128 $page = new WikiPage( $title );
130 $retrieved = $page->getContent();
131 $this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
133 # ------------------------
134 $content = ContentHandler
::makeContent(
135 "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
136 . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.",
138 CONTENT_MODEL_WIKITEXT
141 $page->doEditContent( $content, "testing 2" );
143 # ------------------------
144 $page = new WikiPage( $title );
146 $retrieved = $page->getContent();
147 $this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
149 # ------------------------
150 $dbr = wfGetDB( DB_REPLICA
);
151 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
152 $n = $res->numRows();
155 $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
159 * @covers WikiPage::doDeleteArticle
161 public function testDoDeleteArticle() {
162 $page = $this->createPage(
163 "WikiPageTest_testDoDeleteArticle",
164 "[[original text]] foo",
165 CONTENT_MODEL_WIKITEXT
167 $id = $page->getId();
169 $page->doDeleteArticle( "testing deletion" );
172 $page->getTitle()->getArticleID() > 0,
173 "Title object should now have page id 0"
175 $this->assertFalse( $page->getId() > 0, "WikiPage should now have page id 0" );
178 "WikiPage::exists should return false after page was deleted"
182 "WikiPage::getContent should return null after page was deleted"
185 $t = Title
::newFromText( $page->getTitle()->getPrefixedText() );
188 "Title::exists should return false after page was deleted"
192 JobQueueGroup
::destroySingletons();
194 $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
197 # ------------------------
198 $dbr = wfGetDB( DB_REPLICA
);
199 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
200 $n = $res->numRows();
203 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
207 * @covers WikiPage::doDeleteUpdates
209 public function testDoDeleteUpdates() {
210 $page = $this->createPage(
211 "WikiPageTest_testDoDeleteArticle",
212 "[[original text]] foo",
213 CONTENT_MODEL_WIKITEXT
215 $id = $page->getId();
217 // Similar to MovePage logic
218 wfGetDB( DB_MASTER
)->delete( 'page', [ 'page_id' => $id ], __METHOD__
);
219 $page->doDeleteUpdates( $id );
222 JobQueueGroup
::destroySingletons();
224 $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
227 # ------------------------
228 $dbr = wfGetDB( DB_REPLICA
);
229 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
230 $n = $res->numRows();
233 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
237 * @covers WikiPage::getRevision
239 public function testGetRevision() {
240 $page = $this->newPage( "WikiPageTest_testGetRevision" );
242 $rev = $page->getRevision();
243 $this->assertNull( $rev );
246 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
248 $rev = $page->getRevision();
250 $this->assertEquals( $page->getLatest(), $rev->getId() );
251 $this->assertEquals( "some text", $rev->getContent()->getNativeData() );
255 * @covers WikiPage::getContent
257 public function testGetContent() {
258 $page = $this->newPage( "WikiPageTest_testGetContent" );
260 $content = $page->getContent();
261 $this->assertNull( $content );
264 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
266 $content = $page->getContent();
267 $this->assertEquals( "some text", $content->getNativeData() );
271 * @covers WikiPage::getContentModel
273 public function testGetContentModel() {
274 global $wgContentHandlerUseDB;
276 if ( !$wgContentHandlerUseDB ) {
277 $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
280 $page = $this->createPage(
281 "WikiPageTest_testGetContentModel",
283 CONTENT_MODEL_JAVASCRIPT
286 $page = new WikiPage( $page->getTitle() );
287 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $page->getContentModel() );
291 * @covers WikiPage::getContentHandler
293 public function testGetContentHandler() {
294 global $wgContentHandlerUseDB;
296 if ( !$wgContentHandlerUseDB ) {
297 $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
300 $page = $this->createPage(
301 "WikiPageTest_testGetContentHandler",
303 CONTENT_MODEL_JAVASCRIPT
306 $page = new WikiPage( $page->getTitle() );
307 $this->assertEquals( 'JavaScriptContentHandler', get_class( $page->getContentHandler() ) );
311 * @covers WikiPage::exists
313 public function testExists() {
314 $page = $this->newPage( "WikiPageTest_testExists" );
315 $this->assertFalse( $page->exists() );
318 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
319 $this->assertTrue( $page->exists() );
321 $page = new WikiPage( $page->getTitle() );
322 $this->assertTrue( $page->exists() );
325 $page->doDeleteArticle( "done testing" );
326 $this->assertFalse( $page->exists() );
328 $page = new WikiPage( $page->getTitle() );
329 $this->assertFalse( $page->exists() );
332 public static function provideHasViewableContent() {
334 [ 'WikiPageTest_testHasViewableContent', false, true ],
335 [ 'Special:WikiPageTest_testHasViewableContent', false ],
336 [ 'MediaWiki:WikiPageTest_testHasViewableContent', false ],
337 [ 'Special:Userlogin', true ],
338 [ 'MediaWiki:help', true ],
343 * @dataProvider provideHasViewableContent
344 * @covers WikiPage::hasViewableContent
346 public function testHasViewableContent( $title, $viewable, $create = false ) {
347 $page = $this->newPage( $title );
348 $this->assertEquals( $viewable, $page->hasViewableContent() );
351 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
352 $this->assertTrue( $page->hasViewableContent() );
354 $page = new WikiPage( $page->getTitle() );
355 $this->assertTrue( $page->hasViewableContent() );
359 public static function provideGetRedirectTarget() {
361 [ 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT
, "hello world", null ],
363 'WikiPageTest_testGetRedirectTarget_2',
364 CONTENT_MODEL_WIKITEXT
,
365 "#REDIRECT [[hello world]]",
372 * @dataProvider provideGetRedirectTarget
373 * @covers WikiPage::getRedirectTarget
375 public function testGetRedirectTarget( $title, $model, $text, $target ) {
376 $this->setMwGlobals( [
377 'wgCapitalLinks' => true,
380 $page = $this->createPage( $title, $text, $model );
382 # sanity check, because this test seems to fail for no reason for some people.
383 $c = $page->getContent();
384 $this->assertEquals( 'WikitextContent', get_class( $c ) );
386 # now, test the actual redirect
387 $t = $page->getRedirectTarget();
388 $this->assertEquals( $target, is_null( $t ) ?
null : $t->getPrefixedText() );
392 * @dataProvider provideGetRedirectTarget
393 * @covers WikiPage::isRedirect
395 public function testIsRedirect( $title, $model, $text, $target ) {
396 $page = $this->createPage( $title, $text, $model );
397 $this->assertEquals( !is_null( $target ), $page->isRedirect() );
400 public static function provideIsCountable() {
404 [ 'WikiPageTest_testIsCountable',
405 CONTENT_MODEL_WIKITEXT
,
410 [ 'WikiPageTest_testIsCountable',
411 CONTENT_MODEL_WIKITEXT
,
418 [ 'WikiPageTest_testIsCountable',
419 CONTENT_MODEL_WIKITEXT
,
424 [ 'WikiPageTest_testIsCountable',
425 CONTENT_MODEL_WIKITEXT
,
432 [ 'WikiPageTest_testIsCountable',
433 CONTENT_MODEL_WIKITEXT
,
438 [ 'WikiPageTest_testIsCountable',
439 CONTENT_MODEL_WIKITEXT
,
446 [ 'WikiPageTest_testIsCountable',
447 CONTENT_MODEL_WIKITEXT
,
452 [ 'WikiPageTest_testIsCountable',
453 CONTENT_MODEL_WIKITEXT
,
458 [ 'WikiPageTest_testIsCountable',
459 CONTENT_MODEL_WIKITEXT
,
465 // not a content namespace
466 [ 'Talk:WikiPageTest_testIsCountable',
467 CONTENT_MODEL_WIKITEXT
,
472 [ 'Talk:WikiPageTest_testIsCountable',
473 CONTENT_MODEL_WIKITEXT
,
478 [ 'Talk:WikiPageTest_testIsCountable',
479 CONTENT_MODEL_WIKITEXT
,
485 // not a content namespace, different model
486 [ 'MediaWiki:WikiPageTest_testIsCountable.js',
492 [ 'MediaWiki:WikiPageTest_testIsCountable.js',
498 [ 'MediaWiki:WikiPageTest_testIsCountable.js',
508 * @dataProvider provideIsCountable
509 * @covers WikiPage::isCountable
511 public function testIsCountable( $title, $model, $text, $mode, $expected ) {
512 global $wgContentHandlerUseDB;
514 $this->setMwGlobals( 'wgArticleCountMethod', $mode );
516 $title = Title
::newFromText( $title );
518 if ( !$wgContentHandlerUseDB
520 && ContentHandler
::getDefaultModelFor( $title ) != $model
522 $this->markTestSkipped( "Can not use non-default content model $model for "
523 . $title->getPrefixedDBkey() . " with \$wgContentHandlerUseDB disabled." );
526 $page = $this->createPage( $title, $text, $model );
528 $editInfo = $page->prepareContentForEdit( $page->getContent() );
530 $v = $page->isCountable();
531 $w = $page->isCountable( $editInfo );
536 "isCountable( null ) returned unexpected value " . var_export( $v, true )
537 . " instead of " . var_export( $expected, true )
538 . " in mode `$mode` for text \"$text\""
544 "isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true )
545 . " instead of " . var_export( $expected, true )
546 . " in mode `$mode` for text \"$text\""
550 public static function provideGetParserOutput() {
553 CONTENT_MODEL_WIKITEXT
,
555 "<div class=\"mw-parser-output\"><p>hello <i>world</i></p></div>"
562 * @dataProvider provideGetParserOutput
563 * @covers WikiPage::getParserOutput
565 public function testGetParserOutput( $model, $text, $expectedHtml ) {
566 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text, $model );
568 $opt = $page->makeParserOptions( 'canonical' );
569 $po = $page->getParserOutput( $opt );
570 $text = $po->getText();
572 $text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments
573 $text = preg_replace( '!\s*(</p>|</div>)!sm', '\1', $text ); # don't let tidy confuse us
575 $this->assertEquals( $expectedHtml, $text );
581 * @covers WikiPage::getParserOutput
583 public function testGetParserOutput_nonexisting() {
587 $page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
589 $opt = new ParserOptions();
590 $po = $page->getParserOutput( $opt );
592 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
596 * @covers WikiPage::getParserOutput
598 public function testGetParserOutput_badrev() {
599 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT
);
601 $opt = new ParserOptions();
602 $po = $page->getParserOutput( $opt, $page->getLatest() +
1234 );
604 // @todo would be neat to also test deleted revision
606 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
609 public static $sections =
623 public function dataReplaceSection() {
624 // NOTE: assume the Help namespace to contain wikitext
626 [ 'Help:WikiPageTest_testReplaceSection',
627 CONTENT_MODEL_WIKITEXT
,
632 trim( preg_replace( '/^Intro/sm', 'No more', self
::$sections ) )
634 [ 'Help:WikiPageTest_testReplaceSection',
635 CONTENT_MODEL_WIKITEXT
,
642 [ 'Help:WikiPageTest_testReplaceSection',
643 CONTENT_MODEL_WIKITEXT
,
646 "== TEST ==\nmore fun",
648 trim( preg_replace( '/^== test ==.*== foo ==/sm',
649 "== TEST ==\nmore fun\n\n== foo ==",
652 [ 'Help:WikiPageTest_testReplaceSection',
653 CONTENT_MODEL_WIKITEXT
,
658 trim( self
::$sections )
660 [ 'Help:WikiPageTest_testReplaceSection',
661 CONTENT_MODEL_WIKITEXT
,
666 trim( self
::$sections ) . "\n\n== New ==\n\nNo more"
672 * @dataProvider dataReplaceSection
673 * @covers WikiPage::replaceSectionContent
675 public function testReplaceSectionContent( $title, $model, $text, $section,
676 $with, $sectionTitle, $expected
678 $page = $this->createPage( $title, $text, $model );
680 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
681 $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
683 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
687 * @dataProvider dataReplaceSection
688 * @covers WikiPage::replaceSectionAtRev
690 public function testReplaceSectionAtRev( $title, $model, $text, $section,
691 $with, $sectionTitle, $expected
693 $page = $this->createPage( $title, $text, $model );
694 $baseRevId = $page->getLatest();
696 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
697 $c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
699 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
702 /* @todo FIXME: fix this!
703 public function testGetUndoText() {
704 $this->markTestSkippedIfNoDiff3();
707 $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
708 $rev1 = $page->getRevision();
711 $page->doEditContent(
712 ContentHandler::makeContent( $text, $page->getTitle() ),
715 $rev2 = $page->getRevision();
717 $text .= "\n\nthree";
718 $page->doEditContent(
719 ContentHandler::makeContent( $text, $page->getTitle() ),
720 "adding section three"
722 $rev3 = $page->getRevision();
725 $page->doEditContent(
726 ContentHandler::makeContent( $text, $page->getTitle() ),
727 "adding section four"
729 $rev4 = $page->getRevision();
732 $page->doEditContent(
733 ContentHandler::makeContent( $text, $page->getTitle() ),
734 "adding section five"
736 $rev5 = $page->getRevision();
739 $page->doEditContent(
740 ContentHandler::makeContent( $text, $page->getTitle() ),
743 $rev6 = $page->getRevision();
745 $undo6 = $page->getUndoText( $rev6 );
746 if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
747 $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
749 $undo3 = $page->getUndoText( $rev4, $rev2 );
750 if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
751 $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
753 $undo2 = $page->getUndoText( $rev2 );
754 if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
755 $this->assertEquals( "one\n\nfive", $undo2 );
760 * @covers WikiPage::getOldestRevision
762 public function testGetOldestRevision() {
763 $page = $this->newPage( "WikiPageTest_testGetOldestRevision" );
764 $page->doEditContent(
765 new WikitextContent( 'one' ),
769 $rev1 = $page->getRevision();
771 $page = new WikiPage( $page->getTitle() );
772 $page->doEditContent(
773 new WikitextContent( 'two' ),
778 $page = new WikiPage( $page->getTitle() );
779 $page->doEditContent(
780 new WikitextContent( 'three' ),
786 $this->assertNotEquals(
788 $page->getRevision()->getId(),
789 '$page->getRevision()->getId()'
795 $page->getOldestRevision()->getId(),
796 '$page->getOldestRevision()->getId()'
801 * @todo FIXME: this is a better rollback test than the one below, but it
802 * keeps failing in jenkins for some reason.
804 public function broken_testDoRollback() {
806 $admin->setName( "Admin" );
809 $page = $this->newPage( "WikiPageTest_testDoRollback" );
810 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
811 "section one", EDIT_NEW
, false, $admin );
814 $user1->setName( "127.0.1.11" );
816 $page = new WikiPage( $page->getTitle() );
817 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
818 "adding section two", 0, false, $user1 );
821 $user2->setName( "127.0.2.13" );
822 $text .= "\n\nthree";
823 $page = new WikiPage( $page->getTitle() );
824 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
825 "adding section three", 0, false, $user2 );
827 # we are having issues with doRollback spuriously failing. Apparently
828 # the last revision somehow goes missing or not committed under some
829 # circumstances. So, make sure the last revision has the right user name.
830 $dbr = wfGetDB( DB_REPLICA
);
831 $this->assertEquals( 3, Revision
::countByPageId( $dbr, $page->getId() ) );
833 $page = new WikiPage( $page->getTitle() );
834 $rev3 = $page->getRevision();
835 $this->assertEquals( '127.0.2.13', $rev3->getUserText() );
837 $rev2 = $rev3->getPrevious();
838 $this->assertEquals( '127.0.1.11', $rev2->getUserText() );
840 $rev1 = $rev2->getPrevious();
841 $this->assertEquals( 'Admin', $rev1->getUserText() );
843 # now, try the actual rollback
844 $admin->addToDatabase();
845 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
846 $token = $admin->getEditToken(
847 [ $page->getTitle()->getPrefixedText(), $user2->getName() ],
850 $errors = $page->doRollback(
860 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
861 . ";\n" . print_r( $details, true ) );
864 $page = new WikiPage( $page->getTitle() );
865 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
866 "rollback did not revert to the correct revision" );
867 $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
871 * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason.
872 * @covers WikiPage::doRollback
874 public function testDoRollback() {
876 $admin->setName( "Admin" );
877 $admin->addToDatabase();
880 $page = $this->newPage( "WikiPageTest_testDoRollback" );
881 $page->doEditContent(
882 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
888 $rev1 = $page->getRevision();
891 $user1->setName( "127.0.1.11" );
893 $page = new WikiPage( $page->getTitle() );
894 $page->doEditContent(
895 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
896 "adding section two",
902 # now, try the rollback
903 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
904 $token = $admin->getEditToken( 'rollback' );
905 $errors = $page->doRollback(
915 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
916 . ";\n" . print_r( $details, true ) );
919 $page = new WikiPage( $page->getTitle() );
920 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
921 "rollback did not revert to the correct revision" );
922 $this->assertEquals( "one", $page->getContent()->getNativeData() );
926 * @covers WikiPage::doRollback
928 public function testDoRollbackFailureSameContent() {
930 $admin->setName( "Admin" );
931 $admin->addToDatabase();
932 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
935 $page = $this->newPage( "WikiPageTest_testDoRollback" );
936 $page->doEditContent(
937 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
943 $rev1 = $page->getRevision();
946 $user1->setName( "127.0.1.11" );
947 $user1->addToDatabase();
948 $user1->addGroup( "sysop" ); # XXX: make the test user a sysop...
950 $page = new WikiPage( $page->getTitle() );
951 $page->doEditContent(
952 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
953 "adding section two",
959 # now, do a the rollback from the same user was doing the edit before
961 $token = $user1->getEditToken( 'rollback' );
962 $errors = $page->doRollback(
964 "testing revert same user",
971 $this->assertEquals( [], $errors, "Rollback failed same user" );
973 # now, try the rollback
975 $token = $admin->getEditToken( 'rollback' );
976 $errors = $page->doRollback(
985 $this->assertEquals( [ [ 'alreadyrolled', 'WikiPageTest testDoRollback',
986 '127.0.1.11', 'Admin' ] ], $errors, "Rollback not failed" );
988 $page = new WikiPage( $page->getTitle() );
989 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
990 "rollback did not revert to the correct revision" );
991 $this->assertEquals( "one", $page->getContent()->getNativeData() );
994 public static function provideGetAutoDeleteReason() {
1004 [ "first edit", null ],
1006 "/first edit.*only contributor/",
1012 [ "first edit", null ],
1013 [ "second edit", null ],
1015 "/second edit.*only contributor/",
1021 [ "first edit", "127.0.2.22" ],
1022 [ "second edit", "127.0.3.33" ],
1032 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
1033 . " nonumy eirmod tempor invidunt ut labore et dolore magna "
1034 . "aliquyam erat, sed diam voluptua. At vero eos et accusam "
1035 . "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
1036 . "no sea takimata sanctus est Lorem ipsum dolor sit amet.'",
1040 '/first edit:.*\.\.\."/',
1046 [ "first edit", "127.0.2.22" ],
1047 [ "", "127.0.3.33" ],
1049 "/before blanking.*first edit/",
1057 * @dataProvider provideGetAutoDeleteReason
1058 * @covers WikiPage::getAutoDeleteReason
1060 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
1063 // NOTE: assume Help namespace to contain wikitext
1064 $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
1068 foreach ( $edits as $edit ) {
1071 if ( !empty( $edit[1] ) ) {
1072 $user->setName( $edit[1] );
1077 $content = ContentHandler
::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
1079 $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW
: 0, false, $user );
1084 $reason = $page->getAutoDeleteReason( $hasHistory );
1086 if ( is_bool( $expectedResult ) ||
is_null( $expectedResult ) ) {
1087 $this->assertEquals( $expectedResult, $reason );
1089 $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
1090 "Autosummary didn't match expected pattern $expectedResult: $reason" );
1093 $this->assertEquals( $expectedHistory, $hasHistory,
1094 "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
1096 $page->doDeleteArticle( "done" );
1099 public static function providePreSaveTransform() {
1101 [ 'hello this is ~~~',
1102 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
1104 [ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1105 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1111 * @covers WikiPage::factory
1113 public function testWikiPageFactory() {
1114 $title = Title
::makeTitle( NS_FILE
, 'Someimage.png' );
1115 $page = WikiPage
::factory( $title );
1116 $this->assertEquals( 'WikiFilePage', get_class( $page ) );
1118 $title = Title
::makeTitle( NS_CATEGORY
, 'SomeCategory' );
1119 $page = WikiPage
::factory( $title );
1120 $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
1122 $title = Title
::makeTitle( NS_MAIN
, 'SomePage' );
1123 $page = WikiPage
::factory( $title );
1124 $this->assertEquals( 'WikiPage', get_class( $page ) );