21 parent::__construct(
$name, $data, $dataName );
23 $this->tablesUsed = array_merge( $this->tablesUsed,
55 12313 =>
'Dummy_talk',
60 'wgNamespaceContentModels',
78 $wgContLang->resetNamespaces();
80 if ( !$this->testPage ) {
85 $this->testPage = $this->
createPage( __CLASS__, __CLASS__ );
102 if ( $props ===
null ) {
106 if ( !isset( $props[
'content'] ) && !isset( $props[
'text'] ) ) {
107 $props[
'text'] =
'Lorem Ipsum';
110 if ( !isset( $props[
'user_text'] ) ) {
112 $props[
'user_text'] =
$user->getName();
113 $props[
'user'] =
$user->getId();
116 if ( !isset( $props[
'user'] ) ) {
120 if ( !isset( $props[
'comment'] ) ) {
121 $props[
'comment'] =
'just a test';
124 if ( !isset( $props[
'page'] ) ) {
125 $props[
'page'] = $this->testPage->getId();
128 if ( !isset( $props[
'content_model'] ) ) {
135 $rev->insertOn( $dbw );
147 private function createPage( $titleString, $text, $model =
null ) {
148 if ( !preg_match(
'/:/', $titleString ) &&
159 if ( $wikipage->exists() ) {
160 $wikipage->doDeleteArticle(
"done" );
164 $wikipage->doEditContent( $content, __METHOD__,
EDIT_NEW );
170 $this->assertNotNull(
$rev,
'missing revision' );
172 $this->assertEquals( $orig->
getId(),
$rev->getId() );
173 $this->assertEquals( $orig->
getPage(),
$rev->getPage() );
175 $this->assertEquals( $orig->
getUser(),
$rev->getUser() );
178 $this->assertEquals( $orig->
getSha1(),
$rev->getSha1() );
185 $rev = $this->testPage->getRevision();
186 $recentChange =
$rev->getRecentChange();
189 $this->assertEquals(
$rev->getTimestamp(), $recentChange->getAttribute(
'rc_timestamp' ) );
191 $rev->getTitle()->getNamespace(),
192 $recentChange->getAttribute(
'rc_namespace' )
195 $rev->getTitle()->getDBkey(),
196 $recentChange->getAttribute(
'rc_title' )
198 $this->assertEquals(
$rev->getUser(), $recentChange->getAttribute(
'rc_user' ) );
199 $this->assertEquals(
$rev->getUserText(), $recentChange->getAttribute(
'rc_user_text' ) );
200 $this->assertEquals(
$rev->getComment(), $recentChange->getAttribute(
'rc_comment' ) );
201 $this->assertEquals(
$rev->getPage(), $recentChange->getAttribute(
'rc_cur_id' ) );
202 $this->assertEquals(
$rev->getId(), $recentChange->getAttribute(
'rc_this_oldid' ) );
209 $parentId = $this->testPage->getLatest();
215 'page' => $this->testPage->getId(),
216 'title' => $this->testPage->getTitle(),
217 'text' =>
'Revision Text',
218 'comment' =>
'Revision comment',
223 $this->assertInternalType(
'integer', $revId );
224 $this->assertSame( $revId,
$rev->getId() );
227 $this->assertInternalType(
'integer',
$rev->getTextId() );
229 $mainSlot =
$rev->getRevisionRecord()->getSlot(
'main', RevisionRecord::RAW );
232 $textId = MediaWikiServices::getInstance()
234 ->getTextIdFromAddress( $mainSlot->getAddress() );
238 [
'old_id',
'old_text' ],
240 [ [ strval( $textId ),
'Revision Text' ] ]
254 "rev_id = {$rev->getId()}",
256 strval(
$rev->getId() ),
257 strval( $this->testPage->getId() ),
263 's0ngbdoxagreuf2vjtuxzwdz64n29xm',
274 $this->setExpectedException(
276 "rev_page field must not be 0!"
289 $latestRevId = $this->testPage->getLatest();
293 $this->assertTrue( $this->testPage->getTitle()->equals(
$rev->getTitle() ) );
294 $this->assertEquals( $latestRevId,
$rev->getId() );
301 $latestRevId = $this->testPage->getLatest();
305 $this->assertTrue( $this->testPage->getTitle()->equals(
$rev->getTitle() ) );
306 $this->assertEquals( $latestRevId,
$rev->getId() );
313 $latestRevId = $this->testPage->getLatest();
317 $this->assertNull(
$rev );
330 $this->assertTrue( is_object(
$res ),
'query failed' );
332 $row =
$res->fetchObject();
348 return $f + [
'ar_namespace',
'ar_title' ];
353 unset( $f[
'ar_text_id'] );
359 unset( $f[
'ar_page_id'] );
365 unset( $f[
'ar_parent_id'] );
371 unset( $f[
'ar_rev_id'] );
377 unset( $f[
'ar_sha1'] );
388 $services = MediaWikiServices::getInstance();
392 $services->getService(
'_SqlBlobStore' ),
402 'RevisionStorageTest_testNewFromArchiveRow',
406 $orig = $page->getRevision();
407 $page->doDeleteArticle(
'test Revision::newFromArchiveRow' );
411 $arQuery[
'fields'] = $selectModifier( $arQuery[
'fields'] );
413 $arQuery[
'tables'], $arQuery[
'fields'], [
'ar_rev_id' => $orig->getId() ],
414 __METHOD__, [], $arQuery[
'joins']
416 $this->assertTrue( is_object(
$res ),
'query failed' );
418 $row =
$res->fetchObject();
433 'RevisionStorageTest_testNewFromArchiveRow',
437 $orig = $page->getRevision();
438 $page->doDeleteArticle(
'test Revision::newFromArchiveRow' );
443 $arQuery[
'tables'], $arQuery[
'fields'], [
'ar_rev_id' => $orig->getId() ],
444 __METHOD__, [], $arQuery[
'joins']
446 $this->assertTrue( is_object(
$res ),
'query failed' );
448 $row =
$res->fetchObject();
453 $this->assertNotEquals( $orig->getComment(),
$rev->getComment() );
454 $this->assertEquals(
'SOMEOVERRIDE',
$rev->getComment() );
461 $orig = $this->testPage->getRevision();
472 $this->testPage->getRevision(),
482 $this->testPage->getId(),
483 $this->testPage->getLatest()
486 $this->testPage->getRevision(),
496 $this->testPage->doEditContent( $content, __METHOD__ );
498 $this->testPage->getId(),
499 $this->testPage->getRevision()->getPrevious()->getId()
502 $this->testPage->getRevision()->getPrevious(),
512 $this->testPage->getRevision()->getId();
514 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
515 $id = $this->testPage->getRevision()->getId();
520 # note: order is unspecified
522 while ( ( $row =
$res->fetchObject() ) ) {
523 $rows[$row->rev_id] = $row;
526 $this->assertEmpty(
$rows,
'expected empty set' );
538 $this->assertEquals( $page->getId(),
$rev->getPage() );
545 $rev1 = $this->testPage->getRevision();
547 # @todo find out if this should be true
548 # $this->assertTrue( $rev1->isCurrent() );
551 $this->assertTrue( $rev1x->isCurrent() );
553 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
554 $rev2 = $this->testPage->getRevision();
556 # @todo find out if this should be true
557 # $this->assertTrue( $rev2->isCurrent() );
560 $this->assertFalse( $rev1x->isCurrent() );
563 $this->assertTrue( $rev2x->isCurrent() );
570 $oldestRevision = $this->testPage->getOldestRevision();
571 $latestRevision = $this->testPage->getLatest();
573 $this->assertNull( $oldestRevision->getPrevious() );
575 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
576 $newRevision = $this->testPage->getRevision();
578 $this->assertNotNull( $newRevision->getPrevious() );
579 $this->assertEquals( $latestRevision, $newRevision->getPrevious()->getId() );
586 $rev1 = $this->testPage->getRevision();
588 $this->assertNull( $rev1->getNext() );
590 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
591 $rev2 = $this->testPage->getRevision();
593 $this->assertNotNull( $rev1->getNext() );
594 $this->assertEquals( $rev2->getId(), $rev1->getNext()->getId() );
601 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
602 $orig = $this->testPage->getRevision();
607 $this->assertNotEquals( $orig->getId(),
$rev->getId(),
608 'new null revision should have a different id from the original revision' );
609 $this->assertEquals( $orig->getTextId(),
$rev->getTextId(),
610 'new null revision should have the same text id as the original revision' );
611 $this->assertEquals( $orig->getSha1(),
$rev->getSha1(),
612 'new null revision should have the same SHA1 as the original revision' );
613 $this->assertTrue( $orig->getRevisionRecord()->hasSameContent(
$rev->getRevisionRecord() ),
614 'new null revision should have the same content as the original revision' );
615 $this->assertEquals( __METHOD__,
$rev->getContent()->getNativeData() );
625 $this->assertNull(
$rev );
632 $ip =
'2600:387:ed7:947e:8c16:a1ad:dd34:1dd7';
640 $res =
$dbr->select(
'ip_changes',
'*', [
'ipc_rev_id' => $orig->getId() ] );
641 $row =
$res->fetchObject();
643 $this->assertEquals(
IP::toHex( $ip ), $row->ipc_hex );
645 $orig->getTimestamp(),
651 yield
'actually the last edit' => [ 3,
true ];
652 yield
'not the current edit, but still by this user' => [ 2,
true ];
653 yield
'edit by another user' => [ 1,
false ];
654 yield
'first edit, by this user, but another user edited in the mean time' => [ 0,
false ];
665 if ( $userA->getId() === 0 ) {
669 if ( $userB->getId() === 0 ) {
680 'RevisionStorageTest_testUserWasLastToEdit', $ns ) );
681 $page->insertOn( $dbw );
684 'page' => $page->getId(),
686 'title' => $page->getTitle(),
687 'timestamp' =>
'20120101000000',
688 'user' => $userA->getId(),
691 'comment' =>
'edit zero'
693 $revisions[0]->insertOn( $dbw );
696 'page' => $page->getId(),
698 'title' => $page->getTitle(),
699 'timestamp' =>
'20120101000100',
700 'user' => $userA->getId(),
703 'comment' =>
'edit one'
705 $revisions[1]->insertOn( $dbw );
708 'page' => $page->getId(),
709 'title' => $page->getTitle(),
710 'timestamp' =>
'20120101000200',
711 'user' => $userB->getId(),
714 'comment' =>
'edit two'
716 $revisions[2]->insertOn( $dbw );
719 'page' => $page->getId(),
720 'title' => $page->getTitle(),
721 'timestamp' =>
'20120101000300',
722 'user' => $userA->getId(),
725 'comment' =>
'edit three'
727 $revisions[3]->insertOn( $dbw );
730 'page' => $page->getId(),
731 'title' => $page->getTitle(),
732 'timestamp' =>
'20120101000200',
733 'user' => $userA->getId(),
736 'comment' =>
'edit four'
738 $revisions[4]->insertOn( $dbw );
741 $since = $revisions[$sinceIdx]->getTimestamp();
744 $allRows = iterator_to_array( $dbw->select(
746 [
'rev_id',
'rev_timestamp',
'rev_user' =>
$revQuery[
'fields'][
'rev_user'] ],
748 'rev_page' => $page->getId(),
752 [
'ORDER BY' =>
'rev_timestamp ASC',
'LIMIT' => 50 ],
758 $this->assertEquals( $expectedLast, $wasLast );
772 if ( is_string(
$title ) ) {
784 'content' => $content,
785 'length' => $content->getSize(),
786 'comment' =>
"testing",
787 'minor_edit' =>
false,
789 'content_format' => $format,
812 $this->assertEquals( $expectedModel,
$rev->getContentModel() );
832 $this->assertEquals( $expectedFormat,
$rev->getContentFormat() );
851 $this->assertEquals( $expectedClass, get_class(
$rev->getContentHandler() ) );
882 $audience, $expectedSerialization
885 $content =
$rev->getContent( $audience );
888 $expectedSerialization,
889 is_null( $content ) ?
null : $content->serialize( $format )
898 'page' => $this->testPage->getId(),
899 'content_model' => $this->testPage->getContentModel(),
900 'text_id' => 123456789,
903 Wikimedia\suppressWarnings();
905 $this->assertNull(
$rev->getContent(),
906 "getContent() should return null if the revision's text blob could not be loaded." );
909 $this->assertNull(
$rev->getContent(),
910 "getContent() should return null if the revision's text blob could not be loaded." );
912 Wikimedia\restoreWarnings();
928 $this->assertEquals( $expected_size,
$rev->getSize() );
948 $this->assertEquals( $expected_hash,
$rev->getSha1() );
965 'content' => $content,
966 'length' => $content->getSize(),
967 'comment' =>
"testing",
968 'minor_edit' =>
false,
974 $content->setText(
"bar" );
979 $this->assertNotSame( $content, $content2,
"expected a clone" );
981 $this->assertEquals(
"foo", $content2->getText() );
983 $content2->setText(
"bla bla" );
985 $this->assertEquals(
"bar", $content->getText() );
998 $this->assertSame( $content, $content2 );
1005 $rev = $this->testPage->getRevision();
1018 $this->testPage->getRevision(),
1028 $this->testPage->getRevision(),
1031 $this->testPage->getId(),
1032 $this->testPage->getLatest()
1041 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1043 $this->testPage->getRevision()->getPrevious(),
1046 $this->testPage->getId(),
1047 $this->testPage->getRevision()->getPrevious()->getId()
1057 $this->testPage->getRevision(),
1067 $this->testPage->getRevision(),
1070 $this->testPage->getTitle(),
1071 $this->testPage->getLatest()
1080 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1082 $this->testPage->getRevision()->getPrevious(),
1085 $this->testPage->getTitle(),
1086 $this->testPage->getRevision()->getPrevious()->getId()
1096 $this->testPage->getRevision(),
1099 $this->testPage->getTitle(),
1100 $this->testPage->getRevision()->getTimestamp()
1122 $text =
'831jr091jr0921kr21kr0921kjr0921j09rj1';
1123 $textLength = strlen( $text );
1125 $this->testPage->doEditContent(
new WikitextContent( $text ), __METHOD__ );
1126 $rev[1] = $this->testPage->getLatest();
1129 [
$rev[1] => $textLength ],
1141 $textOne =
'831jr091jr0921kr21kr0921kjr0921j09rj1';
1142 $textOneLength = strlen( $textOne );
1143 $textTwo =
'831jr091jr092121j09rj1';
1144 $textTwoLength = strlen( $textTwo );
1146 $this->testPage->doEditContent(
new WikitextContent( $textOne ), __METHOD__ );
1147 $rev[1] = $this->testPage->getLatest();
1148 $this->testPage->doEditContent(
new WikitextContent( $textTwo ), __METHOD__ );
1149 $rev[2] = $this->testPage->getLatest();
1152 [
$rev[1] => $textOneLength,
$rev[2] => $textTwoLength ],
1165 $this->testPage->getTitle()->equals(
1166 $this->testPage->getRevision()->getTitle()
1175 $rev =
new Revision( [
'id' => $this->testPage->getLatest() ] );
1177 $this->testPage->getTitle()->equals(
1190 $this->testPage->doEditContent(
1197 $rev = $this->testPage->getRevision();
1199 $this->assertSame(
true,
$rev->isMinor() );
1206 $this->testPage->doEditContent(
1211 $rev = $this->testPage->getRevision();
1213 $this->assertSame(
false,
$rev->isMinor() );
1222 $this->testPage->doEditContent(
1226 $rev = $this->testPage->getRevision();
1228 $this->assertInternalType(
'string',
$rev->getTimestamp() );
1229 $this->assertTrue( strlen(
$rev->getTimestamp() ) == strlen(
'YYYYMMDDHHMMSS' ) );
1230 $this->assertContains( substr( $testTimestamp, 0, 10 ),
$rev->getTimestamp() );
1240 $this->testPage->doEditContent(
1247 $rev = $this->testPage->getRevision();
1249 $this->assertSame( $sysop->getId(),
$rev->getUser() );
1250 $this->assertSame( $sysop->getName(),
$rev->getUserText() );
1257 $rev = $this->testPage->getRevision();
1269 $rev = $this->testPage->getRevision();
1271 $this->assertSame( 0,
$rev->getVisibility() );
1278 $expectedSummary =
'goatlicious summary';
1280 $this->testPage->doEditContent(
1284 $rev = $this->testPage->getRevision();
1286 $this->assertSame( $expectedSummary,
$rev->getComment() );
1293 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1294 $rev = $this->testPage->getRevision();
1296 $this->assertGreaterThan( 0,
$rev->isUnpatrolled() );
1297 $this->assertSame(
$rev->getRecentChange()->getAttribute(
'rc_id' ),
$rev->isUnpatrolled() );
1306 $this->testPage->doEditContent(
1313 $rev = $this->testPage->getRevision();
1315 $this->assertSame( 0,
$rev->isUnpatrolled() );
1328 $expectedText =
'testSimpleContentGetters in Revision. Goats love MCR...';
1329 $expectedSummary =
'goatlicious testSimpleContentGetters summary';
1331 $this->testPage->doEditContent(
1335 $rev = $this->testPage->getRevision();
1337 $this->assertSame( $expectedText,
$rev->getContent()->getNativeData() );
1338 $this->assertSame( $expectedText,
$rev->getSerializedData() );
1339 $this->assertSame( $this->testPage->getContentModel(),
$rev->getContentModel() );
1340 $this->assertSame( $this->testPage->getContent()->getDefaultFormat(),
$rev->getContentFormat() );
1341 $this->assertSame( $this->testPage->getContentHandler(),
$rev->getContentHandler() );
1354 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1355 $rev = $this->testPage->getRevision();
1358 $key =
$cache->makeGlobalKey(
'revision-row-1.29',
1364 $this->assertFalse(
$cache->get( $key ) );
1370 $cachedRow =
$cache->get( $key );
1371 $this->assertNotFalse( $cachedRow );
1372 $this->assertEquals(
$rev->getId(), $cachedRow->rev_id );
1378 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1379 $rev = $this->testPage->getRevision();
1381 $pageId = $this->testPage->getId();
1394 yield [ 0, 0, [],
null,
true ];
1431 'wgGroupPermissions',
1434 'deletedtext' =>
true,
1435 'deletedhistory' =>
true,
1438 'viewsuppressed' =>
true,
1439 'suppressrevision' =>
true,
1462 yield [ 0, 0, [],
true ];
1482 public function testUserCan( $bitField, $field, $userGroups, $expected ) {
1484 'wgGroupPermissions',
1487 'deletedtext' =>
true,
1488 'deletedhistory' =>
true,
1491 'viewsuppressed' =>
true,
1492 'suppressrevision' =>
true,
1497 $revision =
new Revision( [
'deleted' => $bitField ], 0, $this->testPage->getTitle() );
1501 $revision->userCan( $field,
$user )