From d5c14ae03a9fb106cc5544af5e5ff14f7dbb5220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 21 Dec 2024 11:31:57 +0100 Subject: [PATCH] fix test bootstrap --- .../class-the-events-calendar.php | 24 +++++++++++++++++++ tests/bootstrap.php | 10 ++------ .../transformer/class-test-gatherpress.php | 2 +- .../class-test-the-events-calendar.php | 2 +- tests/includes/class-test-event-sources.php | 6 +++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/includes/activitypub/transmogrifier/class-the-events-calendar.php b/includes/activitypub/transmogrifier/class-the-events-calendar.php index 2106b20..a0b1ac0 100644 --- a/includes/activitypub/transmogrifier/class-the-events-calendar.php +++ b/includes/activitypub/transmogrifier/class-the-events-calendar.php @@ -40,6 +40,28 @@ class The_Events_Calendar extends Base { return $results; } + /** + * Add venue. + * + * @param int $post_id The post ID. + */ + private function add_venue( $post_id ) { + $location = $this->activitypub_event->get_location(); + + if ( ! $location ) { + return; + } + + if ( ! isset( $location['name'] ) ) { + return; + } + + // Fallback for Gancio instances. + if ( 'online' === $location['name'] ) { + return; + } + } + /** * Save the ActivityPub event object as GatherPress Event. * @@ -77,6 +99,8 @@ class The_Events_Calendar extends Base { return false; } + $this->add_venue( $post->ID ); + // Limit this as a safety measure. remove_filter( 'wp_revisions_to_keep', array( self::class, 'revisions_to_keep' ) ); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7ad614c..bea14fd 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -104,16 +104,10 @@ function _manually_load_plugin() { if ( $plugin_file ) { _manually_load_event_plugin( $plugin_file ); - } elseif ( 'event_sources' === $event_bridge_for_activitypub_integration_filter ) { - // For the Event Sources feature we currently only test with GatherPress. - _manually_load_event_plugin( 'gatherpress/gatherpress.php' ); - \update_option( 'event_bridge_for_activitypub_event_sources_active', true ); - \update_option( 'event_bridge_for_activitypub_integration_used_for_event_sources_feature', 'GatherPress' ); - \update_option( 'activitypub_actor_mode', ACTIVITYPUB_BLOG_MODE ); } else { - // For all other tests we mainly use the Events Calendar as a reference. + // For all other tests we mainly use the Events Calendar and GatherPress as reference. _manually_load_event_plugin( 'the-events-calendar/the-events-calendar.php' ); - _manually_load_event_plugin( 'very-simple-event-list/vsel.php' ); + _manually_load_event_plugin( 'gatherpress/gatherpress.php' ); } // Hot fix that allows using Events Manager within unit tests, because the em_init() is later not run as admin. diff --git a/tests/includes/activitypub/transformer/class-test-gatherpress.php b/tests/includes/activitypub/transformer/class-test-gatherpress.php index a95058e..b7d0a8f 100644 --- a/tests/includes/activitypub/transformer/class-test-gatherpress.php +++ b/tests/includes/activitypub/transformer/class-test-gatherpress.php @@ -40,7 +40,7 @@ class Test_GatherPress extends \WP_UnitTestCase { // even though we support multiple onces in theory. // But testing all combinations is beyond scope. $active_event_plugins = \Event_Bridge_For_ActivityPub\Setup::get_instance()->get_active_event_plugins(); - $this->assertEquals( 1, count( $active_event_plugins ) ); + $this->assertArrayHasKey( 'gatherpress/gatherpress.php', $active_event_plugins ); // Enable ActivityPub support for the event plugin. $this->assertContains( 'gatherpress_event', get_option( 'activitypub_support_post_types' ) ); diff --git a/tests/includes/activitypub/transformer/class-test-the-events-calendar.php b/tests/includes/activitypub/transformer/class-test-the-events-calendar.php index f760c70..7717826 100644 --- a/tests/includes/activitypub/transformer/class-test-the-events-calendar.php +++ b/tests/includes/activitypub/transformer/class-test-the-events-calendar.php @@ -79,7 +79,7 @@ class Test_The_Events_Calendar extends \WP_UnitTestCase { // even though we support multiple onces in theory. // But testing all combinations is beyond scope. $active_event_plugins = \Event_Bridge_For_ActivityPub\Setup::get_instance()->get_active_event_plugins(); - $this->assertEquals( 1, count( $active_event_plugins ) ); + $this->assertArrayHasKey( 'the-events-calendar/the-events-calendar.php', $active_event_plugins ); // Enable ActivityPub support for the event plugin. $this->assertContains( 'tribe_events', get_option( 'activitypub_support_post_types' ) ); diff --git a/tests/includes/class-test-event-sources.php b/tests/includes/class-test-event-sources.php index 8209a32..260a90c 100644 --- a/tests/includes/class-test-event-sources.php +++ b/tests/includes/class-test-event-sources.php @@ -61,6 +61,12 @@ class Test_Event_Sources extends \WP_UnitTestCase { public function set_up() { \add_option( 'permalink_structure', '/%postname%/' ); + \update_option( 'event_bridge_for_activitypub_event_sources_active', true ); + \update_option( + 'event_bridge_for_activitypub_integration_used_for_event_sources_feature', + \Event_Bridge_For_ActivityPub\Integrations\GatherPress::class ); + \update_option( 'activitypub_actor_mode', ACTIVITYPUB_BLOG_MODE ); + global $wp_rest_server; $wp_rest_server = new WP_REST_Server(); $this->server = $wp_rest_server;