From 6964e08559054560765c280e8ba25126a1fa484d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 17 Oct 2024 20:50:21 +0200 Subject: [PATCH] add basic integration tests ffor modern-events-calendar-lite --- .forgejo/workflows/phpunit.yml | 7 +- bin/install-wp-tests.sh | 16 ++++ composer.json | 6 +- improvements.md | 16 ++++ tests/bootstrap.php | 3 + ...ass-plugin-modern-events-calendar-lite.php | 79 +++++++++++++++++++ 6 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 improvements.md create mode 100644 tests/test-class-plugin-modern-events-calendar-lite.php diff --git a/.forgejo/workflows/phpunit.yml b/.forgejo/workflows/phpunit.yml index 3cb7904..a893dce 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-8 + key: cache-wordpress-9 - name: Cache Composer id: cache-composer-phpunit @@ -101,5 +101,10 @@ jobs: - name: Run Integration tests for Eventin (WP Event Solution) run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=eventin + env: + PHP_VERSION: ${{ matrix.php-version }} + + - name: Run Integration tests for Modern Events Calendar Lite + run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=modern_events_calendar_lite 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 759ad25..f0bf333 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -226,6 +226,20 @@ install_wp_plugin() { unzip -q -o "$TMPDIR/$PLUGIN_FILE" -d "$WP_CORE_DIR/wp-content/plugins/" } +install_wp_plugin_mec() { + mkdir -p "$WP_CORE_DIR/wp-content/plugins/" + + if [ -d "$WP_CORE_DIR/wp-content/plugins/modern-events-calendar-lite" ]; then + return; + fi + + PLUGIN_VERSION="v7.15.0" + + URL="https://code.event-federation.eu/Event-Federation/modern-events-calendar-lite" + + git clone $URL "$WP_CORE_DIR/wp-content/plugins/modern-events-calendar-lite" +} + install_wp_plugins() { if [ "$SKIP_PLUGINS_INSTALL" = "true" ]; then echo "Skipping WordPress plugin installation." @@ -240,6 +254,8 @@ install_wp_plugins() { install_wp_plugin events-manager install_wp_plugin wp-event-manager install_wp_plugin wp-event-solution + # Mec is not installable via wordpress.org, we use our own mirror. + install_wp_plugin_mec } install_wp diff --git a/composer.json b/composer.json index 940dff0..eaf1ea5 100644 --- a/composer.json +++ b/composer.json @@ -53,11 +53,12 @@ "@test-gatherpress", "@test-events-manager", "@test-wp-event-manager", - "@test-eventin" + "@test-eventin", + "@test-modern-events-calendar-lite" ], "test-debug": [ "@prepare-test", - "@test-eventin" + "@test-modern-events-calendar-lite" ], "test-vs-event-list": "phpunit --filter=vs_event_list", "test-the-events-calendar": "phpunit --filter=the_events_calendar", @@ -65,6 +66,7 @@ "test-events-manager": "phpunit --filter=events_manager", "test-wp-event-manager": "phpunit --filter=wp_event_manager", "test-eventin": "phpunit --filter=eventin", + "test-modern-events-calendar-lite": "phpunit --filter=modern_events_calendar_lite", "test-all": "phpunit" } } diff --git a/improvements.md b/improvements.md new file mode 100644 index 0000000..c095490 --- /dev/null +++ b/improvements.md @@ -0,0 +1,16 @@ +Make use of: + +https://docs.theeventscalendar.com/reference/classes/tribe__events__api/get_event_terms/ + +for getting all tags/terms for an event! + +``` +public static function get_event_terms( $event_id, array $args = array() ) { + $terms = array(); + foreach ( get_post_taxonomies( $event_id ) as $taxonomy ) { + $tax_terms = wp_get_object_terms( $event_id, $taxonomy, $args ); + $terms[ $taxonomy ] = $tax_terms; + } + return $terms; +} +``` diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4bbd83a..95f0da5 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -62,6 +62,9 @@ function _manually_load_plugin() { case 'eventin': $plugin_file = 'wp-event-solution/eventin.php'; break; + case 'modern_events_calendar_lite': + $plugin_file = 'modern-events-calendar-lite/modern-events-calendar-lite.php'; + break; case 'gatherpress': $plugin_file = 'gatherpress/gatherpress.php'; break; diff --git a/tests/test-class-plugin-modern-events-calendar-lite.php b/tests/test-class-plugin-modern-events-calendar-lite.php new file mode 100644 index 0000000..fa658ec --- /dev/null +++ b/tests/test-class-plugin-modern-events-calendar-lite.php @@ -0,0 +1,79 @@ +activate_activitypub_support_for_active_event_plugins(); + + $this->mec_main = \MEC::getInstance( 'app.libraries.main' ); + + // Delete all posts afterwards. + _delete_all_posts(); + } + + /** + * Test that the right transformer gets applied. + */ + public function test_modern_events_calendar_lite_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( 'mec-events', get_option( 'activitypub_support_post_types' ) ); + + // Insert a new Event. + $event = array( + 'title' => 'MEC Test Event', + 'status' => 'publish', + 'start_time_hour' => '3', + 'start_time_minutes' => '00', + 'start_time_ampm' => 'PM', + 'start' => '2025-01-01', + 'end' => '2025-01-01', + 'end_time_hour' => '4', + 'end_time_minutes' => '00', + 'end_time_ampm' => 'PM', + 'repeat_status' => 0, + 'repeat_type' => 'daily', + 'interval' => 1, + ); + + $post_id = $this->mec_main->save_event( $event ); + + $wp_object = get_post( $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\Modern_Events_Calendar_Lite::class, $transformer ); + } +}