wiki.techinc.nl/tests/phpunit/unit/includes/cache/LinkBatchFactoryTest.php
Tim Starling 16979ecf29 Fix pollution of LinkBatch/LinkCache with interwiki link
* In LinkBatch::addObj(), reject interwiki links with a warning.
  Otherwise the link is added to the batch by ns/title and later
  reconstructed as if it were a local link without an interwiki
  prefix.
* In CommentParser, treat interwiki links as always good, don't defer
  the existence check.
* In LinkBatch, inject a LoggerInstance instead of calling LoggerFactory
  in four places.
* Add a regression test, and some general tests for known links.

Bug: T300311
Change-Id: I0e5825eb48a6ba2932aea69a4d0fff3439c50ff5
2022-01-28 10:52:38 +11:00

54 lines
1.3 KiB
PHP

<?php
use MediaWiki\Cache\LinkBatchFactory;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\Page\PageReference;
use MediaWiki\Page\PageReferenceValue;
use Wikimedia\Rdbms\ILoadBalancer;
/**
* @group Cache
* @covers \MediaWiki\Cache\LinkBatchFactory
*/
class LinkBatchFactoryTest extends MediaWikiUnitTestCase {
use FactoryArgTestTrait;
protected static function getFactoryClass() {
return LinkBatchFactory::class;
}
protected static function getInstanceClass() {
return LinkBatch::class;
}
protected static function getExtraClassArgCount() {
// $arr
return 1;
}
protected function getOverriddenMockValueForParam( ReflectionParameter $param ) {
if ( $param->getName() === 'initialItems' ) {
return [ [] ];
}
return [];
}
public function testNewLinkBatch() {
$factory = new LinkBatchFactory(
$this->createMock( LinkCache::class ),
$this->createMock( TitleFormatter::class ),
$this->createMock( Language::class ),
$this->createMock( GenderCache::class ),
$this->createMock( ILoadBalancer::class ),
LoggerFactory::getInstance( 'LinkBatch' )
);
$linkBatch = $factory->newLinkBatch( [
new TitleValue( NS_MAIN, 'Foo' ),
new PageReferenceValue( NS_TALK, 'Bar', PageReference::LOCAL ),
] );
$this->assertFalse( $linkBatch->isEmpty() );
$this->assertSame( 2, $linkBatch->getSize() );
}
}