8000 Preparations for custom E2E tests by dmvrtx · Pull Request #10811 · Automattic/woocommerce-payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Preparations for custom E2E tests #10811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
8000
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ vendor/*
release/*
tests/e2e/docker*
tests/e2e/deps*
tests/qit-e2e*
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"cweagans/composer-patches": "1.7.1",
"automattic/jetpack-changelogger": "3.3.2",
"spatie/phpunit-watcher": "1.23.6",
"woocommerce/qit-cli": "0.4.0",
"woocommerce/qit-cli": "^0.10.0",
"slevomat/coding-standard": "8.15.0",
"dg/bypass-finals": "1.5.1",
"sirbrillig/phpcs-variable-analysis": "^2.11",
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,24 @@ function () {
self::$duplicate_payment_prevention_service->init( self::$card_gateway, self::$order_service );

wcpay_get_container()->get( \WCPay\Internal\PluginManagement\TranslationsLoader::class )->init_hooks();

if ( defined( 'WP_CLI' ) && WP_CLI
&& function_exists( 'wp_get_environment_type' )
&& in_array( wp_get_environment_type(), [ 'development', 'local' ], true )
) {

require_once WCPAY_ABSPATH . 'includes/wp-cli/class-wp-cli-init-test-drive-account-command.php';
$wp_cli_init_test_drive_account_command = new WP_CLI_Init_Test_Drive_Account_Command( self::$onboarding_service );
WP_CLI::add_command( 'woopayments init-test-drive-account', $wp_cli_init_test_drive_account_command );

require_once WCPAY_ABSPATH . 'includes/wp-cli/class-wp-cli-disable-test-drive-account-command.php';
$wp_cli_init_test_drive_account_command = new WP_CLI_Disable_Test_Drive_Account_Command( self::$onboarding_service );
WP_CLI::add_command( 'woopayments disable-test-drive-account', $wp_cli_init_test_drive_account_command );

require_once WCPAY_ABSPATH . 'includes/wp-cli/class-wp-cli-set-blog-id-command.php';
$wp_cli_set_blog_id_command = new WP_CLI_Set_Blog_Id_Command();
WP_CLI::add_command( 'woopayments set_blog_id', $wp_cli_set_blog_id_command );
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Init test drive account command.
*
* @package WooCommerce\Payments
*/

/**
* Class WP_CLI_Disable_Test_Drive_Account_Command
*/
class WP_CLI_Disable_Test_Drive_Account_Command {
/**
* Onboarding service.
*
* @var WC_Payments_Onboarding_Service
*/
protected $onboarding_service;

/**
* Constructor.
*
* @param WC_Payments_Onboarding_Service $onboarding_service Onboarding service.
*/
public function __construct( WC_Payments_Onboarding_Service $onboarding_service ) {
$this->onboarding_service = $onboarding_service;
}

/**
* Disable the test drive account.
*
* ## EXAMPLES
*
* wp woopayments disable-test-drive-account
*
* @when after_wp_load
*
* @param array $args Command line arguments.
* @param array $assoc_args Associative arguments.
* @return void
*/
public function __invoke( array $args, array $assoc_args ): void {
try {
$result = $this->onboarding_service->disable_test_drive_account( [ 'from' => 'cli' ] );
if ( true === $result ) {
WP_CLI::success( 'Test drive account disabled successfully.' );
} else {
WP_CLI::error( 'Failed to disable test drive account.' );
}
} catch ( \Exception $e ) {
WP_CLI::error( 'Failed to disable test drive account: ' . $e->getMessage() );
}
}
}
71 changes: 71 additions & 0 deletions includes/wp-cli/class-wp-cli-init-test-drive-account-command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Init test drive account command.
*
* @package WooCommerce\Payments
*/

use WCPay\Constants\Country_Code;

/**
* Class WP_CLI_Init_Test_Drive_Account_Command
*/
class WP_CLI_Init_Test_Drive_Account_Command {
/**
* Onboarding service.
*
* @var WC_Payments_Onboarding_Service
*/
protected $onboarding_service;

/**
* Constructor.
*
* @param WC_Payments_Onboarding_Service $onboarding_service Onboarding service.
*/
public function __construct( WC_Payments_Onboarding_Service $onboarding_service ) {
$this->onboarding_service = $onboarding_service;
}

/**
* Initialize the test drive account.
*
* ## OPTIONS
*
* [--country=<country_code>]
* : The country code for the test drive account.
* ---
* default: US
* ---
*
* ## EXAMPLES
*
* wp woopayments init-test-drive-account
* wp woopayments init-test-drive-account --country=GB
*
* @when after_wp_load
*
* @param array $args Command line arguments.
* @param array $assoc_args Associative arguments.
* @return void
*/
public function __invoke( array $args, array $assoc_args ): void {
$country = isset( $assoc_args['country'] ) ? $assoc_args['country'] : 'US';
try {
Country_Code::search( $country );
} catch ( \InvalidArgumentException $e ) {
WP_CLI::error( 'Invalid country code. Please provide a valid country code.' );
}

try {
$result = $this->onboarding_service->init_test_drive_account( $country );
if ( true === $result ) {
WP_CLI::success( 'Test drive account initialized successfully.' );
} else {
WP_CLI::error( 'Failed to initialize test drive account.' );
}
} catch ( \Exception $e ) {
WP_CLI::error( 'Failed to initialize test drive account: ' . $e->getMessage() );
}
}
}
63 changes: 63 additions & 0 deletions includes/wp-cli/class-wp-cli-set-blog-id-command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Set Blog ID command.
*
* @package WooCommerce\Payments
*/

/**
* Set Blog ID command.
*/
class WP_CLI_Set_Blog_Id_Command {
/**
* Sets fake Jetpack options required to send requests to the server on behalf of the blog id.
*
* Available only in the development environment.
*
* ## OPTIONS
*
* <blog_id>
* : The blog ID.
*
* [--blog_token=<value>]
* : Jetpack blog token. Values should be wrapped in quotes.
*
* [--user_token=<value>]
* : Jetpack user token. Values should be wrapped in quotes.
* ---
*
* ## EXAMPLES
*
* # Update Blog ID
* wp woopayments set_blog_id <blog_id>
*
* # Update Blog ID with blog & user tokens
* wp woopayments set_blog_id <blog_id> --blog_token=<value> --user_token=<value>
*
* @when after_wp_load
* @param array $args Positional arguments.
* @param array $assoc_args Associative arguments.
*/
public function __invoke( array $args, array $assoc_args ): void {
$blog_id = $args[0];
if ( ! is_numeric( $blog_id ) ) {
WP_CLI::error( 'Please provide a numeric blog ID.' );
}

if ( ! class_exists( 'Jetpack_Options' ) ) {
WP_CLI::error( 'Jetpack_Options class does not exist. Please check your Jetpack installation.' );
}

$blog_token = ! empty( $assoc_args['blog_token'] ) ? $assoc_args['blog_token'] : '123.ABC';
$user_token = [
1 => ! empty( $assoc_args['user_token'] ) ? $assoc_args['user_token'] : '123.ABC.1',
];

Jetpack_Options::update_option( 'id', intval( $blog_id ) );
Jetpack_Options::update_option( 'master_user', 1 );
Jetpack_Options::update_option( 'blog_token', $blog_token );
Jetpack_Options::update_option( 'user_tokens', $user_token );

WP_CLI::success( "Set Jetpack blog id to $blog_id" );
}
}
18 changes: 18 additions & 0 deletions qit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"wp": "rc",
"woo": "rc",
"php_version": "7.4",
"plugins": [
"woocommerce",
"akismet",
"wordpress-importer"
],
"themes": [
"storefront",
"twentytwentyfour",
"twentytwentyfive"
],
"volumes": [
".:/var/www/html/wp-content/plugins/woocommerce-payments"
]
}
2 changes: 2 additions & 0 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Jetpack_Options::get_option( 'blog_token' );
Jetpack_Options::get_option( 'user_tokens' );
```

Another option is to install Jetpack Beta Tester plugin, and enable Jetpack Debug. In the Jetpack Debug menu check the Broken Token and save. The Broken Token submenu will appear and will contain the aforementioned data.

Set the value of `E2E_USE_LOCAL_SERVER` to `false` to enable live server.

Once you have the blog id & tokens, add the following env variables to your `local.env`.
Expand Down
1 change: 1 addition & 0 deletions tests/qit-e2e/bootstrap/dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
13 changes: 13 additions & 0 deletions tests/qit-e2e/bootstrap/mu-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* mu-plugin File (Optional)
*
* Purpose: This script is executed on every request.
*
* Notes:
* - If this file is not needed for your setup, feel free to delete it.
*
* Documentation: For more information, please visit https://qit.woo.com/docs/custom-tests/bootstrap-and-test-phases
*
* @package Qit
*/
19 changes: 19 additions & 0 deletions tests/qit-e2e/bootstrap/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* External dependencies
*/
import { test } from '@playwright/test';

/**
* Isolated setup that runs before your plugin's tests.
* Use it to:
* - Set up UI settings that can't be done via CLI
* - Prepare plugin-specific browser storage
* - Create any UI-generated test data
* - Set up plugin state via UI interactions
*/
test( 'Isolated Setup', async ( { page } ) => {
// Example: Set up plugin settings via UI
// await page.goto('/wp-admin/admin.php?page=your-plugin-settings');
// await page.fill('input[name="plugin_setting"]', 'test value');
// await page.click('text=Save Changes');
} );
Loading
Loading
0