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:----Pe31MhRRZNUmqzvz58flUgQR9w+pnWqadEX9agoSo9Uac3NMNxWFeuooUpS1iBXFeU1sWQA3NALbh9z9IWZPaHXTyDjbf4vADTs+VnEaHRV22kZ/xBKeKQ/ecci68GjP32Zk+uF24T/znOqprtI0SqbAt/8h/Q31OiWCwIiaZ1g9wv5BIzLmjEtyoKt3qZf9TVGtJHNeJoH/hMTU8raVIozqogVM6mmrjBSwHuw0FfK5oeQynAT6ii3RGYK+YmtV1Ak49kbyRBjk+FWDu6sbArsIm6f74n57VUDVr9cX/c2k/0yo2EjIEcPk0jY4bbVEF6ruOnbFPPQXmadj2/azhFOUyTXqZAjogGiRCpWZff/lKjJ10q33YwATaSow4fCT8gMCkLTSpJgAHuaozyAXyKEp83FDkpbGqXlDGAY7cx2J5OEDscp7lx/MJSMrqbwcNf7XRgKuFVbhSoaSE1NiEh4U24KYNrj1ul1SG0gYQnGCG6EHVuWGMKpdBNW2MVjkKpgsuQw9Lg3q3UhUZDPDRLZi6B1IcUmo/tzb+s9orHEaJ98MEevUXD5JqQnnb/CsW8oRk4OMmbYYFWSQnAjShE7XoPiQ5u5C/bnBs1KY18OBai7V8UR81JgFZ2gceFVcCQQrpndsMCX+Dfyf4RGBIULW5OXCAqdhQZHW5YPj5Og=----ATTACHMENT:----NDMxMjQ0Mjk0Njc0NTY0MCA3NzM5MDQ4MDk2ODQzNTMwIDE1Nzk3MTY4ODAxNTI5Mjg=