MediaWiki  1.33.0
McrRevisionStoreDbTest.php
Go to the documentation of this file.
1 <?php
3 
10 use Title;
12 
24 
26 
28  $numberOfSlots = count( $rev->getSlotRoles() );
29 
30  // new schema is written
31  $this->assertSelect(
32  'slots',
33  [ 'count(*)' ],
34  [ 'slot_revision_id' => $rev->getId() ],
35  [ [ (string)$numberOfSlots ] ]
36  );
37 
38  $store = MediaWikiServices::getInstance()->getRevisionStore();
39  $revQuery = $store->getSlotsQueryInfo( [ 'content' ] );
40 
41  $this->assertSelect(
42  $revQuery['tables'],
43  [ 'count(*)' ],
44  [
45  'slot_revision_id' => $rev->getId(),
46  ],
47  [ [ (string)$numberOfSlots ] ],
48  [],
49  $revQuery['joins']
50  );
51 
52  parent::assertRevisionExistsInDatabase( $rev );
53  }
54 
59  protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
60  parent::assertSameSlotContent( $a, $b );
61 
62  // Assert that the same content ID has been used
63  $this->assertSame( $a->getContentId(), $b->getContentId() );
64  }
65 
67  foreach ( parent::provideInsertRevisionOn_successes() as $case ) {
68  yield $case;
69  }
70 
71  yield 'Multi-slot revision insertion' => [
72  [
73  'content' => [
74  'main' => new WikitextContent( 'Chicken' ),
75  'aux' => new TextContent( 'Egg' ),
76  ],
77  'page' => true,
78  'comment' => $this->getRandomCommentStoreComment(),
79  'timestamp' => '20171117010101',
80  'user' => true,
81  ],
82  ];
83  }
84 
85  public function provideNewNullRevision() {
86  foreach ( parent::provideNewNullRevision() as $case ) {
87  yield $case;
88  }
89 
90  yield [
91  Title::newFromText( 'UTPage_notAutoCreated' ),
92  [
93  'content' => [
94  'main' => new WikitextContent( 'Chicken' ),
95  'aux' => new WikitextContent( 'Omelet' ),
96  ],
97  ],
98  CommentStoreComment::newUnsavedComment( __METHOD__ . ' comment multi' ),
99  ];
100  }
101 
103  foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
104  yield $case;
105  }
106 
107  yield 'Basic array, multiple roles' => [
108  [
109  'id' => 2,
110  'page' => 1,
111  'timestamp' => '20171017114835',
112  'user_text' => '111.0.1.2',
113  'user' => 0,
114  'minor_edit' => false,
115  'deleted' => 0,
116  'len' => 29,
117  'parent_id' => 1,
118  'sha1' => '89qs83keq9c9ccw9olvvm4oc9oq50ii',
119  'comment' => 'Goat Comment!',
120  'content' => [
121  'main' => new WikitextContent( 'Söme Cöntent' ),
122  'aux' => new TextContent( 'Öther Cöntent' ),
123  ]
124  ]
125  ];
126  }
127 
129  $store = MediaWikiServices::getInstance()->getRevisionStore();
130  $queryInfo = $store->getQueryInfo();
131 
132  // with the new schema enabled, query info should not join the main slot info
133  $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['tables'] ) );
134  $this->assertFalse( array_key_exists( 'a_slot_data', $queryInfo['joins'] ) );
135  }
136 
142  public function testInsertRevisionOn_T202032() {
143  // This test only makes sense for MySQL
144  if ( $this->db->getType() !== 'mysql' ) {
145  $this->assertTrue( true );
146  return;
147  }
148 
149  // NOTE: must be done before checking MAX(rev_id)
150  $page = $this->getTestPage();
151 
152  $maxRevId = $this->db->selectField( 'revision', 'MAX(rev_id)' );
153 
154  // Construct a slot row that will conflict with the insertion of the next revision ID,
155  // to emulate the failure mode described in T202032. Nothing will ever read this row,
156  // we just need it to trigger a primary key conflict.
157  $this->db->insert( 'slots', [
158  'slot_revision_id' => $maxRevId + 1,
159  'slot_role_id' => 1,
160  'slot_content_id' => 0,
161  'slot_origin' => 0
162  ], __METHOD__ );
163 
164  $rev = new MutableRevisionRecord( $page->getTitle() );
165  $rev->setTimestamp( '20180101000000' );
166  $rev->setComment( CommentStoreComment::newUnsavedComment( 'test' ) );
167  $rev->setUser( $this->getTestUser()->getUser() );
168  $rev->setContent( 'main', new WikitextContent( 'Text' ) );
169  $rev->setPageId( $page->getId() );
170 
171  $store = MediaWikiServices::getInstance()->getRevisionStore();
172  $return = $store->insertRevisionOn( $rev, $this->db );
173 
174  $this->assertSame( $maxRevId + 2, $return->getId() );
175 
176  // is the new revision correct?
177  $this->assertRevisionCompleteness( $return );
178  $this->assertRevisionRecordsEqual( $rev, $return );
179 
180  // can we find it directly in the database?
181  $this->assertRevisionExistsInDatabase( $return );
182 
183  // can we load it from the store?
184  $loaded = $store->getRevisionById( $return->getId() );
185  $this->assertRevisionCompleteness( $loaded );
186  $this->assertRevisionRecordsEqual( $return, $loaded );
187  }
188 
189 }
CommentStoreComment\newUnsavedComment
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
Definition: CommentStoreComment.php:66
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:180
captcha-old.count
count
Definition: captcha-old.py:249
MediaWiki\Tests\Revision\McrRevisionStoreDbTest\assertRevisionExistsInDatabase
assertRevisionExistsInDatabase(RevisionRecord $rev)
Definition: McrRevisionStoreDbTest.php:27
MediaWiki\Tests\Revision\McrRevisionStoreDbTest
Tests RevisionStore against the post-migration MCR DB schema.
Definition: McrRevisionStoreDbTest.php:23
MediaWiki\Tests\Revision\McrRevisionStoreDbTest\provideInsertRevisionOn_successes
provideInsertRevisionOn_successes()
Definition: McrRevisionStoreDbTest.php:66
MediaWiki\Tests\Revision
Definition: FallbackSlotRoleHandlerTest.php:3
$revQuery
$revQuery
Definition: testCompression.php:51
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertRevisionCompleteness
assertRevisionCompleteness(RevisionRecord $r)
Definition: RevisionStoreDbTestBase.php:309
MediaWiki\Tests\Revision\McrRevisionStoreDbTest\testInsertRevisionOn_T202032
testInsertRevisionOn_T202032()
\MediaWiki\Revision\RevisionStore::insertRevisionOn \MediaWiki\Revision\RevisionStore::insertSlotRowO...
Definition: McrRevisionStoreDbTest.php:142
MediaWiki\Tests\Revision\RevisionStoreDbTestBase
Database RevisionStore.
Definition: RevisionStoreDbTestBase.php:43
MediaWikiTestCase\assertSelect
assertSelect( $table, $fields, $condition, array $expectedRows, array $options=[], array $join_conds=[])
Asserts that the given database query yields the rows given by $expectedRows.
Definition: MediaWikiTestCase.php:2000
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Tests\Revision\McrRevisionStoreDbTest\assertSameSlotContent
assertSameSlotContent(SlotRecord $a, SlotRecord $b)
Definition: McrRevisionStoreDbTest.php:59
MediaWiki\Tests\Revision\McrRevisionStoreDbTest\testGetQueryInfo_NoSlotDataJoin
testGetQueryInfo_NoSlotDataJoin()
Definition: McrRevisionStoreDbTest.php:128
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:36
string
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:175
Revision\RevisionRecord\getId
getId()
Get revision ID.
Definition: RevisionRecord.php:273
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:124
MediaWiki\Tests\Revision\McrRevisionStoreDbTest\provideNewNullRevision
provideNewNullRevision()
Definition: McrRevisionStoreDbTest.php:85
Revision\MutableRevisionRecord
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Definition: MutableRevisionRecord.php:41
MediaWiki\Tests\Revision\McrSchemaOverride
trait McrSchemaOverride
Trait providing schema overrides that allow tests to run against the post-migration MCR database sche...
Definition: McrSchemaOverride.php:11
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getRandomCommentStoreComment
getRandomCommentStoreComment()
Definition: RevisionStoreDbTestBase.php:390
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:37
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertRevisionRecordsEqual
assertRevisionRecordsEqual(RevisionRecord $r1, RevisionRecord $r2)
Definition: RevisionStoreDbTestBase.php:257
Title
Represents a title within MediaWiki.
Definition: Title.php:40
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1769
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MediaWiki\Tests\Revision\McrRevisionStoreDbTest\provideNewMutableRevisionFromArray
provideNewMutableRevisionFromArray()
Definition: McrRevisionStoreDbTest.php:102
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getTestPage
getTestPage()
Definition: RevisionStoreDbTestBase.php:109
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
Revision\SlotRecord\getContentId
getContentId()
Returns the ID of the content meta data row associated with the slot.
Definition: SlotRecord.php:513
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39