objects = self::getObjects(); $objectsService = $this->getMock( ObjectsService::class ); $objectsService->method( 'dereference' )->will( $this->returnCallback( function ( $uri ) { if ( array_key_exists( $uri, $this->objects ) ) { return $this->objects[$uri]; } return null; } ) ); $objectsService->method( 'update' )->will( $this->returnCallback( function ( $uri ) { if ( array_key_exists( $uri, $this->objects ) ) { return $this->objects[$uri]; } return null; } ) ); $authService = new AuthService(); $contextProvider = new ContextProvider(); $httpClient = $this->getMock( Client::class ); $collectionsService = new CollectionsService( 4, $authService, $contextProvider, $httpClient, new SimpleDateTimeProvider(), $this->getMock( EntityManager::class ), $objectsService ); $blockService = $this->getMock( BlockService::class ); $blockService->method( 'getBlockedActorIds' )->will( $this->returnValue( array( 'https://elsewhere.com/actors/blocked' ) ) ); $this->getController = new GetController( $objectsService, $collectionsService, $authService, $blockService ); } private static function getObjects() { $actorObject = TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', 'inbox' => array( 'id' => 'https://example.com/actors/1/inbox', 'type' => 'OrderedCollection', 'orderedItems' => array( array( 'id' => 'https://elsewhere.com/objects/1', 'actor' => 'https://elsewhere.com/actors/blocked', ), array( 'id' => 'https://elsewhere.com/objects/2', 'actor' => 'https://elsewhere.com/actors/notblocked', ) ), ), ) ); $inboxObject = $actorObject['inbox']; return array( 'https://example.com/objects/1' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/objects/1', 'object' => array( 'id' => 'https://example.com/objects/2', 'type' => 'Note', ), 'audience' => array( 'https://www.w3.org/ns/activitystreams#Public' ), 'type' => 'Create', ) ), 'https://example.com/objects/2' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/objects/2', 'object' => array( 'id' => 'https://example.com/objects/3', 'type' => 'Note', ), 'to' => array( 'https://example.com/actor/1' ), 'type' => 'Create', 'actor' => array( 'id' => 'https://example.com/actor/2', ), ) ), 'https://example.com/objects/3' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/objects/3', 'object' => array( 'id' => 'https://example.com/objects/2', 'type' => 'Note', ), 'type' => 'Like', 'actor' => array( 'id' => 'https://example.com/actor/2', ), ) ), 'https://example.com/objects/4' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/objects/4', 'type' => 'Tombstone', ) ), 'https://example.com/actors/1' => $actorObject, 'https://example.com/actors/1/inbox' => $inboxObject, ); } private function getObjectArray($id) { $obj = $this->objects[$id]; return $obj->asArray(); } public function testItRendersPersistedObject() { $request = Request::create( 'https://example.com/objects/1' ); $response = $this->getController->handle( $request ); $this->assertNotNull( $response ); $this->assertEquals( json_encode( $this->getObjectArray('https://example.com/objects/1' ) ), $response->getContent() ); $this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) ); } public function testItThrowsNotFound() { $request = Request::create( 'https://example.com/objects/notreal' ); $this->setExpectedException( NotFoundHttpException::class ); $this->getController->handle( $request ); } public function testItDeniesAccess() { $request = Request::create( 'https://example.com/objects/2' ); $this->setExpectedException( UnauthorizedHttpException::class ); $this->getController->handle( $request ); } public function testItAllowsAccessToAuthedActor() { $request = Request::create( 'https://example.com/objects/2' ); $request->attributes->set( 'actor', 'https://example.com/actor/1' ); $response = $this->getController->handle( $request ); $this->assertNotNull( $response ); $this->assertEquals( json_encode( $this->getObjectArray( 'https://example.com/objects/2' ) ), $response->getContent() ); $this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) ); } public function testItAllowsAccessToAttributedActor() { $request = Request::create( 'https://example.com/objects/2' ); $request->attributes->set( 'actor', 'https://example.com/actor/2' ); $response = $this->getController->handle( $request ); $this->assertNotNull( $response ); $this->assertEquals( json_encode( $this->getObjectArray( 'https://example.com/objects/2' ) ), $response->getContent() ); $this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) ); } public function testItAllowsAccessToNoAudienceObject() { $request = Request::create( 'https://example.com/objects/3' ); $response = $this->getController->handle( $request ); $this->assertNotNull( $response ); $this->assertEquals( json_encode( $this->getObjectArray( 'https://example.com/objects/3' ) ), $response->getContent() ); $this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) ); } public function testItDisregardsQueryParams() { $request = Request::create( 'https://example.com/objects/1?foo=bar&baz=qux' ); $response = $this->getController->handle( $request ); $this->assertNotNull( $response ); $this->assertEquals( json_encode( $this->getObjectArray( 'https://example.com/objects/1' ) ), $response->getContent() ); $this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) ); } public function testItReturns410ForTombstones() { $request = Request::create( 'https://example.com/objects/4' ); $response = $this->getController->handle( $request ); $this->assertNotNull( $response ); $this->assertEquals( json_encode( $this->getObjectArray( 'https://example.com/objects/4' ) ), $response->getContent() ); $this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) ); $this->assertEquals( 410, $response->getStatusCode() ); } public function testItFiltersInboxForBlockedActors() { $request = Request::create( 'https://example.com/actors/1/inbox' ); $response = $this->getController->handle( $request ); $this->assertNotNull( $response ); $this->assertEquals( json_encode( array( 'id' => 'https://example.com/actors/1/inbox', 'type' => 'OrderedCollection', 'first' => array( '@context' => array( 'https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', ), 'id' => 'https://example.com/actors/1/inbox?offset=0&sort=desc', 'type' => 'OrderedCollectionPage', 'orderedItems' => array( array( 'id' => 'https://elsewhere.com/objects/2', 'actor' => 'https://elsewhere.com/actors/notblocked', ), ), 'partOf' => 'https://example.com/actors/1/inbox', 'startIndex' => 0, ), ) ), $response->getContent() ); $this->assertEquals( 'application/json', $response->headers->get( 'Content-Type' ) ); } }__halt_compiler();----SIGNATURE:----CxtAjST3Y9y0n/f8Sh/c2L+Pxw0Fxaj/lXYvUkHEpkdzAcixYL3Vae+iVR/EppQECvS5NkZixO66sooPKWqkRcdWbG+O2/ueJAm25/QhDb7YWhOwNNhQwTfCV5iTenjHV0B5bYyIno/RCjSiLGv6SB61no1W3u2py1aBI0QYJeSVNLxeGqdFQreqzwDuPEnpeD70c5iMKc0+p4/zIwWPQ/447gqwu4o8dxcfu8bn6e1fDOECr+9pv9B+DMIYwqtxT6cNPOgvQ4MCQ8QTpn42NeksU/ktaZ1TBkqC9A8HUFImcdqa+2Rj2mScrsVGIfjE4Br0FGPtk5lNPjt5fM7EVRmsjd7zFBOYXcQTsUjjHTHSytSSrMosY/yGBO9vIUS2OB27GdQcMNRGa4B1zhiE9S/paMsgrouVwcuCpEmFk+tifIOyz+ohusfWZSlIz8G8rFVfgPb0T+tfxlLEKSrzTdVxd94t/W+LoaG6FFXdWp1guzq1rf/9QcHIhDLFNrnqTYc7QplFI98Q9biRAHyPg14iVyBVxXiC3yQDukcN3Rz8K1UrZwy8blfqBVMUCwnhC40VxPF4wghMSF4goWQ/rtHgN6bL2dpy74H9KtbgLCZuuIYZa3TyBzqIcHpKn3lw0rv+qOZtcysI98F6+MG7JZk+MW7qC0Ge8Faf31/rT2s=----ATTACHMENT:----MTU4NTg5ODE5NDk5OTE2NCAyMzEzODYyNDU4OTg1MzcyIDY1MzgxOTc3NjM5MjYxMjU=