4 * Test class for SpecialRedirect class
8 * @license GPL-2.0-or-later
11 class SpecialRedirectTest
extends MediaWikiTestCase
{
13 protected $tablesUsed = [ 'user' ];
15 const CREATE_USER
= 'create_user';
18 * @dataProvider provideDispatch
19 * @covers SpecialRedirect::dispatchUser()
20 * @covers SpecialRedirect::dispatchFile()
21 * @covers SpecialRedirect::dispatchRevision()
22 * @covers SpecialRedirect::dispatchPage()
23 * @covers SpecialRedirect::dispatchLog()
25 public function testDispatch( $method, $type, $value, $expectedStatus ) {
26 $page = new SpecialRedirect();
28 // setup the user object
29 if ( $value === self
::CREATE_USER
) {
30 $user = User
::newFromName( __CLASS__
);
31 $user->addToDatabase();
32 $value = $user->getId();
35 $page->setParameter( $type . '/' . $value );
37 $status = $page->$method();
39 $status->isGood(), $expectedStatus === 'good',
40 $method . ' does not return expected status "' . $expectedStatus . '"'
44 public static function provideDispatch() {
46 [ 'nonumeric', 'fatal' ],
48 [ self
::CREATE_USER
, 'good' ],
49 ] as $dispatchUser ) {
50 yield
[ 'dispatchUser', 'user', $dispatchUser[0], $dispatchUser[1] ];
53 [ 'bad<name', 'fatal' ],
54 [ 'File:Non-exists.jpg', 'fatal' ],
55 // TODO Cannot test the good path here, because a file must exists
56 ] as $dispatchFile ) {
57 yield
[ 'dispatchFile', 'file', $dispatchFile[0], $dispatchFile[1] ];
60 [ 'nonumeric', 'fatal' ],
64 yield
[ 'dispatchRevision', 'revision', $dispatch[0], $dispatch[1] ];
65 yield
[ 'dispatchPage', 'revision', $dispatch[0], $dispatch[1] ];
66 yield
[ 'dispatchLog', 'log', $dispatch[0], $dispatch[1] ];