X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiBaseTest.php;h=3f6cac9a00af64188bb589731fb79ee5cd12df52;hb=767042c3e68adb29513;hp=96f3e44f0f2122c270e510f9015a0ae0d697afba;hpb=ce079cf6ad79ca8d3360817f809b219d166f9153;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiBaseTest.php b/tests/phpunit/includes/api/ApiBaseTest.php index 96f3e44f0f..3f6cac9a00 100644 --- a/tests/phpunit/includes/api/ApiBaseTest.php +++ b/tests/phpunit/includes/api/ApiBaseTest.php @@ -1,5 +1,7 @@ fatal( 'blockedtext' ); $expect->fatal( 'autoblockedtext' ); + $expect->fatal( 'systemblockedtext' ); $expect->fatal( 'mainpage' ); $expect->fatal( 'parentheses', 'foobar' ); $this->assertEquals( $expect, $mock->errorArrayToStatus( [ [ 'blockedtext' ], [ 'autoblockedtext' ], + [ 'systemblockedtext' ], 'mainpage', [ 'parentheses', 'foobar' ], ] ) ); @@ -149,6 +157,7 @@ class ApiBaseTest extends ApiTestCase { $block = new \Block( [ 'address' => $user->getName(), 'user' => $user->getID(), + 'by' => $this->getTestSysop()->getUser()->getId(), 'reason' => __METHOD__, 'expiry' => time() + 100500, ] ); @@ -158,14 +167,55 @@ class ApiBaseTest extends ApiTestCase { $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( 'parentheses', 'foobar' ); $this->assertEquals( $expect, $mock->errorArrayToStatus( [ [ 'blockedtext' ], [ 'autoblockedtext' ], + [ 'systemblockedtext' ], 'mainpage', [ 'parentheses', 'foobar' ], ], $user ) ); } + /** + * @covers ApiBase::dieStatus + */ + public function testDieStatus() { + $mock = new MockApi(); + + $status = StatusValue::newGood(); + $status->error( 'foo' ); + $status->warning( 'bar' ); + try { + $mock->dieStatus( $status ); + $this->fail( 'Expected exception not thrown' ); + } catch ( ApiUsageException $ex ) { + $this->assertTrue( ApiTestCase::apiExceptionHasCode( $ex, 'foo' ), 'Exception has "foo"' ); + $this->assertFalse( ApiTestCase::apiExceptionHasCode( $ex, 'bar' ), 'Exception has "bar"' ); + } + + $status = StatusValue::newGood(); + $status->warning( 'foo' ); + $status->warning( 'bar' ); + try { + $mock->dieStatus( $status ); + $this->fail( 'Expected exception not thrown' ); + } catch ( ApiUsageException $ex ) { + $this->assertTrue( ApiTestCase::apiExceptionHasCode( $ex, 'foo' ), 'Exception has "foo"' ); + $this->assertTrue( ApiTestCase::apiExceptionHasCode( $ex, 'bar' ), 'Exception has "bar"' ); + } + + $status = StatusValue::newGood(); + $status->setOk( false ); + try { + $mock->dieStatus( $status ); + $this->fail( 'Expected exception not thrown' ); + } catch ( ApiUsageException $ex ) { + $this->assertTrue( ApiTestCase::apiExceptionHasCode( $ex, 'unknownerror-nocode' ), + 'Exception has "unknownerror-nocode"' ); + } + } + }