1. The 'dummy' test case already tested ucfirst(), but strtolower()
was not tested. The new 'DUMMY' tests fixes that.
2. Add a new test where the requested action is false.
3. Refactored the dummy builder a bit to make it easier to reuse.
Change-Id: Id7d9adac064b307b04bf6accb83ffd7f217a857c
protected function setUp() {
parent::setUp();
protected function setUp() {
parent::setUp();
+ $context = $this->getContext();
$this->setMwGlobals( 'wgActions', array(
'null' => null,
'dummy' => true,
'string' => 'NamedDummyAction',
'declared' => 'NonExistingClassName',
'callable' => array( $this, 'dummyActionCallback' ),
$this->setMwGlobals( 'wgActions', array(
'null' => null,
'dummy' => true,
'string' => 'NamedDummyAction',
'declared' => 'NonExistingClassName',
'callable' => array( $this, 'dummyActionCallback' ),
- 'object' => new InstantiatedDummyAction( $this->getPage(), $this->getContext() ),
+ 'object' => new InstantiatedDummyAction( $context->getWikiPage(), $context ),
- 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 );
- private function getContext() {
- return new DerivativeContext( RequestContext::getMain() );
}
public function actionProvider() {
}
public function actionProvider() {
array( 'object', 'InstantiatedDummyAction' ),
// Capitalization is ignored
array( 'object', 'InstantiatedDummyAction' ),
// Capitalization is ignored
+ array( 'DUMMY', 'DummyAction' ),
array( 'STRING', 'NamedDummyAction' ),
// Null and non-existing values
array( 'STRING', 'NamedDummyAction' ),
// Null and non-existing values
array( 'undeclared', null ),
array( '', null ),
array( null, null ),
array( 'undeclared', null ),
array( '', null ),
array( null, null ),
public function testActionExists( $requestedAction, $expected ) {
$exists = Action::exists( $requestedAction );
public function testActionExists( $requestedAction, $expected ) {
$exists = Action::exists( $requestedAction );
- $this->assertEquals( isset( $expected ), $exists );
+ $this->assertSame( $expected !== null, $exists );
}
public function testActionExists_doesNotRequireInstantiation() {
}
public function testActionExists_doesNotRequireInstantiation() {
* @param string|null $expected
*/
public function testGetActionName( $requestedAction, $expected ) {
* @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 );
$actionName = Action::getActionName( $context );
- $this->assertEquals( isset( $expected ) ? $expected : 'nosuchaction', $actionName );
+ $this->assertEquals( $expected ?: 'nosuchaction', $actionName );
* @param string|null $expected
*/
public function testActionFactory( $requestedAction, $expected ) {
* @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( isset( $expected ) ? $expected : 'null', $action );
+ $this->assertType( $expected ?: 'null', $action );
}
public function dummyActionCallback() {
}
public function dummyActionCallback() {
- return new CalledDummyAction( $this->getPage(), $this->getContext() );
+ $context = $this->getContext();
+ return new CalledDummyAction( $context->getWikiPage(), $context );