BadFileLookup to replace wfIsBadImage
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / GlobalWithDBTest.php
1 <?php
2
3 /**
4 * @group GlobalFunctions
5 * @group Database
6 */
7 class GlobalWithDBTest extends MediaWikiTestCase {
8 private function setUpBadImageTests( $name ) {
9 if ( in_array( $name, [
10 'Hook bad.jpg',
11 'Redirect to bad.jpg',
12 'Redirect_to_good.jpg',
13 'Redirect to hook bad.jpg',
14 'Redirect to hook good.jpg',
15 ] ) ) {
16 $this->markTestSkipped( "Didn't get RepoGroup working properly yet" );
17 }
18
19 // Don't try to fetch the files from Commons or anything, please
20 $this->setMwGlobals( 'wgForeignFileRepos', [] );
21 // We need to reset services immediately so that editPage() doesn't use the old RepoGroup
22 // and hit the network
23 $this->resetServices();
24
25 // XXX How do we get file redirects to work?
26 $this->editPage( 'File:Redirect to bad.jpg', '#REDIRECT [[Bad.jpg]]' );
27 $this->editPage( 'File:Redirect to good.jpg', '#REDIRECT [[Good.jpg]]' );
28 $this->editPage( 'File:Redirect to hook bad.jpg', '#REDIRECT [[Hook bad.jpg]]' );
29 $this->editPage( 'File:Redirect to hook good.jpg', '#REDIRECT [[Hook good.jpg]]' );
30
31 $this->setTemporaryHook( 'BadImage', 'BadFileLookupTest::badImageHook' );
32 }
33
34 /**
35 * @dataProvider BadFileLookupTest::provideIsBadFile
36 * @covers ::wfIsBadImage
37 */
38 public function testWfIsBadImage( $name, $title, $expected ) {
39 $this->setUpBadImageTests( $name );
40
41 $this->editPage( 'MediaWiki:Bad image list', BadFileLookupTest::BLACKLIST );
42 $this->resetServices();
43 // Enable messages from MediaWiki namespace
44 MessageCache::singleton()->enable();
45
46 $this->assertEquals( $expected, wfIsBadImage( $name, $title ) );
47 }
48
49 /**
50 * @dataProvider BadFileLookupTest::provideIsBadFile
51 * @covers ::wfIsBadImage
52 */
53 public function testWfIsBadImage_blacklistParam( $name, $title, $expected ) {
54 $this->setUpBadImageTests( $name );
55
56 $this->hideDeprecated( 'wfIsBadImage with $blacklist parameter' );
57 $this->assertSame( $expected, wfIsBadImage( $name, $title, BadFileLookupTest::BLACKLIST ) );
58 }
59 }