wiki.techinc.nl/tests/phpunit/includes/specials/SpecialShortPagesTest.php
Alexander Vorwerk decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00

48 lines
1.3 KiB
PHP

<?php
/**
* 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( [
'wgShortPagesNamespaceExclusions' => $blacklistNS,
'wgContentNamespaces' => $contentNS
] );
$this->setTemporaryHook( 'ShortPagesQuery', static function () {
// empty hook handler
} );
$services = $this->getServiceContainer();
$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 ] ]
];
}
}