diff --git a/composer.json b/composer.json index 0f33ee4..f744fb1 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ ], "test-debug": [ "@prepare-test", - "@test-gatherpress" + "@test-general" ], "test-vs-event-list": "phpunit --filter=vs_event_list", "test-the-events-calendar": "phpunit --filter=the_events_calendar", @@ -74,6 +74,6 @@ "test-event-organiser": "phpunit --filter=event_organiser", "test-event-bridge-for-activitypub-shortcodes": "phpunit --filter=shortcodes", "test-event-sources": "phpunit --filter=event_sources", - "test-all": "phpunit" + "test-general": "phpunit" } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index bea14fd..c966f46 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -72,6 +72,12 @@ function _manually_load_plugin() { switch ( $event_bridge_for_activitypub_integration_filter ) { case 'the_events_calendar': $plugin_file = 'the-events-calendar/the-events-calendar.php'; + \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\The_Events_Calendar::class + ); + \update_option( 'activitypub_actor_mode', ACTIVITYPUB_BLOG_MODE ); break; case 'vs_event_list': $plugin_file = 'very-simple-event-list/vsel.php'; @@ -88,7 +94,10 @@ function _manually_load_plugin() { case 'gatherpress': $plugin_file = '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', \Event_Bridge_For_ActivityPub\Integrations\GatherPress::class ); + \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 ); break; case 'wp_event_manager': @@ -106,6 +115,12 @@ function _manually_load_plugin() { _manually_load_event_plugin( $plugin_file ); } else { // For all other tests we mainly use the Events Calendar and GatherPress as reference. + \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 ); _manually_load_event_plugin( 'the-events-calendar/the-events-calendar.php' ); _manually_load_event_plugin( 'gatherpress/gatherpress.php' ); } diff --git a/tests/includes/activitypub/transformer/class-test-event.php b/tests/includes/activitypub/transformer/class-test-event.php index 37e4d14..4efb99d 100644 --- a/tests/includes/activitypub/transformer/class-test-event.php +++ b/tests/includes/activitypub/transformer/class-test-event.php @@ -36,9 +36,11 @@ class Test_Event extends \WP_UnitTestCase { * Test the shortcode for rendering the events start time. */ public function test_start_time() { + $event = Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event']; + // Create a The Events Calendar Event without content. $wp_object = tribe_events() - ->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event'] ) + ->set_args( $event ) ->create(); // Call the transformer Factory. @@ -48,19 +50,22 @@ class Test_Event extends \WP_UnitTestCase { return; } + $datetime_format = \get_option( 'date_format' ) . ' ' . \get_option( 'time_format' ); + $time_string = \wp_date( $datetime_format, \strtotime( $event['start_date'] ) ); + $transformer->register_shortcodes(); $summary = '[ap_start_time]'; $summary = \do_shortcode( $summary ); - $this->assertEquals( '🗓️ Start: December 1, 2024 3:00 pm', $summary ); + $this->assertEquals( "🗓️ Start: {$time_string}", $summary ); $summary = '[ap_start_time icon="false"]'; $summary = \do_shortcode( $summary ); - $this->assertEquals( 'Start: December 1, 2024 3:00 pm', $summary ); + $this->assertEquals( "Start: {$time_string}", $summary ); $summary = '[ap_start_time icon="false" label="false"]'; $summary = \do_shortcode( $summary ); - $this->assertEquals( 'December 1, 2024 3:00 pm', $summary ); + $this->assertEquals( $time_string, $summary ); $transformer->unregister_shortcodes(); } @@ -69,9 +74,11 @@ class Test_Event extends \WP_UnitTestCase { * Test the shortcode for rendering the events end time. */ public function test_end_time() { + $event = Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event']; + // Create a The Events Calendar Event without content. $wp_object = tribe_events() - ->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event'] ) + ->set_args( $event ) ->create(); // Call the transformer Factory. @@ -81,19 +88,22 @@ class Test_Event extends \WP_UnitTestCase { return; } + $datetime_format = \get_option( 'date_format' ) . ' ' . \get_option( 'time_format' ); + $time_string = \wp_date( $datetime_format, \strtotime( $event['start_date'] ) + $event['duration'] ); + $transformer->register_shortcodes(); $summary = '[ap_end_time]'; $summary = \do_shortcode( $summary ); - $this->assertEquals( '⏳ End: December 1, 2024 4:00 pm', $summary ); + $this->assertEquals( "⏳ End: {$time_string}", $summary ); $summary = '[ap_end_time icon="false"]'; $summary = \do_shortcode( $summary ); - $this->assertEquals( 'End: December 1, 2024 4:00 pm', $summary ); + $this->assertEquals( "End: {$time_string}", $summary ); $summary = '[ap_end_time icon="false" label="false"]'; $summary = \do_shortcode( $summary ); - $this->assertEquals( 'December 1, 2024 4:00 pm', $summary ); + $this->assertEquals( $time_string, $summary ); $transformer->unregister_shortcodes(); } diff --git a/tests/includes/activitypub/transmogrifier/class-test-gatherpress.php b/tests/includes/activitypub/transmogrifier/class-test-gatherpress.php index c26e2f3..72eb070 100644 --- a/tests/includes/activitypub/transmogrifier/class-test-gatherpress.php +++ b/tests/includes/activitypub/transmogrifier/class-test-gatherpress.php @@ -82,7 +82,10 @@ class Test_GatherPress extends \WP_UnitTestCase { $aec->activate_activitypub_support_for_active_event_plugins(); \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( + '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 ); } diff --git a/tests/includes/class-test-event-sources.php b/tests/includes/class-test-event-sources.php index 260a90c..548df26 100644 --- a/tests/includes/class-test-event-sources.php +++ b/tests/includes/class-test-event-sources.php @@ -54,18 +54,15 @@ class Test_Event_Sources extends \WP_UnitTestCase { self::$event_source_post_id = $post_id; } - /** * Set up the test. */ public function set_up() { - \add_option( 'permalink_structure', '/%postname%/' ); + if ( ! defined( 'GATHERPRESS_CORE_FILE' ) ) { + self::markTestSkipped( 'GatherPress plugin is not active.' ); + } - \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 ); + \add_option( 'permalink_structure', '/%postname%/' ); global $wp_rest_server; $wp_rest_server = new WP_REST_Server(); @@ -74,6 +71,20 @@ class Test_Event_Sources extends \WP_UnitTestCase { do_action( 'rest_api_init' ); \Activitypub\Rest\Server::add_hooks(); + + // Mock the plugin activation. + \GatherPress\Core\Setup::get_instance()->activate_gatherpress_plugin( false ); + + // Make sure that ActivityPub support is enabled for GatherPress. + $aec = \Event_Bridge_For_ActivityPub\Setup::get_instance(); + $aec->activate_activitypub_support_for_active_event_plugins(); + + \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 ); } /**