| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Title\TitleValue; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class LinkTargetStoreTest extends MediaWikiIntegrationTestCase { |
| 10 |
|
| 11 |
public static function provideLinkTargets() { |
| 12 |
yield [ new TitleValue( NS_SPECIAL, 'BlankPage' ) ]; |
| 13 |
yield [ new TitleValue( NS_MAIN, 'Foobar' ) ]; |
| 14 |
yield [ new TitleValue( NS_USER, 'Someuser' ) ]; |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function testAcquireLinkTargetId( $target ) { |
| 22 |
$linkTargetStore = $this->getServiceContainer()->getLinkTargetLookup(); |
| 23 |
$db = $this->getDb(); |
| 24 |
$id = $linkTargetStore->acquireLinkTargetId( $target, $db ); |
| 25 |
$row = $db->newSelectQueryBuilder() |
| 26 |
->select( [ 'lt_id', 'lt_namespace', 'lt_title' ] ) |
| 27 |
->from( 'linktarget' ) |
| 28 |
->where( [ 'lt_namespace' => $target->getNamespace(), 'lt_title' => $target->getDBkey() ] ) |
| 29 |
->fetchRow(); |
| 30 |
$this->assertSame( (int)$row->lt_id, $id ); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function testGetLinkTargetById( $target ) { |
| 39 |
$linkTargetStore = $this->getServiceContainer()->getLinkTargetLookup(); |
| 40 |
$db = $this->getDb(); |
| 41 |
$id = $linkTargetStore->acquireLinkTargetId( $target, $db ); |
| 42 |
$actualLinkTarget = $linkTargetStore->getLinkTargetById( $id, $db ); |
| 43 |
$this->assertEquals( $target, $actualLinkTarget ); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function testGetLinkTargetByIdWithoutCache( $target ) { |
| 52 |
$linkTargetStore = $this->getServiceContainer()->getLinkTargetLookup(); |
| 53 |
$db = $this->getDb(); |
| 54 |
$id = $linkTargetStore->acquireLinkTargetId( $target, $db ); |
| 55 |
$linkTargetStore->clearClassCache(); |
| 56 |
$actualLinkTarget = $linkTargetStore->getLinkTargetById( $id, $db ); |
| 57 |
$this->assertEquals( $target, $actualLinkTarget ); |
| 58 |
} |
| 59 |
|
| 60 |
} |