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:----mCEM4EJf4uQ+AtwzCTLXK5k+3fSMS7c8oQf3bX/A1XkkaiL8qFcEvkVaSTan8fVshc9NuhCeaStwWB+1lJz+EfCktI1t+b3c7hYF2+e0Y8kgo7RSJIh9V0gD+EKvu0hCN3rU1Q3xgSZfzKmSZQPUYCDAGl6owLChCVIOJTdP//uZ3nVFickPUATweDZ6Ma0pA0x5E+uO1+oohocaHPVq4TVUTZAKFB5BcNc2ZdOMt9Wu8/d+aI3+OmhPcqHNZzI9m1lkpiAUCwTny8a++0sQn8MQ7cgOiSwvF8g8FGOiwPl3ljwj1766xoXU9yGFskPN6be5MKF18aC+hShF/s8jtxunfGMOx0xuGhobtTgV9pgQTmxG78gVo7tVsFD8AvTiV0N+eCPpkEFNvRl+U/ki3q/I6ZRwgQ5JJeZtiSYqY6DuPfDKY1xlbYbgNAl++wStxugD/EdU2iS3v/l8djYc7qoaOWsKXR7UDb0Uq/lwsmi8eXmbJVQcY9L/Wn4LMmPUE1LUOaupzrV7j3cgImVNy+5DE271NyL2Ha0MSWUSKKWpLdhXLLOe++B8c/vn+bDDZTiVmCxxLSQqQ9Ac7ytLjC5lih3O9qP5idKm43ZqhIii90RzdJK28C38Z7MUI0SZFA0uX2uhcfx9CbT6dqsPe3jIojN/X7WOg/Tnv9t2IbE=----ATTACHMENT:----NTc1OTg3OTA1MTQ3NDY0MiA0Mzc1MDM1ODU3MzMxODggMTg0MDg2OTQ5NDg0MDM1Ng==