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_SLAVE
);
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_SLAVE
);
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_SLAVE
);
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_SLAVE
);
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() {
552 [ CONTENT_MODEL_WIKITEXT
, "hello ''world''\n", "<p>hello <i>world</i></p>" ],
558 * @dataProvider provideGetParserOutput
559 * @covers WikiPage::getParserOutput
561 public function testGetParserOutput( $model, $text, $expectedHtml ) {
562 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text, $model );
564 $opt = $page->makeParserOptions( 'canonical' );
565 $po = $page->getParserOutput( $opt );
566 $text = $po->getText();
568 $text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments
569 $text = preg_replace( '!\s*(</p>)!sm', '\1', $text ); # don't let tidy confuse us
571 $this->assertEquals( $expectedHtml, $text );
577 * @covers WikiPage::getParserOutput
579 public function testGetParserOutput_nonexisting() {
583 $page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
585 $opt = new ParserOptions();
586 $po = $page->getParserOutput( $opt );
588 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
592 * @covers WikiPage::getParserOutput
594 public function testGetParserOutput_badrev() {
595 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT
);
597 $opt = new ParserOptions();
598 $po = $page->getParserOutput( $opt, $page->getLatest() +
1234 );
600 // @todo would be neat to also test deleted revision
602 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
605 public static $sections =
619 public function dataReplaceSection() {
620 // NOTE: assume the Help namespace to contain wikitext
622 [ 'Help:WikiPageTest_testReplaceSection',
623 CONTENT_MODEL_WIKITEXT
,
624 WikiPageTest
::$sections,
628 trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest
::$sections ) )
630 [ 'Help:WikiPageTest_testReplaceSection',
631 CONTENT_MODEL_WIKITEXT
,
632 WikiPageTest
::$sections,
638 [ 'Help:WikiPageTest_testReplaceSection',
639 CONTENT_MODEL_WIKITEXT
,
640 WikiPageTest
::$sections,
642 "== TEST ==\nmore fun",
644 trim( preg_replace( '/^== test ==.*== foo ==/sm',
645 "== TEST ==\nmore fun\n\n== foo ==",
646 WikiPageTest
::$sections ) )
648 [ 'Help:WikiPageTest_testReplaceSection',
649 CONTENT_MODEL_WIKITEXT
,
650 WikiPageTest
::$sections,
654 trim( WikiPageTest
::$sections )
656 [ 'Help:WikiPageTest_testReplaceSection',
657 CONTENT_MODEL_WIKITEXT
,
658 WikiPageTest
::$sections,
662 trim( WikiPageTest
::$sections ) . "\n\n== New ==\n\nNo more"
668 * @dataProvider dataReplaceSection
669 * @covers WikiPage::replaceSectionContent
671 public function testReplaceSectionContent( $title, $model, $text, $section,
672 $with, $sectionTitle, $expected
674 $page = $this->createPage( $title, $text, $model );
676 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
677 $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
679 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
683 * @dataProvider dataReplaceSection
684 * @covers WikiPage::replaceSectionAtRev
686 public function testReplaceSectionAtRev( $title, $model, $text, $section,
687 $with, $sectionTitle, $expected
689 $page = $this->createPage( $title, $text, $model );
690 $baseRevId = $page->getLatest();
692 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
693 $c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
695 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
698 /* @todo FIXME: fix this!
699 public function testGetUndoText() {
700 $this->markTestSkippedIfNoDiff3();
703 $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
704 $rev1 = $page->getRevision();
707 $page->doEditContent(
708 ContentHandler::makeContent( $text, $page->getTitle() ),
711 $rev2 = $page->getRevision();
713 $text .= "\n\nthree";
714 $page->doEditContent(
715 ContentHandler::makeContent( $text, $page->getTitle() ),
716 "adding section three"
718 $rev3 = $page->getRevision();
721 $page->doEditContent(
722 ContentHandler::makeContent( $text, $page->getTitle() ),
723 "adding section four"
725 $rev4 = $page->getRevision();
728 $page->doEditContent(
729 ContentHandler::makeContent( $text, $page->getTitle() ),
730 "adding section five"
732 $rev5 = $page->getRevision();
735 $page->doEditContent(
736 ContentHandler::makeContent( $text, $page->getTitle() ),
739 $rev6 = $page->getRevision();
741 $undo6 = $page->getUndoText( $rev6 );
742 if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
743 $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
745 $undo3 = $page->getUndoText( $rev4, $rev2 );
746 if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
747 $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
749 $undo2 = $page->getUndoText( $rev2 );
750 if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
751 $this->assertEquals( "one\n\nfive", $undo2 );
756 * @covers WikiPage::getOldestRevision
758 public function testGetOldestRevision() {
759 $page = $this->newPage( "WikiPageTest_testGetOldestRevision" );
760 $page->doEditContent(
761 new WikitextContent( 'one' ),
765 $rev1 = $page->getRevision();
767 $page = new WikiPage( $page->getTitle() );
768 $page->doEditContent(
769 new WikitextContent( 'two' ),
774 $page = new WikiPage( $page->getTitle() );
775 $page->doEditContent(
776 new WikitextContent( 'three' ),
782 $this->assertNotEquals(
784 $page->getRevision()->getId(),
785 '$page->getRevision()->getId()'
791 $page->getOldestRevision()->getId(),
792 '$page->getOldestRevision()->getId()'
797 * @todo FIXME: this is a better rollback test than the one below, but it
798 * keeps failing in jenkins for some reason.
800 public function broken_testDoRollback() {
802 $admin->setName( "Admin" );
805 $page = $this->newPage( "WikiPageTest_testDoRollback" );
806 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
807 "section one", EDIT_NEW
, false, $admin );
810 $user1->setName( "127.0.1.11" );
812 $page = new WikiPage( $page->getTitle() );
813 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
814 "adding section two", 0, false, $user1 );
817 $user2->setName( "127.0.2.13" );
818 $text .= "\n\nthree";
819 $page = new WikiPage( $page->getTitle() );
820 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
821 "adding section three", 0, false, $user2 );
823 # we are having issues with doRollback spuriously failing. Apparently
824 # the last revision somehow goes missing or not committed under some
825 # circumstances. So, make sure the last revision has the right user name.
826 $dbr = wfGetDB( DB_SLAVE
);
827 $this->assertEquals( 3, Revision
::countByPageId( $dbr, $page->getId() ) );
829 $page = new WikiPage( $page->getTitle() );
830 $rev3 = $page->getRevision();
831 $this->assertEquals( '127.0.2.13', $rev3->getUserText() );
833 $rev2 = $rev3->getPrevious();
834 $this->assertEquals( '127.0.1.11', $rev2->getUserText() );
836 $rev1 = $rev2->getPrevious();
837 $this->assertEquals( 'Admin', $rev1->getUserText() );
839 # now, try the actual rollback
840 $admin->addToDatabase();
841 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
842 $token = $admin->getEditToken(
843 [ $page->getTitle()->getPrefixedText(), $user2->getName() ],
846 $errors = $page->doRollback(
856 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
857 . ";\n" . print_r( $details, true ) );
860 $page = new WikiPage( $page->getTitle() );
861 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
862 "rollback did not revert to the correct revision" );
863 $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
867 * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason.
868 * @covers WikiPage::doRollback
870 public function testDoRollback() {
872 $admin->setName( "Admin" );
873 $admin->addToDatabase();
876 $page = $this->newPage( "WikiPageTest_testDoRollback" );
877 $page->doEditContent(
878 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
884 $rev1 = $page->getRevision();
887 $user1->setName( "127.0.1.11" );
889 $page = new WikiPage( $page->getTitle() );
890 $page->doEditContent(
891 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
892 "adding section two",
898 # now, try the rollback
899 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
900 $token = $admin->getEditToken( 'rollback' );
901 $errors = $page->doRollback(
911 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
912 . ";\n" . print_r( $details, true ) );
915 $page = new WikiPage( $page->getTitle() );
916 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
917 "rollback did not revert to the correct revision" );
918 $this->assertEquals( "one", $page->getContent()->getNativeData() );
922 * @covers WikiPage::doRollback
924 public function testDoRollbackFailureSameContent() {
926 $admin->setName( "Admin" );
927 $admin->addToDatabase();
928 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
931 $page = $this->newPage( "WikiPageTest_testDoRollback" );
932 $page->doEditContent(
933 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
939 $rev1 = $page->getRevision();
942 $user1->setName( "127.0.1.11" );
943 $user1->addToDatabase();
944 $user1->addGroup( "sysop" ); # XXX: make the test user a sysop...
946 $page = new WikiPage( $page->getTitle() );
947 $page->doEditContent(
948 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
949 "adding section two",
955 # now, do a the rollback from the same user was doing the edit before
957 $token = $user1->getEditToken( 'rollback' );
958 $errors = $page->doRollback(
960 "testing revert same user",
967 $this->assertEquals( [], $errors, "Rollback failed same user" );
969 # now, try the rollback
971 $token = $admin->getEditToken( 'rollback' );
972 $errors = $page->doRollback(
981 $this->assertEquals( [ [ 'alreadyrolled', 'WikiPageTest testDoRollback',
982 '127.0.1.11', 'Admin' ] ], $errors, "Rollback not failed" );
984 $page = new WikiPage( $page->getTitle() );
985 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
986 "rollback did not revert to the correct revision" );
987 $this->assertEquals( "one", $page->getContent()->getNativeData() );
990 public static function provideGetAutoDeleteReason() {
1000 [ "first edit", null ],
1002 "/first edit.*only contributor/",
1008 [ "first edit", null ],
1009 [ "second edit", null ],
1011 "/second edit.*only contributor/",
1017 [ "first edit", "127.0.2.22" ],
1018 [ "second edit", "127.0.3.33" ],
1028 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
1029 . " nonumy eirmod tempor invidunt ut labore et dolore magna "
1030 . "aliquyam erat, sed diam voluptua. At vero eos et accusam "
1031 . "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
1032 . "no sea takimata sanctus est Lorem ipsum dolor sit amet.'",
1036 '/first edit:.*\.\.\."/',
1042 [ "first edit", "127.0.2.22" ],
1043 [ "", "127.0.3.33" ],
1045 "/before blanking.*first edit/",
1053 * @dataProvider provideGetAutoDeleteReason
1054 * @covers WikiPage::getAutoDeleteReason
1056 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
1059 // NOTE: assume Help namespace to contain wikitext
1060 $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
1064 foreach ( $edits as $edit ) {
1067 if ( !empty( $edit[1] ) ) {
1068 $user->setName( $edit[1] );
1073 $content = ContentHandler
::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
1075 $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW
: 0, false, $user );
1080 $reason = $page->getAutoDeleteReason( $hasHistory );
1082 if ( is_bool( $expectedResult ) ||
is_null( $expectedResult ) ) {
1083 $this->assertEquals( $expectedResult, $reason );
1085 $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
1086 "Autosummary didn't match expected pattern $expectedResult: $reason" );
1089 $this->assertEquals( $expectedHistory, $hasHistory,
1090 "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
1092 $page->doDeleteArticle( "done" );
1095 public static function providePreSaveTransform() {
1097 [ 'hello this is ~~~',
1098 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
1100 [ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1101 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1107 * @covers WikiPage::factory
1109 public function testWikiPageFactory() {
1110 $title = Title
::makeTitle( NS_FILE
, 'Someimage.png' );
1111 $page = WikiPage
::factory( $title );
1112 $this->assertEquals( 'WikiFilePage', get_class( $page ) );
1114 $title = Title
::makeTitle( NS_CATEGORY
, 'SomeCategory' );
1115 $page = WikiPage
::factory( $title );
1116 $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
1118 $title = Title
::makeTitle( NS_MAIN
, 'SomePage' );
1119 $page = WikiPage
::factory( $title );
1120 $this->assertEquals( 'WikiPage', get_class( $page ) );