3 use MediaWiki\Specials\SpecialRedirect
;
6 * Test class for SpecialRedirect class
10 * @license GPL-2.0-or-later
13 class SpecialRedirectTest
extends MediaWikiIntegrationTestCase
{
15 private const CREATE_USER
= 'create_user';
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(),
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();
43 $expectedStatus === 'good', $status->isGood(),
44 $method . ' does not return expected status "' . $expectedStatus . '"'
48 public static function provideDispatch() {
50 [ 'nonumeric', 'fatal' ],
52 [ self
::CREATE_USER
, 'good' ],
53 ] as $dispatchUser ) {
54 yield
[ 'dispatchUser', 'user', $dispatchUser[0], $dispatchUser[1] ];
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] ];
64 [ 'nonumeric', 'fatal' ],
68 yield
[ 'dispatchRevision', 'revision', $dispatch[0], $dispatch[1] ];
69 yield
[ 'dispatchPage', 'revision', $dispatch[0], $dispatch[1] ];
70 yield
[ 'dispatchLog', 'log', $dispatch[0], $dispatch[1] ];