From b7be4fc028e26b6eda7071aee2b777bab6e3deea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 28 Nov 2024 21:21:30 +0100 Subject: [PATCH 01/11] wip --- .forgejo/workflows/phpunit.yml | 9 +- bin/install-wp-tests.sh | 1 + composer.json | 6 +- .../transformer/class-event-organiser.php | 76 +++++++++++++ includes/class-setup.php | 1 + includes/plugins/class-event-organiser.php | 69 ++++++++++++ tests/bootstrap.php | 8 ++ tests/test-class-plugin-event-organiser.php | 104 ++++++++++++++++++ 8 files changed, 270 insertions(+), 4 deletions(-) create mode 100644 includes/activitypub/transformer/class-event-organiser.php create mode 100644 includes/plugins/class-event-organiser.php create mode 100644 tests/test-class-plugin-event-organiser.php diff --git a/.forgejo/workflows/phpunit.yml b/.forgejo/workflows/phpunit.yml index c79e189..2f737d7 100644 --- a/.forgejo/workflows/phpunit.yml +++ b/.forgejo/workflows/phpunit.yml @@ -38,7 +38,7 @@ jobs: path: | ${{ env.WP_CORE_DIR }} ${{ env.WP_TESTS_DIR }} - key: cache-wordpress-67-3 + key: cache-wordpress-67-4 - name: Cache Composer id: cache-composer-phpunit @@ -113,4 +113,9 @@ jobs: - name: Run Integration tests for EventPrime run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=eventprime env: - PHP_VERSION: ${{ matrix.php-version }} \ No newline at end of file + PHP_VERSION: ${{ matrix.php-version }} + + - name: Run Integration tests for Event Organiser + run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=event_organiser + env: + PHP_VERSION: ${{ matrix.php-version }} diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 7cbf282..95fc2e5 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -261,6 +261,7 @@ install_wp_plugins() { install_wp_plugin events-manager "6.6.3" install_wp_plugin wp-event-manager "3.1.45.1" install_wp_plugin wp-event-solution "4.0.14" + install_wp_plugin event-organiser "3.12.8" # Mec is not installable via wordpress.org, we use our own mirror. install_wp_plugin_mec } diff --git a/composer.json b/composer.json index d4c2b0b..36e5525 100644 --- a/composer.json +++ b/composer.json @@ -55,11 +55,12 @@ "@test-wp-event-manager", "@test-eventin", "@test-modern-events-calendar-lite", - "@test-eventprime" + "@test-eventprime", + "@test-event-organiser" ], "test-debug": [ "@prepare-test", - "@test-eventprime" + "@test-event-organiser" ], "test-vs-event-list": "phpunit --filter=vs_event_list", "test-the-events-calendar": "phpunit --filter=the_events_calendar", @@ -69,6 +70,7 @@ "test-eventin": "phpunit --filter=eventin", "test-modern-events-calendar-lite": "phpunit --filter=modern_events_calendar_lite", "test-eventprime": "phpunit --filter=eventprime", + "test-event-organiser": "phpunit --filter=event_organiser", "test-all": "phpunit" } } diff --git a/includes/activitypub/transformer/class-event-organiser.php b/includes/activitypub/transformer/class-event-organiser.php new file mode 100644 index 0000000..4d65dfa --- /dev/null +++ b/includes/activitypub/transformer/class-event-organiser.php @@ -0,0 +1,76 @@ +wp_object->ID ); + } + + /** + * Get the end time from the event object. + */ + protected function get_start_time(): string { + return eo_get_the_start( 'Y-m-d\TH:i:s\Z', $this->wp_object->ID ); + } + + /** + * Get location from the event object. + */ + protected function get_location(): ?Place { + $venue_id = eo_get_venue( $this->wp_object->ID ); + + if ( ! $venue_id ) { + return null; + } + + $address = eo_get_venue_address( $venue_id ); + + $address['name'] = eo_get_venue_name( $this->wp_object->ID ); + + $address['streetAddress'] = $address['address']; + unset( $address['address'] ); + + $address['postalCode'] = $address['postcode']; + unset( $address['postcode'] ); + + $address['addressRegion'] = $address['state']; + unset( $address['state'] ); + + $address['addressLocality'] = $address['city']; + unset( $address['city'] ); + + $address['addressCountry'] = $address['country']; + unset( $address['country'] ); + + $address['type'] = 'PostalAddress'; + + $location = new Place(); + $location->set_name( eo_get_venue_name( $this->wp_object->ID ) ); + $location->set_latitude( eo_get_venue_lat( $this->wp_object->ID ) ); + $location->set_longitude( eo_get_venue_lng( $this->wp_object->ID ) ); + $location->set_address( $address ); + + return $address; + } +} diff --git a/includes/class-setup.php b/includes/class-setup.php index 3b5ef0b..b99eda5 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -133,6 +133,7 @@ class Setup { '\ActivityPub_Event_Bridge\Plugins\Eventin', '\ActivityPub_Event_Bridge\Plugins\Modern_Events_Calendar_Lite', '\ActivityPub_Event_Bridge\Plugins\EventPrime', + '\ActivityPub_Event_Bridge\Plugins\Event_Organiser', ); /** diff --git a/includes/plugins/class-event-organiser.php b/includes/plugins/class-event-organiser.php new file mode 100644 index 0000000..d418bba --- /dev/null +++ b/includes/plugins/class-event-organiser.php @@ -0,0 +1,69 @@ +install(); } + if ( 'event-organiser' === $activitypub_event_bridge_integration_filter ) { + require_once $plugin_dir . 'event-organiser/includes/event-organiser-install.php'; + eventorganiser_install(); + } + // At last manually load our WordPress plugin. require dirname( __DIR__ ) . '/activitypub-event-bridge.php'; } diff --git a/tests/test-class-plugin-event-organiser.php b/tests/test-class-plugin-event-organiser.php new file mode 100644 index 0000000..a918487 --- /dev/null +++ b/tests/test-class-plugin-event-organiser.php @@ -0,0 +1,104 @@ +activate_gatherpress_plugin( false ); + + // Make sure that ActivityPub support is enabled for The Events Calendar. + $aec = \ActivityPub_Event_Bridge\Setup::get_instance(); + $aec->activate_activitypub_support_for_active_event_plugins(); + + // Delete all posts afterwards. + _delete_all_posts(); + } + + /** + * Test that the right transformer gets applied. + */ + public function test_transformer_class() { + // We only test for one event plugin being active at the same time, + // even though we support multiple onces in theory. + // But testing all combinations is beyond scope. + $active_event_plugins = \ActivityPub_Event_Bridge\Setup::get_instance()->get_active_event_plugins(); + $this->assertEquals( 1, count( $active_event_plugins ) ); + + // Enable ActivityPub support for the event plugin. + $this->assertContains( 'gatherpress_event', get_option( 'activitypub_support_post_types' ) ); + + // Mock GatherPress Event. + $post_id = wp_insert_post( + array( + 'post_title' => 'Unit Test Event', + 'post_type' => 'gatherpress_event', + 'post_content' => 'Unit Test description.', + 'post_status' => 'publish', + ) + ); + $event = new \GatherPress\Core\Event( $post_id ); + $params = array( + 'datetime_start' => '+10 days 15:00:00', + 'datetime_end' => '+10 days 16:00:00', + 'timezone' => 'America/New_York', + ); + + $event->save_datetimes( $params ); + + // Call the transformer Factory. + $transformer = \Activitypub\Transformer\Factory::get_transformer( $event->event ); + + // Check that we got the right transformer. + $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\GatherPress::class, $transformer ); + } + + /** + * Test transformation to ActivityPUb for basic event. + */ + public function test_transform_of_basic_event() { + // Mock GatherPress Event. + $post_id = wp_insert_post( + array( + 'post_title' => 'Unit Test Event', + 'post_type' => 'gatherpress_event', + 'post_content' => 'Unit Test description.', + 'post_status' => 'publish', + ) + ); + $event = new \GatherPress\Core\Event( $post_id ); + $params = array( + 'datetime_start' => '+10 days 15:00:00', + 'datetime_end' => '+10 days 16:00:00', + 'timezone' => 'America/New_York', + ); + $event->save_datetimes( $params ); + + // Call the transformer Factory. + $event_array = \Activitypub\Transformer\Factory::get_transformer( $event->event )->to_object()->to_array(); + + // Check that the event ActivityStreams representation contains everything as expected. + $this->assertEquals( 'Event', $event_array['type'] ); + $this->assertEquals( 'Unit Test Event', $event_array['name'] ); + $this->assertEquals( 'Unit Test description.', wp_strip_all_tags( $event_array['content'] ) ); + $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); + $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); + $this->assertEquals( 'external', $event_array['joinMode'] ); + $this->assertArrayNotHasKey( 'location', $event_array ); + } +} -- 2.39.5 From 8f179ff9f37b34cd5d6abcadaec8103e36247520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 28 Nov 2024 21:55:28 +0100 Subject: [PATCH 02/11] basic tests --- tests/test-class-plugin-event-organiser.php | 67 +++++++++------------ 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/tests/test-class-plugin-event-organiser.php b/tests/test-class-plugin-event-organiser.php index a918487..2fe8f66 100644 --- a/tests/test-class-plugin-event-organiser.php +++ b/tests/test-class-plugin-event-organiser.php @@ -15,14 +15,11 @@ class Test_Event_Organiser extends WP_UnitTestCase { public function set_up() { parent::set_up(); - if ( ! function_exists( 'eo_get_events' ) ) { + if ( ! class_exists( '\EO_Query_Result' ) ) { self::markTestSkipped( 'Event Organiser plugin is not active.' ); } - // Mock the plugin activation. - GatherPress\Core\Setup::get_instance()->activate_gatherpress_plugin( false ); - - // Make sure that ActivityPub support is enabled for The Events Calendar. + // Make sure that ActivityPub support is enabled. $aec = \ActivityPub_Event_Bridge\Setup::get_instance(); $aec->activate_activitypub_support_for_active_event_plugins(); @@ -41,56 +38,50 @@ class Test_Event_Organiser extends WP_UnitTestCase { $this->assertEquals( 1, count( $active_event_plugins ) ); // Enable ActivityPub support for the event plugin. - $this->assertContains( 'gatherpress_event', get_option( 'activitypub_support_post_types' ) ); + $this->assertContains( 'event', get_option( 'activitypub_support_post_types' ) ); - // Mock GatherPress Event. - $post_id = wp_insert_post( - array( - 'post_title' => 'Unit Test Event', - 'post_type' => 'gatherpress_event', - 'post_content' => 'Unit Test description.', - 'post_status' => 'publish', - ) - ); - $event = new \GatherPress\Core\Event( $post_id ); - $params = array( - 'datetime_start' => '+10 days 15:00:00', - 'datetime_end' => '+10 days 16:00:00', - 'timezone' => 'America/New_York', + $event_data = array( + 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ), + 'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ), + 'all_day' => 0, + 'schedule' => 'once', ); - $event->save_datetimes( $params ); + $post_data = array( + 'post_title' => 'Unit Test Event', + 'post_content' => 'Unit Test description.', + ); + + $post_id = eo_insert_event( $post_data, $event_data ); // Call the transformer Factory. - $transformer = \Activitypub\Transformer\Factory::get_transformer( $event->event ); + $transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) ); // Check that we got the right transformer. - $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\GatherPress::class, $transformer ); + $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event_Organiser::class, $transformer ); } /** * Test transformation to ActivityPUb for basic event. */ public function test_transform_of_basic_event() { - // Mock GatherPress Event. - $post_id = wp_insert_post( - array( - 'post_title' => 'Unit Test Event', - 'post_type' => 'gatherpress_event', - 'post_content' => 'Unit Test description.', - 'post_status' => 'publish', - ) + // Mock Event. + $event_data = array( + 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ), + 'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ), + 'all_day' => 0, + 'schedule' => 'once', ); - $event = new \GatherPress\Core\Event( $post_id ); - $params = array( - 'datetime_start' => '+10 days 15:00:00', - 'datetime_end' => '+10 days 16:00:00', - 'timezone' => 'America/New_York', + + $post_data = array( + 'post_title' => 'Unit Test Event', + 'post_content' => 'Unit Test description.', ); - $event->save_datetimes( $params ); + + $post_id = eo_insert_event( $post_data, $event_data ); // Call the transformer Factory. - $event_array = \Activitypub\Transformer\Factory::get_transformer( $event->event )->to_object()->to_array(); + $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) )->to_object()->to_array(); // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); -- 2.39.5 From 6a09f6acef1b339d0412b1a3a6856a39dbba3250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 28 Nov 2024 21:58:11 +0100 Subject: [PATCH 03/11] phpcs --- tests/test-class-plugin-event-organiser.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test-class-plugin-event-organiser.php b/tests/test-class-plugin-event-organiser.php index 2fe8f66..939b5b6 100644 --- a/tests/test-class-plugin-event-organiser.php +++ b/tests/test-class-plugin-event-organiser.php @@ -41,10 +41,10 @@ class Test_Event_Organiser extends WP_UnitTestCase { $this->assertContains( 'event', get_option( 'activitypub_support_post_types' ) ); $event_data = array( - 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ), - 'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ), - 'all_day' => 0, - 'schedule' => 'once', + 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ), + 'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ), + 'all_day' => 0, + 'schedule' => 'once', ); $post_data = array( @@ -67,10 +67,10 @@ class Test_Event_Organiser extends WP_UnitTestCase { public function test_transform_of_basic_event() { // Mock Event. $event_data = array( - 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ), - 'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ), - 'all_day' => 0, - 'schedule' => 'once', + 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ), + 'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ), + 'all_day' => 0, + 'schedule' => 'once', ); $post_data = array( @@ -81,7 +81,7 @@ class Test_Event_Organiser extends WP_UnitTestCase { $post_id = eo_insert_event( $post_data, $event_data ); // Call the transformer Factory. - $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) )->to_object()->to_array(); + $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) )->to_object()->to_array(); // Check that the event ActivityStreams representation contains everything as expected. $this->assertEquals( 'Event', $event_array['type'] ); -- 2.39.5 From 93564769018c0bdc629f1df2a9ce48ac2cd813b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 28 Nov 2024 22:05:15 +0100 Subject: [PATCH 04/11] fix test initialization --- tests/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6c3af80..ecaebc2 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -74,7 +74,7 @@ function _manually_load_plugin() { case 'eventprime': $plugin_file = 'eventprime-event-calendar-management/event-prime.php'; break; - case 'event-organiser': + case 'event_organiser': $plugin_file = 'event-organiser/event-organiser.php'; break; } -- 2.39.5 From e981827e0a10a7724f37510264befa0048f625ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 30 Nov 2024 11:20:31 +0100 Subject: [PATCH 05/11] basic tests for event organiser --- .../transformer/class-event-organiser.php | 25 +++++++++++++++++-- tests/bootstrap.php | 4 +-- tests/test-class-plugin-event-organiser.php | 5 +++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/includes/activitypub/transformer/class-event-organiser.php b/includes/activitypub/transformer/class-event-organiser.php index 4d65dfa..077a74f 100644 --- a/includes/activitypub/transformer/class-event-organiser.php +++ b/includes/activitypub/transformer/class-event-organiser.php @@ -20,18 +20,39 @@ use ActivityPub_Event_Bridge\Activitypub\Transformer\Event; * @since 1.0.0 */ final class Event_Organiser extends Event { + /** + * Extended constructor. + * + * The wp_object is overridden with a the wp_object with filters. This object + * also contains attributes specific to the Event organiser plugin like the + * occurrence id. + * + * @param WP_Post $wp_object The WordPress object. + * @param string $wp_taxonomy The taxonomy slug of the event post type. + */ + public function __construct( $wp_object, $wp_taxonomy ) { + parent::__construct( $wp_object, $wp_taxonomy ); + $this->wp_object = get_posts( + array( + 'ID' => $wp_object->ID, + 'post_type' => 'event', + 'suppress_filters' => false, + ) + )[0]; + } + /** * Get the end time from the event object. */ protected function get_end_time(): ?string { - return eo_get_the_end( 'Y-m-d\TH:i:s\Z', $this->wp_object->ID ); + return eo_get_the_end( 'Y-m-d\TH:i:s\Z', $this->wp_object->ID, $this->wp_object->occurrence_id ); } /** * Get the end time from the event object. */ protected function get_start_time(): string { - return eo_get_the_start( 'Y-m-d\TH:i:s\Z', $this->wp_object->ID ); + return eo_get_the_start( 'Y-m-d\TH:i:s\Z', $this->wp_object->ID, $this->wp_object->occurrence_id ); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ecaebc2..514f8c2 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -103,9 +103,9 @@ function _manually_load_plugin() { $mec_factory->install(); } - if ( 'event-organiser' === $activitypub_event_bridge_integration_filter ) { + if ( 'event_organiser' === $activitypub_event_bridge_integration_filter ) { require_once $plugin_dir . 'event-organiser/includes/event-organiser-install.php'; - eventorganiser_install(); + // eventorganiser_install(); } // At last manually load our WordPress plugin. diff --git a/tests/test-class-plugin-event-organiser.php b/tests/test-class-plugin-event-organiser.php index 939b5b6..2a1b45a 100644 --- a/tests/test-class-plugin-event-organiser.php +++ b/tests/test-class-plugin-event-organiser.php @@ -15,7 +15,7 @@ class Test_Event_Organiser extends WP_UnitTestCase { public function set_up() { parent::set_up(); - if ( ! class_exists( '\EO_Query_Result' ) ) { + if ( ! function_exists( 'eo_get_events' ) ) { self::markTestSkipped( 'Event Organiser plugin is not active.' ); } @@ -50,6 +50,7 @@ class Test_Event_Organiser extends WP_UnitTestCase { $post_data = array( 'post_title' => 'Unit Test Event', 'post_content' => 'Unit Test description.', + 'post_status' => 'publish', ); $post_id = eo_insert_event( $post_data, $event_data ); @@ -59,6 +60,7 @@ class Test_Event_Organiser extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event_Organiser::class, $transformer ); + } /** @@ -76,6 +78,7 @@ class Test_Event_Organiser extends WP_UnitTestCase { $post_data = array( 'post_title' => 'Unit Test Event', 'post_content' => 'Unit Test description.', + 'post_status' => 'publish', ); $post_id = eo_insert_event( $post_data, $event_data ); -- 2.39.5 From adfa25d1480cba783b7288c20d55d2e59eccd219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 30 Nov 2024 11:22:30 +0100 Subject: [PATCH 06/11] phpcs --- includes/activitypub/transformer/class-event-organiser.php | 2 +- tests/bootstrap.php | 5 ----- tests/test-class-plugin-event-organiser.php | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/includes/activitypub/transformer/class-event-organiser.php b/includes/activitypub/transformer/class-event-organiser.php index 077a74f..95b4bea 100644 --- a/includes/activitypub/transformer/class-event-organiser.php +++ b/includes/activitypub/transformer/class-event-organiser.php @@ -27,7 +27,7 @@ final class Event_Organiser extends Event { * also contains attributes specific to the Event organiser plugin like the * occurrence id. * - * @param WP_Post $wp_object The WordPress object. + * @param WP_Post $wp_object The WordPress object. * @param string $wp_taxonomy The taxonomy slug of the event post type. */ public function __construct( $wp_object, $wp_taxonomy ) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 514f8c2..7056b81 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -103,11 +103,6 @@ function _manually_load_plugin() { $mec_factory->install(); } - if ( 'event_organiser' === $activitypub_event_bridge_integration_filter ) { - require_once $plugin_dir . 'event-organiser/includes/event-organiser-install.php'; - // eventorganiser_install(); - } - // At last manually load our WordPress plugin. require dirname( __DIR__ ) . '/activitypub-event-bridge.php'; } diff --git a/tests/test-class-plugin-event-organiser.php b/tests/test-class-plugin-event-organiser.php index 2a1b45a..a07b5a1 100644 --- a/tests/test-class-plugin-event-organiser.php +++ b/tests/test-class-plugin-event-organiser.php @@ -60,7 +60,6 @@ class Test_Event_Organiser extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event_Organiser::class, $transformer ); - } /** -- 2.39.5 From 06d73671fe4ffaf7a6af86bf935ffa79ee4f23c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 30 Nov 2024 11:23:25 +0100 Subject: [PATCH 07/11] add install script to boostrap test --- tests/bootstrap.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7056b81..a456c24 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -103,6 +103,11 @@ function _manually_load_plugin() { $mec_factory->install(); } + if ( 'event_organiser' === $activitypub_event_bridge_integration_filter ) { + require_once $plugin_dir . 'event-organiser/includes/event-organiser-install.php'; + eventorganiser_install(); + } + // At last manually load our WordPress plugin. require dirname( __DIR__ ) . '/activitypub-event-bridge.php'; } -- 2.39.5 From 226095bd058a538b67da23e8f2e842ecf24a866d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 30 Nov 2024 11:26:46 +0100 Subject: [PATCH 08/11] run eventorganiser_install in test set_up function --- tests/bootstrap.php | 5 ----- tests/test-class-plugin-event-organiser.php | 2 ++ 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a456c24..7056b81 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -103,11 +103,6 @@ function _manually_load_plugin() { $mec_factory->install(); } - if ( 'event_organiser' === $activitypub_event_bridge_integration_filter ) { - require_once $plugin_dir . 'event-organiser/includes/event-organiser-install.php'; - eventorganiser_install(); - } - // At last manually load our WordPress plugin. require dirname( __DIR__ ) . '/activitypub-event-bridge.php'; } diff --git a/tests/test-class-plugin-event-organiser.php b/tests/test-class-plugin-event-organiser.php index a07b5a1..368443f 100644 --- a/tests/test-class-plugin-event-organiser.php +++ b/tests/test-class-plugin-event-organiser.php @@ -23,6 +23,8 @@ class Test_Event_Organiser extends WP_UnitTestCase { $aec = \ActivityPub_Event_Bridge\Setup::get_instance(); $aec->activate_activitypub_support_for_active_event_plugins(); + eventorganiser_install(); + // Delete all posts afterwards. _delete_all_posts(); } -- 2.39.5 From 9818f0bd42334fb9711af7121cd5590c9530e4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 30 Nov 2024 12:17:15 +0100 Subject: [PATCH 09/11] add test with location/venue --- .../transformer/class-event-organiser.php | 10 ++-- tests/test-class-plugin-event-organiser.php | 56 ++++++++++++++++++- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/includes/activitypub/transformer/class-event-organiser.php b/includes/activitypub/transformer/class-event-organiser.php index 95b4bea..fbbf1ea 100644 --- a/includes/activitypub/transformer/class-event-organiser.php +++ b/includes/activitypub/transformer/class-event-organiser.php @@ -67,7 +67,7 @@ final class Event_Organiser extends Event { $address = eo_get_venue_address( $venue_id ); - $address['name'] = eo_get_venue_name( $this->wp_object->ID ); + $venue_name = eo_get_venue_name( $venue_id ); $address['streetAddress'] = $address['address']; unset( $address['address'] ); @@ -88,10 +88,12 @@ final class Event_Organiser extends Event { $location = new Place(); $location->set_name( eo_get_venue_name( $this->wp_object->ID ) ); - $location->set_latitude( eo_get_venue_lat( $this->wp_object->ID ) ); - $location->set_longitude( eo_get_venue_lng( $this->wp_object->ID ) ); + $location->set_latitude( eo_get_venue_lat( $this->wp_object->ID ) ?? null ); + $location->set_longitude( eo_get_venue_lng( $this->wp_object->ID ) ?? null ); $location->set_address( $address ); + $location->set_name( $venue_name ); + $location->set_content( eo_get_venue_description( $venue_id ) ); - return $address; + return $location; } } diff --git a/tests/test-class-plugin-event-organiser.php b/tests/test-class-plugin-event-organiser.php index 368443f..55eaf5a 100644 --- a/tests/test-class-plugin-event-organiser.php +++ b/tests/test-class-plugin-event-organiser.php @@ -23,6 +23,7 @@ class Test_Event_Organiser extends WP_UnitTestCase { $aec = \ActivityPub_Event_Bridge\Setup::get_instance(); $aec->activate_activitypub_support_for_active_event_plugins(); + // Run the install script just in time which makes sure the custom tables exist and more. eventorganiser_install(); // Delete all posts afterwards. @@ -65,7 +66,7 @@ class Test_Event_Organiser extends WP_UnitTestCase { } /** - * Test transformation to ActivityPUb for basic event. + * Test transformation to ActivityPub for basic event. */ public function test_transform_of_basic_event() { // Mock Event. @@ -96,4 +97,57 @@ class Test_Event_Organiser extends WP_UnitTestCase { $this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertArrayNotHasKey( 'location', $event_array ); } + + /** + * Test transformation to ActivityPub for event with location. + */ + public function test_transform_of_event_with_location() { + // Create venue. + $venue_args = array( + 'description' => 'This is a test venue for the Fediverse.', + 'address' => 'Fediverse-Street 1337', + 'city' => 'Fediverse-Town', + 'state' => 'Fediverse-Sate', + 'postcode' => '1337', + 'country' => 'Fediverse-Country', + 'latitude' => 7.076668, + 'longitude' => 15.421371, + ); + $venue_name = 'Fediverse Venue'; + $venue = eo_insert_venue( $venue_name, $venue_args ); + + // Mock Event. + $event_data = array( + 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ), + 'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ), + 'all_day' => 0, + 'schedule' => 'once', + ); + $post_data = array( + 'post_title' => 'Unit Test Event', + 'post_content' => 'Unit Test description.', + 'post_status' => 'publish', + ); + $post_id = eo_insert_event( $post_data, $event_data ); + wp_set_object_terms( $post_id, $venue['term_id'], 'event-venue' ); + + // Call the transformer Factory. + $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) )->to_object()->to_array(); + + // Check that the event ActivityStreams representation contains everything as expected. + $this->assertEquals( 'Event', $event_array['type'] ); + $this->assertEquals( 'Unit Test Event', $event_array['name'] ); + $this->assertEquals( 'Unit Test description.', wp_strip_all_tags( $event_array['content'] ) ); + $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); + $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); + $this->assertEquals( 'external', $event_array['joinMode'] ); + $this->assertArrayHasKey( 'location', $event_array ); + $this->assertEquals( $venue_args['description'], wp_strip_all_tags( $event_array['location']['content'] ) ); + $this->assertEquals( $venue_args['address'], $event_array['location']['address']['streetAddress'] ); + $this->assertEquals( $venue_args['city'], $event_array['location']['address']['addressLocality'] ); + $this->assertEquals( $venue_args['state'], $event_array['location']['address']['addressRegion'] ); + $this->assertEquals( $venue_args['country'], $event_array['location']['address']['addressCountry'] ); + $this->assertEquals( $venue_args['postcode'], $event_array['location']['address']['postalCode'] ); + $this->assertEquals( $venue_name, $event_array['location']['name'] ); + } } -- 2.39.5 From 0b832f565053612e0661532fa6dea3fe5fe0cb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 30 Nov 2024 12:21:31 +0100 Subject: [PATCH 10/11] Add changelog --- CHANGELOG.md | 1 + README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce5ffe0..86dac31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +* Integration for Event Organiser * Integration for EventPrime – Events Calendar, Bookings and Tickets ### Fixed diff --git a/README.md b/README.md index 7e64f0f..ec4d0c8 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ We're always interested in your feedback. Feel free to reach out to us via [E-Ma ### Added +* Integration for Event Organiser * Integration for EventPrime – Events Calendar, Bookings and Tickets ### Fixed -- 2.39.5 From e2667d2ccbc33d5d7329bfc4d5a24f77b09a89fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 30 Nov 2024 12:26:04 +0100 Subject: [PATCH 11/11] update readme --- README.md | 1 + readme.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index ec4d0c8..c3d4e91 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ This plugin depends on the [ActivityPub plugin](https://wordpress.org/plugins/ac * [Modern Events Calendar Lite](https://webnus.net/modern-events-calendar/) * [GatherPress](https://gatherpress.org/) * [EventPrime – Events Calendar, Bookings and Tickets](https://wordpress.org/plugins/eventprime-event-calendar-management/) +* [Event Organiser](https://wordpress.org/plugins/event-organiser/) ## Configuration ## diff --git a/readme.txt b/readme.txt index f200dd6..e581fcb 100644 --- a/readme.txt +++ b/readme.txt @@ -58,6 +58,7 @@ This plugin depends on the [ActivityPub plugin](https://wordpress.org/plugins/ac * [Modern Events Calendar Lite](https://webnus.net/modern-events-calendar/) * [GatherPress](https://gatherpress.org/) * [EventPrime – Events Calendar, Bookings and Tickets](https://wordpress.org/plugins/eventprime-event-calendar-management/) +* [Event Organiser](https://wordpress.org/plugins/event-organiser/) == Configuration == -- 2.39.5