Introduce SpecialPageFatalTest
authoraddshore <addshorewiki@gmail.com>
Thu, 24 Mar 2016 14:11:58 +0000 (14:11 +0000)
committerWMDE-Fisch <christoph.jauera@wikimedia.de>
Tue, 31 Jul 2018 07:11:48 +0000 (07:11 +0000)
This test makes sure that special pages do not fatal
in their most basic form (anon user viewing the page).

Depends-On: I3a9f5b315eb114cb12ea4071f8da9079f797fcf6
Change-Id: Ic675e92d8dd8f11fa67914d2ce1dc00a379106ca

tests/phpunit/structure/SpecialPageFatalTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/structure/SpecialPageFatalTest.php b/tests/phpunit/structure/SpecialPageFatalTest.php
new file mode 100644 (file)
index 0000000..abf1cdd
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * Test that runs against all registered special pages to make sure that regular
+ * execution of the special page does not cause a fatal error.
+ *
+ * UTSysop 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
+ */
+class SpecialPageFatalTest extends MediaWikiTestCase {
+
+       public static function setUpBeforeClass() {
+               parent::setUpBeforeClass();
+               SpecialPageFactory::resetList();
+       }
+
+       public static function tearDownAfterClass() {
+               SpecialPageFactory::resetList();
+               parent::tearDownAfterClass();
+       }
+
+       public function provideSpecialPages() {
+               $specialPages = [];
+               foreach ( SpecialPageFactory::getNames() as $name ) {
+                       $specialPages[$name] = [ SpecialPageFactory::getPage( $name ) ];
+               }
+               return $specialPages;
+       }
+
+       /**
+        * @dataProvider provideSpecialPages
+        */
+       public function testSpecialPageDoesNotFatal( SpecialPage $page ) {
+               $executor = new SpecialPageExecutor();
+               $user = User::newFromName( 'UTSysop' );
+
+               try {
+                       $executor->executeSpecialPage( $page, '', null, null, $user );
+               } catch ( Exception $e ) {
+                       // Exceptions are allowed
+               }
+
+               // If the page fataled phpunit will have already died
+               $this->addToAssertionCount( 1 );
+       }
+
+}