Add tests for NULL to ActionTest
authorThiemo Mättig <thiemo.maettig@wikimedia.de>
Thu, 17 Jul 2014 08:08:49 +0000 (10:08 +0200)
committerThiemo Mättig <thiemo.maettig@wikimedia.de>
Tue, 22 Jul 2014 11:55:44 +0000 (13:55 +0200)
NULL should default to 'view'. But both the exists check and the
factory should fail when asked for a NULL action.

Change-Id: I5751489eed890bb44101f2a4ef73002bff68b207

tests/phpunit/includes/actions/ActionTest.php

index 4eb30ec..6175ee6 100644 (file)
@@ -17,6 +17,7 @@ class ActionTest extends MediaWikiTestCase {
                $this->setMwGlobals( 'wgActions', array(
                        'null' => null,
                        'disabled' => false,
+                       'view' => true,
                        'dummy' => true,
                        'string' => 'NamedDummyAction',
                        'declared' => 'NonExistingClassName',
@@ -25,14 +26,16 @@ class ActionTest extends MediaWikiTestCase {
                ) );
        }
 
+       private function getPage() {
+               return WikiPage::factory( Title::makeTitle( 0, 'Title' ) );
+       }
+
        private function getContext( $requestedAction = null ) {
                $request = new FauxRequest( array( 'action' => $requestedAction ) );
 
-               $page = WikiPage::factory( Title::makeTitle( 0, 'Title' ) );
-
                $context = new DerivativeContext( RequestContext::getMain() );
                $context->setRequest( $request );
-               $context->setWikiPage( $page );
+               $context->setWikiPage( $this->getPage() );
 
                return $context;
        }
@@ -52,7 +55,6 @@ class ActionTest extends MediaWikiTestCase {
                        array( 'null', null ),
                        array( 'undeclared', null ),
                        array( '', null ),
-                       array( null, null ),
                        array( false, null ),
                );
        }
@@ -99,6 +101,26 @@ class ActionTest extends MediaWikiTestCase {
                $this->assertType( $expected ?: 'null', $action );
        }
 
+       public function testNull_doesNotExist() {
+               $exists = Action::exists( null );
+
+               $this->assertFalse( $exists );
+       }
+
+       public function testNull_defaultsToView() {
+               $context = $this->getContext( null );
+               $actionName = Action::getActionName( $context );
+
+               $this->assertEquals( 'view', $actionName );
+       }
+
+       public function testNull_canNotBeInstantiated() {
+               $page = $this->getPage();
+               $action = Action::factory( null, $page );
+
+               $this->assertNull( $action );
+       }
+
        public function testDisabledAction_exists() {
                $exists = Action::exists( 'disabled' );
 
@@ -113,8 +135,8 @@ class ActionTest extends MediaWikiTestCase {
        }
 
        public function testDisabledAction_factoryReturnsFalse() {
-               $context = $this->getContext( 'disabled' );
-               $action = Action::factory( 'disabled', $context->getWikiPage(), $context );
+               $page = $this->getPage();
+               $action = Action::factory( 'disabled', $page );
 
                $this->assertFalse( $action );
        }