Merge "RevisionStoreDbTestBase, remove redundant needsDB override"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / PreMcrRevisionStoreDbTest.php
1 <?php
2 namespace MediaWiki\Tests\Storage;
3
4 use InvalidArgumentException;
5 use MediaWiki\Storage\RevisionRecord;
6 use Revision;
7 use WikitextContent;
8
9 /**
10 * Tests RevisionStore against the pre-MCR DB schema.
11 *
12 * @covers \MediaWiki\Storage\RevisionStore
13 *
14 * @group RevisionStore
15 * @group Storage
16 * @group Database
17 * @group medium
18 */
19 class PreMcrRevisionStoreDbTest extends RevisionStoreDbTestBase {
20
21 use PreMcrSchemaOverride;
22
23 protected function revisionToRow( Revision $rev, $options = [ 'page', 'user', 'comment' ] ) {
24 $row = parent::revisionToRow( $rev, $options );
25
26 $row->rev_text_id = (string)$rev->getTextId();
27 $row->rev_content_format = (string)$rev->getContentFormat();
28 $row->rev_content_model = (string)$rev->getContentModel();
29
30 return $row;
31 }
32
33 protected function assertRevisionExistsInDatabase( RevisionRecord $rev ) {
34 // Legacy schema is still being written
35 $this->assertSelect(
36 [ 'revision', 'text' ],
37 [ 'count(*)' ],
38 [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ],
39 [ [ 1 ] ],
40 [],
41 [ 'text' => [ 'INNER JOIN', [ 'rev_text_id = old_id' ] ] ]
42 );
43
44 parent::assertRevisionExistsInDatabase( $rev );
45 }
46
47 public function provideInsertRevisionOn_failures() {
48 foreach ( parent::provideInsertRevisionOn_failures() as $case ) {
49 yield $case;
50 }
51
52 yield 'slot that is not main slot' => [
53 [
54 'content' => [
55 'main' => new WikitextContent( 'Chicken' ),
56 'lalala' => new WikitextContent( 'Duck' ),
57 ],
58 'comment' => $this->getRandomCommentStoreComment(),
59 'timestamp' => '20171117010101',
60 'user' => true,
61 ],
62 new InvalidArgumentException( 'Only the main slot is supported' )
63 ];
64 }
65
66 public function provideNewMutableRevisionFromArray() {
67 foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
68 yield $case;
69 }
70
71 yield 'Basic array, with page & id' => [
72 [
73 'id' => 2,
74 'page' => 1,
75 'text_id' => 2,
76 'timestamp' => '20171017114835',
77 'user_text' => '111.0.1.2',
78 'user' => 0,
79 'minor_edit' => false,
80 'deleted' => 0,
81 'len' => 46,
82 'parent_id' => 1,
83 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
84 'comment' => 'Goat Comment!',
85 'content_format' => 'text/x-wiki',
86 'content_model' => 'wikitext',
87 ]
88 ];
89 }
90
91 }