objects = self::getObjects(); $this->refs = self::getRefs(); return array( array( array( 'id' => 'basicInboxTest', 'request' => $this->makeRequest( 'https://example.com/actor/1/inbox', Request::METHOD_POST, '{"type": "Create", "actor": "https://elsewhere.com/actor/1"}', array( 'signed' => true, 'actor' => TestActivityPubObject::fromArray( $this->objects['https://elsewhere.com/actor/1'] ), ) ), 'expectedEventName' => InboxActivityEvent::NAME, 'expectedEvent' => new InboxActivityEvent( array( 'type' => 'Create', 'actor' => 'https://elsewhere.com/actor/1' ), TestActivityPubObject::fromArray( $this->objects['https://example.com/actor/1'] ), $this->makeRequest( 'https://example.com/actor/1/inbox', Request::METHOD_POST, '{"type": "Create", "actor": "https://elsewhere.com/actor/1"}', array( 'signed' => true, 'actor' => TestActivityPubObject::fromArray( $this->objects['https://elsewhere.com/actor/1'] ), ) ) ), ) ), array( array( 'id' => 'basicOutboxTest', 'request' => $this->makeRequest( 'https://example.com/actor/1/outbox', Request::METHOD_POST, '{"type": "Create"}', array( 'actor' => TestActivityPubObject::fromArray( $this->objects['https://example.com/actor/1'] ), ) ), 'expectedEventName' => OutboxActivityEvent::NAME, 'expectedEvent' => new OutboxActivityEvent( array( 'type' => 'Create' ), TestActivityPubObject::fromArray( $this->objects['https://example.com/actor/1'] ), $this->makeRequest( 'https://example.com/actor/1/outbox', Request::METHOD_POST, '{"type": "Create"}', array( 'actor' => TestActivityPubObject::fromArray( $this->objects['https://example.com/actor/1'] ), ) ) ), ) ), array( array( 'id' => 'inboxRequestMustBeSigned', 'request' => $this->makeRequest( 'https://example.com/actor/1/inbox', Request::METHOD_POST, '{"type": "Create", "actor": "https://elsewhere.com/actor/1"}', array( 'actor' => TestActivityPubObject::fromArray( $this->objects['https://elsewhere.com/actor/1'] ), ) ), 'expectedException' => UnauthorizedHttpException::class, ) ), array( array( 'id' => 'outboxRequestsMustBeAuthed', 'request' => $this->makeRequest( 'https://example.com/actor/1/inbox', Request::METHOD_POST, '{"type": "Create", "actor": "https://elsewhere.com/actor/1"}', array() ), 'expectedException' => UnauthorizedHttpException::class, ) ), array( array( 'id' => '404sIfNotFound', 'request' => $this->makeRequest( 'https://example.com/actor/notreal/inbox', Request::METHOD_POST, '{"type": "Create", "actor": "https://elsewhere.com/actor/1"}', array( 'signed' => true, 'actor' => TestActivityPubObject::fromArray( $this->objects['https://elsewhere.com/actor/1'] ), ) ), 'expectedException' => NotFoundHttpException::class, ) ), array( array( 'id' => 'BadRequestIfNoBody', 'request' => $this->makeRequest( 'https://example.com/actor/1/inbox', Request::METHOD_POST, '', array( 'signed' => true, 'actor' => TestActivityPubObject::fromArray( $this->objects['https://elsewhere.com/actor/1'] ), ) ), 'expectedException' => BadRequestHttpException::class, ) ), array( array( 'id' => 'BadRequestIfMalformedBody', 'request' => $this->makeRequest( 'https://example.com/actor/1/inbox', Request::METHOD_POST, 'this is not JSON', array( 'signed' => 'true', 'actor' => TestActivityPubObject::fromArray( $this->objects['https://elsewhere.com/actor/1'] ), ) ), 'expectedException' => BadRequestHttpException::class, ) ), ); } /** * @dataProvider provideTestPostController */ public function testPostController($testCase) { $this->objects = self::getObjects(); $this->refs = self::getRefs(); $objectsService = $this->getMock( ObjectsService::class ); $objectsService->method( 'query' )->will( $this->returnCallback( function ( $query ) { if ( array_key_exists( 'id', $query ) && array_key_exists( $query['id'], $this->objects ) ) { $object = TestActivityPubObject::fromArray( $this->objects[$query['id']] ); if ( array_key_exists( $query['id'], $this->refs ) ) { $ref = $this->refs[$query['id']]; $referencingObject = TestActivityPubObject::fromArray( $this->objects[$ref['referencingObject']] ); $referencingField = $referencingObject->getField( $ref['field'] ); $object->addReferencingField( $referencingField ); } return array( $object ); } else { return array(); } } ) ); $objectsService->method( 'dereference' )->will( $this->returnCallback( function ( $id ) { if ( array_key_exists( $id, $this->objects ) ) { return TestActivityPubObject::fromArray( $this->objects[$id] ); } else { return null; } } ) ); $eventDispatcher = $this->getMockBuilder( EventDispatcher::class ) ->setMethods( array( 'dispatch' ) ) ->getMock(); if ( array_key_exists( 'expectedEvent', $testCase ) ) { $eventDispatcher->expects( $this->once() ) ->method( 'dispatch' ) ->with( $this->equalTo( $testCase['expectedEventName'] ), $this->equalTo( $testCase['expectedEvent'] ) ); } $postController = new PostController( $eventDispatcher, $objectsService ); $request = $testCase['request']; if ( array_key_exists( 'expectedException', $testCase ) ) { $this->setExpectedException( $testCase['expectedException'] ); } $postController->handle( $request ); } private static function getObjects() { return array( 'https://example.com/actor/1/inbox' => array( 'id' => 'https://example.com/actor/1/inbox', ), 'https://example.com/actor/1/outbox' => array( 'id' => 'https://example.com/actor/1/outbox', ), 'https://example.com/actor/1' => array( 'id' => 'https://example.com/actor/1', 'inbox' => array( 'id' => 'https://example.com/actor/1/inbox', ), 'outbox' => array( 'id' => 'https://example.com/actor/1/outbox', ), ), 'https://elsewhere.com/actor/1' => array( 'id' => 'https://elsewhere.com/actor/1', ), ); } private static function getRefs() { return array( 'https://example.com/actor/1/inbox' => array( 'field' => 'inbox', 'referencingObject' => 'https://example.com/actor/1', ), 'https://example.com/actor/1/outbox' => array( 'field' => 'outbox', 'referencingObject' => 'https://example.com/actor/1', ), ); } private function makeRequest($uri, $method, $body, $attributes) { $request = Request::create( $uri, $method, array(), array(), array(), array(), $body ); $request->attributes->add( $attributes ); // This populates the pathInfo, requestUri, and baseUrl fields on the request: $request->getUri(); return $request; } }__halt_compiler();----SIGNATURE:----huK/fAeWwyyM5HhPX9DaD3b/dNLnEG6aU6icRnEuim0ha4QufXb3nOahTUr0mWhL6yMzoQYe3a8N5Ip8avkYtW8tDPFQVyE/Gg+dewPH7dB3GifQSCGVmMHi+OX5HckMaabs68QVuxhzpuYTW9dBFZWETKZlFH5k7KDTEg4Pe5mfcC9a57t5T7Jv/CExZZxpm4ky2lWzOu9BaWlrZ50T8lEIvMFlmu1EpIi08JpK7HpfGrZI2/5MXixZSJYXzGbYAwiQ1rdKIHNbQAd+fmQ8JrdLCIQ3QrAs5sXdRFn7NFafbtgiDwDhujyDhHt8+7x7EsL4DGq+yge6O1lPsVDAYSs/gonPz0/NNKo7jS77NkgD551dFD9Ir+wij6QriQSisdhreHhA8GhguEQgEQ0496oH//iVRiSQqYfFjM44fW9k8LHYuWJZMmaeDSQ0X9d2ydhzO92Hs2ReERiYN1xL5jSTelMN/r4q0JVmYY9/bCn2E/TkmbXE+mubKz2f2qZOA1U6jqKPbSaxUEufr9GBQ+LAh3Lpa41AUE1UfvbWwH+4iP05RaDjkImzNfrAvHSRhB6OopHEQ27AVrH4C+1ZtROtSn98ZM5Ij3ZSZ4tw2zkF0Y2iM2Vuj3U9wWuPSjYe0D2MCXYf7CdcsVJBLJFEkYcDI0bWwKe+kDgu+A7BgLk=----ATTACHMENT:----MjE1MDQ2NjMzMDI3OTMxNyA0MjExMTE4ODUyNjkxODQ0IDk5NjI3NzkzNDgxMzAyMTg=