23 parent::__construct(
$name, $data, $dataName );
25 $this->tablesUsed = array_merge( $this->tablesUsed,
71 12313 =>
'Dummy_talk',
76 'wgNamespaceContentModels',
99 if ( !$this->testPage ) {
104 $this->testPage = $this->
createPage( __CLASS__, __CLASS__ );
114 ->disableOriginalConstructor()
116 $mock->expects( $this->
any() )
117 ->method(
'getNamespace' )
119 $mock->expects( $this->
any() )
120 ->method(
'getPrefixedText' )
121 ->will( $this->returnValue( __CLASS__ ) );
122 $mock->expects( $this->
any() )
123 ->method(
'getDBkey' )
124 ->will( $this->returnValue( __CLASS__ ) );
125 $mock->expects( $this->
any() )
126 ->method(
'getArticleID' )
127 ->will( $this->returnValue( 23 ) );
135 if ( $props ===
null ) {
139 if ( !isset( $props[
'content'] ) && !isset( $props[
'text'] ) ) {
140 $props[
'text'] =
'Lorem Ipsum';
143 if ( !isset( $props[
'user_text'] ) ) {
145 $props[
'user_text'] =
$user->getName();
146 $props[
'user'] =
$user->getId();
149 if ( !isset( $props[
'user'] ) ) {
153 if ( !isset( $props[
'comment'] ) ) {
154 $props[
'comment'] =
'just a test';
157 if ( !isset( $props[
'page'] ) ) {
158 $props[
'page'] = $this->testPage->getId();
161 if ( !isset( $props[
'content_model'] ) ) {
168 $rev->insertOn( $dbw );
180 private function createPage( $titleString, $text, $model =
null ) {
181 if ( !preg_match(
'/:/', $titleString ) &&
192 if ( $wikipage->exists() ) {
193 $wikipage->doDeleteArticle(
"done" );
203 $this->assertNotNull(
$rev,
'missing revision' );
205 $this->assertEquals( $orig->
getId(),
$rev->getId() );
206 $this->assertEquals( $orig->
getPage(),
$rev->getPage() );
208 $this->assertEquals( $orig->
getUser(),
$rev->getUser() );
211 $this->assertEquals( $orig->
getSha1(),
$rev->getSha1() );
218 $rev = $this->testPage->getRevision();
219 $recentChange =
$rev->getRecentChange();
222 $this->assertEquals(
$rev->getTimestamp(), $recentChange->getAttribute(
'rc_timestamp' ) );
224 $rev->getTitle()->getNamespace(),
225 $recentChange->getAttribute(
'rc_namespace' )
228 $rev->getTitle()->getDBkey(),
229 $recentChange->getAttribute(
'rc_title' )
231 $this->assertEquals(
$rev->getUser(), $recentChange->getAttribute(
'rc_user' ) );
232 $this->assertEquals(
$rev->getUserText(), $recentChange->getAttribute(
'rc_user_text' ) );
233 $this->assertEquals(
$rev->getComment(), $recentChange->getAttribute(
'rc_comment' ) );
234 $this->assertEquals(
$rev->getPage(), $recentChange->getAttribute(
'rc_cur_id' ) );
235 $this->assertEquals(
$rev->getId(), $recentChange->getAttribute(
'rc_this_oldid' ) );
242 $parentId = $this->testPage->getLatest();
248 'page' => $this->testPage->getId(),
249 'title' => $this->testPage->getTitle(),
250 'text' =>
'Revision Text',
251 'comment' =>
'Revision comment',
256 $this->assertInternalType(
'integer', $revId );
257 $this->assertSame( $revId,
$rev->getId() );
260 $this->assertInternalType(
'integer',
$rev->getTextId() );
262 $mainSlot =
$rev->getRevisionRecord()->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
265 $textId = MediaWikiServices::getInstance()
267 ->getTextIdFromAddress( $mainSlot->getAddress() );
271 [
'old_id',
'old_text' ],
273 [ [ strval( $textId ),
'Revision Text' ] ]
286 "rev_id = {$rev->getId()}",
288 strval(
$rev->getId() ),
289 strval( $this->testPage->getId() ),
294 's0ngbdoxagreuf2vjtuxzwdz64n29xm',
303 yield
'no parent' => [
310 "rev_page field must not be 0!"
313 yield
'no comment' => [
320 "comment must not be NULL!"
323 yield
'no content' => [
330 "Uninitialized field: content_address"
341 $this->setExpectedException( $expException, $expMessage );
353 $latestRevId = $this->testPage->getLatest();
357 $this->assertTrue( $this->testPage->getTitle()->equals(
$rev->getTitle() ) );
358 $this->assertEquals( $latestRevId,
$rev->getId() );
365 $latestRevId = $this->testPage->getLatest();
369 $this->assertTrue( $this->testPage->getTitle()->equals(
$rev->getTitle() ) );
370 $this->assertEquals( $latestRevId,
$rev->getId() );
377 $latestRevId = $this->testPage->getLatest();
381 $this->assertNull(
$rev );
394 $this->assertTrue( is_object(
$res ),
'query failed' );
396 $row =
$res->fetchObject();
412 return $f + [
'ar_namespace',
'ar_title' ];
417 unset( $f[
'ar_text_id'] );
423 unset( $f[
'ar_page_id'] );
429 unset( $f[
'ar_parent_id'] );
435 unset( $f[
'ar_rev_id'] );
441 unset( $f[
'ar_sha1'] );
452 $services = MediaWikiServices::getInstance();
456 $services->getService(
'_SqlBlobStore' ),
469 'RevisionStorageTest_testNewFromArchiveRow',
473 $orig = $page->getRevision();
474 $page->doDeleteArticle(
'test Revision::newFromArchiveRow' );
478 $arQuery[
'fields'] = $selectModifier( $arQuery[
'fields'] );
480 $arQuery[
'tables'], $arQuery[
'fields'], [
'ar_rev_id' => $orig->getId() ],
481 __METHOD__, [], $arQuery[
'joins']
483 $this->assertTrue( is_object(
$res ),
'query failed' );
485 $row =
$res->fetchObject();
500 'RevisionStorageTest_testNewFromArchiveRow',
504 $orig = $page->getRevision();
505 $page->doDeleteArticle(
'test Revision::newFromArchiveRow' );
510 $arQuery[
'tables'], $arQuery[
'fields'], [
'ar_rev_id' => $orig->getId() ],
511 __METHOD__, [], $arQuery[
'joins']
513 $this->assertTrue( is_object(
$res ),
'query failed' );
515 $row =
$res->fetchObject();
520 $this->assertNotEquals( $orig->getComment(),
$rev->getComment() );
521 $this->assertEquals(
'SOMEOVERRIDE',
$rev->getComment() );
528 $orig = $this->testPage->getRevision();
539 $this->testPage->getRevision(),
549 $this->testPage->getId(),
550 $this->testPage->getLatest()
553 $this->testPage->getRevision(),
563 $this->testPage->doEditContent(
$content, __METHOD__ );
565 $this->testPage->getId(),
566 $this->testPage->getRevision()->getPrevious()->getId()
569 $this->testPage->getRevision()->getPrevious(),
579 $this->testPage->getRevision()->getId();
581 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
582 $id = $this->testPage->getRevision()->getId();
587 # note: order is unspecified
589 while ( ( $row =
$res->fetchObject() ) ) {
590 $rows[$row->rev_id] = $row;
593 $this->assertEmpty(
$rows,
'expected empty set' );
605 $this->assertEquals( $page->getId(),
$rev->getPage() );
612 $rev1 = $this->testPage->getRevision();
614 # @todo find out if this should be true
615 # $this->assertTrue( $rev1->isCurrent() );
618 $this->assertTrue( $rev1x->isCurrent() );
620 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
621 $rev2 = $this->testPage->getRevision();
623 # @todo find out if this should be true
624 # $this->assertTrue( $rev2->isCurrent() );
627 $this->assertFalse( $rev1x->isCurrent() );
630 $this->assertTrue( $rev2x->isCurrent() );
637 $oldestRevision = $this->testPage->getOldestRevision();
638 $latestRevision = $this->testPage->getLatest();
640 $this->assertNull( $oldestRevision->getPrevious() );
642 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
643 $newRevision = $this->testPage->getRevision();
645 $this->assertNotNull( $newRevision->getPrevious() );
646 $this->assertEquals( $latestRevision, $newRevision->getPrevious()->getId() );
653 $rev1 = $this->testPage->getRevision();
655 $this->assertNull( $rev1->getNext() );
657 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
658 $rev2 = $this->testPage->getRevision();
660 $this->assertNotNull( $rev1->getNext() );
661 $this->assertEquals( $rev2->getId(), $rev1->getNext()->getId() );
668 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
669 $orig = $this->testPage->getRevision();
674 $this->assertNotEquals( $orig->getId(),
$rev->getId(),
675 'new null revision should have a different id from the original revision' );
676 $this->assertEquals( $orig->getTextId(),
$rev->getTextId(),
677 'new null revision should have the same text id as the original revision' );
678 $this->assertEquals( $orig->getSha1(),
$rev->getSha1(),
679 'new null revision should have the same SHA1 as the original revision' );
680 $this->assertTrue( $orig->getRevisionRecord()->hasSameContent(
$rev->getRevisionRecord() ),
681 'new null revision should have the same content as the original revision' );
682 $this->assertEquals( __METHOD__,
$rev->getContent()->getNativeData() );
692 $this->assertNull(
$rev );
699 $ip =
'2600:387:ed7:947e:8c16:a1ad:dd34:1dd7';
707 $res =
$dbr->select(
'ip_changes',
'*', [
'ipc_rev_id' => $orig->getId() ] );
708 $row =
$res->fetchObject();
710 $this->assertEquals(
IP::toHex( $ip ), $row->ipc_hex );
712 $orig->getTimestamp(),
718 yield
'actually the last edit' => [ 3,
true ];
719 yield
'not the current edit, but still by this user' => [ 2,
true ];
720 yield
'edit by another user' => [ 1,
false ];
721 yield
'first edit, by this user, but another user edited in the mean time' => [ 0,
false ];
732 if ( $userA->getId() === 0 ) {
736 if ( $userB->getId() === 0 ) {
747 'RevisionStorageTest_testUserWasLastToEdit', $ns ) );
748 $page->insertOn( $dbw );
751 'page' => $page->getId(),
753 'title' => $page->getTitle(),
754 'timestamp' =>
'20120101000000',
755 'user' => $userA->getId(),
758 'comment' =>
'edit zero'
763 'page' => $page->getId(),
765 'title' => $page->getTitle(),
766 'timestamp' =>
'20120101000100',
767 'user' => $userA->getId(),
770 'comment' =>
'edit one'
775 'page' => $page->getId(),
776 'title' => $page->getTitle(),
777 'timestamp' =>
'20120101000200',
778 'user' => $userB->getId(),
781 'comment' =>
'edit two'
786 'page' => $page->getId(),
787 'title' => $page->getTitle(),
788 'timestamp' =>
'20120101000300',
789 'user' => $userA->getId(),
792 'comment' =>
'edit three'
797 'page' => $page->getId(),
798 'title' => $page->getTitle(),
799 'timestamp' =>
'20120101000200',
800 'user' => $userA->getId(),
803 'comment' =>
'edit four'
808 $since = $revisions[$sinceIdx]->getTimestamp();
811 $allRows = iterator_to_array( $dbw->select(
813 [
'rev_id',
'rev_timestamp',
'rev_user' =>
$revQuery[
'fields'][
'rev_user'] ],
815 'rev_page' => $page->getId(),
819 [
'ORDER BY' =>
'rev_timestamp ASC',
'LIMIT' => 50 ],
825 $this->assertEquals( $expectedLast, $wasLast );
839 if ( is_string(
$title ) ) {
853 'comment' =>
"testing",
854 'minor_edit' =>
false,
856 'content_format' => $format,
879 $this->assertEquals( $expectedModel,
$rev->getContentModel() );
899 $this->assertEquals( $expectedFormat,
$rev->getContentFormat() );
918 $this->assertEquals( $expectedClass, get_class(
$rev->getContentHandler() ) );
949 $audience, $expectedSerialization
955 $expectedSerialization,
965 'page' => $this->testPage->getId(),
966 'content_model' => $this->testPage->getContentModel(),
970 Wikimedia\suppressWarnings();
972 $this->assertNull(
$rev->getContent(),
973 "getContent() should return null if the revision's text blob could not be loaded." );
976 $this->assertNull(
$rev->getContent(),
977 "getContent() should return null if the revision's text blob could not be loaded." );
979 Wikimedia\restoreWarnings();
995 $this->assertEquals( $expected_size,
$rev->getSize() );
1015 $this->assertEquals( $expected_hash,
$rev->getSha1() );
1034 'comment' =>
"testing",
1035 'minor_edit' =>
false,
1046 $this->assertNotSame(
$content, $content2,
"expected a clone" );
1048 $this->assertEquals(
"foo", $content2->getText() );
1050 $content2->setText(
"bla bla" );
1052 $this->assertEquals(
"bar",
$content->getText() );
1065 $this->assertSame(
$content, $content2 );
1072 $rev = $this->testPage->getRevision();
1085 $this->testPage->getRevision(),
1095 $this->testPage->getRevision(),
1098 $this->testPage->getId(),
1099 $this->testPage->getLatest()
1108 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1110 $this->testPage->getRevision()->getPrevious(),
1113 $this->testPage->getId(),
1114 $this->testPage->getRevision()->getPrevious()->getId()
1124 $this->testPage->getRevision(),
1134 $this->testPage->getRevision(),
1137 $this->testPage->getTitle(),
1138 $this->testPage->getLatest()
1147 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1149 $this->testPage->getRevision()->getPrevious(),
1152 $this->testPage->getTitle(),
1153 $this->testPage->getRevision()->getPrevious()->getId()
1163 $this->testPage->getRevision(),
1166 $this->testPage->getTitle(),
1167 $this->testPage->getRevision()->getTimestamp()
1189 $text =
'831jr091jr0921kr21kr0921kjr0921j09rj1';
1190 $textLength = strlen( $text );
1192 $this->testPage->doEditContent(
new WikitextContent( $text ), __METHOD__ );
1193 $rev[1] = $this->testPage->getLatest();
1196 [
$rev[1] => $textLength ],
1208 $textOne =
'831jr091jr0921kr21kr0921kjr0921j09rj1';
1209 $textOneLength = strlen( $textOne );
1210 $textTwo =
'831jr091jr092121j09rj1';
1211 $textTwoLength = strlen( $textTwo );
1213 $this->testPage->doEditContent(
new WikitextContent( $textOne ), __METHOD__ );
1214 $rev[1] = $this->testPage->getLatest();
1215 $this->testPage->doEditContent(
new WikitextContent( $textTwo ), __METHOD__ );
1216 $rev[2] = $this->testPage->getLatest();
1219 [
$rev[1] => $textOneLength,
$rev[2] => $textTwoLength ],
1232 $this->testPage->getTitle()->equals(
1233 $this->testPage->getRevision()->getTitle()
1242 $rev =
new Revision( [
'id' => $this->testPage->getLatest() ] );
1244 $this->testPage->getTitle()->equals(
1257 $this->testPage->doEditContent(
1264 $rev = $this->testPage->getRevision();
1266 $this->assertSame(
true,
$rev->isMinor() );
1273 $this->testPage->doEditContent(
1278 $rev = $this->testPage->getRevision();
1280 $this->assertSame(
false,
$rev->isMinor() );
1289 $this->testPage->doEditContent(
1293 $rev = $this->testPage->getRevision();
1295 $this->assertInternalType(
'string',
$rev->getTimestamp() );
1296 $this->assertTrue( strlen(
$rev->getTimestamp() ) == strlen(
'YYYYMMDDHHMMSS' ) );
1297 $this->assertContains( substr( $testTimestamp, 0, 10 ),
$rev->getTimestamp() );
1307 $this->testPage->doEditContent(
1314 $rev = $this->testPage->getRevision();
1316 $this->assertSame( $sysop->getId(),
$rev->getUser() );
1317 $this->assertSame( $sysop->getName(),
$rev->getUserText() );
1324 $rev = $this->testPage->getRevision();
1336 $rev = $this->testPage->getRevision();
1338 $this->assertSame( 0,
$rev->getVisibility() );
1345 $expectedSummary =
'goatlicious summary';
1347 $this->testPage->doEditContent(
1351 $rev = $this->testPage->getRevision();
1353 $this->assertSame( $expectedSummary,
$rev->getComment() );
1360 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1361 $rev = $this->testPage->getRevision();
1363 $this->assertGreaterThan( 0,
$rev->isUnpatrolled() );
1364 $this->assertSame(
$rev->getRecentChange()->getAttribute(
'rc_id' ),
$rev->isUnpatrolled() );
1373 $this->testPage->doEditContent(
1380 $rev = $this->testPage->getRevision();
1382 $this->assertSame( 0,
$rev->isUnpatrolled() );
1395 $expectedText =
'testSimpleContentGetters in Revision. Goats love MCR...';
1396 $expectedSummary =
'goatlicious testSimpleContentGetters summary';
1398 $this->testPage->doEditContent(
1402 $rev = $this->testPage->getRevision();
1404 $this->assertSame( $expectedText,
$rev->getContent()->getNativeData() );
1405 $this->assertSame( $expectedText,
$rev->getSerializedData() );
1406 $this->assertSame( $this->testPage->getContentModel(),
$rev->getContentModel() );
1407 $this->assertSame( $this->testPage->getContent()->getDefaultFormat(),
$rev->getContentFormat() );
1408 $this->assertSame( $this->testPage->getContentHandler(),
$rev->getContentHandler() );
1422 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1423 $rev = $this->testPage->getRevision();
1426 $key =
$cache->makeGlobalKey(
1427 RevisionStore::ROW_CACHE_KEY,
1433 $this->assertFalse(
$cache->get( $key ) );
1439 $cachedRow =
$cache->get( $key );
1440 $this->assertNotFalse( $cachedRow );
1441 $this->assertEquals(
$rev->getId(), $cachedRow->rev_id );
1447 $this->testPage->doEditContent(
new WikitextContent( __METHOD__ ), __METHOD__ );
1448 $rev = $this->testPage->getRevision();
1450 $pageId = $this->testPage->getId();
1463 yield [ 0, 0, [],
null,
true ];
1502 'wgGroupPermissions',
1505 'deletedtext' =>
true,
1506 'deletedhistory' =>
true,
1509 'viewsuppressed' =>
true,
1510 'suppressrevision' =>
true,
1533 yield [ 0, 0, [],
true ];
1553 public function testUserCan( $bitField, $field, $userGroups, $expected ) {
1555 'wgGroupPermissions',
1558 'deletedtext' =>
true,
1559 'deletedhistory' =>
true,
1562 'viewsuppressed' =>
true,
1563 'suppressrevision' =>
true,
1568 $revision =
new Revision( [
'deleted' => $bitField ], 0, $this->testPage->getTitle() );
1572 $revision->userCan( $field,
$user )
1580 'slot_revision_id' => 42,
1581 'slot_content_id' => 1,
1582 'content_address' =>
'tt:789',
1584 'role_name' => SlotRecord::MAIN,
1590 $rec->setSlot( $slot );
1592 yield [ $rec, 789 ];
1600 $rev =
new Revision( $spec, 0, $this->testPage->getTitle() );
1601 $this->assertSame( $expected,
$rev->getTextId() );