Debian Codegraph @

tests/phpunit/structure/SpecialPageFatalTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\MediaWikiServices;
4 use MediaWiki\Permissions\UltimateAuthority;
5 use MediaWiki\User\UserIdentityValue;
6
7 /**
8 * Test that runs against all registered special pages to make sure that regular
9 * execution of the special page does not cause a fatal error.
10 *
11 * UltimateAuthority is used to run as much of the special page code as possible without
12 * actually knowing the details of the special page.
13 *
14 * @since 1.32
15 * @author Addshore
16 * @coversNothing
17 * @group Database
18 */
19 class SpecialPageFatalTest extends MediaWikiIntegrationTestCase {
20
21 protected function setUp(): void {
22 parent::setUp();
23 // Deprecations don't matter for what this test cares about. This made browser tests fail
24 // on many occasions already. (T236809)
25 $this->filterDeprecated( '//' );
26 }
27
28 public static function provideSpecialPageDoesNotFatal() {
29 $spf = MediaWikiServices::getInstance()->getSpecialPageFactory();
30 foreach ( $spf->getNames() as $name ) {
31 yield $name => [ $name ];
32 }
33 }
34
35 /**
36 * @dataProvider provideSpecialPageDoesNotFatal
37 */
38 public function testSpecialPageDoesNotFatal( string $name ) {
39 $spf = $this->getServiceContainer()->getSpecialPageFactory();
40
41 $page = $spf->getPage( $name );
42 if ( !$page ) {
43 $this->markTestSkipped( "Could not create special page $name" );
44 }
45
46 $executor = new SpecialPageExecutor();
47 $authority = new UltimateAuthority( new UserIdentityValue( 42, 'SpecialPageTester' ) );
48
49 try {
50 $executor->executeSpecialPage( $page, '', null, 'qqx', $authority );
51 } catch ( \PHPUnit\Framework\Error\Error $error ) {
52 // Let phpunit settings working:
53 // - convertDeprecationsToExceptions="true"
54 // - convertErrorsToExceptions="true"
55 // - convertNoticesToExceptions="true"
56 // - convertWarningsToExceptions="true"
57 throw $error;
58 } catch ( Exception $e ) {
59 // Other exceptions are allowed
60 }
61
62 // If the page fataled phpunit will have already died
63 $this->addToAssertionCount( 1 );
64 }
65
66 }