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:----i9hRrjeyNTSomjvmM5qYsst5RJSraHLxILUh4e5fsYbHjVw/8OayRHZBCwHDA9ZhrTTVkBb4jrQdIqyvnIhxQRDJNI+Zyf00TLDGXxsK8rl5Q7e3/BUNgeQ8n6sI8b/H+bf3CYM93gCp97X3tQz8ptdpc5aXVuxkMHChcKXQEXFapsLgpPuPrcwV7m7XLMzF9AE2+ctp8bpcemKUwFeuJvsS1evV1F2JKIhsTbYu5JHd2j48Aa1rkE6lugZoKEuUnRL89grbv7NQzABKAah7g03NZL77ZlCoirMrjvhvf/7OGrGPaJORha3zZntviahKzVl/AN/BpXUm5/j8nWtt5GwYaxwXW+BJ9HcTpr/JlTTnqARlzoVWWcDx/SdAHvXb96Kd2+36MKTPk2oKox00AKAWBzZGu571c53QQ8zqbVE6kAsz/p10LUMfxtR3LnyAgfBZvtTB7cRZgGQfxw6I5SrGb53dpLDnV3pekgj6BZ9AXlrvTWyNVZPJTyJiHlNQZwEqAw3Z49MulqnGxJD4UfilXOQIwpaal2f8UQ5igxfaRJtOnamvjp572q8WJSSQgBs+eTox6BVIyjcHIBTo0FIVmHU/H2VgRD1xEDDEMjfiZ1L2UeTNyMeYkAY6J9FwJKU3AtzEt9FKRFh6HefKAgopFuhn6IhCmFuHeNpTMVk=----ATTACHMENT:----NzMzMTczOTE5MDgwODMyNSAzNDEzODkxMTEyODMzODAwIDM0MzgxMjA4Njg4NjQ5MTc=