Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }'`,
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Filter the HTTP requests made during testing.
*
* @package BeyondWords
* @license GPL-2.0-or-later
*
* @wordpress-plugin
* Plugin Name: BeyondWords Filter: pre_http_request
* Description: Filter WordPress HTTP requests made during testing.
* Author: BeyondWords
* Text Domain: speechkit
* License: No License
*/
function my_pre_http_request( false|array|WP_Error $response, array $parsed_args, string $url ) {
// @todo Check this is a HTTP request to a specific domain.
if (strpos($url, 'http(s)://any_domain.com') === false) {
return $response;
}

// @todo check the parsed_args param to determine which response we should return.

// @todo Return a response object to short-circuit the request.
return [
'body' => [
'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' );
Loading