Give more specific error messages on Special:Redirect
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialRedirectTest.php
1 <?php
2
3 /**
4 * Test class for SpecialRedirect class
5 *
6 * @since 1.32
7 *
8 * @license GPL-2.0-or-later
9 * @group Database
10 */
11 class SpecialRedirectTest extends MediaWikiTestCase {
12
13 protected $tablesUsed = [ 'user' ];
14
15 const CREATE_USER = 'create_user';
16
17 /**
18 * @dataProvider provideDispatch
19 * @covers SpecialRedirect::dispatchUser()
20 * @covers SpecialRedirect::dispatchFile()
21 * @covers SpecialRedirect::dispatchRevision()
22 * @covers SpecialRedirect::dispatchPage()
23 * @covers SpecialRedirect::dispatchLog()
24 */
25 public function testDispatch( $method, $type, $value, $expectedStatus ) {
26 $page = new SpecialRedirect();
27
28 // setup the user object
29 if ( $value === self::CREATE_USER ) {
30 $user = User::newFromName( __CLASS__ );
31 $user->addToDatabase();
32 $value = $user->getId();
33 }
34
35 $page->setParameter( $type . '/' . $value );
36
37 $status = $page->$method();
38 $this->assertSame(
39 $status->isGood(), $expectedStatus === 'good',
40 $method . ' does not return expected status "' . $expectedStatus . '"'
41 );
42 }
43
44 public static function provideDispatch() {
45 foreach ( [
46 [ 'nonumeric', 'fatal' ],
47 [ '3', 'fatal' ],
48 [ self::CREATE_USER, 'good' ],
49 ] as $dispatchUser ) {
50 yield [ 'dispatchUser', 'user', $dispatchUser[0], $dispatchUser[1] ];
51 }
52 foreach ( [
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] ];
58 }
59 foreach ( [
60 [ 'nonumeric', 'fatal' ],
61 [ '0', 'fatal' ],
62 [ '1', 'good' ],
63 ] as $dispatch ) {
64 yield [ 'dispatchRevision', 'revision', $dispatch[0], $dispatch[1] ];
65 yield [ 'dispatchPage', 'revision', $dispatch[0], $dispatch[1] ];
66 yield [ 'dispatchLog', 'log', $dispatch[0], $dispatch[1] ];
67 }
68 }
69
70 }