File: SpecialPageFatalTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (66 lines) | stat: -rw-r--r-- 1,967 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\UltimateAuthority;
use MediaWiki\User\UserIdentityValue;

/**
 * Test that runs against all registered special pages to make sure that regular
 * execution of the special page does not cause a fatal error.
 *
 * UltimateAuthority is used to run as much of the special page code as possible without
 * actually knowing the details of the special page.
 *
 * @since 1.32
 * @author Addshore
 * @coversNothing
 * @group Database
 */
class SpecialPageFatalTest extends MediaWikiIntegrationTestCase {

	protected function setUp(): void {
		parent::setUp();
		// Deprecations don't matter for what this test cares about. This made browser tests fail
		// on many occasions already. (T236809)
		$this->filterDeprecated( '//' );
	}

	public static function provideSpecialPageDoesNotFatal() {
		$spf = MediaWikiServices::getInstance()->getSpecialPageFactory();
		foreach ( $spf->getNames() as $name ) {
			yield $name => [ $name ];
		}
	}

	/**
	 * @dataProvider provideSpecialPageDoesNotFatal
	 */
	public function testSpecialPageDoesNotFatal( string $name ) {
		$spf = $this->getServiceContainer()->getSpecialPageFactory();

		$page = $spf->getPage( $name );
		if ( !$page ) {
			$this->markTestSkipped( "Could not create special page $name" );
		}

		$executor = new SpecialPageExecutor();
		$authority = new UltimateAuthority( new UserIdentityValue( 42, 'SpecialPageTester' ) );

		try {
			$executor->executeSpecialPage( $page, '', null, 'qqx', $authority );
		} catch ( \PHPUnit\Framework\Error\Error $error ) {
			// Let phpunit settings working:
			// - convertDeprecationsToExceptions="true"
			// - convertErrorsToExceptions="true"
			// - convertNoticesToExceptions="true"
			// - convertWarningsToExceptions="true"
			throw $error;
		} catch ( Exception $e ) {
			// Other exceptions are allowed
		}

		// If the page fataled phpunit will have already died
		$this->addToAssertionCount( 1 );
	}

}