Debian Codegraph @

tests/phpunit/includes/specials/SpecialMIMESearchTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Context\RequestContext;
4 use MediaWiki\Request\FauxRequest;
5 use MediaWiki\Specials\SpecialMIMESearch;
6 use MediaWiki\Title\Title;
7
8 /**
9 * @group Database
10 * @covers \MediaWiki\Specials\SpecialMIMESearch
11 */
12 class SpecialMIMESearchTest extends MediaWikiIntegrationTestCase {
13
14 /** @var SpecialMIMESearch */
15 private $page;
16
17 protected function setUp(): void {
18 parent::setUp();
19
20 $services = $this->getServiceContainer();
21 $this->page = new SpecialMIMESearch(
22 $services->getConnectionProvider(),
23 $services->getLinkBatchFactory(),
24 $services->getLanguageConverterFactory()
25 );
26 $context = new RequestContext();
27 $context->setTitle( Title::makeTitle( NS_SPECIAL, 'MIMESearch' ) );
28 $context->setRequest( new FauxRequest() );
29 $this->page->setContext( $context );
30 }
31
32 /**
33 * @dataProvider providerMimeFiltering
34 * @param string $par Subpage for special page
35 * @param string $major Major MIME type we expect to look for
36 * @param string $minor Minor MIME type we expect to look for
37 */
38 public function testMimeFiltering( $par, $major, $minor ) {
39 $this->page->run( $par );
40 $qi = $this->page->getQueryInfo();
41 $this->assertEquals( $qi['conds']['img_major_mime'], $major );
42 if ( $minor !== null ) {
43 $this->assertEquals( $qi['conds']['img_minor_mime'], $minor );
44 } else {
45 $this->assertArrayNotHasKey( 'img_minor_mime', $qi['conds'] );
46 }
47 $this->assertContains( 'image', $qi['tables'] );
48 }
49
50 public static function providerMimeFiltering() {
51 return [
52 [ 'image/gif', 'image', 'gif' ],
53 [ 'image/png', 'image', 'png' ],
54 [ 'application/pdf', 'application', 'pdf' ],
55 [ 'image/*', 'image', null ],
56 [ 'multipart/*', 'multipart', null ],
57 ];
58 }
59 }