<?php
+use MediaWiki\Block\DatabaseBlock;
+use MediaWiki\MediaWikiServices;
use Wikimedia\TestingAccessWrapper;
/**
'foo',
[ [ 'apiwarn-deprecation-parameter', 'myParam' ] ],
],
+ 'Deprecated parameter with default, unspecified' => [
+ null,
+ [ ApiBase::PARAM_DEPRECATED => true, ApiBase::PARAM_DFLT => 'foo' ],
+ 'foo',
+ [],
+ ],
+ 'Deprecated parameter with default, specified' => [
+ 'foo',
+ [ ApiBase::PARAM_DEPRECATED => true, ApiBase::PARAM_DFLT => 'foo' ],
+ 'foo',
+ [ [ 'apiwarn-deprecation-parameter', 'myParam' ] ],
+ ],
'Deprecated parameter value' => [
'a',
[ ApiBase::PARAM_DEPRECATED_VALUES => [ 'a' => true ] ],
'a',
[ [ 'apiwarn-deprecation-parameter', 'myParam=a' ] ],
],
+ 'Deprecated parameter value as default, unspecified' => [
+ null,
+ [ ApiBase::PARAM_DEPRECATED_VALUES => [ 'a' => true ], ApiBase::PARAM_DFLT => 'a' ],
+ 'a',
+ [],
+ ],
+ 'Deprecated parameter value as default, specified' => [
+ 'a',
+ [ ApiBase::PARAM_DEPRECATED_VALUES => [ 'a' => true ], ApiBase::PARAM_DFLT => 'a' ],
+ 'a',
+ [ [ 'apiwarn-deprecation-parameter', 'myParam=a' ] ],
+ ],
'Multiple deprecated parameter values' => [
'a|b|c|d',
[ ApiBase::PARAM_DEPRECATED_VALUES =>
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => 'namespace',
],
- MWNamespace::getValidNamespaces(),
+ MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces(),
[],
],
// PARAM_ALL is ignored with namespace types.
ApiBase::PARAM_TYPE => 'namespace',
ApiBase::PARAM_ALL => false,
],
- MWNamespace::getValidNamespaces(),
+ MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces(),
[],
],
'Namespace with wildcard "x"' => [
public function testErrorArrayToStatus() {
$mock = new MockApi();
+ $msg = new Message( 'mainpage' );
+
// Sanity check empty array
$expect = Status::newGood();
$this->assertEquals( $expect, $mock->errorArrayToStatus( [] ) );
$expect->fatal( 'autoblockedtext' );
$expect->fatal( 'systemblockedtext' );
$expect->fatal( 'mainpage' );
+ $expect->fatal( $msg );
+ $expect->fatal( $msg, 'foobar' );
$expect->fatal( 'parentheses', 'foobar' );
$this->assertEquals( $expect, $mock->errorArrayToStatus( [
[ 'blockedtext' ],
[ 'autoblockedtext' ],
[ 'systemblockedtext' ],
'mainpage',
+ $msg,
+ [ $msg, 'foobar' ],
[ 'parentheses', 'foobar' ],
] ) );
// Has a blocked $user, so special block handling
$user = $this->getMutableTestUser()->getUser();
- $block = new \Block( [
+ $block = new DatabaseBlock( [
'address' => $user->getName(),
'user' => $user->getID(),
'by' => $this->getTestSysop()->getUser()->getId(),
'expiry' => time() + 100500,
] );
$block->insert();
- $blockinfo = [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ];
+ $userInfoTrait = TestingAccessWrapper::newFromObject(
+ $this->getMockForTrait( ApiBlockInfoTrait::class )
+ );
+ $blockinfo = [ 'blockinfo' => $userInfoTrait->getBlockDetails( $block ) ];
$expect = Status::newGood();
$expect->fatal( ApiMessage::create( 'apierror-blocked', 'blocked', $blockinfo ) );
$expect->fatal( ApiMessage::create( 'apierror-autoblocked', 'autoblocked', $blockinfo ) );
$expect->fatal( ApiMessage::create( 'apierror-systemblocked', 'blocked', $blockinfo ) );
$expect->fatal( 'mainpage' );
+ $expect->fatal( $msg );
+ $expect->fatal( $msg, 'foobar' );
$expect->fatal( 'parentheses', 'foobar' );
$this->assertEquals( $expect, $mock->errorArrayToStatus( [
[ 'blockedtext' ],
[ 'autoblockedtext' ],
[ 'systemblockedtext' ],
'mainpage',
+ $msg,
+ [ $msg, 'foobar' ],
[ 'parentheses', 'foobar' ],
], $user ) );
}
+ public function testAddBlockInfoToStatus() {
+ $mock = new MockApi();
+
+ $msg = new Message( 'mainpage' );
+
+ // Sanity check empty array
+ $expect = Status::newGood();
+ $test = Status::newGood();
+ $mock->addBlockInfoToStatus( $test );
+ $this->assertEquals( $expect, $test );
+
+ // No blocked $user, so no special block handling
+ $expect = Status::newGood();
+ $expect->fatal( 'blockedtext' );
+ $expect->fatal( 'autoblockedtext' );
+ $expect->fatal( 'systemblockedtext' );
+ $expect->fatal( 'mainpage' );
+ $expect->fatal( $msg );
+ $expect->fatal( $msg, 'foobar' );
+ $expect->fatal( 'parentheses', 'foobar' );
+ $test = clone $expect;
+ $mock->addBlockInfoToStatus( $test );
+ $this->assertEquals( $expect, $test );
+
+ // Has a blocked $user, so special block handling
+ $user = $this->getMutableTestUser()->getUser();
+ $block = new DatabaseBlock( [
+ 'address' => $user->getName(),
+ 'user' => $user->getID(),
+ 'by' => $this->getTestSysop()->getUser()->getId(),
+ 'reason' => __METHOD__,
+ 'expiry' => time() + 100500,
+ ] );
+ $block->insert();
+ $userInfoTrait = TestingAccessWrapper::newFromObject(
+ $this->getObjectForTrait( ApiBlockInfoTrait::class )
+ );
+ $blockinfo = [ 'blockinfo' => $userInfoTrait->getBlockDetails( $block ) ];
+
+ $expect = Status::newGood();
+ $expect->fatal( ApiMessage::create( 'apierror-blocked', 'blocked', $blockinfo ) );
+ $expect->fatal( ApiMessage::create( 'apierror-autoblocked', 'autoblocked', $blockinfo ) );
+ $expect->fatal( ApiMessage::create( 'apierror-systemblocked', 'blocked', $blockinfo ) );
+ $expect->fatal( 'mainpage' );
+ $expect->fatal( $msg );
+ $expect->fatal( $msg, 'foobar' );
+ $expect->fatal( 'parentheses', 'foobar' );
+ $test = Status::newGood();
+ $test->fatal( 'blockedtext' );
+ $test->fatal( 'autoblockedtext' );
+ $test->fatal( 'systemblockedtext' );
+ $test->fatal( 'mainpage' );
+ $test->fatal( $msg );
+ $test->fatal( $msg, 'foobar' );
+ $test->fatal( 'parentheses', 'foobar' );
+ $mock->addBlockInfoToStatus( $test, $user );
+ $this->assertEquals( $expect, $test );
+ }
+
public function testDieStatus() {
$mock = new MockApi();
}
$status = StatusValue::newGood();
- $status->setOk( false );
+ $status->setOK( false );
try {
$mock->dieStatus( $status );
$this->fail( 'Expected exception not thrown' );