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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
<?php
use MediaWiki\Specials\SpecialRedirect;
/**
* Test class for SpecialRedirect class
*
* @since 1.32
*
* @license GPL-2.0-or-later
* @group Database
*/
class SpecialRedirectTest extends MediaWikiIntegrationTestCase {
private const CREATE_USER = 'create_user';
/**
* @dataProvider provideDispatch
* @covers \MediaWiki\Specials\SpecialRedirect::dispatchUser
* @covers \MediaWiki\Specials\SpecialRedirect::dispatchFile
* @covers \MediaWiki\Specials\SpecialRedirect::dispatchRevision
* @covers \MediaWiki\Specials\SpecialRedirect::dispatchPage
* @covers \MediaWiki\Specials\SpecialRedirect::dispatchLog
*/
public function testDispatch( $method, $type, $value, $expectedStatus ) {
$userFactory = $this->getServiceContainer()->getUserFactory();
$page = new SpecialRedirect(
$this->getServiceContainer()->getRepoGroup(),
$userFactory
);
// setup the user object
if ( $value === self::CREATE_USER ) {
$user = $userFactory->newFromName( __CLASS__ );
$user->addToDatabase();
$value = $user->getId();
}
$page->setParameter( $type . '/' . $value );
$status = $page->$method();
$this->assertSame(
$expectedStatus === 'good', $status->isGood(),
$method . ' does not return expected status "' . $expectedStatus . '"'
);
}
public static function provideDispatch() {
foreach ( [
[ 'nonumeric', 'fatal' ],
[ '3', 'fatal' ],
[ self::CREATE_USER, 'good' ],
] as $dispatchUser ) {
yield [ 'dispatchUser', 'user', $dispatchUser[0], $dispatchUser[1] ];
}
foreach ( [
[ 'bad<name', 'fatal' ],
[ 'File:Non-exists.jpg', 'fatal' ],
// TODO Cannot test the good path here, because a file must exists
] as $dispatchFile ) {
yield [ 'dispatchFile', 'file', $dispatchFile[0], $dispatchFile[1] ];
}
foreach ( [
[ 'nonumeric', 'fatal' ],
[ '0', 'fatal' ],
[ '1', 'good' ],
] as $dispatch ) {
yield [ 'dispatchRevision', 'revision', $dispatch[0], $dispatch[1] ];
yield [ 'dispatchPage', 'revision', $dispatch[0], $dispatch[1] ];
yield [ 'dispatchLog', 'log', $dispatch[0], $dispatch[1] ];
}
}
}
|