diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bb345c67..7ca438f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -446,11 +446,20 @@ jobs: - name: Uninstall plugins run: wp plugin uninstall --deactivate --all - - name: Install BeyondWords plugin - run: wp plugin install /tmp/${{ vars.WP_ORG_PLUGIN_NAME }}.zip --force --activate - - - name: Install third-party plugins + - name: Install plugins run: | + wp plugin uninstall --deactivate --all + wp plugin install /tmp/${{ vars.WP_ORG_PLUGIN_NAME }}.zip --force --activate + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/beyondwords-filter-content-params.zip --force + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/beyondwords-filter-player-script-onload.zip --force + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/beyondwords-filter-player-inline-script-tag.zip --force + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/beyondwords-filter-player-sdk-params.zip --force + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/cpt-active.zip --force --activate + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/cpt-inactive.zip --force --activate + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/cpt-unsupported.zip --force --activate + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/filter-pre-http-request.zip --force --activate + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/rest-api-insert.zip --force + wp plugin install ${{ github.workspace }}/tests/fixtures/wp-content/plugins/rest-api-publish.zip --force wp plugin install amp --force wp plugin install classic-editor --force wp plugin install plugin-check --force diff --git a/.wp-env.json b/.wp-env.json index cb611548..3c054900 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -27,6 +27,14 @@ }, "env": { "tests": { + "plugins": [ + "WP-API/Basic-Auth", + "./tests/fixtures/wp-content/plugins/cpt-active", + "./tests/fixtures/wp-content/plugins/cpt-inactive", + "./tests/fixtures/wp-content/plugins/cpt-unsupported", + "./tests/fixtures/wp-content/plugins/filter-pre-http-request", + "./" + ], "config": { "BEYONDWORDS_API_URL": "http://host.docker.internal:3000/v1", "BEYONDWORDS_AUTO_SYNC_SETTINGS": false diff --git a/cypress.config.js b/cypress.config.js index 887f1440..b0dee818 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -86,7 +86,7 @@ function setupNodeEvents( on, config ) { 'plugin activate wp-reset', 'reset reset --yes', 'plugin deactivate --all', - 'plugin activate speechkit Basic-Auth cpt-active cpt-inactive cpt-unsupported', + 'plugin activate speechkit Basic-Auth cpt-active cpt-inactive cpt-unsupported filter-pre-http-request', // Configure plugin credentials for most tests `option update beyondwords_api_key '${ apiKey }'`, `option update beyondwords_project_id '${ projectId }'`, @@ -118,7 +118,7 @@ function setupNodeEvents( on, config ) { 'plugin activate wp-reset', 'reset reset --yes', 'plugin deactivate --all', - 'plugin activate speechkit Basic-Auth cpt-active cpt-inactive cpt-unsupported', + 'plugin activate speechkit Basic-Auth cpt-active cpt-inactive cpt-unsupported filter-pre-http-request', ] ); // Reset the flag so next test file will run setupDatabase again diff --git a/tests/fixtures/wp-content/plugins/filter-pre-http-request.zip b/tests/fixtures/wp-content/plugins/filter-pre-http-request.zip new file mode 100644 index 00000000..15bafbd5 Binary files /dev/null and b/tests/fixtures/wp-content/plugins/filter-pre-http-request.zip differ diff --git a/tests/fixtures/wp-content/plugins/filter-pre-http-request/filter-pre-http-request.php b/tests/fixtures/wp-content/plugins/filter-pre-http-request/filter-pre-http-request.php new file mode 100644 index 00000000..59e96754 --- /dev/null +++ b/tests/fixtures/wp-content/plugins/filter-pre-http-request/filter-pre-http-request.php @@ -0,0 +1,43 @@ + [ + 'id' => 1, + ], + 'headers' => [ + 'content-type' => 'application/json', + ], + 'response' => [ + 'code' => 201, + ], + ]; + + // @todo Alternatively return a WP_Error object to block the request. + return new WP_Error( + 'http_request_block', + __( 'This request is not allowed', 'speechkit' ) + ); +} + +add_filter( 'pre_http_request', 'my_pre_http_request' );