wiki.techinc.nl/tests/phpunit/includes/specials/SpecialShortPagesTest.php
Umherirrender 4829c65848 Inject LinkBatchFactory into QueryPage and use it
The LinkBatchFactory service is only used in one method call in the
QueryPage class, so make it optional and provide it
when needed with a setter

Bug: T259960
Change-Id: Iee446b1defc9a4f116dc264b012ab972f89d95fc
2020-11-02 14:51:56 +01:00

50 lines
1.4 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
/**
* Test class for SpecialShortPages class
*
* @since 1.30
*
* @license GPL-2.0-or-later
*/
class SpecialShortPagesTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideGetQueryInfoRespectsContentNs
* @covers SpecialShortPages::getQueryInfo()
*/
public function testGetQueryInfoRespectsContentNS( $contentNS, $blacklistNS, $expectedNS ) {
$this->setMwGlobals( [
'wgShortPagesNamespaceBlacklist' => $blacklistNS,
'wgContentNamespaces' => $contentNS
] );
$this->setTemporaryHook( 'ShortPagesQuery', function () {
// empty hook handler
} );
$services = MediaWikiServices::getInstance();
$page = new SpecialShortPages(
$services->getNamespaceInfo(),
$services->getDBLoadBalancer(),
$services->getLinkBatchFactory()
);
$queryInfo = $page->getQueryInfo();
$this->assertArrayHasKey( 'conds', $queryInfo );
$this->assertArrayHasKey( 'page_namespace', $queryInfo[ 'conds' ] );
$this->assertEquals( $expectedNS, $queryInfo[ 'conds' ][ 'page_namespace' ] );
}
public function provideGetQueryInfoRespectsContentNs() {
return [
[ [ NS_MAIN, NS_FILE ], [], [ NS_MAIN, NS_FILE ] ],
[ [ NS_MAIN, NS_TALK ], [ NS_FILE ], [ NS_MAIN, NS_TALK ] ],
[ [ NS_MAIN, NS_FILE ], [ NS_FILE ], [ NS_MAIN ] ],
// NS_MAIN namespace is always forced
[ [], [ NS_FILE ], [ NS_MAIN ] ]
];
}
}