X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiBaseTest.php;h=96f3e44f0f2122c270e510f9015a0ae0d697afba;hb=950b3f960aea995ab7c95b01519866a2a1c923ab;hp=8b75d562816fcb59521effef480be683155e72a6;hpb=75d8b6c6cd2b70d98242e1246678c12e973a5dfa;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiBaseTest.php b/tests/phpunit/includes/api/ApiBaseTest.php index 8b75d56281..96f3e44f0f 100644 --- a/tests/phpunit/includes/api/ApiBaseTest.php +++ b/tests/phpunit/includes/api/ApiBaseTest.php @@ -20,7 +20,7 @@ class ApiBaseTest extends ApiTestCase { } /** - * @expectedException UsageException + * @expectedException ApiUsageException * @covers ApiBase::requireOnlyOneParameter */ public function testRequireOnlyOneParameterZero() { @@ -32,7 +32,7 @@ class ApiBaseTest extends ApiTestCase { } /** - * @expectedException UsageException + * @expectedException ApiUsageException * @covers ApiBase::requireOnlyOneParameter */ public function testRequireOnlyOneParameterTrue() { @@ -58,10 +58,10 @@ class ApiBaseTest extends ApiTestCase { $context->setRequest( new FauxRequest( $input !== null ? [ 'foo' => $input ] : [] ) ); $wrapper->mMainModule = new ApiMain( $context ); - if ( $expected instanceof UsageException ) { + if ( $expected instanceof ApiUsageException ) { try { $wrapper->getParameterFromSettings( 'foo', $paramSettings, true ); - } catch ( UsageException $ex ) { + } catch ( ApiUsageException $ex ) { $this->assertEquals( $expected, $ex ); } } else { @@ -73,9 +73,7 @@ class ApiBaseTest extends ApiTestCase { public static function provideGetParameterFromSettings() { $warnings = [ - 'The value passed for \'foo\' contains invalid or non-normalized data. Textual data should ' . - 'be valid, NFC-normalized Unicode without C0 control characters other than ' . - 'HT (\\t), LF (\\n), and CR (\\r).' + [ 'apiwarn-badutf8', 'foo' ], ]; $c0 = ''; @@ -96,7 +94,7 @@ class ApiBaseTest extends ApiTestCase { 'String param, required, empty' => [ '', [ ApiBase::PARAM_DFLT => 'default', ApiBase::PARAM_REQUIRED => true ], - new UsageException( 'The foo parameter must be set', 'nofoo' ), + ApiUsageException::newWithMessage( null, [ 'apierror-missingparam', 'foo' ] ), [] ], 'Multi-valued parameter' => [ @@ -126,4 +124,48 @@ class ApiBaseTest extends ApiTestCase { ]; } + public function testErrorArrayToStatus() { + $mock = new MockApi(); + + // Sanity check empty array + $expect = Status::newGood(); + $this->assertEquals( $expect, $mock->errorArrayToStatus( [] ) ); + + // No blocked $user, so no special block handling + $expect = Status::newGood(); + $expect->fatal( 'blockedtext' ); + $expect->fatal( 'autoblockedtext' ); + $expect->fatal( 'mainpage' ); + $expect->fatal( 'parentheses', 'foobar' ); + $this->assertEquals( $expect, $mock->errorArrayToStatus( [ + [ 'blockedtext' ], + [ 'autoblockedtext' ], + 'mainpage', + [ 'parentheses', 'foobar' ], + ] ) ); + + // Has a blocked $user, so special block handling + $user = $this->getMutableTestUser()->getUser(); + $block = new \Block( [ + 'address' => $user->getName(), + 'user' => $user->getID(), + 'reason' => __METHOD__, + 'expiry' => time() + 100500, + ] ); + $block->insert(); + $blockinfo = [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $block ) ]; + + $expect = Status::newGood(); + $expect->fatal( ApiMessage::create( 'apierror-blocked', 'blocked', $blockinfo ) ); + $expect->fatal( ApiMessage::create( 'apierror-autoblocked', 'autoblocked', $blockinfo ) ); + $expect->fatal( 'mainpage' ); + $expect->fatal( 'parentheses', 'foobar' ); + $this->assertEquals( $expect, $mock->errorArrayToStatus( [ + [ 'blockedtext' ], + [ 'autoblockedtext' ], + 'mainpage', + [ 'parentheses', 'foobar' ], + ], $user ) ); + } + }