wiki.techinc.nl/tests/phpunit/includes/linker/LinkTargetStoreTest.php
Tim Starling 5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00

67 lines
2.3 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
/**
* @group Database
* @covers MediaWiki\Linker\LinkTargetStore
*/
class LinkTargetStoreTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
$this->tablesUsed[] = 'linktarget';
}
public static function provideLinkTargets() {
yield [ new TitleValue( NS_SPECIAL, 'BlankPage' ) ];
yield [ new TitleValue( NS_MAIN, 'Foobar' ) ];
yield [ new TitleValue( NS_USER, 'Someuser' ) ];
}
/**
* @dataProvider provideLinkTargets
* @covers \MediaWiki\Linker\LinkTargetStore::acquireLinkTargetId
*/
public function testAcquireLinkTargetId( $target ) {
$linkTargetStore = $this->getServiceContainer()->getLinkTargetLookup();
$db = $this->getServiceContainer()->getDBLoadBalancer()->getConnection( DB_PRIMARY );
$id = $linkTargetStore->acquireLinkTargetId( $target, $db );
$row = $db->selectRow(
'linktarget',
[ 'lt_id', 'lt_namespace', 'lt_title' ],
[
'lt_namespace' => $target->getNamespace(),
'lt_title' => $target->getDBkey()
]
);
$this->assertSame( (int)$row->lt_id, $id );
}
/**
* @dataProvider provideLinkTargets
* @covers \MediaWiki\Linker\LinkTargetStore::acquireLinkTargetId
* @covers \MediaWiki\Linker\LinkTargetStore::getLinkTargetById
*/
public function testGetLinkTargetById( $target ) {
$linkTargetStore = MediaWikiServices::getInstance()->getLinkTargetLookup();
$db = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_PRIMARY );
$id = $linkTargetStore->acquireLinkTargetId( $target, $db );
$actualLinkTarget = $linkTargetStore->getLinkTargetById( $id, $db );
$this->assertEquals( $target, $actualLinkTarget );
}
/**
* @dataProvider provideLinkTargets
* @covers \MediaWiki\Linker\LinkTargetStore::acquireLinkTargetId
* @covers \MediaWiki\Linker\LinkTargetStore::getLinkTargetById
*/
public function testGetLinkTargetByIdWithoutCache( $target ) {
$linkTargetStore = MediaWikiServices::getInstance()->getLinkTargetLookup();
$db = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_PRIMARY );
$id = $linkTargetStore->acquireLinkTargetId( $target, $db );
$linkTargetStore->clearClassCache();
$actualLinkTarget = $linkTargetStore->getLinkTargetById( $id, $db );
$this->assertEquals( $target, $actualLinkTarget );
}
}