From 8d2c8b2d358a3a1bb544ec17bef9f15e5fc9b466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Mon, 23 Sep 2024 20:07:36 +0200 Subject: [PATCH] install event plugins in ci --- .forgejo/workflows/phpunit.yml | 1 + tests/bootstrap.php | 5 ++++ tests/install-wp-tests.sh | 46 ++++++++++++++++++++++++++++++---- tests/test-class-sample.php | 9 +++++++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/.forgejo/workflows/phpunit.yml b/.forgejo/workflows/phpunit.yml index 7cd24a9..3c118eb 100644 --- a/.forgejo/workflows/phpunit.yml +++ b/.forgejo/workflows/phpunit.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - improve_tests pull_request: env: diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7d30eb9..c5bd5d3 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -30,6 +30,11 @@ require_once "{$_tests_dir}/includes/functions.php"; */ function _manually_load_plugin() { require dirname( __DIR__ ) . '/activitypub-event-extensions.php'; + $event_plugin = getenv( 'WP_EVENT_PLUGIN' ); + switch ( $event_plugin ) { + case 'the-events-calendar': + require ABSPATH . '/wp-content/mu-plugins/the-events-calendar/the-events-calendar.php'; + } } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); diff --git a/tests/install-wp-tests.sh b/tests/install-wp-tests.sh index 286ea40..2bcf328 100755 --- a/tests/install-wp-tests.sh +++ b/tests/install-wp-tests.sh @@ -15,6 +15,16 @@ SKIP_WP_INSTALL=${7-false} SKIP_PLUGINS_INSTALL=${8-false} SKIP_TEST_SUITE_INSTALL=${9-false} +# Initialize the plugin list +PLUGINS="" + +# Parse optional --plugins argument +while [[ "$#" -gt 0 ]]; do + case $1 in + --plugins) PLUGINS="$2"; shift ;; + esac + shift +done TMPDIR=${TMPDIR-/tmp} TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") @@ -189,16 +199,42 @@ install_db() { fi } +install_wp_plugin() { + PLUGIN_NAME=$1 + + if [ -d "$WP_CORE_DIR/wp-content/mu-plugins/$PLUGIN_NAME" ]; then + return; + fi + + # Get the latest tag. + LATEST_TAG=$(svn log https://plugins.svn.wordpress.org/$PLUGIN_NAME/tags --limit 1 | awk 'NR == 4 { print $4 }') + PLUGIN_FILE="$PLUGIN_NAME.$LATEST_TAG.zip" + URL="https://downloads.wordpress.org/plugin/$PLUGIN_FILE" + + # Check if the plugin file already exists + if ! test -f "$TMPDIR/$PLUGIN_FILE"; then + download $URL "$TMPDIR/$PLUGIN_FILE" + fi + + # Unzip the plugin into the WordPress must-use plugins directory + unzip -o "$TMPDIR/$PLUGIN_FILE" -d "$WP_CORE_DIR/wp-content/mu-plugins/" +} + install_wp_plugins() { if [ "$SKIP_PLUGINS_INSTALL" = "true" ]; then echo "Skipping WordPress plugin installation." return 0 fi - ACTIVITYPUB_FILE="activitypub.3.2.5.zip" - if ! test -f $TMPDIR/$ACTIVITYPUB_FILE; then - download https://downloads.wordpress.org/plugin/$ACTIVITYPUB_FILE $TMPDIR/$ACTIVITYPUB_FILE - fi - unzip -o $TMPDIR/$ACTIVITYPUB_FILE -d $WP_CORE_DIR/wp-content/plugins/ + # Always install the ActivityPub plugin. + install_wp_plugin activitypub + install_wp_plugin the-events-calendar + # Install additional plugins. + # if [[ -n "$PLUGINS" ]]; then + # IFS=',' read -ra PLUGIN_ARRAY <<< "$PLUGINS" + # for plugin in "${PLUGIN_ARRAY[@]}"; do + # install_wp_plugin "$plugin" + # done + # fi } install_wp diff --git a/tests/test-class-sample.php b/tests/test-class-sample.php index 3e9bf11..a0a2e39 100644 --- a/tests/test-class-sample.php +++ b/tests/test-class-sample.php @@ -17,4 +17,13 @@ class Test_Sample extends WP_UnitTestCase { // Replace this with some actual testing code. $this->assertTrue( true ); } + + /** + * Tesd tes + */ + public function test_the_events_calendar() { + // Replace this with some actual testing code. + $class_exists = class_exists( 'Tribe__Events__Main' ); + $this->assertTrue( $class_exists ); + } }