| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Specials\SpecialRedirect; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class SpecialRedirectTest extends MediaWikiIntegrationTestCase { |
| 14 |
|
| 15 |
private const CREATE_USER = 'create_user'; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public function testDispatch( $method, $type, $value, $expectedStatus ) { |
| 26 |
$userFactory = $this->getServiceContainer()->getUserFactory(); |
| 27 |
$page = new SpecialRedirect( |
| 28 |
$this->getServiceContainer()->getRepoGroup(), |
| 29 |
$userFactory |
| 30 |
); |
| 31 |
|
| 32 |
|
| 33 |
if ( $value === self::CREATE_USER ) { |
| 34 |
$user = $userFactory->newFromName( __CLASS__ ); |
| 35 |
$user->addToDatabase(); |
| 36 |
$value = $user->getId(); |
| 37 |
} |
| 38 |
|
| 39 |
$page->setParameter( $type . '/' . $value ); |
| 40 |
|
| 41 |
$status = $page->$method(); |
| 42 |
$this->assertSame( |
| 43 |
$expectedStatus === 'good', $status->isGood(), |
| 44 |
$method . ' does not return expected status "' . $expectedStatus . '"' |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 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] ]; |
| 55 |
} |
| 56 |
foreach ( [ |
| 57 |
[ 'bad<name', 'fatal' ], |
| 58 |
[ 'File:Non-exists.jpg', 'fatal' ], |
| 59 |
|
| 60 |
] as $dispatchFile ) { |
| 61 |
yield [ 'dispatchFile', 'file', $dispatchFile[0], $dispatchFile[1] ]; |
| 62 |
} |
| 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] ]; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
} |