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 ); + } +}