* In queryLinks(), use the full result cache even if a limit is specified. Truncate the result in the caller if necessary. * Remove the confusing boolean parameter from partitionResult(). Make it always false and fix up the results afterwards. So the batches are always the inclusive start and end IDs, false is never returned. * Inject a logger instead of using wfDebug() * Use private not protected. Defaulting to protected was just a coding style quirk I had at the time. * In queryLinks(), use early return. * In hooks BacklinkCacheGetConditionsHook and BacklinkCacheGetPrefixHook adjust the parameter type hint to avoid the need for a Phan override. Change-Id: Ia53f494633affe48316f0a8b63d03596239ad53c
42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Cache\BacklinkCacheFactory;
|
|
use MediaWiki\Config\ServiceOptions;
|
|
use MediaWiki\Linker\LinksMigration;
|
|
use MediaWiki\Logger\LoggerFactory;
|
|
use MediaWiki\Page\PageReferenceValue;
|
|
use Wikimedia\Rdbms\IConnectionProvider;
|
|
|
|
/**
|
|
* @group Cache
|
|
*/
|
|
class BacklinkCacheFactoryTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @covers \MediaWiki\Cache\BacklinkCacheFactory::getBacklinkCache
|
|
*/
|
|
public function testGetBacklinkCache() {
|
|
$wanCache = new WANObjectCache( [ 'cache' => new EmptyBagOStuff() ] );
|
|
$dbProvider = $this->createMock( IConnectionProvider::class );
|
|
$page = PageReferenceValue::localReference( NS_CATEGORY, "kittens" );
|
|
$factory = new BacklinkCacheFactory(
|
|
$this->createMock( ServiceOptions::class ),
|
|
$this->createMock( LinksMigration::class ),
|
|
$wanCache,
|
|
$this->createHookContainer(),
|
|
$dbProvider,
|
|
LoggerFactory::getInstance( 'BacklinkCache' )
|
|
);
|
|
$cache = $factory->getBacklinkCache( $page );
|
|
$this->assertTrue( $cache->getPage()->isSamePageAs( $page ) );
|
|
|
|
$cache2 = $factory->getBacklinkCache( $page );
|
|
$this->assertSame( $cache, $cache2 );
|
|
|
|
$page2 = PageReferenceValue::localReference( NS_CATEGORY, "doggos" );
|
|
$cache2 = $factory->getBacklinkCache( $page2 );
|
|
$this->assertNotSame( $cache, $cache2 );
|
|
$this->assertTrue( $cache2->getPage()->isSamePageAs( $page2 ) );
|
|
}
|
|
|
|
}
|