wiki.techinc.nl/tests/phpunit/includes/objectcache/RESTBagOStuffTest.php
Bill Pirkle bf2d6d7240 Add additional configuation parameters to RESTBagOStuff
Class RESTBagOStuff is needed for the Kask session storage
service. Add additional configuration parameters so that
they will work together.

Bug: T215533
Change-Id: Ifbb9f8847bd10d65cc5e24f4aa6cb20cb71de3ca
2019-05-21 08:07:44 -05:00

96 lines
2.9 KiB
PHP

<?php
/**
* @group BagOStuff
*
* @covers RESTBagOStuff
*/
class RESTBagOStuffTest extends MediaWikiTestCase {
/**
* @var MultiHttpClient
*/
private $client;
/**
* @var RESTBagOStuff
*/
private $bag;
public function setUp() {
parent::setUp();
$this->client =
$this->getMockBuilder( MultiHttpClient::class )
->setConstructorArgs( [ [] ] )
->setMethods( [ 'run' ] )
->getMock();
$this->bag = new RESTBagOStuff( [ 'client' => $this->client, 'url' => 'http://test/rest/' ] );
}
public function testGet() {
$this->client->expects( $this->once() )->method( 'run' )->with( [
'method' => 'GET',
'url' => 'http://test/rest/42xyz42',
'headers' => []
// list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
] )->willReturn( [ 200, 'OK', [], '"somedata"', 0 ] );
$result = $this->bag->get( '42xyz42' );
$this->assertEquals( 'somedata', $result );
}
public function testGetNotExist() {
$this->client->expects( $this->once() )->method( 'run' )->with( [
'method' => 'GET',
'url' => 'http://test/rest/42xyz42',
'headers' => []
// list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
] )->willReturn( [ 404, 'Not found', [], 'Nothing to see here', 0 ] );
$result = $this->bag->get( '42xyz42' );
$this->assertFalse( $result );
}
public function testGetBadClient() {
$this->client->expects( $this->once() )->method( 'run' )->with( [
'method' => 'GET',
'url' => 'http://test/rest/42xyz42',
'headers' => []
// list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
] )->willReturn( [ 0, '', [], '', 'cURL has failed you today' ] );
$result = $this->bag->get( '42xyz42' );
$this->assertFalse( $result );
$this->assertEquals( BagOStuff::ERR_UNREACHABLE, $this->bag->getLastError() );
}
public function testGetBadServer() {
$this->client->expects( $this->once() )->method( 'run' )->with( [
'method' => 'GET',
'url' => 'http://test/rest/42xyz42',
'headers' => []
// list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
] )->willReturn( [ 500, 'Too busy', [], 'Server is too busy', '' ] );
$result = $this->bag->get( '42xyz42' );
$this->assertFalse( $result );
$this->assertEquals( BagOStuff::ERR_UNEXPECTED, $this->bag->getLastError() );
}
public function testPut() {
$this->client->expects( $this->once() )->method( 'run' )->with( [
'method' => 'PUT',
'url' => 'http://test/rest/42xyz42',
'body' => '"postdata"',
'headers' => []
// list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
] )->willReturn( [ 200, 'OK', [], 'Done', 0 ] );
$result = $this->bag->set( '42xyz42', 'postdata' );
$this->assertTrue( $result );
}
public function testDelete() {
$this->client->expects( $this->once() )->method( 'run' )->with( [
'method' => 'DELETE',
'url' => 'http://test/rest/42xyz42',
'headers' => []
// list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
] )->willReturn( [ 200, 'OK', [], 'Done', 0 ] );
$result = $this->bag->delete( '42xyz42' );
$this->assertTrue( $result );
}
}