X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Funit%2Fincludes%2Fobjectcache%2FRESTBagOStuffTest.php;h=689ac21df07440408b912c9ceb5079589310e90c;hp=459e3eebc258d7606980f8b9301a3c759fbe0d4c;hb=4bfbf2c225d7f45aff167613f35d7d9153abe252;hpb=d60849c5de08db4cf027325f17f1a3705e106b5d;ds=sidebyside diff --git a/tests/phpunit/unit/includes/objectcache/RESTBagOStuffTest.php b/tests/phpunit/unit/includes/objectcache/RESTBagOStuffTest.php index 459e3eebc2..689ac21df0 100644 --- a/tests/phpunit/unit/includes/objectcache/RESTBagOStuffTest.php +++ b/tests/phpunit/unit/includes/objectcache/RESTBagOStuffTest.php @@ -25,17 +25,41 @@ class RESTBagOStuffTest extends \MediaWikiUnitTestCase { $this->bag = new RESTBagOStuff( [ 'client' => $this->client, 'url' => 'http://test/rest/' ] ); } - public function testGet() { + /** + * @dataProvider dataGet + */ + public function testGet( $serializationType, $hmacKey, $data ) { + $classReflect = new ReflectionClass( RESTBagOStuff::class ); + + $serializationTypeReflect = $classReflect->getProperty( 'serializationType' ); + $serializationTypeReflect->setAccessible( true ); + $serializationTypeReflect->setValue( $this->bag, $serializationType ); + + $hmacKeyReflect = $classReflect->getProperty( 'hmacKey' ); + $hmacKeyReflect->setAccessible( true ); + $hmacKeyReflect->setValue( $this->bag, $hmacKey ); + $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 ] ); + ] )->willReturn( [ 200, 'OK', [], $data, 0 ] ); $result = $this->bag->get( '42xyz42' ); $this->assertEquals( 'somedata', $result ); } + public static function dataGet() { + // Make sure the defaults are last, so the $bag is left as expected for the next test + return [ + [ 'JSON', '12345', 'JSON.Us1wli82zEJ6DNQnCG//w+MShOFrdx9wCdfTUhPPA2w=."somedata"' ], + [ 'JSON', '', 'JSON.."somedata"' ], + [ 'PHP', '12345', 'PHP.t2EKhUF4l65kZqWhoAnKW8ZPzekDYfrDxTkQcVmGsuM=.s:8:"somedata";' ], + [ 'PHP', '', 'PHP..s:8:"somedata";' ], + [ 'legacy', '', 's:8:"somedata";' ], + ]; + } + public function testGetNotExist() { $this->client->expects( $this->once() )->method( 'run' )->with( [ 'method' => 'GET', @@ -71,18 +95,42 @@ class RESTBagOStuffTest extends \MediaWikiUnitTestCase { $this->assertEquals( BagOStuff::ERR_UNEXPECTED, $this->bag->getLastError() ); } - public function testPut() { + /** + * @dataProvider dataPut + */ + public function testPut( $serializationType, $hmacKey, $data ) { + $classReflect = new ReflectionClass( RESTBagOStuff::class ); + + $serializationTypeReflect = $classReflect->getProperty( 'serializationType' ); + $serializationTypeReflect->setAccessible( true ); + $serializationTypeReflect->setValue( $this->bag, $serializationType ); + + $hmacKeyReflect = $classReflect->getProperty( 'hmacKey' ); + $hmacKeyReflect->setAccessible( true ); + $hmacKeyReflect->setValue( $this->bag, $hmacKey ); + $this->client->expects( $this->once() )->method( 'run' )->with( [ 'method' => 'PUT', 'url' => 'http://test/rest/42xyz42', - 'body' => '"postdata"', + 'body' => $data, 'headers' => [] // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) ] )->willReturn( [ 200, 'OK', [], 'Done', 0 ] ); - $result = $this->bag->set( '42xyz42', 'postdata' ); + $result = $this->bag->set( '42xyz42', 'somedata' ); $this->assertTrue( $result ); } + public static function dataPut() { + // Make sure the defaults are last, so the $bag is left as expected for the next test + return [ + [ 'JSON', '12345', 'JSON.Us1wli82zEJ6DNQnCG//w+MShOFrdx9wCdfTUhPPA2w=."somedata"' ], + [ 'JSON', '', 'JSON.."somedata"' ], + [ 'PHP', '12345', 'PHP.t2EKhUF4l65kZqWhoAnKW8ZPzekDYfrDxTkQcVmGsuM=.s:8:"somedata";' ], + [ 'PHP', '', 'PHP..s:8:"somedata";' ], + [ 'legacy', '', 's:8:"somedata";' ], + ]; + } + public function testDelete() { $this->client->expects( $this->once() )->method( 'run' )->with( [ 'method' => 'DELETE',