| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Config\HashConfig; |
| 4 |
use MediaWiki\Linker\LinksMigration; |
| 5 |
use MediaWiki\Linker\LinkTargetLookup; |
| 6 |
use MediaWiki\MainConfigNames; |
| 7 |
use MediaWiki\Title\TitleValue; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class LinksMigrationTest extends MediaWikiUnitTestCase { |
| 13 |
|
| 14 |
public static function provideReadNew() { |
| 15 |
yield [ SCHEMA_COMPAT_READ_NEW ]; |
| 16 |
yield [ SCHEMA_COMPAT_NEW ]; |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public function testGetLinksConditionsReadNew( $configValue ) { |
| 24 |
$title = new TitleValue( NS_USER, 'Someuser' ); |
| 25 |
$linkTargetStore = $this->createMock( LinkTargetLookup::class ); |
| 26 |
$linkTargetStore->method( 'getLinkTargetId' ) |
| 27 |
->with( $title ) |
| 28 |
->willReturn( 1 ); |
| 29 |
$linkTargetStore->expects( $this->never() )->method( 'acquireLinkTargetId' ); |
| 30 |
|
| 31 |
$config = new HashConfig( |
| 32 |
[ |
| 33 |
MainConfigNames::PageLinksSchemaMigrationStage => $configValue |
| 34 |
] |
| 35 |
); |
| 36 |
$linksMigration = new LinksMigration( $config, $linkTargetStore ); |
| 37 |
$this->assertSame( |
| 38 |
[ 'pl_target_id' => 1 ], |
| 39 |
$linksMigration->getLinksConditions( 'pagelinks', $title ) |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
public static function provideReadOld() { |
| 44 |
yield [ SCHEMA_COMPAT_READ_OLD ]; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function testGetLinksConditionsReadOld( $configValue ) { |
| 52 |
$this->markTestSkipped( 'No table currently with support for read old' ); |
| 53 |
$title = new TitleValue( NS_USER, 'Someuser' ); |
| 54 |
$linkTargetStore = $this->createMock( LinkTargetLookup::class ); |
| 55 |
$linkTargetStore->expects( $this->never() )->method( 'getLinkTargetId' ); |
| 56 |
$linkTargetStore->expects( $this->never() )->method( 'acquireLinkTargetId' ); |
| 57 |
|
| 58 |
$config = new HashConfig( |
| 59 |
[ |
| 60 |
MainConfigNames::PageLinksSchemaMigrationStage => $configValue |
| 61 |
] |
| 62 |
); |
| 63 |
$linksMigration = new LinksMigration( $config, $linkTargetStore ); |
| 64 |
$this->assertSame( |
| 65 |
[ 'pl_namespace' => 2, 'pl_title' => 'Someuser' ], |
| 66 |
$linksMigration->getLinksConditions( 'pagelinks', $title ) |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
} |