diff --git a/composer.json b/composer.json index 06122c9..8b178f9 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ ], "test-debug": [ "@prepare-test", - "@test-gatherpress" + "@test-event-sources" ], "test-vs-event-list": "phpunit --filter=vs_event_list", "test-the-events-calendar": "phpunit --filter=the_events_calendar", diff --git a/includes/activitypub/handler/class-undo.php b/includes/activitypub/handler/class-undo.php index f95ef99..ed752eb 100644 --- a/includes/activitypub/handler/class-undo.php +++ b/includes/activitypub/handler/class-undo.php @@ -64,7 +64,7 @@ class Undo { $query = new \WP_Query( $args ); // If no event source with that accept ID is found return. - if ( ! $query->have_posts ) { + if ( ! $query->have_posts() ) { return; } diff --git a/tests/includes/class-test-event-sources.php b/tests/includes/class-test-event-sources.php index 72901ca..da343c9 100644 --- a/tests/includes/class-test-event-sources.php +++ b/tests/includes/class-test-event-sources.php @@ -250,7 +250,6 @@ class Test_Event_Sources extends \WP_UnitTestCase { /** * Test receiving "Accept" of "Follow". * - * */ public function test_incoming_accept_of_follow() { \add_filter( 'activitypub_defer_signature_verification', '__return_true' ); @@ -258,7 +257,7 @@ class Test_Event_Sources extends \WP_UnitTestCase { $blog = new Blog(); $json = array( - 'id' => 'https://remote.example/random-id', + 'id' => 'https://remote.example/random-accept-id', 'type' => 'Accept', 'actor' => 'https://remote.example/@organizer', 'object' => array( @@ -270,8 +269,8 @@ class Test_Event_Sources extends \WP_UnitTestCase { ); $event_source = \Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source::get_by_id( 'https://remote.example/@organizer' ); - $accepted = get_post_meta( $event_source->get__id(), '_event_bridge_or_activitypub_accept_of_follow', true ); - $this->assertNotFalse( $accepted ); + $accepted = get_post_meta( $event_source->get__id(), '_event_bridge_for_activitypub_accept_of_follow', true ); + $this->assertEmpty( $accepted ); // Receive Accept. $request = new WP_REST_Request( 'POST', '/activitypub/1.0/users/0/inbox' ); @@ -280,10 +279,37 @@ class Test_Event_Sources extends \WP_UnitTestCase { $response = \rest_do_request( $request ); $this->assertEquals( 202, $response->get_status() ); + $accepted = get_post_meta( $event_source->get__id(), '_event_bridge_for_activitypub_accept_of_follow', true ); - $accepted = get_post_meta( $event_source->get__id(), '_event_bridge_or_activitypub_accept_of_follow', true ); + $this->assertEquals( 'https://remote.example/random-accept-id', $accepted ); - $this->assertNotFalse( $accepted ); + // Receive Undo of the Accept. + $json = array( + 'id' => 'https://remote.example/random-undo-id', + 'type' => 'Undo', + 'actor' => 'https://remote.example/@organizer', + 'object' => array( + 'id' => 'https://remote.example/random-accept-id', + 'type' => 'Accept', + 'actor' => 'https://remote.example/@organizer', + 'object' => array( + 'id' => Event_Sources::compose_follow_id( $blog->get_id(), 'https://remote.example/@organizer' ), + 'type' => 'Follow', + 'to' => 'https://www.w3.org/ns/activitystreams#Public', + 'object' => 'https://remote.example/@organizer', + ), + ), + ); + + $request = new WP_REST_Request( 'POST', '/activitypub/1.0/users/0/inbox' ); + $request->set_header( 'Content-Type', 'application/activity+json' ); + $request->set_body( \wp_json_encode( $json ) ); + $response = \rest_do_request( $request ); + $this->assertEquals( 202, $response->get_status() ); + + $accepted = get_post_meta( $event_source->get__id(), '_event_bridge_for_activitypub_accept_of_follow', true ); + + $this->assertEmpty( $accepted ); \remove_filter( 'activitypub_defer_signature_verification', '__return_true' ); }