From 8069f747b44750e08930e19aeacb919452b66ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 9 Oct 2024 16:51:45 +0200 Subject: [PATCH 01/10] wip: wp event manager --- .../transformer/class-events-manager.php | 1 - .../transformer/class-gatherpress.php | 1 - .../transformer/class-the-events-calendar.php | 1 - .../transformer/class-vs-event-list.php | 1 - .../transformer/class-wp-event-manager.php | 124 ++++++++++++++++++ includes/class-setup.php | 1 + includes/plugins/class-wp-event-manager.php | 72 ++++++++++ 7 files changed, 197 insertions(+), 4 deletions(-) create mode 100644 includes/activitypub/transformer/class-wp-event-manager.php create mode 100644 includes/plugins/class-wp-event-manager.php diff --git a/includes/activitypub/transformer/class-events-manager.php b/includes/activitypub/transformer/class-events-manager.php index 3acf6aa..1def3f7 100644 --- a/includes/activitypub/transformer/class-events-manager.php +++ b/includes/activitypub/transformer/class-events-manager.php @@ -11,7 +11,6 @@ namespace ActivityPub_Event_Bridge\Activitypub\Transformer; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore -use Activitypub\Activity\Extended_Object\Event; use Activitypub\Activity\Extended_Object\Place; use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer; use DateTime; diff --git a/includes/activitypub/transformer/class-gatherpress.php b/includes/activitypub/transformer/class-gatherpress.php index e3ec013..b67bc58 100644 --- a/includes/activitypub/transformer/class-gatherpress.php +++ b/includes/activitypub/transformer/class-gatherpress.php @@ -13,7 +13,6 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore use Activitypub\Activity\Extended_Object\Event as Event_Object; use Activitypub\Activity\Extended_Object\Place; -use Activitypub\Model\Blog; use ActivityPub_Event_Bridge\Activitypub\Transformer\Event; use GatherPress\Core\Event as GatherPress_Event; diff --git a/includes/activitypub/transformer/class-the-events-calendar.php b/includes/activitypub/transformer/class-the-events-calendar.php index 72e25c8..9d76aaa 100644 --- a/includes/activitypub/transformer/class-the-events-calendar.php +++ b/includes/activitypub/transformer/class-the-events-calendar.php @@ -11,7 +11,6 @@ namespace ActivityPub_Event_Bridge\Activitypub\Transformer; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore -use Activitypub\Activity\Extended_Object\Event as Event_Object; use Activitypub\Activity\Extended_Object\Place; use ActivityPub_Event_Bridge\Activitypub\Transformer\Event; use WP_Post; diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php index 35d33a2..c476404 100644 --- a/includes/activitypub/transformer/class-vs-event-list.php +++ b/includes/activitypub/transformer/class-vs-event-list.php @@ -11,7 +11,6 @@ namespace ActivityPub_Event_Bridge\Activitypub\Transformer; // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore -use Activitypub\Activity\Extended_Object\Event; use Activitypub\Activity\Extended_Object\Place; use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer; diff --git a/includes/activitypub/transformer/class-wp-event-manager.php b/includes/activitypub/transformer/class-wp-event-manager.php new file mode 100644 index 0000000..4f560b5 --- /dev/null +++ b/includes/activitypub/transformer/class-wp-event-manager.php @@ -0,0 +1,124 @@ +wp_object->ID, '_event_online', true ); + $is_online = false; + // Radio buttons. + if ( 'yes' === $is_online_text ) { + $is_online = true; + } + // Checkbox. + if ( '1' === $is_online_text ) { + $is_online = true; + } + return $is_online; + } + + /** + * Get the event location. + * + * @return array The Place. + */ + public function get_location(): ?Place { + $location = new Place(); + $location_name = get_post_meta( $this->wp_object->ID, '_event_online', true ); + $location->set_name( $location_name ); + $location->set_sensitive( null ); + $location->set_address( $location_name ); + return $location; + } + + /** + * Get the end time from the events metadata. + */ + public function get_end_time(): ?string { + $end_date = get_post_meta( $this->wp_object->ID, '_event_end_date', true ); + $end_datetime = new DateTime( $end_date ); + return \gmdate( 'Y-m-d\TH:i:s\Z', $end_datetime->getTimestamp() ); + } + + /** + * Get the end time from the events metadata. + */ + public function get_start_time(): string { + $start_date = get_post_meta( $this->wp_object->ID, '_event_start_date', true ); + $start_datetime = new DateTime( $start_date ); + return \gmdate( 'Y-m-d\TH:i:s\Z', $start_datetime->getTimestamp() ); + } + + /** + * Get the event link as an ActivityPub Link object, but as an associative array. + * + * @return array + */ + private function get_event_link_attachment(): array { + $event_link_url = get_post_meta( $this->wp_object->ID, '_event_video_url', true ); + + if ( str_starts_with( $event_link_url, 'http' ) ) { + return array( + 'type' => 'Link', + 'name' => 'Video URL', + 'href' => \esc_url( $event_link_url ), + 'mediaType' => 'text/html', + ); + } else { + return null; + } + } + + /** + * Overrides/extends the get_attachments function to also add the event Link. + */ + protected function get_attachment() { + // Get attachments via parent function. + $attachments = parent::get_attachment(); + + // The first attachment is the featured image, make sure it is compatible with Mobilizon. + if ( count( $attachments ) ) { + $attachments[0]['type'] = 'Document'; + $attachments[0]['name'] = 'Banner'; + } + + if ( $this->get_event_link_attachment() ) { + $attachments[] = $this->get_event_link_attachment(); + } + return $attachments; + } + + /** + * Get the events title/name. + * + * @return string + */ + protected function get_name(): string { + return $this->wp_object->post_title; + } +} diff --git a/includes/class-setup.php b/includes/class-setup.php index 39a4766..bafe050 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -128,6 +128,7 @@ class Setup { '\ActivityPub_Event_Bridge\Plugins\GatherPress', '\ActivityPub_Event_Bridge\Plugins\The_Events_Calendar', '\ActivityPub_Event_Bridge\Plugins\VS_Event_List', + '\ActivityPub_Event_Bridge\Plugins\WP_Event_Manager', ); /** diff --git a/includes/plugins/class-wp-event-manager.php b/includes/plugins/class-wp-event-manager.php new file mode 100644 index 0000000..e3d3493 --- /dev/null +++ b/includes/plugins/class-wp-event-manager.php @@ -0,0 +1,72 @@ + Date: Wed, 9 Oct 2024 18:03:02 +0200 Subject: [PATCH 02/10] wp event manager: small improvements --- .../transformer/class-wp-event-manager.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/includes/activitypub/transformer/class-wp-event-manager.php b/includes/activitypub/transformer/class-wp-event-manager.php index 4f560b5..8b7236a 100644 --- a/includes/activitypub/transformer/class-wp-event-manager.php +++ b/includes/activitypub/transformer/class-wp-event-manager.php @@ -48,12 +48,17 @@ final class WP_Event_Manager extends Event_Transformer { * @return array The Place. */ public function get_location(): ?Place { - $location = new Place(); $location_name = get_post_meta( $this->wp_object->ID, '_event_online', true ); - $location->set_name( $location_name ); - $location->set_sensitive( null ); - $location->set_address( $location_name ); - return $location; + + if ( $location_name ) { + $location = new Place(); + $location->set_name( $location_name ); + $location->set_sensitive( null ); + $location->set_address( $location_name ); + + return $location; + } + return null; } /** -- 2.39.5 From f0a4f251ea88252fe384a2a9164edeb07ad13f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 9 Oct 2024 18:18:25 +0200 Subject: [PATCH 03/10] add tests for wp event manager --- .forgejo/workflows/phpunit.yml | 7 +- bin/install-wp-tests.sh | 1 + tests/bootstrap.php | 3 + tests/test-class-plugin-wp-event-manager.php | 145 +++++++++++++++++++ 4 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 tests/test-class-plugin-wp-event-manager.php diff --git a/.forgejo/workflows/phpunit.yml b/.forgejo/workflows/phpunit.yml index 5bdae8d..b67d8e9 100644 --- a/.forgejo/workflows/phpunit.yml +++ b/.forgejo/workflows/phpunit.yml @@ -37,7 +37,7 @@ jobs: path: | ${{ env.WP_CORE_DIR }} ${{ env.WP_TESTS_DIR }} - key: cache-wordpress-4 + key: cache-wordpress-5 - name: Cache Composer id: cache-composer-phpunit @@ -91,5 +91,10 @@ jobs: - name: Run Integration tests for Events Manager run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=events_manager + env: + PHP_VERSION: ${{ matrix.php-version }} + + - name: Run Integration tests for WP Event Manager + run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=wp_event_manager env: PHP_VERSION: ${{ matrix.php-version }} \ No newline at end of file diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 8d495bf..0e0e4ad 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -238,6 +238,7 @@ install_wp_plugins() { install_wp_plugin very-simple-event-list install_wp_plugin gatherpress install_wp_plugin events-manager + install_wp_plugin wp-event-manager } install_wp diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f17b5f9..359543a 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -58,6 +58,9 @@ function _manually_load_plugin() { case 'gatherpress': $plugin_file = 'gatherpress/gatherpress.php'; break; + case 'wp_event_manager': + $plugin_file = 'wp-event-manager/wp-event-manager.php'; + break; } if ( $plugin_file ) { diff --git a/tests/test-class-plugin-wp-event-manager.php b/tests/test-class-plugin-wp-event-manager.php new file mode 100644 index 0000000..62edc5a --- /dev/null +++ b/tests/test-class-plugin-wp-event-manager.php @@ -0,0 +1,145 @@ +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( 'event_listing', get_option( 'activitypub_support_post_types' ) ); + + // Insert a new Event. + $wp_post_id = wp_insert_post( + array( + 'post_title' => 'WP Event Manager TestEvent', + 'post_status' => 'published', + 'post_type' => 'event_listing', + 'meta_input' => array( + 'event-start-date' => strtotime( '+10 days 15:00:00' ), + ), + ) + ); + + $wp_object = get_post( $wp_post_id ); + + // Call the transformer Factory. + $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); + + // Check that we got the right transformer. + $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\WP_Event_Manager::class, $transformer ); + } + + /** + * Test the transformation to ActivityStreams of minimal event. + */ + public function test_transform_of_minimal_event() { + // Insert a new Event. + $wp_post_id = wp_insert_post( + array( + 'post_title' => 'WP Event Manager TestEvent', + 'post_status' => 'published', + 'post_type' => 'event_listing', + 'post_content' => 'Come to my WP Event Manager event!', + 'meta_input' => array( + '_event_start_date' => strtotime( '+10 days 15:00:00' ), + ), + ) + ); + + // Transform the event to ActivityStreams. + $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array(); + + // Check that the event ActivityStreams representation contains everything as expected. + $this->assertEquals( 'Event', $event_array['type'] ); + $this->assertEquals( 'WP Event Manager TestEvent', $event_array['name'] ); + $this->assertEquals( 'Come to my WP Event Manager event!', wp_strip_all_tags( $event_array['content'] ) ); + $this->assertEquals( '', $event_array['content'] ); + $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); + $this->assertArrayNotHasKey( 'endTime', $event_array ); + $this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); + $this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); + $this->assertEquals( 'external', $event_array['joinMode'] ); + $this->assertEquals( esc_url( get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] ); + $this->assertArrayNotHasKey( 'location', $event_array ); + $this->assertEquals( 'MEETING', $event_array['category'] ); + } + + /** + * Test the transformation to ActivityStreams of minimal event. + */ + public function test_transform_of_full_online_event() { + // Insert a new Event. + $wp_post_id = wp_insert_post( + array( + 'post_title' => 'WP Event Manager TestEvent', + 'post_status' => 'published', + 'post_type' => 'event_listing', + 'post_content' => 'Come to my WP Event Manager event!', + 'meta_input' => array( + 'event-start-date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 15:00:00' ) ), + 'event-date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 16:00:00' ) ), + '_event_video_url' => 'https://event-federation.eu/meeting-room', + '_event_online' => 'yes', + ), + ) + ); + + // Transform the event to ActivityStreams. + $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array(); + + // Check that the event ActivityStreams representation contains everything as expected. + $this->assertEquals( 'Event', $event_array['type'] ); + $this->assertEquals( 'WP Event Manager TestEvent', $event_array['name'] ); + $this->assertEquals( 'Come to my WP Event Manager event!', 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 15:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); + $this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); + $this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); + $this->assertEquals( 'external', $event_array['joinMode'] ); + $this->assertEquals( true, $event_array['isOnline'] ); + $this->assertEquals( esc_url( get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] ); + $this->assertArrayNotHasKey( 'location', $event_array ); + $this->assertEquals( 'MEETING', $event_array['category'] ); + $this->assertContains( + array( + 'type' => 'Link', + 'name' => 'Video Link', + 'href' => 'https://event-federation.eu/meeting-room', + 'mediaType' => 'text/html', + ), + $event_array['attachment'] + ); + } +} -- 2.39.5 From 583fd2c78030a0b5ba390399c0102fc9d9bf8b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 9 Oct 2024 19:00:42 +0200 Subject: [PATCH 04/10] phpcs --- tests/test-class-plugin-wp-event-manager.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test-class-plugin-wp-event-manager.php b/tests/test-class-plugin-wp-event-manager.php index 62edc5a..bee4a4c 100644 --- a/tests/test-class-plugin-wp-event-manager.php +++ b/tests/test-class-plugin-wp-event-manager.php @@ -15,8 +15,8 @@ class Test_WP_Event_Manager extends WP_UnitTestCase { public function set_up() { parent::set_up(); - if ( ! function_exists( 'vsel_custom_post_type' ) ) { - self::markTestSkipped( 'VS Event List plugin is not active.' ); + if ( ! function_exists( 'wp_event_manager_notify_new_user' ) ) { + self::markTestSkipped( 'WP Event Manager plugin is not active.' ); } // Make sure that ActivityPub support is enabled for The Events Calendar. @@ -103,11 +103,11 @@ class Test_WP_Event_Manager extends WP_UnitTestCase { // Insert a new Event. $wp_post_id = wp_insert_post( array( - 'post_title' => 'WP Event Manager TestEvent', - 'post_status' => 'published', - 'post_type' => 'event_listing', + 'post_title' => 'WP Event Manager TestEvent', + 'post_status' => 'published', + 'post_type' => 'event_listing', 'post_content' => 'Come to my WP Event Manager event!', - 'meta_input' => array( + 'meta_input' => array( 'event-start-date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 15:00:00' ) ), 'event-date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 16:00:00' ) ), '_event_video_url' => 'https://event-federation.eu/meeting-room', -- 2.39.5 From 5b0f6f4b28f541f1a14404847534e14f520bfc91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 9 Oct 2024 19:42:33 +0200 Subject: [PATCH 05/10] fix return type --- includes/activitypub/transformer/class-wp-event-manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/activitypub/transformer/class-wp-event-manager.php b/includes/activitypub/transformer/class-wp-event-manager.php index 8b7236a..f66d061 100644 --- a/includes/activitypub/transformer/class-wp-event-manager.php +++ b/includes/activitypub/transformer/class-wp-event-manager.php @@ -82,9 +82,9 @@ final class WP_Event_Manager extends Event_Transformer { /** * Get the event link as an ActivityPub Link object, but as an associative array. * - * @return array + * @return ?array */ - private function get_event_link_attachment(): array { + private function get_event_link_attachment(): ?array { $event_link_url = get_post_meta( $this->wp_object->ID, '_event_video_url', true ); if ( str_starts_with( $event_link_url, 'http' ) ) { -- 2.39.5 From a54b9c2054345284f67c5baddd193b440ca7dc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 9 Oct 2024 20:08:21 +0200 Subject: [PATCH 06/10] fix tests --- composer.json | 8 ++++--- .../transformer/class-wp-event-manager.php | 23 ++++++++++++++----- tests/test-class-plugin-vs-event-list.php | 10 ++++---- tests/test-class-plugin-wp-event-manager.php | 6 ++--- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 44b5406..1b3bb36 100644 --- a/composer.json +++ b/composer.json @@ -50,15 +50,17 @@ "@test-vs-event-list", "@test-the-events-calendar", "@test-gatherpress", - "@test-events-manager" + "@test-events-manager", + "@test-wp-event-manager" ], "test-debug": [ "@prepare-test", - "@test-gatherpress" + "@test-wp-event-manager" ], "test-vs-event-list": "phpunit --filter=vs_event_list", "test-the-events-calendar": "phpunit --filter=the_events_calendar", "test-gatherpress": "phpunit --filter=gatherpress", - "test-events-manager": "phpunit --filter=events_manager" + "test-events-manager": "phpunit --filter=events_manager", + "test-wp-event-manager": "phpunit --filter=wp_event_manager" } } diff --git a/includes/activitypub/transformer/class-wp-event-manager.php b/includes/activitypub/transformer/class-wp-event-manager.php index f66d061..1e6c3bd 100644 --- a/includes/activitypub/transformer/class-wp-event-manager.php +++ b/includes/activitypub/transformer/class-wp-event-manager.php @@ -63,20 +63,31 @@ final class WP_Event_Manager extends Event_Transformer { /** * Get the end time from the events metadata. + * + * @return ?string The events end-datetime if is set, null otherwise. */ public function get_end_time(): ?string { - $end_date = get_post_meta( $this->wp_object->ID, '_event_end_date', true ); - $end_datetime = new DateTime( $end_date ); - return \gmdate( 'Y-m-d\TH:i:s\Z', $end_datetime->getTimestamp() ); + $end_date = get_post_meta( $this->wp_object->ID, '_event_end_date', true ); + if ( $end_date ) { + $end_datetime = new DateTime( $end_date ); + return \gmdate( 'Y-m-d\TH:i:s\Z', $end_datetime->getTimestamp() ); + } + return null; } /** * Get the end time from the events metadata. */ public function get_start_time(): string { - $start_date = get_post_meta( $this->wp_object->ID, '_event_start_date', true ); - $start_datetime = new DateTime( $start_date ); - return \gmdate( 'Y-m-d\TH:i:s\Z', $start_datetime->getTimestamp() ); + $start_date = get_post_meta( $this->wp_object->ID, '_event_start_date', true ); + if ( ! is_numeric( $start_date ) ) { + $start_datetime = new DateTime( $start_date ); + $start_timestamp = $start_datetime->getTimestamp(); + } else { + $start_timestamp = (int) $start_date; + } + + return \gmdate( 'Y-m-d\TH:i:s\Z', $start_timestamp ); } /** diff --git a/tests/test-class-plugin-vs-event-list.php b/tests/test-class-plugin-vs-event-list.php index 48e513d..d15e7ef 100644 --- a/tests/test-class-plugin-vs-event-list.php +++ b/tests/test-class-plugin-vs-event-list.php @@ -44,7 +44,7 @@ class Test_VS_Event_List extends WP_UnitTestCase { $wp_post_id = wp_insert_post( array( 'post_title' => 'VSEL Test Event', - 'post_status' => 'published', + 'post_status' => 'publish', 'post_type' => 'event', 'meta_input' => array( 'event-start-date' => strtotime( '+10 days 15:00:00' ), @@ -69,7 +69,7 @@ class Test_VS_Event_List extends WP_UnitTestCase { $wp_post_id = wp_insert_post( array( 'post_title' => 'VSEL Test Event', - 'post_status' => 'published', + 'post_status' => 'publish', 'post_type' => 'event', 'meta_input' => array( 'event-start-date' => strtotime( '+10 days 15:00:00' ), @@ -102,7 +102,7 @@ class Test_VS_Event_List extends WP_UnitTestCase { $wp_post_id = wp_insert_post( array( 'post_title' => 'VSEL Test Event', - 'post_status' => 'published', + 'post_status' => 'publish', 'post_type' => 'event', 'meta_input' => array( 'event-start-date' => strtotime( '+10 days 15:00:00' ), @@ -147,7 +147,7 @@ class Test_VS_Event_List extends WP_UnitTestCase { $wp_post_id = wp_insert_post( array( 'post_title' => 'VSEL Test Event', - 'post_status' => 'published', + 'post_status' => 'publish', 'post_type' => 'event', 'meta_input' => array( 'event-start-date' => strtotime( '+10 days 15:00:00' ), @@ -182,7 +182,7 @@ class Test_VS_Event_List extends WP_UnitTestCase { $wp_post_id = wp_insert_post( array( 'post_title' => 'VSEL Test Event', - 'post_status' => 'published', + 'post_status' => 'publish', 'post_type' => 'event', 'meta_input' => array( 'event-start-date' => strtotime( '+10 days 15:00:00' ), diff --git a/tests/test-class-plugin-wp-event-manager.php b/tests/test-class-plugin-wp-event-manager.php index bee4a4c..3cfd488 100644 --- a/tests/test-class-plugin-wp-event-manager.php +++ b/tests/test-class-plugin-wp-event-manager.php @@ -44,7 +44,7 @@ class Test_WP_Event_Manager extends WP_UnitTestCase { $wp_post_id = wp_insert_post( array( 'post_title' => 'WP Event Manager TestEvent', - 'post_status' => 'published', + 'post_status' => 'publish', 'post_type' => 'event_listing', 'meta_input' => array( 'event-start-date' => strtotime( '+10 days 15:00:00' ), @@ -69,7 +69,7 @@ class Test_WP_Event_Manager extends WP_UnitTestCase { $wp_post_id = wp_insert_post( array( 'post_title' => 'WP Event Manager TestEvent', - 'post_status' => 'published', + 'post_status' => 'publish', 'post_type' => 'event_listing', 'post_content' => 'Come to my WP Event Manager event!', 'meta_input' => array( @@ -104,7 +104,7 @@ class Test_WP_Event_Manager extends WP_UnitTestCase { $wp_post_id = wp_insert_post( array( 'post_title' => 'WP Event Manager TestEvent', - 'post_status' => 'published', + 'post_status' => 'publish', 'post_type' => 'event_listing', 'post_content' => 'Come to my WP Event Manager event!', 'meta_input' => array( -- 2.39.5 From 8038d92cdb31a7eba0e97fddcde1f73be376d595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 9 Oct 2024 20:10:47 +0200 Subject: [PATCH 07/10] fix start time in mockup event --- tests/test-class-plugin-wp-event-manager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-class-plugin-wp-event-manager.php b/tests/test-class-plugin-wp-event-manager.php index 3cfd488..2a522c9 100644 --- a/tests/test-class-plugin-wp-event-manager.php +++ b/tests/test-class-plugin-wp-event-manager.php @@ -108,10 +108,10 @@ class Test_WP_Event_Manager extends WP_UnitTestCase { 'post_type' => 'event_listing', 'post_content' => 'Come to my WP Event Manager event!', 'meta_input' => array( - 'event-start-date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 15:00:00' ) ), - 'event-date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 16:00:00' ) ), - '_event_video_url' => 'https://event-federation.eu/meeting-room', - '_event_online' => 'yes', + '_event_start_date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 15:00:00' ) ), + '_event_end_date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 16:00:00' ) ), + '_event_video_url' => 'https://event-federation.eu/meeting-room', + '_event_online' => 'yes', ), ) ); -- 2.39.5 From 376e33756fc43d5686ac609e60ad6f80df1be68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 9 Oct 2024 20:40:24 +0200 Subject: [PATCH 08/10] fix tests --- tests/test-class-plugin-wp-event-manager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test-class-plugin-wp-event-manager.php b/tests/test-class-plugin-wp-event-manager.php index 2a522c9..e1e9d70 100644 --- a/tests/test-class-plugin-wp-event-manager.php +++ b/tests/test-class-plugin-wp-event-manager.php @@ -85,7 +85,6 @@ class Test_WP_Event_Manager extends WP_UnitTestCase { $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'WP Event Manager TestEvent', $event_array['name'] ); $this->assertEquals( 'Come to my WP Event Manager event!', wp_strip_all_tags( $event_array['content'] ) ); - $this->assertEquals( '', $event_array['content'] ); $this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertArrayNotHasKey( 'endTime', $event_array ); $this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); -- 2.39.5 From 0e3a904fa9e04ebd43b0f82fdda2f2a56314bc45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 9 Oct 2024 20:49:30 +0200 Subject: [PATCH 09/10] fix tests --- includes/activitypub/transformer/class-wp-event-manager.php | 4 ++-- tests/test-class-plugin-wp-event-manager.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/activitypub/transformer/class-wp-event-manager.php b/includes/activitypub/transformer/class-wp-event-manager.php index 1e6c3bd..6330152 100644 --- a/includes/activitypub/transformer/class-wp-event-manager.php +++ b/includes/activitypub/transformer/class-wp-event-manager.php @@ -48,7 +48,7 @@ final class WP_Event_Manager extends Event_Transformer { * @return array The Place. */ public function get_location(): ?Place { - $location_name = get_post_meta( $this->wp_object->ID, '_event_online', true ); + $location_name = get_post_meta( $this->wp_object->ID, '_event_location', true ); if ( $location_name ) { $location = new Place(); @@ -101,7 +101,7 @@ final class WP_Event_Manager extends Event_Transformer { if ( str_starts_with( $event_link_url, 'http' ) ) { return array( 'type' => 'Link', - 'name' => 'Video URL', + 'name' => \esc_html__( 'Video URL', 'activitypub-event-bridge' ), 'href' => \esc_url( $event_link_url ), 'mediaType' => 'text/html', ); diff --git a/tests/test-class-plugin-wp-event-manager.php b/tests/test-class-plugin-wp-event-manager.php index e1e9d70..f0bc7da 100644 --- a/tests/test-class-plugin-wp-event-manager.php +++ b/tests/test-class-plugin-wp-event-manager.php @@ -134,7 +134,7 @@ class Test_WP_Event_Manager extends WP_UnitTestCase { $this->assertContains( array( 'type' => 'Link', - 'name' => 'Video Link', + 'name' => __( 'Video URL', 'activitypub-event-bridge' ), 'href' => 'https://event-federation.eu/meeting-room', 'mediaType' => 'text/html', ), -- 2.39.5 From 804303603d2306b31419b1af90e6417a315b9363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 10 Oct 2024 14:24:19 +0200 Subject: [PATCH 10/10] add tests or text address location --- tests/test-class-plugin-wp-event-manager.php | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test-class-plugin-wp-event-manager.php b/tests/test-class-plugin-wp-event-manager.php index f0bc7da..318a295 100644 --- a/tests/test-class-plugin-wp-event-manager.php +++ b/tests/test-class-plugin-wp-event-manager.php @@ -141,4 +141,42 @@ class Test_WP_Event_Manager extends WP_UnitTestCase { $event_array['attachment'] ); } + + /** + * Test the transformation to ActivityStreams of minimal event. + */ + public function test_transform_of_event_with_location() { + // Insert a new Event. + $wp_post_id = wp_insert_post( + array( + 'post_title' => 'WP Event Manager TestEvent', + 'post_status' => 'publish', + 'post_type' => 'event_listing', + 'post_content' => 'Come to my WP Event Manager event!', + 'meta_input' => array( + '_event_start_date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 15:00:00' ) ), + '_event_end_date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 16:00:00' ) ), + '_event_location' => 'Some text location', + '_event_online' => 'no', + ), + ) + ); + + // Transform the event to ActivityStreams. + $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array(); + + // Check that the event ActivityStreams representation contains everything as expected. + $this->assertEquals( 'Event', $event_array['type'] ); + $this->assertEquals( 'WP Event Manager TestEvent', $event_array['name'] ); + $this->assertEquals( 'Come to my WP Event Manager event!', 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 15:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); + $this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); + $this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); + $this->assertEquals( 'external', $event_array['joinMode'] ); + $this->assertEquals( false, $event_array['isOnline'] ); + $this->assertEquals( esc_url( get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] ); + $this->assertArrayHasKey( 'location', $event_array ); + $this->assertEquals( 'Some text location', $event_array['location']['address'] ); + } } -- 2.39.5