Merge "Drop cache interwiki"
[mediawiki.git] / tests / phpunit / includes / specials / SpecialRedirectTest.php
blob3df9d7aa326afce16db868b779b85e4d4babb87a
1 <?php
3 use MediaWiki\Specials\SpecialRedirect;
5 /**
6 * Test class for SpecialRedirect class
8 * @since 1.32
10 * @license GPL-2.0-or-later
11 * @group Database
13 class SpecialRedirectTest extends MediaWikiIntegrationTestCase {
15 private const CREATE_USER = 'create_user';
17 /**
18 * @dataProvider provideDispatch
19 * @covers \MediaWiki\Specials\SpecialRedirect::dispatchUser
20 * @covers \MediaWiki\Specials\SpecialRedirect::dispatchFile
21 * @covers \MediaWiki\Specials\SpecialRedirect::dispatchRevision
22 * @covers \MediaWiki\Specials\SpecialRedirect::dispatchPage
23 * @covers \MediaWiki\Specials\SpecialRedirect::dispatchLog
25 public function testDispatch( $method, $type, $value, $expectedStatus ) {
26 $userFactory = $this->getServiceContainer()->getUserFactory();
27 $page = new SpecialRedirect(
28 $this->getServiceContainer()->getRepoGroup(),
29 $userFactory
32 // setup the user object
33 if ( $value === self::CREATE_USER ) {
34 $user = $userFactory->newFromName( __CLASS__ );
35 $user->addToDatabase();
36 $value = $user->getId();
39 $page->setParameter( $type . '/' . $value );
41 $status = $page->$method();
42 $this->assertSame(
43 $expectedStatus === 'good', $status->isGood(),
44 $method . ' does not return expected status "' . $expectedStatus . '"'
48 public static function provideDispatch() {
49 foreach ( [
50 [ 'nonumeric', 'fatal' ],
51 [ '3', 'fatal' ],
52 [ self::CREATE_USER, 'good' ],
53 ] as $dispatchUser ) {
54 yield [ 'dispatchUser', 'user', $dispatchUser[0], $dispatchUser[1] ];
56 foreach ( [
57 [ 'bad<name', 'fatal' ],
58 [ 'File:Non-exists.jpg', 'fatal' ],
59 // TODO Cannot test the good path here, because a file must exists
60 ] as $dispatchFile ) {
61 yield [ 'dispatchFile', 'file', $dispatchFile[0], $dispatchFile[1] ];
63 foreach ( [
64 [ 'nonumeric', 'fatal' ],
65 [ '0', 'fatal' ],
66 [ '1', 'good' ],
67 ] as $dispatch ) {
68 yield [ 'dispatchRevision', 'revision', $dispatch[0], $dispatch[1] ];
69 yield [ 'dispatchPage', 'revision', $dispatch[0], $dispatch[1] ];
70 yield [ 'dispatchLog', 'log', $dispatch[0], $dispatch[1] ];