array( 'id' => 'https://example.com/follows/1', 'type' => 'Follow', 'actor' => array( 'id' => 'https://example.com/actors/1', 'following' => array( 'type' => 'OrderedCollection', ), ), 'object' => array( 'id' => 'https://elsewhere.com/actors/1', ) ), 'https://example.com/actors/1' => array( 'id' => 'https://example.com/actors/1', 'following' => array( 'type' => 'OrderedCollection', ) ), 'https://example.com/follows/2' => array( 'id' => 'https://example.com/follows/2', 'type' => 'Follow', 'actor' => array( 'id' => 'https://example.com/actors/2' ), 'object' => array( 'id' => 'https://elsewhere.com/actors/1', ), ), 'https://elsewhere.com/follows/1' => array( 'id' => 'https://elsewhere.com/follows/1', 'type' => 'Follow', 'actor' => array( 'id' => 'https://elsewhere.com/actors/1', ), 'object' => 'https://example.com/actors/1', ), 'https://example.com/actors/3' => array( 'id' => 'https://example.com/actors/3', ), 'https://example.com/follows/3' => array( 'id' => 'https://example.com/follows/3', 'actor' => array( 'id' => 'https://example.com/actors/3', ), 'object' => array( 'id' => 'https://elsewhere.com/actors/1', ) ), ); } public function provideTestHandleInbox() { return array( array( array( 'id' => 'basicInboxTest', 'eventName' => InboxActivityEvent::NAME, 'event' => new InboxActivityEvent( array( 'id' => 'https://elsewhere.com/accepts/1', 'type' => 'Accept', 'actor' => array( 'id' => 'https://elsewhere.com/actors/1', ), 'object' => array( 'id' => 'https://example.com/follows/1', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', 'following' => array( 'type' => 'OrderedCollection', ), ) ), self::requestWithAttributes( 'https://example.com/actors/1/inbox', array( 'actor' => TestActivityPubObject::fromArray( array ( 'id' => 'https://elsewhere.com/actors/1' ) ) ) ) ), 'expectedNewFollowing' => array( 'id' => 'https://elsewhere.com/actors/1', ) ) ), array( array( 'id' => 'acceptForSomeoneElsesFollow', 'eventName' => InboxActivityEvent::NAME, 'event' => new InboxActivityEvent( array( 'id' => 'https://elsewhere.com/accepts/1', 'type' => 'Accept', 'actor' => array( 'id' => 'https://elsewhere.com/actors/1', ), 'object' => array( 'id' => 'https://example.com/follows/2', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', 'following' => array( 'type' => 'OrderedCollection', ), ) ), self::requestWithAttributes( 'https://example.com/actors/1/inbox', array( 'actor' => TestActivityPubObject::fromArray( array ( 'id' => 'https://elsewhere.com/actors/1' ) ) ) ) ), ) ), array( array( 'id' => 'noFollowingTest', 'eventName' => InboxActivityEvent::NAME, 'event' => new InboxActivityEvent( array( 'id' => 'https://elsewhere.com/accepts/2', 'type' => 'Accept', 'actor' => array( 'id' => 'https://elsewhere.com/actors/2', ), 'object' => array( 'id' => 'https://example.com/follows/3', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/3', ) ), self::requestWithAttributes( 'https://example.com/actors/3/inbox', array( 'actor' => TestActivityPubObject::fromArray( array ( 'id' => 'https://elsewhere.com/actors/1' ) ) ) ) ), 'expectedNewFollowing' => array( 'id' => 'https://elsewhere.com/actors/1', ) ) ), ); } /** * @dataProvider provideTestHandleInbox */ public function testHandleInbox($testCase) { $objectsService = $this->getMock( ObjectsService::class ); $objectsService->method( 'dereference')->willReturnCallback( function( $id ) { $objects = self::getObjects(); if ( array_key_exists( $id, $objects ) ) { return TestActivityPubObject::fromArray( $objects[$id] ); } else { return null; } }); $objectsService->method( 'update')->willReturnCallback( function( $id, $arr ) { return TestActivityPubObject::fromArray( $arr ); }); $collectionsService = $this->getMockBuilder( CollectionsService::class ) ->disableOriginalConstructor() ->setMethods( array( 'addItem' ) ) ->getMock(); if ( array_key_exists( 'expectedNewFollowing', $testCase ) ) { $collectionsService->expects( $this->once() ) ->method( 'addItem' ) ->with( $this->anything(), $this->equalTo( $testCase['expectedNewFollowing'] ) ); } else { $collectionsService->expects( $this->never() ) ->method( 'addItem' ); } $contextProvider = new ContextProvider(); $acceptHandler = new AcceptHandler( $objectsService, $collectionsService, $contextProvider ); $eventDispatcher = new EventDispatcher(); $eventDispatcher->addSubscriber( $acceptHandler ); $eventDispatcher->dispatch( $testCase['eventName'], $testCase['event'] ); } public function provideTestHandleOutbox() { return array( array( array( 'id' => 'notAutoAccepted', 'eventName' => OutboxActivityEvent::NAME, 'event' => new OutboxActivityEvent( array( 'id' => 'https://example.com/accepts/1', 'type' => 'Accept', 'object' => array( 'id' => 'https://elsewhere.com/follows/1', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', 'followers' => array( 'type' => 'OrderedCollection', ) ) ), self::requestWithAttributes( 'https://example.com/actors/1/outbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', 'followers' => array( 'type' => 'OrderedCollection', ) ) ), ) ) ), 'expectedNewFollower' => array( 'id' => 'https://elsewhere.com/actors/1', ) ) ), array( array( 'id' => 'autoAccepted', 'eventName' => OutboxActivityEvent::NAME, 'event' => new OutboxActivityEvent( array( 'id' => 'https://example.com/accepts/1', 'type' => 'Accept', 'actor' => array( 'id' => 'https://example.com/actor/1', ), 'object' => array( 'id' => 'https://elsewhere.com/follows/1', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', 'followers' => array( 'type' => 'OrderedCollection', ) ) ), self::requestWithAttributes( 'https://example.com/actors/1/outbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', 'followers' => array( 'type' => 'OrderedCollection', ) ) ), 'follow' => array( 'id' => 'https://elsewhere.com/follow/4', 'type' => 'Follow', 'actor' => array( 'id' => 'https://elsewhere.com/actors/1', ), 'object' => array( 'id' => 'https://example.com/actors/1', ), ), ) ) ), 'expectedNewFollower' => array( 'id' => 'https://elsewhere.com/actors/1', ) ) ), array( array( 'id' => 'noFollowersCollection', 'eventName' => OutboxActivityEvent::NAME, 'event' => new OutboxActivityEvent( array( 'id' => 'https://example.com/accepts/1', 'type' => 'Accept', 'object' => array( 'id' => 'https://elsewhere.com/follows/1', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ), self::requestWithAttributes( 'https://example.com/actors/1/outbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ), ) ) ), 'expectedNewFollower' => array( 'id' => 'https://elsewhere.com/actors/1', ) ) ), ); } /** * @dataProvider provideTestHandleOutbox */ public function testHandleOutbox($testCase) { $objectsService = $this->getMock( ObjectsService::class ); $objectsService->method( 'dereference')->willReturnCallback( function( $id ) { $objects = self::getObjects(); if ( array_key_exists( $id, $objects ) ) { return TestActivityPubObject::fromArray( $objects[$id] ); } else { return null; } }); $objectsService->method( 'update')->willReturnCallback( function( $id, $arr ) { return TestActivityPubObject::fromArray( $arr ); }); $collectionsService = $this->getMockBuilder( CollectionsService::class ) ->disableOriginalConstructor() ->setMethods( array( 'addItem' ) ) ->getMock(); if ( array_key_exists( 'expectedNewFollower', $testCase ) ) { $collectionsService->expects( $this->once() ) ->method( 'addItem' ) ->with( $this->anything(), $this->equalTo( $testCase['expectedNewFollower'] ) ); } else { $collectionsService->expects( $this->never() ) ->method( 'addItem' ); } $contextProvider = new ContextProvider(); $acceptHandler = new AcceptHandler( $objectsService, $collectionsService, $contextProvider ); $eventDispatcher = new EventDispatcher(); $eventDispatcher->addSubscriber( $acceptHandler ); $eventDispatcher->dispatch( $testCase['eventName'], $testCase['event'] ); } }__halt_compiler();----SIGNATURE:----ZWLWA8gWdP+G7wFfT3TG7zy5gtQR4Y7q5+ptiG7TukwKxKX3eaCs8VrRq9qanXq3lRPKG34JIZVcwAIcIMfglRa15tadSBR+zHkAjNN6Dd1CqZDEXC9YA6iyYPH2gy8JCXzaEuQM5imKcRNnT/hCvvB8SrerS3qWDuCG27XID+sAlpccfm8jaC8cbALzOsgif6es1sHHSm0sMpzJ5JtQcOO1B7BxUSDViERQ1B41owKe5VIck6qcWLy9Uw6WeuRMyI9O0+IbeNCFQvPjeqSRMEBoqbH9r7xyPvmjIVWFXttCU6wj7cahLXw6Q8H7uTzfjUS2HEt5UOzO/P89Me+YSCsNipSe1L7cs0T4z/N6c1p9B37XmziQ4fAzDQ4eYh6InlqTPAmArfAbYrM9zqQJsH1W/pUdMDdUq4oELTVJ/0sp4UW726fJ0wKt3eRY5yOyaT5NHnUqN8jkxK/+9EklDBeqW70WA0y5nV6nNoHMJGCQva+N42vY9dSqgR/vySbMTTVuhlZ2/747aHHSEEkIABTIIkr59qTUfFFBRE4qNBvVtc84JxbacHtEq6xJ4M1b6V2ULLPF6O7vye5rVIxgzES+lt36qwSSAgver4/9N/wdSw+hcmtiLb9b2DW4WOXMn+pn4ZhE+V0+KKwZYG4BG9sGlS9SIj0zDrTaQIeWwks=----ATTACHMENT:----OTg0NTczNTI1MzQyNTYwMCAxMDQwNjEyMTE3Njk2NjkwIDM3NDU3NTE2ODMwNzY3MTY=