Merge "Avoid pre-send parse in DerivedPageDataUpdater due to isCountable()"
[lhc/web/wiklou.git] / tests / phpunit / structure / SpecialPageFatalTest.php
1 <?php
2
3 use MediaWiki\MediaWikiServices;
4
5 /**
6 * Test that runs against all registered special pages to make sure that regular
7 * execution of the special page does not cause a fatal error.
8 *
9 * UTSysop is used to run as much of the special page code as possible without
10 * actually knowing the details of the special page.
11 *
12 * @since 1.32
13 * @author Addshore
14 * @coversNothing
15 */
16 class SpecialPageFatalTest extends MediaWikiTestCase {
17 public function provideSpecialPages() {
18 $specialPages = [];
19 $spf = MediaWikiServices::getInstance()->getSpecialPageFactory();
20 foreach ( $spf->getNames() as $name ) {
21 $specialPages[$name] = [ $spf->getPage( $name ) ];
22 }
23 return $specialPages;
24 }
25
26 /**
27 * @dataProvider provideSpecialPages
28 */
29 public function testSpecialPageDoesNotFatal( SpecialPage $page ) {
30 $executor = new SpecialPageExecutor();
31 $user = User::newFromName( 'UTSysop' );
32
33 try {
34 $executor->executeSpecialPage( $page, '', null, null, $user );
35 } catch ( \PHPUnit\Framework\Error\Deprecated $deprecated ) {
36 // Allow deprecation,
37 // this test want to check fatals or other things breaking the extension
38 } catch ( \PHPUnit\Framework\Error\Error $error ) {
39 // Let phpunit settings working:
40 // - convertErrorsToExceptions="true"
41 // - convertNoticesToExceptions="true"
42 // - convertWarningsToExceptions="true"
43 throw $error;
44 } catch ( Exception $e ) {
45 // Other exceptions are allowed
46 }
47
48 // If the page fataled phpunit will have already died
49 $this->addToAssertionCount( 1 );
50 }
51
52 }