summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/specials/SpecialMIMESearchTest.php
blob: 14d196851aa5d9fbd3079334bb9e908dd8ab941f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
 * @group Database
 */

class SpecialMIMESearchTest extends MediaWikiTestCase {

	/** @var MIMESearchPage */
	private $page;

	function setUp() {
		$this->page = new MIMESearchPage;
		$context = new RequestContext();
		$context->setTitle( Title::makeTitle( NS_SPECIAL, 'MIMESearch' ) );
		$context->setRequest( new FauxRequest() );
		$this->page->setContext( $context );

		parent::setUp();
	}

	/**
	 * @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
	 */
	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'] );
	}

	function providerMimeFiltering() {
		return array(
			array( 'image/gif', 'image', 'gif' ),
			array( 'image/png', 'image', 'png' ),
			array( 'application/pdf', 'application', 'pdf' ),
			array( 'image/*', 'image', null ),
			array( 'multipart/*', 'multipart', null ),
		);
	}
}