Debian Codegraph @

tests/phpunit/includes/specials/SpecialRedirectTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Specials\SpecialRedirect;
4
5 /**
6 * Test class for SpecialRedirect class
7 *
8 * @since 1.32
9 *
10 * @license GPL-2.0-or-later
11 * @group Database
12 */
13 class SpecialRedirectTest extends MediaWikiIntegrationTestCase {
14
15 private const CREATE_USER = 'create_user';
16
17 /**
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
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 // setup the user object
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 // TODO Cannot test the good path here, because a file must exists
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 }