wiki.techinc.nl/tests/phpunit/includes/specials/SpecialMIMESearchTest.php
DannyS712 6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00

56 lines
1.5 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
/**
* @group Database
* @covers SpecialMIMESearch
*/
class SpecialMIMESearchTest extends MediaWikiIntegrationTestCase {
/** @var SpecialMIMESearch */
private $page;
protected function setUp() : void {
parent::setUp();
$services = MediaWikiServices::getInstance();
$this->page = new SpecialMIMESearch(
$services->getDBLoadBalancer(),
$services->getLinkBatchFactory(),
$services->getLanguageConverterFactory()
);
$context = new RequestContext();
$context->setTitle( Title::makeTitle( NS_SPECIAL, 'MIMESearch' ) );
$context->setRequest( new FauxRequest() );
$this->page->setContext( $context );
}
/**
* @dataProvider providerMimeFiltering
* @param string $par Subpage for special page
* @param string $major Major MIME type we expect to look for
* @param string $minor Minor MIME type we expect to look for
*/
public function testMimeFiltering( $par, $major, $minor ) {
$this->page->run( $par );
$qi = $this->page->getQueryInfo();
$this->assertEquals( $qi['conds']['img_major_mime'], $major );
if ( $minor !== null ) {
$this->assertEquals( $qi['conds']['img_minor_mime'], $minor );
} else {
$this->assertArrayNotHasKey( 'img_minor_mime', $qi['conds'] );
}
$this->assertContains( 'image', $qi['tables'] );
}
public function providerMimeFiltering() {
return [
[ 'image/gif', 'image', 'gif' ],
[ 'image/png', 'image', 'png' ],
[ 'application/pdf', 'application', 'pdf' ],
[ 'image/*', 'image', null ],
[ 'multipart/*', 'multipart', null ],
];
}
}