From dedc0079ac4b44c2d1e8085f5c603cb273a94448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 12 Oct 2024 10:34:21 +0200 Subject: [PATCH 1/6] wip --- .../activitypub/transformer/class-eventin.php | 63 +++++++++++++++++++ includes/class-setup.php | 1 + includes/plugins/class-eventin.php | 60 ++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 includes/activitypub/transformer/class-eventin.php create mode 100644 includes/plugins/class-eventin.php diff --git a/includes/activitypub/transformer/class-eventin.php b/includes/activitypub/transformer/class-eventin.php new file mode 100644 index 0000000..b95393e --- /dev/null +++ b/includes/activitypub/transformer/class-eventin.php @@ -0,0 +1,63 @@ +event_model = new Event_Model( $this->wp_object->ID ); + } + + /** + * Get the end time from the event object. + */ + protected function get_start_time(): string { + return \gmdate( 'Y-m-d\TH:i:s\Z', \time() ); + } + + /** + * Get status of the tribe event + * + * @return string status of the event + */ + public function get_status(): ?string { + return 'CONFIRMED'; + } +} diff --git a/includes/class-setup.php b/includes/class-setup.php index bafe050..e03c7d0 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -129,6 +129,7 @@ class Setup { '\ActivityPub_Event_Bridge\Plugins\The_Events_Calendar', '\ActivityPub_Event_Bridge\Plugins\VS_Event_List', '\ActivityPub_Event_Bridge\Plugins\WP_Event_Manager', + '\ActivityPub_Event_Bridge\Plugins\Eventin', ); /** diff --git a/includes/plugins/class-eventin.php b/includes/plugins/class-eventin.php new file mode 100644 index 0000000..fcab7c8 --- /dev/null +++ b/includes/plugins/class-eventin.php @@ -0,0 +1,60 @@ + Date: Sat, 12 Oct 2024 13:52:06 +0200 Subject: [PATCH 2/6] initial draft --- .forgejo/workflows/phpunit.yml | 7 +- bin/install-wp-tests.sh | 1 + composer.json | 10 +- .../activitypub/transformer/class-eventin.php | 117 ++++++++++++++++-- tests/bootstrap.php | 6 + tests/test-class-plugin-eventin.php | 64 ++++++++++ 6 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 tests/test-class-plugin-eventin.php diff --git a/.forgejo/workflows/phpunit.yml b/.forgejo/workflows/phpunit.yml index b67d8e9..aec7273 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-5 + key: cache-wordpress-8 - name: Cache Composer id: cache-composer-phpunit @@ -96,5 +96,10 @@ jobs: - 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 }} + + - name: Run Integration tests for Eventin (WP Event Solution) + run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=wp_event_solution 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 0e0e4ad..759ad25 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -239,6 +239,7 @@ install_wp_plugins() { install_wp_plugin gatherpress install_wp_plugin events-manager install_wp_plugin wp-event-manager + install_wp_plugin wp-event-solution } install_wp diff --git a/composer.json b/composer.json index 1b3bb36..940dff0 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "menrath/wordpress-activitypub-event-bridge", + "version": "1.0.0", "description": "The ActivityPub Event Bridge help for event custom post types to federate properly.", "type": "wordpress-plugin", "require": { @@ -51,16 +52,19 @@ "@test-the-events-calendar", "@test-gatherpress", "@test-events-manager", - "@test-wp-event-manager" + "@test-wp-event-manager", + "@test-eventin" ], "test-debug": [ "@prepare-test", - "@test-wp-event-manager" + "@test-eventin" ], "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-wp-event-manager": "phpunit --filter=wp_event_manager" + "test-wp-event-manager": "phpunit --filter=wp_event_manager", + "test-eventin": "phpunit --filter=eventin", + "test-all": "phpunit" } } diff --git a/includes/activitypub/transformer/class-eventin.php b/includes/activitypub/transformer/class-eventin.php index b95393e..db80179 100644 --- a/includes/activitypub/transformer/class-eventin.php +++ b/includes/activitypub/transformer/class-eventin.php @@ -15,8 +15,12 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore use Activitypub\Activity\Extended_Object\Place; use ActivityPub_Event_Bridge\Activitypub\Transformer\Event; +use DateTime; +use DateTimeZone; use Etn\Core\Event\Event_Model; +use function Activitypub\esc_hashtag; + /** * ActivityPub Transformer for Events managed with Eventin. * @@ -48,16 +52,115 @@ final class Eventin extends Event { /** * Get the end time from the event object. */ - protected function get_start_time(): string { - return \gmdate( 'Y-m-d\TH:i:s\Z', \time() ); + public function get_start_time(): string { + $datetime = new DateTime( $this->event_model->get_start_datetime(), new DateTimeZone( $this->event_model->get_timezone() ) ); + return \gmdate( 'Y-m-d\TH:i:s\Z', $datetime->getTimestamp() ); } /** - * Get status of the tribe event - * - * @return string status of the event + * Get the end time from the event object. */ - public function get_status(): ?string { - return 'CONFIRMED'; + public function get_end_time(): string { + $datetime = new DateTime( $this->event_model->get_end_datetime(), new DateTimeZone( $this->event_model->get_timezone() ) ); + return \gmdate( 'Y-m-d\TH:i:s\Z', $datetime->getTimestamp() ); + } + + /** + * Get the timezone of the event. + */ + public function get_timezone(): string { + return $this->event_model->get_timezone(); + } + + /** + * Get whether the event is online. + * + * @return bool + */ + public function get_is_online(): bool { + return 'online' === $this->event_model->__get( 'event_type' ) ? true : false; + } + + /** + * Maybe add online link to attachments. + * + * @return array + */ + public function get_attachment(): array { + $attachment = parent::get_attachment(); + + $location = (array) $this->event_model->__get( 'location' ); + if ( array_key_exists( 'integration', $location ) && array_key_exists( $location['integration'], $location ) ) { + $online_link = array( + 'type' => 'Link', + 'mediaType' => 'text/html', + 'name' => $location[ $location['integration'] ], + 'href' => $location[ $location['integration'] ], + ); + $attachment[] = $online_link; + } + return $attachment; + } + + /** + * Compose the events tags. + */ + public function get_tag() { + // The parent tag function also fetches the mentions. + $tags = parent::get_tag(); + + $post_tags = \wp_get_post_terms( $this->wp_object->ID, 'etn_tags' ); + $post_categories = \wp_get_post_terms( $this->wp_object->ID, 'etn_category' ); + + if ( ! is_wp_error( $post_tags ) && $post_tags ) { + foreach ( $post_tags as $term ) { + $tag = array( + 'type' => 'Hashtag', + 'href' => \esc_url( \get_tag_link( $term->term_id ) ), + 'name' => esc_hashtag( $term->name ), + ); + $tags[] = $tag; + } + } + + if ( ! is_wp_error( $post_categories ) && $post_categories ) { + foreach ( $post_categories as $term ) { + $tag = array( + 'type' => 'Hashtag', + 'href' => \esc_url( \get_tag_link( $term->term_id ) ), + 'name' => esc_hashtag( $term->name ), + ); + $tags[] = $tag; + } + } + + if ( empty( $tags ) ) { + return null; + } + + return $tags; + } + + /** + * Get the location. + * + * @return ?Place + */ + public function get_location(): ?Place { + $location = (array) $this->event_model->__get( 'location' ); + + if ( ! array_key_exists( 'address', $location ) ) { + return null; + } + + $place = new Place(); + + $address = $location['address']; + + $place->set_name( $address ); + $place->set_address( $address ); + $place->set_sensitive( null); + + return $place; } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 359543a..ece3323 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -43,6 +43,8 @@ function _manually_load_plugin() { } } + update_option( 'purchase_history_table_structure_migration_done', true ); + $plugin_file = null; // See if we want to run integration tests for a specific event-plugin. switch ( $activitypub_event_extension_integration_filter ) { @@ -55,6 +57,9 @@ function _manually_load_plugin() { case 'events_manager': $plugin_file = 'events-manager/events-manager.php'; break; + case 'eventin': + $plugin_file = 'wp-event-solution/eventin.php'; + break; case 'gatherpress': $plugin_file = 'gatherpress/gatherpress.php'; break; @@ -66,6 +71,7 @@ function _manually_load_plugin() { if ( $plugin_file ) { // Manually load the event plugin. require_once $plugin_dir . $plugin_file; + update_option( 'purchase_history_table_structure_migration_done', true ); $current = get_option( 'active_plugins', array() ); $current[] = $plugin_file; sort( $current ); diff --git a/tests/test-class-plugin-eventin.php b/tests/test-class-plugin-eventin.php new file mode 100644 index 0000000..0303265 --- /dev/null +++ b/tests/test-class-plugin-eventin.php @@ -0,0 +1,64 @@ +activate_activitypub_support_for_active_event_plugins(); + + // Delete all posts afterwards. + _delete_all_posts(); + } + + /** + * Test that the right transformer gets applied. + */ + public function test_eventin_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( 'etn', get_option( 'activitypub_support_post_types' ) ); + + // Create a Eventin Event without content. + $event_model = new \Etn\Core\Event\Event_Model(); + $event_model->create( + array( + 'post_status' => 'publish', + 'post_title' => 'Eventin Test Event Title', + 'post_content' => 'Eventin Test Event Description', + 'etn_start_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ), + 'etn_end_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ), + 'etn_start_time' => \gmdate( 'H:i', strtotime( '+10 days 15:00:00' ) ), + 'etn_end_time' => \gmdate( 'H:i', strtotime( '+10 days 15:00:00' ) ), + 'etn_timezone' => 'Europe/Vienna', + ) + ); + + // Call the transformer Factory. + $transformer = \Activitypub\Transformer\Factory::get_transformer( $event_model->id ); + + // Check that we got the right transformer. + $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Eventin::class, $transformer ); + } +} -- 2.39.5 From 960f80ae28bdb50207fa04dc1c3792de9e10c379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 12 Oct 2024 13:59:50 +0200 Subject: [PATCH 3/6] fix tests --- includes/activitypub/transformer/class-eventin.php | 2 +- tests/bootstrap.php | 2 ++ tests/test-class-plugin-eventin.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/activitypub/transformer/class-eventin.php b/includes/activitypub/transformer/class-eventin.php index db80179..7b4dab7 100644 --- a/includes/activitypub/transformer/class-eventin.php +++ b/includes/activitypub/transformer/class-eventin.php @@ -159,7 +159,7 @@ final class Eventin extends Event { $place->set_name( $address ); $place->set_address( $address ); - $place->set_sensitive( null); + $place->set_sensitive( null ); return $place; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ece3323..4bbd83a 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -43,7 +43,9 @@ function _manually_load_plugin() { } } + // Hot fixes for eventin. update_option( 'purchase_history_table_structure_migration_done', true ); + update_option( 'etn_wizard', 'active' ); $plugin_file = null; // See if we want to run integration tests for a specific event-plugin. diff --git a/tests/test-class-plugin-eventin.php b/tests/test-class-plugin-eventin.php index 0303265..504045e 100644 --- a/tests/test-class-plugin-eventin.php +++ b/tests/test-class-plugin-eventin.php @@ -56,7 +56,7 @@ class Test_Eventin extends WP_UnitTestCase { ); // Call the transformer Factory. - $transformer = \Activitypub\Transformer\Factory::get_transformer( $event_model->id ); + $transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $event_model->id ) ); // Check that we got the right transformer. $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Eventin::class, $transformer ); -- 2.39.5 From a70c188922f7d005f2c5e7d2facf476442a32df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 12 Oct 2024 14:03:11 +0200 Subject: [PATCH 4/6] run unit tests for eventin --- .forgejo/workflows/phpunit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/phpunit.yml b/.forgejo/workflows/phpunit.yml index aec7273..3cb7904 100644 --- a/.forgejo/workflows/phpunit.yml +++ b/.forgejo/workflows/phpunit.yml @@ -100,6 +100,6 @@ jobs: PHP_VERSION: ${{ matrix.php-version }} - name: Run Integration tests for Eventin (WP Event Solution) - run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=wp_event_solution + run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=eventin env: PHP_VERSION: ${{ matrix.php-version }} \ No newline at end of file -- 2.39.5 From aaa0ffc026d7fafd0351b2fa4312e6980c326c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 12 Oct 2024 14:26:35 +0200 Subject: [PATCH 5/6] todo: fix timezones --- tests/test-class-plugin-eventin.php | 45 ++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/test-class-plugin-eventin.php b/tests/test-class-plugin-eventin.php index 504045e..a4acc05 100644 --- a/tests/test-class-plugin-eventin.php +++ b/tests/test-class-plugin-eventin.php @@ -51,7 +51,7 @@ class Test_Eventin extends WP_UnitTestCase { 'etn_end_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ), 'etn_start_time' => \gmdate( 'H:i', strtotime( '+10 days 15:00:00' ) ), 'etn_end_time' => \gmdate( 'H:i', strtotime( '+10 days 15:00:00' ) ), - 'etn_timezone' => 'Europe/Vienna', + 'event_timezone' => 'Europe/Vienna', ) ); @@ -61,4 +61,47 @@ class Test_Eventin extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Eventin::class, $transformer ); } + + /** + * Test that the right transformer gets applied. + */ + public function test_eventin_test_minimal_event() { + // 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( 'etn', get_option( 'activitypub_support_post_types' ) ); + + // Create a Eventin Event without content. + $event = new \Etn\Core\Event\Event_Model(); + $event->create( + array( + 'post_status' => 'publish', + 'post_title' => 'Eventin Test Event Title', + 'post_content' => 'Eventin Test Event Description', + 'etn_start_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ), + 'etn_end_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ), + 'etn_start_time' => '03:00 PM', + 'etn_end_time' => '04:00 PM', + 'event_timezone' => 'Europe/Vienna', + ) + ); + + // Call the transformer Factory. + $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) )->to_object()->to_array(); + + $this->assertEquals( 'Event', $event_array['type'] ); + $this->assertEquals( 'Eventin Test Event Title', $event_array['name'] ); + $this->assertEquals( 'Eventin Test Event 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( comments_open( $event->id ), $event_array['commentsEnabled'] ); + $this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); + $this->assertEquals( 'external', $event_array['joinMode'] ); + $this->assertArrayNotHasKey( 'location', $event_array ); + $this->assertArrayNotHasKey( 'endTime', $event_array ); + $this->assertEquals( 'MEETING', $event_array['category'] ); + } } -- 2.39.5 From 7151f186b948f380195679a361a239e128df96d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 12 Oct 2024 20:20:17 +0200 Subject: [PATCH 6/6] add more tests --- .../activitypub/transformer/class-eventin.php | 6 +- tests/test-class-plugin-eventin.php | 142 +++++++++++++----- 2 files changed, 107 insertions(+), 41 deletions(-) diff --git a/includes/activitypub/transformer/class-eventin.php b/includes/activitypub/transformer/class-eventin.php index 7b4dab7..b47d93e 100644 --- a/includes/activitypub/transformer/class-eventin.php +++ b/includes/activitypub/transformer/class-eventin.php @@ -53,16 +53,14 @@ final class Eventin extends Event { * Get the end time from the event object. */ public function get_start_time(): string { - $datetime = new DateTime( $this->event_model->get_start_datetime(), new DateTimeZone( $this->event_model->get_timezone() ) ); - return \gmdate( 'Y-m-d\TH:i:s\Z', $datetime->getTimestamp() ); + return \gmdate( 'Y-m-d\TH:i:s\Z', strtotime( $this->event_model->get_start_datetime() ) ); } /** * Get the end time from the event object. */ public function get_end_time(): string { - $datetime = new DateTime( $this->event_model->get_end_datetime(), new DateTimeZone( $this->event_model->get_timezone() ) ); - return \gmdate( 'Y-m-d\TH:i:s\Z', $datetime->getTimestamp() ); + return \gmdate( 'Y-m-d\TH:i:s\Z', strtotime( $this->event_model->get_end_datetime() ) ); } /** diff --git a/tests/test-class-plugin-eventin.php b/tests/test-class-plugin-eventin.php index a4acc05..d844922 100644 --- a/tests/test-class-plugin-eventin.php +++ b/tests/test-class-plugin-eventin.php @@ -9,6 +9,22 @@ * Test cases for WP Event Solution. */ class Test_Eventin extends WP_UnitTestCase { + /** + * Basic Mock-up event. + */ + private function get_mockup_event(): array { + return array( + 'post_status' => 'publish', + 'post_title' => 'Eventin Test Event Title', + 'post_content' => 'Eventin Test Event Description', + 'etn_start_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ), + 'etn_end_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ), + 'etn_start_time' => \gmdate( 'H:i', strtotime( '+10 days 15:00:00' ) ), + 'etn_end_time' => \gmdate( 'H:i', strtotime( '+10 days 16:00:00' ) ), + 'event_timezone' => 'Europe/Vienna', + ); + } + /** * Override the setup function, so that tests don't run if the Events Calendar is not active. */ @@ -41,22 +57,11 @@ class Test_Eventin extends WP_UnitTestCase { $this->assertContains( 'etn', get_option( 'activitypub_support_post_types' ) ); // Create a Eventin Event without content. - $event_model = new \Etn\Core\Event\Event_Model(); - $event_model->create( - array( - 'post_status' => 'publish', - 'post_title' => 'Eventin Test Event Title', - 'post_content' => 'Eventin Test Event Description', - 'etn_start_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ), - 'etn_end_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ), - 'etn_start_time' => \gmdate( 'H:i', strtotime( '+10 days 15:00:00' ) ), - 'etn_end_time' => \gmdate( 'H:i', strtotime( '+10 days 15:00:00' ) ), - 'event_timezone' => 'Europe/Vienna', - ) - ); + $event = new \Etn\Core\Event\Event_Model(); + $event->create( $this->get_mockup_event() ); // Call the transformer Factory. - $transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $event_model->id ) ); + $transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) ); // Check that we got the right transformer. $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Eventin::class, $transformer ); @@ -66,29 +71,9 @@ class Test_Eventin extends WP_UnitTestCase { * Test that the right transformer gets applied. */ public function test_eventin_test_minimal_event() { - // 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( 'etn', get_option( 'activitypub_support_post_types' ) ); - // Create a Eventin Event without content. $event = new \Etn\Core\Event\Event_Model(); - $event->create( - array( - 'post_status' => 'publish', - 'post_title' => 'Eventin Test Event Title', - 'post_content' => 'Eventin Test Event Description', - 'etn_start_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ), - 'etn_end_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ), - 'etn_start_time' => '03:00 PM', - 'etn_end_time' => '04:00 PM', - 'event_timezone' => 'Europe/Vienna', - ) - ); + $event->create( $this->get_mockup_event() ); // Call the transformer Factory. $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) )->to_object()->to_array(); @@ -96,12 +81,95 @@ class Test_Eventin extends WP_UnitTestCase { $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Eventin Test Event Title', $event_array['name'] ); $this->assertEquals( 'Eventin Test Event 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\TH:i:s\Z', strtotime( '+10 days 15:00:00' ) ), $event_array['startTime'] ); + $this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 16:00:00' ) ), $event_array['endTime'] ); + $this->assertEquals( 'Europe/Vienna', $event_array['timezone'] ); $this->assertEquals( comments_open( $event->id ), $event_array['commentsEnabled'] ); $this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertArrayNotHasKey( 'location', $event_array ); - $this->assertArrayNotHasKey( 'endTime', $event_array ); $this->assertEquals( 'MEETING', $event_array['category'] ); + $this->assertEquals( false, $event_array['isOnline'] ); + } + + /** + * Test that the right transformer gets applied. + */ + public function test_eventin_test_online_event_with_custom_link() { + // Create a Eventin Event without content. + $event = new \Etn\Core\Event\Event_Model(); + $args = array_merge( + $this->get_mockup_event(), + array( + 'event_type' => 'online', + 'location' => array( + 'integration' => 'custom_url', + 'custom_url' => 'https://jit.si/eventmeeting', + ), + ) + ); + $event->create( $args ); + + // Call the transformer Factory. + $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) )->to_object()->to_array(); + + $this->assertEquals( 'Event', $event_array['type'] ); + $this->assertEquals( 'Eventin Test Event Title', $event_array['name'] ); + $this->assertEquals( 'Eventin Test Event Description', wp_strip_all_tags( $event_array['content'] ) ); + $this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 15:00:00' ) ), $event_array['startTime'] ); + $this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 16:00:00' ) ), $event_array['endTime'] ); + $this->assertEquals( 'Europe/Vienna', $event_array['timezone'] ); + $this->assertEquals( comments_open( $event->id ), $event_array['commentsEnabled'] ); + $this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); + $this->assertEquals( 'external', $event_array['joinMode'] ); + $this->assertArrayNotHasKey( 'location', $event_array ); + $this->assertEquals( 'MEETING', $event_array['category'] ); + $this->assertEquals( true, $event_array['isOnline'] ); + $this->assertContains( + array( + 'type' => 'Link', + 'mediaType' => 'text/html', + 'name' => 'https://jit.si/eventmeeting', + 'href' => 'https://jit.si/eventmeeting', + ), + $event_array['attachment'] + ); + } + + + /** + * Test that the right transformer gets applied. + */ + public function test_eventin_test_online_event_with_physical_location() { + // Create a Eventin Event without content. + $event = new \Etn\Core\Event\Event_Model(); + $args = array_merge( + $this->get_mockup_event(), + array( + 'event_type' => 'offline', + 'location' => array( + 'address' => 'The NlNet center', + ), + ) + ); + $event->create( $args ); + + // Call the transformer Factory. + $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) )->to_object()->to_array(); + + $this->assertEquals( 'Event', $event_array['type'] ); + $this->assertEquals( 'Eventin Test Event Title', $event_array['name'] ); + $this->assertEquals( 'Eventin Test Event Description', wp_strip_all_tags( $event_array['content'] ) ); + $this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 15:00:00' ) ), $event_array['startTime'] ); + $this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 16:00:00' ) ), $event_array['endTime'] ); + $this->assertEquals( 'Europe/Vienna', $event_array['timezone'] ); + $this->assertEquals( comments_open( $event->id ), $event_array['commentsEnabled'] ); + $this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); + $this->assertEquals( 'external', $event_array['joinMode'] ); + $this->assertArrayHasKey( 'location', $event_array ); + $this->assertEquals( 'MEETING', $event_array['category'] ); + $this->assertEquals( false, $event_array['isOnline'] ); + $this->assertEquals( 'The NlNet center', $event_array['location']['address'] ); + $this->assertEquals( 'The NlNet center', $event_array['location']['name'] ); } } -- 2.39.5