2 namespace MediaWiki\Tests\Revision
;
4 use InvalidArgumentException
;
5 use MediaWiki\MediaWikiServices
;
6 use MediaWiki\Revision\RevisionRecord
;
7 use MediaWiki\Revision\SlotRecord
;
12 * Tests RevisionStore against the intermediate MCR DB schema for use during schema migration.
14 * @covers \MediaWiki\Revision\RevisionStore
16 * @group RevisionStore
21 class McrWriteBothRevisionStoreDbTest
extends RevisionStoreDbTestBase
{
23 use McrWriteBothSchemaOverride
;
25 protected function revisionToRow( Revision
$rev, $options = [ 'page', 'user', 'comment' ] ) {
26 $row = parent
::revisionToRow( $rev, $options );
28 $row->rev_text_id
= (string)$rev->getTextId();
29 $row->rev_content_format
= (string)$rev->getContentFormat();
30 $row->rev_content_model
= (string)$rev->getContentModel();
35 protected function assertRevisionExistsInDatabase( RevisionRecord
$rev ) {
36 // New schema is being written
40 [ 'slot_revision_id' => $rev->getId() ],
47 [ 'content_address' => $rev->getSlot( 'main' )->getAddress() ],
51 // Legacy schema is still being written
53 [ 'revision', 'text' ],
55 [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ],
58 [ 'text' => [ 'INNER JOIN', [ 'rev_text_id = old_id' ] ] ]
61 parent
::assertRevisionExistsInDatabase( $rev );
65 * @param SlotRecord $a
66 * @param SlotRecord $b
68 protected function assertSameSlotContent( SlotRecord
$a, SlotRecord
$b ) {
69 parent
::assertSameSlotContent( $a, $b );
71 // Assert that the same content ID has been used
72 if ( $a->hasContentId() && $b->hasContentId() ) {
73 $this->assertSame( $a->getContentId(), $b->getContentId() );
77 public function provideInsertRevisionOn_failures() {
78 foreach ( parent
::provideInsertRevisionOn_failures() as $case ) {
82 yield
'slot that is not main slot' => [
85 'main' => new WikitextContent( 'Chicken' ),
86 'lalala' => new WikitextContent( 'Duck' ),
88 'comment' => $this->getRandomCommentStoreComment(),
89 'timestamp' => '20171117010101',
92 new InvalidArgumentException( 'Only the main slot is supported' )
96 public function provideNewMutableRevisionFromArray() {
97 foreach ( parent
::provideNewMutableRevisionFromArray() as $case ) {
101 yield
'Basic array, with page & id' => [
106 'timestamp' => '20171017114835',
107 'user_text' => '111.0.1.2',
109 'minor_edit' => false,
113 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
114 'comment' => 'Goat Comment!',
115 'content_format' => 'text/x-wiki',
116 'content_model' => 'wikitext',
122 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow
123 * @covers \MediaWiki\Revision\RevisionStore::insertRevisionOn
125 public function testInsertRevisionFromArchiveRow_unmigratedArchiveRow() {
126 // The main purpose of this test is to assert that after reading an archive
127 // row using the old schema it can be inserted into the revision table,
128 // and a slot row is created based on slot emulated from the old-style archive row,
129 // when none such slot row exists yet.
131 $title = $this->getTestPage()->getTitle();
135 [ 'old_text' => 'Just a test', 'old_flags' => 'utf-8' ],
139 $textId = $this->db
->insertId();
142 'ar_minor_edit' => '0',
144 'ar_user_text' => '127.0.0.1',
148 'ar_rev_id' => 112277,
149 'ar_timestamp' => $this->db
->timestamp( '20180101000000' ),
150 'ar_sha1' => 'deadbeef',
151 'ar_page_id' => $title->getArticleID(),
152 'ar_comment_text' => 'just a test',
153 'ar_comment_data' => null,
154 'ar_comment_cid' => null,
155 'ar_content_format' => null,
156 'ar_content_model' => null,
159 'ar_namespace' => $title->getNamespace(),
160 'ar_title' => $title->getDBkey(),
161 'ar_text_id' => $textId,
162 'ar_parent_id' => 112211,
165 $store = MediaWikiServices
::getInstance()->getRevisionStore();
166 $rev = $store->newRevisionFromArchiveRow( $row );
168 // re-insert archived revision
169 $return = $store->insertRevisionOn( $rev, $this->db
);
171 // is the new revision correct?
172 $this->assertRevisionCompleteness( $return );
173 $this->assertRevisionRecordsEqual( $rev, $return );
175 // can we load it from the store?
176 $loaded = $store->getRevisionById( $return->getId() );
177 $this->assertNotNull( $loaded );
178 $this->assertRevisionCompleteness( $loaded );
179 $this->assertRevisionRecordsEqual( $return, $loaded );
181 // can we find it directly in the database?
182 $this->assertRevisionExistsInDatabase( $return );