X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiBaseTest.php;h=3f6cac9a00af64188bb589731fb79ee5cd12df52;hb=767042c3e68adb29513;hp=7327e8547163f51cbda2f9f59cbfe482f24c899c;hpb=4c1639f33a1ae9e0d1a072127b248ca83e8381f5;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiBaseTest.php b/tests/phpunit/includes/api/ApiBaseTest.php index 7327e85471..3f6cac9a00 100644 --- a/tests/phpunit/includes/api/ApiBaseTest.php +++ b/tests/phpunit/includes/api/ApiBaseTest.php @@ -1,5 +1,7 @@ $user->getName(), 'user' => $user->getID(), + 'by' => $this->getTestSysop()->getUser()->getId(), 'reason' => __METHOD__, 'expiry' => time() + 100500, ] ); @@ -172,4 +179,43 @@ class ApiBaseTest extends ApiTestCase { ], $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"' ); + } + } + }