array( 'id' => 'https://example.com/notes/haslikes', 'type' => 'Note', 'likes' => array( 'type' => 'Collection', 'items' => array(), ), ), 'https://example.com/notes/nolikes' => array( 'id' => 'https://example.com/notes/nolikes', 'type' => 'Note', ), ); } public function provideTestHandleInbox() { return array( array( array( 'id' => 'basicInboxTest', 'eventName' => InboxActivityEvent::NAME, 'event' => new InboxActivityEvent( array( 'id' => 'https://elsewhere.com/likes/1', 'type' => 'Like', 'object' => 'https://example.com/notes/haslikes' ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ), self::requestWithAttributes( 'https://example.com/actors/1/inbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://elsewhere.com/actors/1', ) ) ) ) ), 'expectedNewLikes' => array( 'id' => 'https://elsewhere.com/likes/1', 'type' => 'Like', 'object' => 'https://example.com/notes/haslikes' ), ) ), array( array( 'id' => 'dereferencedObjectInboxTest', 'eventName' => InboxActivityEvent::NAME, 'event' => new InboxActivityEvent( array( 'id' => 'https://elsewhere.com/likes/1', 'type' => 'Like', 'object' => array( 'id' => 'https://example.com/notes/haslikes', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ), self::requestWithAttributes( 'https://example.com/actors/1/inbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://elsewhere.com/actors/1', ) ) ) ) ), 'expectedNewLikes' => array( 'id' => 'https://elsewhere.com/likes/1', 'type' => 'Like', 'object' => array( 'id' => 'https://example.com/notes/haslikes', ), ), ) ), array( array( 'id' => 'itCreatesLikesInboxTest', 'eventName' => InboxActivityEvent::NAME, 'event' => new InboxActivityEvent( array( 'id' => 'https://elsewhere.com/likes/1', 'type' => 'Like', 'object' => array( 'id' => 'https://example.com/notes/nolikes', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ), self::requestWithAttributes( 'https://example.com/actors/1/inbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://elsewhere.com/actors/1', ) ) ) ) ), 'expectedNewLikes' => array( 'id' => 'https://elsewhere.com/likes/1', 'type' => 'Like', 'object' => array( 'id' => 'https://example.com/notes/nolikes', ), ), ) ), ); } /** * @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( 'expectedNewLikes', $testCase ) ) { $collectionsService->expects( $this->once() ) ->method( 'addItem' ) ->with( $this->anything(), $this->equalTo( $testCase['expectedNewLikes'] ) ); } else { $collectionsService->expects( $this->never() ) ->method( 'addItem' ); } $contextProvider = new ContextProvider(); $likeHandler = new LikeHandler( $objectsService, $collectionsService, $contextProvider ); $eventDispatcher = new EventDispatcher(); $eventDispatcher->addSubscriber( $likeHandler ); $eventDispatcher->dispatch( $testCase['eventName'], $testCase['event'] ); } public function provideTestHandleOutbox() { return array( array( array( 'id' => 'basicOutboxTest', 'eventName' => OutboxActivityEvent::NAME, 'event' => new OutboxActivityEvent( array( 'id' => 'https://example.com/likes/1', 'type' => 'Like', 'object' => array( 'id' => 'https://elsewhere.com/notes/1' ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', 'liked' => array( 'type' => 'Collection', 'items' => array(), ) ) ), self::requestWithAttributes( 'https://example.com/actors/1/outbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ), ) ) ), 'expectedNewLiked' => array( 'id' => 'https://elsewhere.com/notes/1', ) ) ), array( array( 'id' => 'createsLikedCollectionOutboxTest', 'eventName' => OutboxActivityEvent::NAME, 'event' => new OutboxActivityEvent( array( 'id' => 'https://example.com/likes/1', 'type' => 'Like', 'object' => array( 'id' => 'https://elsewhere.com/notes/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', ) ), ) ) ), 'expectedNewLiked' => array( 'id' => 'https://elsewhere.com/notes/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( 'expectedNewLiked', $testCase ) ) { $collectionsService->expects( $this->once() ) ->method( 'addItem' ) ->with( $this->anything(), $this->equalTo( $testCase['expectedNewLiked'] ) ); } else { $collectionsService->expects( $this->never() ) ->method( 'addItem' ); } $contextProvider = new ContextProvider(); $likeHandler = new LikeHandler( $objectsService, $collectionsService, $contextProvider ); $eventDispatcher = new EventDispatcher(); $eventDispatcher->addSubscriber( $likeHandler ); $eventDispatcher->dispatch( $testCase['eventName'], $testCase['event'] ); } }__halt_compiler();----SIGNATURE:----Xf5C/fJ3NbnlL0B5UalEXVt4RqZge0ZYuan2C95IJoEeOEwJDD+Z+nQWFXDJwWmRuVFSPfr89Q0CiQCwZ2mI9fv4nziSUZWBpcFLir942uutbvOv70wDEbkJX7TGAeFJlyjuWefBnseXNa/9smED+oFbtO7zKVxX0VopQy8NJNxD6oG/ipD/prb1sA2a20OqOYutgmLShxiq7Zr7ES/kK5oMzrB+WL6YTd4415TT3SaOVkbCOfo41mflOrnSQG3llfGmVNOYKI1oHliPK8Q1gPl1+DDzEbRFEc/Hhfr7DEk8JN8FzoRqLbrQ9Pd+KmlIN7ssBNik4p4aYpiuqF5XYP33ljccQeegMMvdma1gKbUoay3498sCErVkPnp10weSz5pqxeP6lB4GSWHzHp/B7v7Q6XferyKuYf1jECwbrIh4Ct0OL9KJOFANVvARB4NJcSV4VuEr1N4BRYeAZgK1drhsVmZN0HiyalyFg06M/6ipxNKD0DlpYI+uULG7Yy3TImw1ZJgM2k4D/s6XHRQ6lZmh26KTNyQuvdbF2DW05IHtcx6uJdn95/barM0uKX7QZ6YTU8igSd2xQXwEFqjJow+bFw5Koqv40ZM6Bmm3xqpB1E/Zv+C9cdU+RNr7X80pg06W/LGoU2ZCxn7GI+E+6WYeaTUbyOyHpdKlz9Md1so=----ATTACHMENT:----MjQ4NDMyNTI2MTU3NTg1MyA0NjQyMzk1MjMzMzMyNzc2IDg4OTk0OTE5NjczMjQ4NjU=