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/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..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 ## @@ -105,6 +106,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 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..fbbf1ea --- /dev/null +++ b/includes/activitypub/transformer/class-event-organiser.php @@ -0,0 +1,99 @@ +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, $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, $this->wp_object->occurrence_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 ); + + $venue_name = eo_get_venue_name( $venue_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 ) ?? 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 $location; + } +} 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 @@ +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. + _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', 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', + ); + + $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 ); + + // Call the transformer Factory. + $transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) ); + + // Check that we got the right 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 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 ); + + // 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->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'] ); + } +}