9d85fdebeb3022fd00f99407c2d941f5e8d1a5bd
[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
17 public static function setUpBeforeClass() {
18 parent::setUpBeforeClass();
19 self::overrideMwServices();
20 }
21
22 public static function tearDownAfterClass() {
23 self::overrideMwServices();
24 parent::tearDownAfterClass();
25 }
26
27 public function provideSpecialPages() {
28 $specialPages = [];
29 $spf = MediaWikiServices::getInstance()->getSpecialPageFactory();
30 foreach ( $spf->getNames() as $name ) {
31 $specialPages[$name] = [ $spf->getPage( $name ) ];
32 }
33 return $specialPages;
34 }
35
36 /**
37 * @dataProvider provideSpecialPages
38 */
39 public function testSpecialPageDoesNotFatal( SpecialPage $page ) {
40 $executor = new SpecialPageExecutor();
41 $user = User::newFromName( 'UTSysop' );
42
43 try {
44 $executor->executeSpecialPage( $page, '', null, null, $user );
45 } catch ( Exception $e ) {
46 // Exceptions are allowed
47 }
48
49 // If the page fataled phpunit will have already died
50 $this->addToAssertionCount( 1 );
51 }
52
53 }