2 namespace MediaWiki\Tests\Storage
;
4 use CommentStoreComment
;
5 use MediaWiki\MediaWikiServices
;
6 use MediaWiki\Storage\RevisionRecord
;
7 use MediaWiki\Storage\SlotRecord
;
13 * Tests RevisionStore against the intermediate MCR DB schema for use during schema migration.
15 * @covers \MediaWiki\Storage\RevisionStore
17 * @group RevisionStore
22 class McrReadNewRevisionStoreDbTest
extends RevisionStoreDbTestBase
{
24 use McrReadNewSchemaOverride
;
26 protected function assertRevisionExistsInDatabase( RevisionRecord
$rev ) {
27 $numberOfSlots = count( $rev->getSlotRoles() );
29 // new schema is written
33 [ 'slot_revision_id' => $rev->getId() ],
34 [ [ (string)$numberOfSlots ] ]
37 $store = MediaWikiServices
::getInstance()->getRevisionStore();
38 $revQuery = $store->getSlotsQueryInfo( [ 'content' ] );
44 'slot_revision_id' => $rev->getId(),
46 [ [ (string)$numberOfSlots ] ],
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 $this->assertSame( $a->getContentId(), $b->getContentId() );
75 public function provideInsertRevisionOn_successes() {
76 foreach ( parent
::provideInsertRevisionOn_successes() as $case ) {
80 yield
'Multi-slot revision insertion' => [
83 'main' => new WikitextContent( 'Chicken' ),
84 'aux' => new TextContent( 'Egg' ),
87 'comment' => $this->getRandomCommentStoreComment(),
88 'timestamp' => '20171117010101',
94 public function provideNewNullRevision() {
95 foreach ( parent
::provideNewNullRevision() as $case ) {
100 Title
::newFromText( 'UTPage_notAutoCreated' ),
103 'main' => new WikitextContent( 'Chicken' ),
104 'aux' => new WikitextContent( 'Omelet' ),
107 CommentStoreComment
::newUnsavedComment( __METHOD__
. ' comment multi' ),
111 public function testGetQueryInfo_NoSlotDataJoin() {
112 $store = MediaWikiServices
::getInstance()->getRevisionStore();
113 $queryInfo = $store->getQueryInfo();
115 // with the new schema enabled, query info should not join the main slot info
116 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['tables'] ) );
117 $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['joins'] ) );
120 public function provideGetArchiveQueryInfo() {
126 'fields' => array_merge(
127 $this->getDefaultArchiveFields( false ),
129 'ar_comment_text' => 'ar_comment',
130 'ar_comment_data' => 'NULL',
131 'ar_comment_cid' => 'NULL',
132 'ar_user_text' => 'ar_user_text',
133 'ar_user' => 'ar_user',
134 'ar_actor' => 'NULL',
143 public function provideGetQueryInfo() {
144 // TODO: more option variations
153 'fields' => array_merge(
154 $this->getDefaultQueryFields( false ),
155 $this->getCommentQueryFields(),
156 $this->getActorQueryFields(),
168 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
169 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
175 public function provideGetSlotsQueryInfo() {
183 'fields' => array_merge(
192 'slot_roles' => [ 'INNER JOIN', [ 'slot_role_id = role_id' ] ],
205 'fields' => array_merge(
218 'slot_roles' => [ 'INNER JOIN', [ 'slot_role_id = role_id' ] ],
219 'content' => [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ],
220 'content_models' => [ 'INNER JOIN', [ 'content_model = model_id' ] ],
226 public function provideNewMutableRevisionFromArray() {
227 foreach ( parent
::provideNewMutableRevisionFromArray() as $case ) {
231 yield
'Basic array, multiple roles' => [
235 'timestamp' => '20171017114835',
236 'user_text' => '111.0.1.2',
238 'minor_edit' => false,
242 'sha1' => '89qs83keq9c9ccw9olvvm4oc9oq50ii',
243 'comment' => 'Goat Comment!',
245 'main' => new WikitextContent( 'Söme Cöntent' ),
246 'aux' => new TextContent( 'Öther Cöntent' ),