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