Merge "RevisionStoreDbTestBase, remove redundant needsDB override"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / McrSchemaOverride.php
1 <?php
2 namespace MediaWiki\Tests\Storage;
3
4 use Wikimedia\Rdbms\IMaintainableDatabase;
5 use MediaWiki\DB\PatchFileLocation;
6
7 /**
8 * Trait providing schema overrides that allow tests to run against the post-migration
9 * MCR database schema.
10 */
11 trait McrSchemaOverride {
12
13 use PatchFileLocation;
14 use McrSchemaDetection;
15
16 /**
17 * @return int
18 */
19 protected function getMcrMigrationStage() {
20 return MIGRATION_NEW;
21 }
22
23 /**
24 * @return string[]
25 */
26 protected function getMcrTablesToReset() {
27 return [
28 'content',
29 'content_models',
30 'slots',
31 'slot_roles',
32 ];
33 }
34
35 protected function getSchemaOverrides( IMaintainableDatabase $db ) {
36 $overrides = [
37 'scripts' => [],
38 'drop' => [],
39 'create' => [],
40 'alter' => [],
41 ];
42
43 if ( !$this->hasMcrTables( $db ) ) {
44 $overrides['create'] = [ 'slots', 'content', 'slot_roles', 'content_models', ];
45 $overrides['scripts'][] = $this->getSqlPatchPath( $db, 'patch-slot_roles' );
46 $overrides['scripts'][] = $this->getSqlPatchPath( $db, 'patch-content_models' );
47 $overrides['scripts'][] = $this->getSqlPatchPath( $db, 'patch-content' );
48 $overrides['scripts'][] = $this->getSqlPatchPath( $db, 'patch-slots.sql' );
49 }
50
51 if ( !$this->hasPreMcrFields( $db ) ) {
52 $overrides['alter'][] = 'revision';
53 $overrides['scripts'][] = $this->getSqlPatchPath( $db, 'drop-pre-mcr-fields', __DIR__ );
54 }
55
56 return $overrides;
57 }
58
59 }