5 class RESTBagOStuffTest
extends MediaWikiTestCase
{
16 public function setUp() {
19 $this->getMockBuilder( 'MultiHttpClient' )
20 ->setConstructorArgs( [ [] ] )
21 ->setMethods( [ 'run' ] )
23 $this->bag
= new RESTBagOStuff( [ 'client' => $this->client
, 'url' => 'http://test/rest/' ] );
26 public function testGet() {
27 $this->client
->expects( $this->once() )->method( 'run' )->with( [
29 'url' => 'http://test/rest/42xyz42'
30 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
31 ] )->willReturn( [ 200, 'OK', [], 's:8:"somedata";', 0 ] );
32 $result = $this->bag
->get( '42xyz42' );
33 $this->assertEquals( 'somedata', $result );
36 public function testGetNotExist() {
37 $this->client
->expects( $this->once() )->method( 'run' )->with( [
39 'url' => 'http://test/rest/42xyz42'
40 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
41 ] )->willReturn( [ 404, 'Not found', [], 'Nothing to see here', 0 ] );
42 $result = $this->bag
->get( '42xyz42' );
43 $this->assertFalse( $result );
46 public function testGetBadClient() {
47 $this->client
->expects( $this->once() )->method( 'run' )->with( [
49 'url' => 'http://test/rest/42xyz42'
50 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
51 ] )->willReturn( [ 0, '', [], '', 'cURL has failed you today' ] );
52 $result = $this->bag
->get( '42xyz42' );
53 $this->assertFalse( $result );
54 $this->assertEquals( BagOStuff
::ERR_UNREACHABLE
, $this->bag
->getLastError() );
57 public function testGetBadServer() {
58 $this->client
->expects( $this->once() )->method( 'run' )->with( [
60 'url' => 'http://test/rest/42xyz42'
61 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
62 ] )->willReturn( [ 500, 'Too busy', [], 'Server is too busy', '' ] );
63 $result = $this->bag
->get( '42xyz42' );
64 $this->assertFalse( $result );
65 $this->assertEquals( BagOStuff
::ERR_UNEXPECTED
, $this->bag
->getLastError() );
68 public function testPut() {
69 $this->client
->expects( $this->once() )->method( 'run' )->with( [
71 'url' => 'http://test/rest/42xyz42',
72 'body' => 's:8:"postdata";'
73 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
74 ] )->willReturn( [ 200, 'OK', [], 'Done', 0 ] );
75 $result = $this->bag
->set( '42xyz42', 'postdata' );
76 $this->assertTrue( $result );
79 public function testDelete() {
80 $this->client
->expects( $this->once() )->method( 'run' )->with( [
82 'url' => 'http://test/rest/42xyz42',
83 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
84 ] )->willReturn( [ 200, 'OK', [], 'Done', 0 ] );
85 $result = $this->bag
->delete( '42xyz42' );
86 $this->assertTrue( $result );