Merge "Simplify Block::getBy and Block::getByName"
[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\Error $error ) {
36 // Let phpunit settings working:
37 // - convertErrorsToExceptions="true"
38 // - convertNoticesToExceptions="true"
39 // - convertWarningsToExceptions="true"
40 throw $error;
41 } catch ( Exception $e ) {
42 // Other exceptions are allowed
43 }
44
45 // If the page fataled phpunit will have already died
46 $this->addToAssertionCount( 1 );
47 }
48
49 }