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 * @todo FIXME: this is a better rollback test than the one below, but it
757 * keeps failing in jenkins for some reason.
759 public function broken_testDoRollback() {
761 $admin->setName( "Admin" );
764 $page = $this->newPage( "WikiPageTest_testDoRollback" );
765 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
766 "section one", EDIT_NEW
, false, $admin );
769 $user1->setName( "127.0.1.11" );
771 $page = new WikiPage( $page->getTitle() );
772 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
773 "adding section two", 0, false, $user1 );
776 $user2->setName( "127.0.2.13" );
777 $text .= "\n\nthree";
778 $page = new WikiPage( $page->getTitle() );
779 $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
780 "adding section three", 0, false, $user2 );
782 # we are having issues with doRollback spuriously failing. Apparently
783 # the last revision somehow goes missing or not committed under some
784 # circumstances. So, make sure the last revision has the right user name.
785 $dbr = wfGetDB( DB_SLAVE
);
786 $this->assertEquals( 3, Revision
::countByPageId( $dbr, $page->getId() ) );
788 $page = new WikiPage( $page->getTitle() );
789 $rev3 = $page->getRevision();
790 $this->assertEquals( '127.0.2.13', $rev3->getUserText() );
792 $rev2 = $rev3->getPrevious();
793 $this->assertEquals( '127.0.1.11', $rev2->getUserText() );
795 $rev1 = $rev2->getPrevious();
796 $this->assertEquals( 'Admin', $rev1->getUserText() );
798 # now, try the actual rollback
799 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
800 $token = $admin->getEditToken(
801 [ $page->getTitle()->getPrefixedText(), $user2->getName() ],
804 $errors = $page->doRollback(
814 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
815 . ";\n" . print_r( $details, true ) );
818 $page = new WikiPage( $page->getTitle() );
819 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
820 "rollback did not revert to the correct revision" );
821 $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
825 * @todo FIXME: the above rollback test is better, but it keeps failing in jenkins for some reason.
826 * @covers WikiPage::doRollback
828 public function testDoRollback() {
830 $admin->setName( "Admin" );
833 $page = $this->newPage( "WikiPageTest_testDoRollback" );
834 $page->doEditContent(
835 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
841 $rev1 = $page->getRevision();
844 $user1->setName( "127.0.1.11" );
846 $page = new WikiPage( $page->getTitle() );
847 $page->doEditContent(
848 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
849 "adding section two",
855 # now, try the rollback
856 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
857 $token = $admin->getEditToken(
858 [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
861 $errors = $page->doRollback(
871 $this->fail( "Rollback failed:\n" . print_r( $errors, true )
872 . ";\n" . print_r( $details, true ) );
875 $page = new WikiPage( $page->getTitle() );
876 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
877 "rollback did not revert to the correct revision" );
878 $this->assertEquals( "one", $page->getContent()->getNativeData() );
882 * @covers WikiPage::doRollback
884 public function testDoRollbackFailureSameContent() {
886 $admin->setName( "Admin" );
887 $admin->addGroup( "sysop" ); # XXX: make the test user a sysop...
890 $page = $this->newPage( "WikiPageTest_testDoRollback" );
891 $page->doEditContent(
892 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
898 $rev1 = $page->getRevision();
901 $user1->setName( "127.0.1.11" );
902 $user1->addGroup( "sysop" ); # XXX: make the test user a sysop...
904 $page = new WikiPage( $page->getTitle() );
905 $page->doEditContent(
906 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
907 "adding section two",
913 # now, do a the rollback from the same user was doing the edit before
915 $token = $user1->getEditToken(
916 [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
919 $errors = $page->doRollback(
921 "testing revert same user",
928 $this->assertEquals( [], $errors, "Rollback failed same user" );
930 # now, try the rollback
932 $token = $admin->getEditToken(
933 [ $page->getTitle()->getPrefixedText(), $user1->getName() ],
936 $errors = $page->doRollback(
945 $this->assertEquals( [ [ 'alreadyrolled', 'WikiPageTest testDoRollback',
946 '127.0.1.11', 'Admin' ] ], $errors, "Rollback not failed" );
948 $page = new WikiPage( $page->getTitle() );
949 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
950 "rollback did not revert to the correct revision" );
951 $this->assertEquals( "one", $page->getContent()->getNativeData() );
954 public static function provideGetAutoDeleteReason() {
964 [ "first edit", null ],
966 "/first edit.*only contributor/",
972 [ "first edit", null ],
973 [ "second edit", null ],
975 "/second edit.*only contributor/",
981 [ "first edit", "127.0.2.22" ],
982 [ "second edit", "127.0.3.33" ],
992 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
993 . " nonumy eirmod tempor invidunt ut labore et dolore magna "
994 . "aliquyam erat, sed diam voluptua. At vero eos et accusam "
995 . "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
996 . "no sea takimata sanctus est Lorem ipsum dolor sit amet.'",
1000 '/first edit:.*\.\.\."/',
1006 [ "first edit", "127.0.2.22" ],
1007 [ "", "127.0.3.33" ],
1009 "/before blanking.*first edit/",
1017 * @dataProvider provideGetAutoDeleteReason
1018 * @covers WikiPage::getAutoDeleteReason
1020 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
1023 // NOTE: assume Help namespace to contain wikitext
1024 $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
1028 foreach ( $edits as $edit ) {
1031 if ( !empty( $edit[1] ) ) {
1032 $user->setName( $edit[1] );
1037 $content = ContentHandler
::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
1039 $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW
: 0, false, $user );
1044 $reason = $page->getAutoDeleteReason( $hasHistory );
1046 if ( is_bool( $expectedResult ) ||
is_null( $expectedResult ) ) {
1047 $this->assertEquals( $expectedResult, $reason );
1049 $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
1050 "Autosummary didn't match expected pattern $expectedResult: $reason" );
1053 $this->assertEquals( $expectedHistory, $hasHistory,
1054 "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
1056 $page->doDeleteArticle( "done" );
1059 public static function providePreSaveTransform() {
1061 [ 'hello this is ~~~',
1062 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
1064 [ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1065 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1071 * @covers WikiPage::factory
1073 public function testWikiPageFactory() {
1074 $title = Title
::makeTitle( NS_FILE
, 'Someimage.png' );
1075 $page = WikiPage
::factory( $title );
1076 $this->assertEquals( 'WikiFilePage', get_class( $page ) );
1078 $title = Title
::makeTitle( NS_CATEGORY
, 'SomeCategory' );
1079 $page = WikiPage
::factory( $title );
1080 $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
1082 $title = Title
::makeTitle( NS_MAIN
, 'SomePage' );
1083 $page = WikiPage
::factory( $title );
1084 $this->assertEquals( 'WikiPage', get_class( $page ) );