Skip to content

Commit

Permalink
Merge pull request #131 from woocommerce/24-02/activation-test-loopback
Browse files Browse the repository at this point in the history
Add self-tests for Activation Tests loopback
  • Loading branch information
Luc45 authored Feb 28, 2024
2 parents 8e7013e + 8e5a395 commit 3220d0f
Show file tree
Hide file tree
Showing 4 changed files with 423 additions and 3 deletions.
14 changes: 11 additions & 3 deletions _tests/QITSelfTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ function run_test_runs( array $test_runs ) {

$qit_run_processes = [];

// If running a lot of tests, wait between any remote request to prevent 429.
$should_wait = count( $test_runs ) > 3;

// Dispatch all tests in parallel using the qit binary.
foreach ( $test_runs as $test_type => &$test_type_test_runs ) {
foreach ( $test_type_test_runs as &$t ) {
Expand Down Expand Up @@ -364,15 +367,20 @@ function run_test_runs( array $test_runs ) {

$t['non_json_output_file'] = tempnam( sys_get_temp_dir(), 'qit_non_json_' );

$qit_process->setEnv( [
$env = [
'QIT_TEST_PATH' => $t['path'],
'QIT_TEST_TYPE' => $test_type,
'QIT_TEST_FUNCTION_NAME' => $t['test_function_name'],
'QIT_WAIT_BEFORE_REQUEST' => 'yes',
'QIT_RAN_TEST' => false,
'QIT_REMOVE_FROM_SNAPSHOT' => $t['remove_from_snapshot'],
'QIT_NON_JSON_OUTPUT' => $t['non_json_output_file'],
] );
];

if ( $should_wait ) {
$env['QIT_WAIT_BEFORE_REQUEST'] = 'yes';
}

$qit_process->setEnv( $env );

add_task_id_to_process( $qit_process, $t );

Expand Down
6 changes: 6 additions & 0 deletions _tests/activation/loopback/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
return [
'php' => '7.4',
'wp' => 'rc',
'woo' => 'rc',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* Plugin name: Activation - Plugin A
*/

add_action( 'wp', static function () {
trigger_error( 'Site URL: ' . get_site_url() );
$response = wp_remote_get( get_site_url() . '/wp-json/' );

if ( is_wp_error( $response ) ) {
trigger_error( 'Loopback error: ' . $response->get_error_message() );
} else {
$data = json_decode( wp_remote_retrieve_body( $response ), true );

if ( isset( $data['name'] ) ) {
trigger_error( 'Site name from wp-json: ' . $data['name'] );
} else {
trigger_error( 'Site name not found in wp-json response' );
}
}
} );
Loading

0 comments on commit 3220d0f

Please sign in to comment.