Merge "Exclude redirects from Special:Fewestrevisions"
[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 */
15 class SpecialPageFatalTest extends MediaWikiTestCase {
16 public function provideSpecialPages() {
17 $specialPages = [];
18 $spf = MediaWikiServices::getInstance()->getSpecialPageFactory();
19 foreach ( $spf->getNames() as $name ) {
20 $specialPages[$name] = [ $spf->getPage( $name ) ];
21 }
22 return $specialPages;
23 }
24
25 /**
26 * @dataProvider provideSpecialPages
27 */
28 public function testSpecialPageDoesNotFatal( SpecialPage $page ) {
29 $executor = new SpecialPageExecutor();
30 $user = User::newFromName( 'UTSysop' );
31
32 try {
33 $executor->executeSpecialPage( $page, '', null, 'qqx', $user );
34 } catch ( \PHPUnit\Framework\Error\Deprecated $deprecated ) {
35 // Allow deprecation,
36 // this test want to check fatals or other things breaking the extension
37 } catch ( \PHPUnit\Framework\Error\Error $error ) {
38 // Let phpunit settings working:
39 // - convertErrorsToExceptions="true"
40 // - convertNoticesToExceptions="true"
41 // - convertWarningsToExceptions="true"
42 throw $error;
43 } catch ( Exception $e ) {
44 // Other exceptions are allowed
45 }
46
47 // If the page fataled phpunit will have already died
48 $this->addToAssertionCount( 1 );
49 }
50
51 }