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::doEdit
160 * @deprecated since 1.21. Should be removed when WikiPage::doEdit() gets removed
162 public function testDoEdit() {
163 $this->hideDeprecated( "WikiPage::doEdit" );
164 $this->hideDeprecated( "Revision::getText" );
166 // NOTE: assume help namespace will default to wikitext
167 $title = Title
::newFromText( "Help:WikiPageTest_testDoEdit" );
169 $page = $this->newPage( $title );
171 $text = "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
172 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";
174 $page->doEdit( $text, "[[testing]] 1" );
176 $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
177 $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" );
178 $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
179 $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
181 $id = $page->getId();
183 # ------------------------
184 $dbr = wfGetDB( DB_SLAVE
);
185 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
186 $n = $res->numRows();
189 $this->assertEquals( 1, $n, 'pagelinks should contain one link from the page' );
191 # ------------------------
192 $text = "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
193 . "Stet clita kasd [[gubergren]], no sea takimata sanctus est.";
195 $page->doEdit( $text, "testing 2" );
197 # ------------------------
198 $page = new WikiPage( $title );
200 $retrieved = $page->getContent()->getNativeData();
201 $this->assertEquals( $text, $retrieved, 'retrieved text doesn\'t equal original' );
203 # ------------------------
204 $dbr = wfGetDB( DB_SLAVE
);
205 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
206 $n = $res->numRows();
209 $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
213 * @covers WikiPage::doDeleteArticle
215 public function testDoDeleteArticle() {
216 $page = $this->createPage(
217 "WikiPageTest_testDoDeleteArticle",
218 "[[original text]] foo",
219 CONTENT_MODEL_WIKITEXT
221 $id = $page->getId();
223 $page->doDeleteArticle( "testing deletion" );
226 $page->getTitle()->getArticleID() > 0,
227 "Title object should now have page id 0"
229 $this->assertFalse( $page->getId() > 0, "WikiPage should now have page id 0" );
232 "WikiPage::exists should return false after page was deleted"
236 "WikiPage::getContent should return null after page was deleted"
239 $t = Title
::newFromText( $page->getTitle()->getPrefixedText() );
242 "Title::exists should return false after page was deleted"
246 JobQueueGroup
::destroySingletons();
248 $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
251 # ------------------------
252 $dbr = wfGetDB( DB_SLAVE
);
253 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
254 $n = $res->numRows();
257 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
261 * @covers WikiPage::doDeleteUpdates
263 public function testDoDeleteUpdates() {
264 $page = $this->createPage(
265 "WikiPageTest_testDoDeleteArticle",
266 "[[original text]] foo",
267 CONTENT_MODEL_WIKITEXT
269 $id = $page->getId();
271 // Similar to MovePage logic
272 wfGetDB( DB_MASTER
)->delete( 'page', [ 'page_id' => $id ], __METHOD__
);
273 $page->doDeleteUpdates( $id );
276 JobQueueGroup
::destroySingletons();
278 $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
281 # ------------------------
282 $dbr = wfGetDB( DB_SLAVE
);
283 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
284 $n = $res->numRows();
287 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
291 * @covers WikiPage::getRevision
293 public function testGetRevision() {
294 $page = $this->newPage( "WikiPageTest_testGetRevision" );
296 $rev = $page->getRevision();
297 $this->assertNull( $rev );
300 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
302 $rev = $page->getRevision();
304 $this->assertEquals( $page->getLatest(), $rev->getId() );
305 $this->assertEquals( "some text", $rev->getContent()->getNativeData() );
309 * @covers WikiPage::getContent
311 public function testGetContent() {
312 $page = $this->newPage( "WikiPageTest_testGetContent" );
314 $content = $page->getContent();
315 $this->assertNull( $content );
318 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
320 $content = $page->getContent();
321 $this->assertEquals( "some text", $content->getNativeData() );
325 * @covers WikiPage::getContentModel
327 public function testGetContentModel() {
328 global $wgContentHandlerUseDB;
330 if ( !$wgContentHandlerUseDB ) {
331 $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
334 $page = $this->createPage(
335 "WikiPageTest_testGetContentModel",
337 CONTENT_MODEL_JAVASCRIPT
340 $page = new WikiPage( $page->getTitle() );
341 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $page->getContentModel() );
345 * @covers WikiPage::getContentHandler
347 public function testGetContentHandler() {
348 global $wgContentHandlerUseDB;
350 if ( !$wgContentHandlerUseDB ) {
351 $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' );
354 $page = $this->createPage(
355 "WikiPageTest_testGetContentHandler",
357 CONTENT_MODEL_JAVASCRIPT
360 $page = new WikiPage( $page->getTitle() );
361 $this->assertEquals( 'JavaScriptContentHandler', get_class( $page->getContentHandler() ) );
365 * @covers WikiPage::exists
367 public function testExists() {
368 $page = $this->newPage( "WikiPageTest_testExists" );
369 $this->assertFalse( $page->exists() );
372 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
373 $this->assertTrue( $page->exists() );
375 $page = new WikiPage( $page->getTitle() );
376 $this->assertTrue( $page->exists() );
379 $page->doDeleteArticle( "done testing" );
380 $this->assertFalse( $page->exists() );
382 $page = new WikiPage( $page->getTitle() );
383 $this->assertFalse( $page->exists() );
386 public static function provideHasViewableContent() {
388 [ 'WikiPageTest_testHasViewableContent', false, true ],
389 [ 'Special:WikiPageTest_testHasViewableContent', false ],
390 [ 'MediaWiki:WikiPageTest_testHasViewableContent', false ],
391 [ 'Special:Userlogin', true ],
392 [ 'MediaWiki:help', true ],
397 * @dataProvider provideHasViewableContent
398 * @covers WikiPage::hasViewableContent
400 public function testHasViewableContent( $title, $viewable, $create = false ) {
401 $page = $this->newPage( $title );
402 $this->assertEquals( $viewable, $page->hasViewableContent() );
405 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
406 $this->assertTrue( $page->hasViewableContent() );
408 $page = new WikiPage( $page->getTitle() );
409 $this->assertTrue( $page->hasViewableContent() );
413 public static function provideGetRedirectTarget() {
415 [ 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT
, "hello world", null ],
417 'WikiPageTest_testGetRedirectTarget_2',
418 CONTENT_MODEL_WIKITEXT
,
419 "#REDIRECT [[hello world]]",
426 * @dataProvider provideGetRedirectTarget
427 * @covers WikiPage::getRedirectTarget
429 public function testGetRedirectTarget( $title, $model, $text, $target ) {
430 $this->setMwGlobals( [
431 'wgCapitalLinks' => true,
434 $page = $this->createPage( $title, $text, $model );
436 # sanity check, because this test seems to fail for no reason for some people.
437 $c = $page->getContent();
438 $this->assertEquals( 'WikitextContent', get_class( $c ) );
440 # now, test the actual redirect
441 $t = $page->getRedirectTarget();
442 $this->assertEquals( $target, is_null( $t ) ?
null : $t->getPrefixedText() );
446 * @dataProvider provideGetRedirectTarget
447 * @covers WikiPage::isRedirect
449 public function testIsRedirect( $title, $model, $text, $target ) {
450 $page = $this->createPage( $title, $text, $model );
451 $this->assertEquals( !is_null( $target ), $page->isRedirect() );
454 public static function provideIsCountable() {
458 [ 'WikiPageTest_testIsCountable',
459 CONTENT_MODEL_WIKITEXT
,
464 [ 'WikiPageTest_testIsCountable',
465 CONTENT_MODEL_WIKITEXT
,
472 [ 'WikiPageTest_testIsCountable',
473 CONTENT_MODEL_WIKITEXT
,
478 [ 'WikiPageTest_testIsCountable',
479 CONTENT_MODEL_WIKITEXT
,
486 [ 'WikiPageTest_testIsCountable',
487 CONTENT_MODEL_WIKITEXT
,
492 [ 'WikiPageTest_testIsCountable',
493 CONTENT_MODEL_WIKITEXT
,
500 [ 'WikiPageTest_testIsCountable',
501 CONTENT_MODEL_WIKITEXT
,
506 [ 'WikiPageTest_testIsCountable',
507 CONTENT_MODEL_WIKITEXT
,
512 [ 'WikiPageTest_testIsCountable',
513 CONTENT_MODEL_WIKITEXT
,
519 // not a content namespace
520 [ 'Talk:WikiPageTest_testIsCountable',
521 CONTENT_MODEL_WIKITEXT
,
526 [ 'Talk:WikiPageTest_testIsCountable',
527 CONTENT_MODEL_WIKITEXT
,
532 [ 'Talk:WikiPageTest_testIsCountable',
533 CONTENT_MODEL_WIKITEXT
,
539 // not a content namespace, different model
540 [ 'MediaWiki:WikiPageTest_testIsCountable.js',
546 [ 'MediaWiki:WikiPageTest_testIsCountable.js',
552 [ 'MediaWiki:WikiPageTest_testIsCountable.js',
562 * @dataProvider provideIsCountable
563 * @covers WikiPage::isCountable
565 public function testIsCountable( $title, $model, $text, $mode, $expected ) {
566 global $wgContentHandlerUseDB;
568 $this->setMwGlobals( 'wgArticleCountMethod', $mode );
570 $title = Title
::newFromText( $title );
572 if ( !$wgContentHandlerUseDB
574 && ContentHandler
::getDefaultModelFor( $title ) != $model
576 $this->markTestSkipped( "Can not use non-default content model $model for "
577 . $title->getPrefixedDBkey() . " with \$wgContentHandlerUseDB disabled." );
580 $page = $this->createPage( $title, $text, $model );
582 $editInfo = $page->prepareContentForEdit( $page->getContent() );
584 $v = $page->isCountable();
585 $w = $page->isCountable( $editInfo );
590 "isCountable( null ) returned unexpected value " . var_export( $v, true )
591 . " instead of " . var_export( $expected, true )
592 . " in mode `$mode` for text \"$text\""
598 "isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true )
599 . " instead of " . var_export( $expected, true )
600 . " in mode `$mode` for text \"$text\""
604 public static function provideGetParserOutput() {
606 [ CONTENT_MODEL_WIKITEXT
, "hello ''world''\n", "<p>hello <i>world</i></p>" ],
612 * @dataProvider provideGetParserOutput
613 * @covers WikiPage::getParserOutput
615 public function testGetParserOutput( $model, $text, $expectedHtml ) {
616 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', $text, $model );
618 $opt = $page->makeParserOptions( 'canonical' );
619 $po = $page->getParserOutput( $opt );
620 $text = $po->getText();
622 $text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments
623 $text = preg_replace( '!\s*(</p>)!sm', '\1', $text ); # don't let tidy confuse us
625 $this->assertEquals( $expectedHtml, $text );
631 * @covers WikiPage::getParserOutput
633 public function testGetParserOutput_nonexisting() {
637 $page = new WikiPage( new Title( "WikiPageTest_testGetParserOutput_nonexisting_$count" ) );
639 $opt = new ParserOptions();
640 $po = $page->getParserOutput( $opt );
642 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
646 * @covers WikiPage::getParserOutput
648 public function testGetParserOutput_badrev() {
649 $page = $this->createPage( 'WikiPageTest_testGetParserOutput', "dummy", CONTENT_MODEL_WIKITEXT
);
651 $opt = new ParserOptions();
652 $po = $page->getParserOutput( $opt, $page->getLatest() +
1234 );
654 // @todo would be neat to also test deleted revision
656 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
659 public static $sections =
673 public function dataReplaceSection() {
674 // NOTE: assume the Help namespace to contain wikitext
676 [ 'Help:WikiPageTest_testReplaceSection',
677 CONTENT_MODEL_WIKITEXT
,
678 WikiPageTest
::$sections,
682 trim( preg_replace( '/^Intro/sm', 'No more', WikiPageTest
::$sections ) )
684 [ 'Help:WikiPageTest_testReplaceSection',
685 CONTENT_MODEL_WIKITEXT
,
686 WikiPageTest
::$sections,
692 [ 'Help:WikiPageTest_testReplaceSection',
693 CONTENT_MODEL_WIKITEXT
,
694 WikiPageTest
::$sections,
696 "== TEST ==\nmore fun",
698 trim( preg_replace( '/^== test ==.*== foo ==/sm',
699 "== TEST ==\nmore fun\n\n== foo ==",
700 WikiPageTest
::$sections ) )
702 [ 'Help:WikiPageTest_testReplaceSection',
703 CONTENT_MODEL_WIKITEXT
,
704 WikiPageTest
::$sections,
708 trim( WikiPageTest
::$sections )
710 [ 'Help:WikiPageTest_testReplaceSection',
711 CONTENT_MODEL_WIKITEXT
,
712 WikiPageTest
::$sections,
716 trim( WikiPageTest
::$sections ) . "\n\n== New ==\n\nNo more"
722 * @dataProvider dataReplaceSection
723 * @covers WikiPage::replaceSectionContent
725 public function testReplaceSectionContent( $title, $model, $text, $section,
726 $with, $sectionTitle, $expected
728 $page = $this->createPage( $title, $text, $model );
730 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
731 $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
733 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
737 * @dataProvider dataReplaceSection
738 * @covers WikiPage::replaceSectionAtRev
740 public function testReplaceSectionAtRev( $title, $model, $text, $section,
741 $with, $sectionTitle, $expected
743 $page = $this->createPage( $title, $text, $model );
744 $baseRevId = $page->getLatest();
746 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
747 $c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
749 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
752 /* @todo FIXME: fix this!
753 public function testGetUndoText() {
754 $this->markTestSkippedIfNoDiff3();
757 $page = $this->createPage( "WikiPageTest_testGetUndoText", $text );
758 $rev1 = $page->getRevision();
761 $page->doEditContent(
762 ContentHandler::makeContent( $text, $page->getTitle() ),
765 $rev2 = $page->getRevision();
767 $text .= "\n\nthree";
768 $page->doEditContent(
769 ContentHandler::makeContent( $text, $page->getTitle() ),
770 "adding section three"
772 $rev3 = $page->getRevision();
775 $page->doEditContent(
776 ContentHandler::makeContent( $text, $page->getTitle() ),
777 "adding section four"
779 $rev4 = $page->getRevision();
782 $page->doEditContent(
783 ContentHandler::makeContent( $text, $page->getTitle() ),
784 "adding section five"
786 $rev5 = $page->getRevision();
789 $page->doEditContent(
790 ContentHandler::makeContent( $text, $page->getTitle() ),
793 $rev6 = $page->getRevision();
795 $undo6 = $page->getUndoText( $rev6 );
796 if ( $undo6 === false ) $this->fail( "getUndoText failed for rev6" );
797 $this->assertEquals( "one\n\ntwo\n\nthree\n\nfour\n\nfive", $undo6 );
799 $undo3 = $page->getUndoText( $rev4, $rev2 );
800 if ( $undo3 === false ) $this->fail( "getUndoText failed for rev4..rev2" );
801 $this->assertEquals( "one\n\ntwo\n\nfive", $undo3 );
803 $undo2 = $page->getUndoText( $rev2 );
804 if ( $undo2 === false ) $this->fail( "getUndoText failed for rev2" );
805 $this->assertEquals( "one\n\nfive", $undo2 );
810 * @todo FIXME: this is a better rollback test than the one below, but it
811 * keeps failing in jenkins for some reason.
813 public function broken_testDoRollback() {
815 $admin->setName( "Admin" );
818 $page = $this->newPage( "WikiPageTest_testDoRollback" );
819 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
820 "section one", EDIT_NEW
, false, $admin );
823 $user1->setName( "127.0.1.11" );
825 $page = new WikiPage( $page->getTitle() );
826 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
827 "adding section two", 0, false, $user1 );
830 $user2->setName( "127.0.2.13" );
831 $text .= "\n\nthree";
832 $page = new WikiPage( $page->getTitle() );
833 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
834 "adding section three", 0, false, $user2 );
836 # we are having issues with doRollback spuriously failing. Apparently
837 # the last revision somehow goes missing or not committed under some
838 # circumstances. So, make sure the last revision has the right user name.
839 $dbr = wfGetDB( DB_SLAVE
);
840 $this->assertEquals( 3, Revision
::countByPageId( $dbr, $page->getId() ) );
842 $page = new WikiPage( $page->getTitle() );
843 $rev3 = $page->getRevision();
844 $this->assertEquals( '127.0.2.13', $rev3->getUserText() );
846 $rev2 = $rev3->getPrevious();
847 $this->assertEquals( '127.0.1.11', $rev2->getUserText() );
849 $rev1 = $rev2->getPrevious();
850 $this->assertEquals( 'Admin', $rev1->getUserText() );
852 # now, try the actual rollback
853 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
854 $token = $admin->getEditToken(
855 [ $page->getTitle()->getPrefixedText(), $user2->getName() ],
858 $errors = $page->doRollback(
868 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
869 . ";\n" . print_r( $details, true ) );
872 $page = new WikiPage( $page->getTitle() );
873 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
874 "rollback did not revert to the correct revision" );
875 $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
879 * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason.
880 * @covers WikiPage::doRollback
882 public function testDoRollback() {
884 $admin->setName( "Admin" );
887 $page = $this->newPage( "WikiPageTest_testDoRollback" );
888 $page->doEditContent(
889 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
895 $rev1 = $page->getRevision();
898 $user1->setName( "127.0.1.11" );
900 $page = new WikiPage( $page->getTitle() );
901 $page->doEditContent(
902 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
903 "adding section two",
909 # now, try the rollback
910 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
911 $token = $admin->getEditToken(
912 [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
915 $errors = $page->doRollback(
925 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
926 . ";\n" . print_r( $details, true ) );
929 $page = new WikiPage( $page->getTitle() );
930 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
931 "rollback did not revert to the correct revision" );
932 $this->assertEquals( "one", $page->getContent()->getNativeData() );
936 * @covers WikiPage::doRollback
938 public function testDoRollbackFailureSameContent() {
940 $admin->setName( "Admin" );
941 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
944 $page = $this->newPage( "WikiPageTest_testDoRollback" );
945 $page->doEditContent(
946 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
952 $rev1 = $page->getRevision();
955 $user1->setName( "127.0.1.11" );
956 $user1->addGroup( "sysop" ); # XXX: make the test user a sysop...
958 $page = new WikiPage( $page->getTitle() );
959 $page->doEditContent(
960 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
961 "adding section two",
967 # now, do a the rollback from the same user was doing the edit before
969 $token = $user1->getEditToken(
970 [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
973 $errors = $page->doRollback(
975 "testing revert same user",
982 $this->assertEquals( [], $errors, "Rollback failed same user" );
984 # now, try the rollback
986 $token = $admin->getEditToken(
987 [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
990 $errors = $page->doRollback(
999 $this->assertEquals( [ [ 'alreadyrolled', 'WikiPageTest testDoRollback',
1000 '127.0.1.11', 'Admin' ] ], $errors, "Rollback not failed" );
1002 $page = new WikiPage( $page->getTitle() );
1003 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
1004 "rollback did not revert to the correct revision" );
1005 $this->assertEquals( "one", $page->getContent()->getNativeData() );
1008 public static function provideGetAutoDeleteReason() {
1018 [ "first edit", null ],
1020 "/first edit.*only contributor/",
1026 [ "first edit", null ],
1027 [ "second edit", null ],
1029 "/second edit.*only contributor/",
1035 [ "first edit", "127.0.2.22" ],
1036 [ "second edit", "127.0.3.33" ],
1046 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
1047 . " nonumy eirmod tempor invidunt ut labore et dolore magna "
1048 . "aliquyam erat, sed diam voluptua. At vero eos et accusam "
1049 . "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
1050 . "no sea takimata sanctus est Lorem ipsum dolor sit amet.'",
1054 '/first edit:.*\.\.\."/',
1060 [ "first edit", "127.0.2.22" ],
1061 [ "", "127.0.3.33" ],
1063 "/before blanking.*first edit/",
1071 * @dataProvider provideGetAutoDeleteReason
1072 * @covers WikiPage::getAutoDeleteReason
1074 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
1077 // NOTE: assume Help namespace to contain wikitext
1078 $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
1082 foreach ( $edits as $edit ) {
1085 if ( !empty( $edit[1] ) ) {
1086 $user->setName( $edit[1] );
1091 $content = ContentHandler
::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
1093 $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW
: 0, false, $user );
1098 $reason = $page->getAutoDeleteReason( $hasHistory );
1100 if ( is_bool( $expectedResult ) ||
is_null( $expectedResult ) ) {
1101 $this->assertEquals( $expectedResult, $reason );
1103 $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
1104 "Autosummary didn't match expected pattern $expectedResult: $reason" );
1107 $this->assertEquals( $expectedHistory, $hasHistory,
1108 "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
1110 $page->doDeleteArticle( "done" );
1113 public static function providePreSaveTransform() {
1115 [ 'hello this is ~~~',
1116 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
1118 [ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1119 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1125 * @covers WikiPage::factory
1127 public function testWikiPageFactory() {
1128 $title = Title
::makeTitle( NS_FILE
, 'Someimage.png' );
1129 $page = WikiPage
::factory( $title );
1130 $this->assertEquals( 'WikiFilePage', get_class( $page ) );
1132 $title = Title
::makeTitle( NS_CATEGORY
, 'SomeCategory' );
1133 $page = WikiPage
::factory( $title );
1134 $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
1136 $title = Title
::makeTitle( NS_MAIN
, 'SomePage' );
1137 $page = WikiPage
::factory( $title );
1138 $this->assertEquals( 'WikiPage', get_class( $page ) );