Added a BloomCacheRedisTest class
[lhc/web/wiklou.git] / tests / phpunit / includes / actions / ActionTest.php
index 839a0c5..eb370d9 100644 (file)
@@ -13,13 +13,18 @@ class ActionTest extends MediaWikiTestCase {
        protected function setUp() {
                parent::setUp();
 
+               $context = $this->getContext();
                $this->setMwGlobals( 'wgActions', array(
-                       'null'     => null,
-                       'dummy'    => true,
-                       'string'   => 'NamedDummyAction',
+                       'null' => null,
+                       'disabled' => false,
+                       'view' => true,
+                       'edit' => true,
+                       'revisiondelete' => true,
+                       'dummy' => true,
+                       'string' => 'NamedDummyAction',
                        'declared' => 'NonExistingClassName',
                        'callable' => array( $this, 'dummyActionCallback' ),
-                       'object'   => new InstantiatedDummyAction( $this->getPage(), $this->getContext() ),
+                       'object' => new InstantiatedDummyAction( $context->getWikiPage(), $context ),
                ) );
        }
 
@@ -27,25 +32,32 @@ class ActionTest extends MediaWikiTestCase {
                return WikiPage::factory( Title::makeTitle( 0, 'Title' ) );
        }
 
-       private function getContext() {
-               return new DerivativeContext( RequestContext::getMain() );
+       private function getContext( $requestedAction = null ) {
+               $request = new FauxRequest( array( 'action' => $requestedAction ) );
+
+               $context = new DerivativeContext( RequestContext::getMain() );
+               $context->setRequest( $request );
+               $context->setWikiPage( $this->getPage() );
+
+               return $context;
        }
 
        public function actionProvider() {
                return array(
-                       array( 'dummy',    'DummyAction' ),
-                       array( 'string',   'NamedDummyAction' ),
+                       array( 'dummy', 'DummyAction' ),
+                       array( 'string', 'NamedDummyAction' ),
                        array( 'callable', 'CalledDummyAction' ),
-                       array( 'object',   'InstantiatedDummyAction' ),
+                       array( 'object', 'InstantiatedDummyAction' ),
 
                        // Capitalization is ignored
-                       array( 'STRING',   'NamedDummyAction' ),
+                       array( 'DUMMY', 'DummyAction' ),
+                       array( 'STRING', 'NamedDummyAction' ),
 
                        // Null and non-existing values
-                       array( 'null',       null ),
+                       array( 'null', null ),
                        array( 'undeclared', null ),
-                       array( '',           null ),
-                       array( null,         null ),
+                       array( '', null ),
+                       array( false, null ),
                );
        }
 
@@ -57,7 +69,7 @@ class ActionTest extends MediaWikiTestCase {
        public function testActionExists( $requestedAction, $expected ) {
                $exists = Action::exists( $requestedAction );
 
-               $this->assertEquals( isset( $expected ), $exists );
+               $this->assertSame( $expected !== null, $exists );
        }
 
        public function testActionExists_doesNotRequireInstantiation() {
@@ -73,13 +85,35 @@ class ActionTest extends MediaWikiTestCase {
         * @param string|null $expected
         */
        public function testGetActionName( $requestedAction, $expected ) {
-               $context = $this->getContext();
-               $context->setWikiPage( $this->getPage() );
-               $context->setRequest( new FauxRequest( array( 'action' => $requestedAction ) ) );
+               $context = $this->getContext( $requestedAction );
+               $actionName = Action::getActionName( $context );
+
+               $this->assertEquals( $expected ?: 'nosuchaction', $actionName );
+       }
 
+       public function testGetActionName_editredlinkWorkaround() {
+               // See https://bugzilla.wikimedia.org/show_bug.cgi?id=20966
+               $context = $this->getContext( 'editredlink' );
                $actionName = Action::getActionName( $context );
 
-               $this->assertEquals( isset( $expected ) ? $expected : 'nosuchaction', $actionName );
+               $this->assertEquals( 'edit', $actionName );
+       }
+
+       public function testGetActionName_historysubmitWorkaround() {
+               // See https://bugzilla.wikimedia.org/show_bug.cgi?id=20966
+               $context = $this->getContext( 'historysubmit' );
+               $actionName = Action::getActionName( $context );
+
+               $this->assertEquals( 'view', $actionName );
+       }
+
+       public function testGetActionName_revisiondeleteWorkaround() {
+               // See https://bugzilla.wikimedia.org/show_bug.cgi?id=20966
+               $context = $this->getContext( 'historysubmit' );
+               $context->getRequest()->setVal( 'revisiondelete', true );
+               $actionName = Action::getActionName( $context );
+
+               $this->assertEquals( 'revisiondelete', $actionName );
        }
 
        /**
@@ -88,13 +122,55 @@ class ActionTest extends MediaWikiTestCase {
         * @param string|null $expected
         */
        public function testActionFactory( $requestedAction, $expected ) {
-               $action = Action::factory( $requestedAction, $this->getPage(), $this->getContext() );
+               $context = $this->getContext();
+               $action = Action::factory( $requestedAction, $context->getWikiPage(), $context );
+
+               $this->assertType( $expected ?: 'null', $action );
+       }
+
+       public function testNull_doesNotExist() {
+               $exists = Action::exists( null );
+
+               $this->assertFalse( $exists );
+       }
 
-               $this->assertType( isset( $expected ) ? $expected : 'null', $action );
+       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' );
+
+               $this->assertTrue( $exists );
+       }
+
+       public function testDisabledAction_isNotResolved() {
+               $context = $this->getContext( 'disabled' );
+               $actionName = Action::getActionName( $context );
+
+               $this->assertEquals( 'nosuchaction', $actionName );
+       }
+
+       public function testDisabledAction_factoryReturnsFalse() {
+               $page = $this->getPage();
+               $action = Action::factory( 'disabled', $page );
+
+               $this->assertFalse( $action );
        }
 
        public function dummyActionCallback() {
-               return new CalledDummyAction( $this->getPage(), $this->getContext() );
+               $context = $this->getContext();
+               return new CalledDummyAction( $context->getWikiPage(), $context );
        }
 
 }
@@ -105,14 +181,18 @@ class DummyAction extends Action {
                return get_called_class();
        }
 
-       public function show() { }
-
-       public function execute() { }
+       public function show() {
+       }
 
+       public function execute() {
+       }
 }
 
-class NamedDummyAction extends DummyAction { }
+class NamedDummyAction extends DummyAction {
+}
 
-class CalledDummyAction extends DummyAction { }
+class CalledDummyAction extends DummyAction {
+}
 
-class InstantiatedDummyAction extends DummyAction { }
+class InstantiatedDummyAction extends DummyAction {
+}