Merge branch 'trunk' into e2e/add-force-to-test-scaffold

This commit is contained in:
Lucas Bustamante 2022-02-03 20:35:34 -03:00
commit d63a697d20
30 changed files with 299 additions and 233 deletions

View File

@ -96,7 +96,9 @@ jobs:
await script({github, context})
- name: Remove label from pull request.
if: always() && ${{ contains( github.event.pull_request.labels.*.name, format('run{0} smoke tests', ':')) }}
if: |
always()
&& contains( github.event.pull_request.labels.*.name, format('run{0} smoke tests', ':'))
uses: actions-ecosystem/action-remove-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

View File

@ -88,7 +88,7 @@ jobs:
- plugin: 'WooCommerce PayPal Payments'
repo: 'woocommerce/woocommerce-paypal-payments'
- plugin: 'WooCommerce Shipping & Tax'
repo: 'woocommerce/woocommerce-services'
repo: 'automattic/woocommerce-services'
- plugin: 'WooCommerce Subscriptions'
repo: WC_SUBSCRIPTIONS_REPO
private: true
@ -146,9 +146,9 @@ jobs:
WC_E2E_SCREENSHOTS: 1
E2E_SLACK_TOKEN: ${{ secrets.SMOKE_TEST_SLACK_TOKEN }}
E2E_SLACK_CHANNEL: ${{ secrets.RELEASE_TEST_SLACK_CHANNEL }}
GITHUB_REPOSITORY: ${{ matrix.private && secrets[matrix.repo] || matrix.repo }}
PLUGIN_REPOSITORY: ${{ matrix.private && secrets[matrix.repo] || matrix.repo }}
PLUGIN_NAME: ${{ matrix.plugin }}
GITHUB_TOKEN: ${{ secrets.E2E_GH_TOKEN }}
run: |
pnpx wc-e2e test:e2e tests/e2e/specs/smoke-tests/upload-plugin.js
pnpm nx test-e2e woocommerce
pnpx wc-e2e test:e2e

View File

@ -118,7 +118,7 @@ jobs:
- plugin: 'WooCommerce PayPal Payments'
repo: 'woocommerce/woocommerce-paypal-payments'
- plugin: 'WooCommerce Shipping & Tax'
repo: 'woocommerce/woocommerce-services'
repo: 'automattic/woocommerce-services'
- plugin: 'WooCommerce Subscriptions'
repo: WC_SUBSCRIPTIONS_REPO
private: true
@ -170,9 +170,9 @@ jobs:
WC_E2E_SCREENSHOTS: 1
E2E_SLACK_TOKEN: ${{ secrets.SMOKE_TEST_SLACK_TOKEN }}
E2E_SLACK_CHANNEL: ${{ secrets.RELEASE_TEST_SLACK_CHANNEL }}
GITHUB_REPOSITORY: ${{ matrix.private && secrets[matrix.repo] || matrix.repo }}
PLUGIN_REPOSITORY: ${{ matrix.private && secrets[matrix.repo] || matrix.repo }}
PLUGIN_NAME: ${{ matrix.plugin }}
GITHUB_TOKEN: ${{ secrets.E2E_GH_TOKEN }}
run: |
pnpx wc-e2e test:e2e tests/e2e/specs/smoke-tests/upload-plugin.js
pnpm nx test-e2e woocommerce
pnpx wc-e2e test:e2e

View File

@ -4,7 +4,6 @@
"description": "API tests for WooCommerce",
"main": "index.js",
"scripts": {
"preinstall": "npx only-allow pnpm",
"test": "jest",
"test:api": "jest --group=api",
"test:hello": "jest --group=hello",

View File

@ -26,7 +26,6 @@
],
"sideEffects": false,
"scripts": {
"preinstall": "npx only-allow pnpm",
"clean": "rm -rf ./dist ./tsconfig.tsbuildinfo",
"compile": "tsc -b",
"build": "pnpm run clean && npm run compile",

View File

@ -1,5 +1,9 @@
# Unreleased
## Changed
- Updated top level menu css selectors
## Fixed
- Moved `merchant.login()` out of `beforeAll()` block and into test body for retried runs.

View File

@ -45,7 +45,6 @@
"access": "public"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"prepare": "pnpm run build",
"clean": "rm -rf ./build ./build-module",
"compile": "node ./../bin/build.js",

View File

@ -5,13 +5,9 @@
export const MENUS = [
[
'WooCommerce',
'#adminmenu > li:nth-child(8) > a',
'.menu-top > a[href*=wc-admin].menu-top-first',
[
[
'Home',
'',
'Home',
],
[ 'Home', '', 'Home' ],
[
'Orders',
'#toplevel_page_woocommerce > ul > li:nth-child(3) > a',
@ -37,7 +33,7 @@ export const MENUS = [
],
[
'Products',
'#adminmenu > li:nth-child(9) > a',
'.menu-top > a[href*=product].menu-top',
[
[
'All Products',
@ -68,7 +64,7 @@ export const MENUS = [
],
[
'Marketing',
'#adminmenu > li:nth-child(11) > a',
'.menu-top > a[href*=marketing].menu-top',
[
[
'Overview',

View File

@ -1,5 +1,8 @@
# Unreleased
## Changes
- Updated `deleteDownloadedPluginFiles()` to also be able to delete directories.
## Added
- Added `post-results-to-github-pr.js` to post smoke test results to a GitHub PR.

View File

@ -5,14 +5,22 @@ const resultsFile = path.resolve( __dirname, '../test-results.json' );
const buildOutput = ( results ) => {
const { TITLE, SMOKE_TEST_URL } = process.env;
const resultKeys = Object.keys( results );
let output = `## ${ TITLE }:\n\n`;
output += `**Test URL:** ${ SMOKE_TEST_URL }\n`;
output += `**Total Number of Passed Tests:** ${ results.numTotalTests }\n`;
output += `**Total Number of Failed Tests:** ${ results.numFailedTests }\n`;
output += `**Total Number of Test Suites:** ${ results.numTotalTestSuites }\n`;
output += `**Total Number of Passed Test Suites:** ${ results.numPassedTestSuites }\n`;
output += `**Total Number of Failed Test Suites:** ${ results.numFailedTestSuites }\n`;
resultKeys.forEach( ( key ) => {
// The keys that we care about all start with 'num'
if ( key.includes( 'num' ) ) {
// match only capitalized words
const words = key.match( /[A-Z][a-z]+/g );
output += `**Total Number of ${ words.join( ' ' ) }:** ${
results[ key ]
}\n`;
}
} );
return output;
};
@ -26,7 +34,8 @@ module.exports = async ( { github, context } ) => {
output = buildOutput( results );
} else {
output = `## Test Results Not Found!`;
output = `## Test Results Not Found! \n\n`;
output += 'The path to the `test-results.json` file may need to be updated.';
}
await github.rest.issues.createComment( {

View File

@ -35,7 +35,8 @@
"jest-each": "25.5.0",
"jest-puppeteer": "^4.4.0",
"node-stream-zip": "^1.13.6",
"readline-sync": "^1.4.10",
"puppeteer": "2.1.1",
"readline-sync": "^1.4.10",
"request": "^2.88.2",
"sprintf-js": "^1.1.2"
},

View File

@ -152,13 +152,20 @@ const downloadZip = async ( fileUrl, downloadPath, authorizationToken ) => {
const deleteDownloadedPluginFiles = async () => {
const pluginSavePath = resolveLocalE2ePath( 'plugins' );
fs.readdir( pluginSavePath, ( err, files ) => {
fs.readdir( pluginSavePath, ( err, contents ) => {
if ( err ) throw err;
for ( const file of files ) {
fs.unlink( path.join( pluginSavePath, file ), ( error ) => {
if ( error ) throw error;
} );
for ( const content of contents ) {
const contentPath = path.join( pluginSavePath, content );
const stats = fs.lstatSync( contentPath );
if ( stats.isDirectory() ) {
fs.rmSync( contentPath, { recursive: true, force: true } );
} else {
fs.unlink( contentPath, ( error ) => {
if ( error ) throw error;
} );
}
}
} );
};

View File

@ -41,7 +41,6 @@
"access": "public"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"clean": "rm -rf ./build ./build-module",
"compile": "node ./../bin/build.js",
"build": "pnpm run clean && pnpm run compile",

View File

@ -17,8 +17,8 @@ export function simpleProductFactory( httpClient ) {
} );
return {
name: params.name ?? faker.commerce.productName(),
regularPrice: params.regularPrice ?? faker.commerce.price(),
name: params.name ? params.name : faker.commerce.productName(),
regularPrice: params.regularPrice ? params.regularPrice : faker.commerce.price(),
};
} );
}

View File

@ -7,6 +7,7 @@
*/
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
@ -20,40 +21,14 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
class WC_Admin_Dashboard_Setup {
/**
* List of tasks.
*
* @var array
* The task list.
*/
private $tasks = array(
'store_details' => array(
'completed' => false,
'button_link' => 'admin.php?page=wc-admin&path=%2Fsetup-wizard',
),
'products' => array(
'completed' => false,
'button_link' => 'admin.php?page=wc-admin&task=products',
),
'woocommerce-payments' => array(
'completed' => false,
'button_link' => 'admin.php?page=wc-admin&path=%2Fpayments%2Fconnect',
),
'payments' => array(
'completed' => false,
'button_link' => 'admin.php?page=wc-admin&task=payments',
),
'tax' => array(
'completed' => false,
'button_link' => 'admin.php?page=wc-admin&task=tax',
),
'shipping' => array(
'completed' => false,
'button_link' => 'admin.php?page=wc-admin&task=shipping',
),
'appearance' => array(
'completed' => false,
'button_link' => 'admin.php?page=wc-admin&task=appearance',
),
);
private $task_list = null;
/**
* The tasks.
*/
private $tasks = null;
/**
* # of completed tasks.
@ -67,9 +42,6 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
*/
public function __construct() {
if ( $this->should_display_widget() ) {
$this->populate_general_tasks();
$this->populate_payment_tasks();
$this->completed_tasks_count = $this->get_completed_tasks_count();
add_meta_box(
'wc_admin_dashboard_setup',
__( 'WooCommerce Setup', 'woocommerce' ),
@ -93,9 +65,10 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
return;
}
$button_link = $task['button_link'];
$completed_tasks_count = $this->completed_tasks_count;
$tasks_count = count( $this->tasks );
$button_link = $this->get_button_link( $task );
$completed_tasks_count = $this->get_completed_tasks_count();
$step_number = $this->get_completed_tasks_count() + 1;
$tasks_count = count( $this->get_tasks() );
// Given 'r' (circle element's r attr), dashoffset = ((100-$desired_percentage)/100) * PI * (r*2).
$progress_percentage = ( $completed_tasks_count / $tasks_count ) * 100;
@ -106,35 +79,68 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
}
/**
* Populate tasks from the database.
* Get the button link for a given task.
*
* @param Task $task Task.
* @return string
*/
private function populate_general_tasks() {
$tasks = get_option( 'woocommerce_task_list_tracked_completed_tasks', array() );
foreach ( $tasks as $task ) {
if ( isset( $this->tasks[ $task ] ) ) {
$this->tasks[ $task ]['completed'] = true;
$this->tasks[ $task ]['button_link'] = wc_admin_url( $this->tasks[ $task ]['button_link'] );
}
public function get_button_link( $task ) {
$url = $task->get_json()['actionUrl'];
if ( substr( $url, 0, 4 ) === 'http' ) {
return $url;
} elseif ( $url ) {
return wc_admin_url( '&path=' . $url );
}
return admin_url( 'admin.php?page=wc-admin&task=' . $task->get_id() );
}
/**
* Getter for $tasks
* Get the task list.
*
* @return array
*/
public function get_task_list() {
if ( $this->task_list ) {
return $this->task_list;
}
$this->set_task_list( TaskLists::get_list( 'setup' ) );
return $this->task_list;
}
/**
* Set the task list.
*/
public function set_task_list( $task_list ) {
return $this->task_list = $task_list;
}
/**
* Get the tasks.
*
* @return array
*/
public function get_tasks() {
if ( $this->tasks ) {
return $this->tasks;
}
$this->tasks = $this->get_task_list()->get_viewable_tasks();
return $this->tasks;
}
/**
* Return # of completed tasks
*
* @return integer
*/
public function get_completed_tasks_count() {
$completed_tasks = array_filter(
$this->tasks,
$this->get_tasks(),
function( $task ) {
return $task['completed'];
return $task->is_complete();
}
);
@ -148,7 +154,7 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
*/
private function get_next_task() {
foreach ( $this->get_tasks() as $task ) {
if ( false === $task['completed'] ) {
if ( false === $task->is_complete() ) {
return $task;
}
}
@ -161,51 +167,13 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
*
* @return bool
*/
private function should_display_widget() {
return WC()->is_wc_admin_active() &&
'yes' !== get_option( 'woocommerce_task_list_complete' ) &&
'yes' !== get_option( 'woocommerce_task_list_hidden' );
public function should_display_widget() {
return current_user_can( 'manage_woocommerce' ) &&
WC()->is_wc_admin_active() &&
! $this->get_task_list()->is_complete() &&
! $this->get_task_list()->is_hidden();
}
/**
* Populate payment tasks's visibility and completion
*/
private function populate_payment_tasks() {
$is_woo_payment_installed = is_plugin_active( 'woocommerce-payments/woocommerce-payments.php' );
$country = explode( ':', get_option( 'woocommerce_default_country', 'US:CA' ) )[0];
// woocommerce-payments requires its plugin activated and country must be US.
if ( ! $is_woo_payment_installed || 'US' !== $country ) {
unset( $this->tasks['woocommerce-payments'] );
}
// payments can't be used when woocommerce-payments exists and country is US.
if ( $is_woo_payment_installed && 'US' === $country ) {
unset( $this->tasks['payments'] );
}
if ( isset( $this->tasks['payments'] ) ) {
$gateways = WC()->payment_gateways->get_available_payment_gateways();
$enabled_gateways = array_filter(
$gateways,
function ( $gateway ) {
return 'yes' === $gateway->enabled;
}
);
$this->tasks['payments']['completed'] = ! empty( $enabled_gateways );
}
if ( isset( $this->tasks['woocommerce-payments'] ) ) {
$wc_pay_is_connected = false;
if ( class_exists( '\WC_Payments' ) ) {
$wc_payments_gateway = \WC_Payments::get_gateway();
$wc_pay_is_connected = method_exists( $wc_payments_gateway, 'is_connected' )
? $wc_payments_gateway->is_connected()
: false;
}
$this->tasks['woocommerce-payments']['completed'] = $wc_pay_is_connected;
}
}
}
endif;

View File

@ -138,6 +138,11 @@ class WC_Admin_Notices {
'php72_required_in_woo_65',
__( '<h4>PHP version requirements will change soon</h4><p>WooCommerce 6.5, scheduled for <b>May 2022</b>, will require PHP 7.2 or newer to work. Your server is currently running an older version of PHP, so this change will impact your store. Upgrading to at least PHP 7.4 is recommended. <b><a href="https://developer.woocommerce.com/2022/01/05/new-requirement-for-woocommerce-6-5-php-7-2/">Learn more about this change.</a></b></p>', 'woocommerce' )
);
$wp_version_is_ok = version_compare( get_bloginfo( 'version' ), WC_NOTICE_MIN_WP_VERSION, '>=' );
if ( $wp_version_is_ok ) {
self::hide_notice( WC_PHP_MIN_REQUIREMENTS_NOTICE );
}
}
/**
@ -209,14 +214,23 @@ class WC_Admin_Notices {
$hide_notice = sanitize_text_field( wp_unslash( $_GET['wc-hide-notice'] ) ); // WPCS: input var ok, CSRF ok.
self::remove_notice( $hide_notice );
update_user_meta( get_current_user_id(), 'dismissed_' . $hide_notice . '_notice', true );
do_action( 'woocommerce_hide_' . $hide_notice . '_notice' );
self::hide_notice( $hide_notice );
}
}
/**
* Hide a single notice.
*
* @param $name Notice name.
*/
private static function hide_notice( $name ) {
self::remove_notice( $name );
update_user_meta( get_current_user_id(), 'dismissed_' . $name . '_notice', true );
do_action( 'woocommerce_hide_' . $name . '_notice' );
}
/**
* Add notices + styles if needed.
*/

View File

@ -92,7 +92,13 @@ class WC_Product_CSV_Importer_Controller {
* @return bool
*/
public static function is_file_valid_csv( $file, $check_path = true ) {
if ( $check_path && apply_filters( 'woocommerce_product_csv_importer_check_import_file_path', true ) && false !== stripos( $file, '://' ) ) {
/**
* Can be used to override the decision to check the import file path.
*
* @param bool $check_import_file_path If the import file path should be checked.
* @param string $file Path of the file to be checked.
*/
if ( $check_path && apply_filters( 'woocommerce_product_csv_importer_check_import_file_path', true, $file ) && false !== stripos( $file, '://' ) ) {
return false;
}

View File

@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<circle r="6.5" cx="10" cy="10" fill="transparent" stroke-dasharray="40.859" stroke-dashoffset="0"></circle>
<circle class="bar" r="6.5" cx="190" cy="10" fill="transparent" stroke-dasharray="40.859" stroke-dashoffset="<?php echo esc_attr( $circle_dashoffset ); ?>" transform='rotate(-90 100 100)'></circle>
</svg>
<span><?php echo esc_html_e( 'Step', 'woocommerce' ); ?> <?php echo esc_html( $completed_tasks_count ); ?> <?php echo esc_html_e( 'of', 'woocommerce' ); ?> <?php echo esc_html( $tasks_count ); ?></span>
<span><?php echo esc_html_e( 'Step', 'woocommerce' ); ?> <?php echo esc_html( $step_number ); ?> <?php echo esc_html_e( 'of', 'woocommerce' ); ?> <?php echo esc_html( $tasks_count ); ?></span>
</span>
<div class="description">

View File

@ -47,7 +47,7 @@ final class WC_Cart_Session {
public function init() {
add_action( 'wp_loaded', array( $this, 'get_cart_from_session' ) );
add_action( 'woocommerce_cart_emptied', array( $this, 'destroy_cart_session' ) );
add_action( 'woocommerce_after_calculate_totals', array( $this, 'set_session' ) );
add_action( 'woocommerce_after_calculate_totals', array( $this, 'set_session' ), 1000 );
add_action( 'woocommerce_cart_loaded_from_session', array( $this, 'set_session' ) );
add_action( 'woocommerce_removed_coupon', array( $this, 'set_session' ) );

View File

@ -247,19 +247,21 @@ class WC_Checkout {
if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) {
$this->fields['account']['account_username'] = array(
'type' => 'text',
'label' => __( 'Account username', 'woocommerce' ),
'required' => true,
'placeholder' => esc_attr__( 'Username', 'woocommerce' ),
'type' => 'text',
'label' => __( 'Account username', 'woocommerce' ),
'required' => true,
'placeholder' => esc_attr__( 'Username', 'woocommerce' ),
'autocomplete' => 'username',
);
}
if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) {
$this->fields['account']['account_password'] = array(
'type' => 'password',
'label' => __( 'Create account password', 'woocommerce' ),
'required' => true,
'placeholder' => esc_attr__( 'Password', 'woocommerce' ),
'type' => 'password',
'label' => __( 'Create account password', 'woocommerce' ),
'required' => true,
'placeholder' => esc_attr__( 'Password', 'woocommerce' ),
'autocomplete' => 'new-password',
);
}
$this->fields = apply_filters( 'woocommerce_checkout_fields', $this->fields );

View File

@ -151,6 +151,9 @@ class WC_Tracker {
// Payment gateway info.
$data['gateways'] = self::get_active_payment_gateways();
// WcPay settings info.
$data['wcpay_settings'] = self::get_wcpay_settings();
// Shipping method info.
$data['shipping_methods'] = self::get_active_shipping_methods();
@ -303,6 +306,15 @@ class WC_Tracker {
);
}
/**
* Get the settings of WooCommerce Payments plugin
*
* @return array
*/
private static function get_wcpay_settings() {
return get_option( 'woocommerce_woocommerce_payments_settings' );
}
/**
* Check to see if the helper is connected to woocommerce.com
*
@ -589,6 +601,7 @@ class WC_Tracker {
return $active_gateways;
}
/**
* Get a list of all active shipping methods.
*

View File

@ -651,7 +651,7 @@ class WC_Email extends WC_Settings_API {
$message = apply_filters( 'woocommerce_mail_content', $this->style_inline( $message ) );
$mail_callback = apply_filters( 'woocommerce_mail_callback', 'wp_mail', $this );
$mail_callback_params = apply_filters( 'woocommerce_mail_callback_params', array( $to, $subject, $message, $headers, $attachments ), $this );
$mail_callback_params = apply_filters( 'woocommerce_mail_callback_params', array( $to, wp_specialchars_decode( $subject ), $message, $headers, $attachments ), $this );
$return = $mail_callback( ...$mail_callback_params );
remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );

View File

@ -244,7 +244,7 @@ class WC_REST_Customers_V1_Controller extends WC_REST_Controller {
$prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ];
$prepared_args['search'] = $request['search'];
if ( '' !== $prepared_args['search'] ) {
if ( ! empty( $prepared_args['search'] ) ) {
$prepared_args['search'] = '*' . $prepared_args['search'] . '*';
}

View File

@ -465,9 +465,10 @@ function wc_is_file_valid_csv( $file, $check_path = true ) {
* Filter check for CSV file path.
*
* @since 3.6.4
* @param bool $check_import_file_path If requires file path check. Defaults to true.
* @param bool $check_import_file_path If requires file path check. Defaults to true.
* @param string $file Path of the file to be checked.
*/
$check_import_file_path = apply_filters( 'woocommerce_csv_importer_check_import_file_path', true );
$check_import_file_path = apply_filters( 'woocommerce_csv_importer_check_import_file_path', true, $file );
if ( $check_path && $check_import_file_path && false !== stripos( $file, '://' ) ) {
return false;

View File

@ -601,7 +601,7 @@ dl.variation,
margin-right: 0.5rem;
}
input {
input[type="number"] {
width: 5em;
}
}

View File

@ -1263,4 +1263,23 @@ $tt2-gray: #f7f7f7;
}
}
}
}
}
.woocommerce-store-notice {
color: var(--wp--preset--color--black);
border-top: 2px solid var( --wp--preset--color--primary );
background: $tt2-gray;
padding: 2rem;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
z-index: 999;
margin: 0;
.woocommerce-store-notice__dismiss-link {
float: right;
margin-right: 4rem;
}
}

View File

@ -28,7 +28,7 @@ if ( apply_filters( 'woocommerce_checkout_show_terms', true ) && function_exists
<p class="form-row validate-required">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms'] ) ), true ); // WPCS: input var ok, csrf ok. ?> id="terms" />
<span class="woocommerce-terms-and-conditions-checkbox-text"><?php wc_terms_and_conditions_checkbox_text(); ?></span>&nbsp;<span class="required">*</span>
<span class="woocommerce-terms-and-conditions-checkbox-text"><?php wc_terms_and_conditions_checkbox_text(); ?></span>&nbsp;<abbr class="required" title="<?php esc_attr_e( 'required', 'woocommerce' ); ?>">*</abbr>
</label>
<input type="hidden" name="terms-field" value="1" />
</p>

View File

@ -13,30 +13,36 @@ const {
beforeAll,
} = require( '@jest/globals' );
const { GITHUB_REPOSITORY, PLUGIN_NAME, GITHUB_TOKEN } = process.env;
const { GITHUB_REPOSITORY, PLUGIN_NAME, GITHUB_TOKEN, PLUGIN_REPOSITORY } = process.env;
// allows us to upload plugins from different repositories.
const pluginName = PLUGIN_NAME ? PLUGIN_NAME : 'WooCommerce';
const repository = PLUGIN_REPOSITORY ? PLUGIN_REPOSITORY : GITHUB_REPOSITORY;
let zipUrl;
let pluginPath;
utils.describeIf( GITHUB_REPOSITORY )( 'Upload and activate plugin', () => {
beforeAll( async () => {
zipUrl = await getLatestReleaseZipUrl( GITHUB_REPOSITORY, GITHUB_TOKEN );
utils.describeIf( repository )(
`Upload and activate ${ pluginName } from ${ repository }`,
() => {
beforeAll( async () => {
zipUrl = await getLatestReleaseZipUrl( repository, GITHUB_TOKEN );
pluginPath = await getRemotePluginZip( zipUrl, GITHUB_TOKEN );
pluginPath = await getRemotePluginZip( zipUrl, GITHUB_TOKEN );
await merchant.login();
});
await merchant.login();
} );
afterAll( async () => {
await merchant.logout();
});
afterAll( async () => {
await merchant.logout();
} );
it( 'can upload and activate the provided plugin', async () => {
await merchant.uploadAndActivatePlugin( pluginPath, PLUGIN_NAME );
});
it( 'can upload and activate the provided plugin', async () => {
await merchant.uploadAndActivatePlugin( pluginPath, PLUGIN_NAME );
} );
it( 'can remove downloaded plugin zip', async () => {
await deleteDownloadedPluginFiles();
} );
});
it( 'can remove downloaded plugin zip', async () => {
await deleteDownloadedPluginFiles();
} );
}
);

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Tests\Admin
*/
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskList;
/**
* Class WC_Admin_Dashboard_Setup_Test
*/
@ -17,6 +19,16 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
// Set default country to non-US so that 'payments' task gets added but 'woocommerce-payments' doesn't,
// by default it won't be considered completed but we can manually change that as needed.
update_option( 'woocommerce_default_country', 'JP' );
$password = wp_generate_password( 8, false, false );
$this->admin = wp_insert_user(
array(
'user_login' => "test_admin$password",
'user_pass' => $password,
'user_email' => "admin$password@example.com",
'role' => 'administrator',
)
);
wp_set_current_user( $this->admin );
parent::setUp();
}
@ -52,38 +64,71 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
return ob_get_clean();
}
/**
* Tests widget does not get rendered when woocommerce_task_list_hidden or woocommerce_task_list_hidden
* is true.
*
* @dataProvider should_display_widget_data_provider
*
* @param array $options a set of options.
*/
public function test_widget_does_not_get_rendered( array $options ) {
global $wp_meta_boxes;
foreach ( $options as $name => $value ) {
update_option( $name, $value );
}
$this->get_widget();
$this->assertNull( $wp_meta_boxes );
}
/**
* Given both woocommerce_task_list_hidden and woocommerce_task_list_complete are false
* Then the widget should be added to the $wp_meta_boxes
* Given the task list is not hidden and is not complete, make sure the widget is rendered.
*/
public function test_widget_gets_rendered_when_both_options_are_false() {
public function test_widget_render() {
// Force the "payments" task to be considered incomplete.
add_filter(
'woocommerce_available_payment_gateways',
function() {
return array();
}
);
global $wp_meta_boxes;
update_option( 'woocommerce_task_list_complete', false );
update_option( 'woocommerce_task_list_hidden', false );
$task_list = $this->get_widget()->get_task_list();
$task_list->unhide();
$this->get_widget();
$this->assertArrayHasKey( 'wc_admin_dashboard_setup', $wp_meta_boxes['dashboard']['normal']['high'] );
}
/**
* Tests widget does not display when task list is complete.
*/
public function test_widget_does_not_display_when_task_list_complete() {
$task_list = new class {
public function is_complete() {
return true;
}
};
$widget = $this->get_widget();
$widget->set_task_list( $task_list );
$this->assertFalse( $widget->should_display_widget() );
}
/**
* Tests widget does not display when task list is hidden.
*/
public function test_widget_does_not_display_when_task_list_hidden() {
$widget = $this->get_widget();
$widget->get_task_list()->hide();
$this->assertFalse( $widget->should_display_widget() );
}
/**
* Tests widget does not display when user cannot manage woocommerce.
*/
public function test_widget_does_not_display_when_missing_capabilities() {
$password = wp_generate_password( 8, false, false );
$author = wp_insert_user(
array(
'user_login' => "test_author$password",
'user_pass' => $password,
'user_email' => "author$password@example.com",
'role' => 'author',
)
);
wp_set_current_user( $author );
$widget = $this->get_widget();
$this->assertFalse( $widget->should_display_widget() );
}
/**
* Tests the widget output when 1 task has been completed.
*/
@ -99,10 +144,9 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
$html = $this->get_widget_output();
$required_strings = array(
'Step 0 of 6',
'Step \d+ of \d+',
'You&#039;re almost there! Once you complete store setup you can start receiving orders.',
'Start selling',
'admin.php\?page=wc-admin&amp;path=%2Fsetup-wizard',
);
foreach ( $required_strings as $required_string ) {
@ -126,42 +170,13 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
}
);
$completed_tasks = array( 'payments' );
$tasks = $this->get_widget()->get_tasks();
$tasks_count = count( $tasks );
unset( $tasks['payments'] ); // That one is completed already.
foreach ( $tasks as $key => $task ) {
array_push( $completed_tasks, $key );
update_option( 'woocommerce_task_list_tracked_completed_tasks', $completed_tasks );
$completed_tasks_count = count( $completed_tasks );
// When all tasks are completed, assert that the widget output is empty.
// As widget won't be rendered when tasks are completed.
if ( $completed_tasks_count === $tasks_count ) {
$this->assertEmpty( $this->get_widget_output() );
} else {
$this->assertRegexp( "/Step ${completed_tasks_count} of 6/", $this->get_widget_output() );
}
$completed_tasks_count = $this->get_widget()->get_completed_tasks_count();
$tasks_count = count( $this->get_widget()->get_tasks() );
$step_number = $completed_tasks_count + 1;
if ( $completed_tasks_count === $tasks_count ) {
$this->assertEmpty( $this->get_widget_output() );
} else {
$this->assertRegexp( "/Step ${step_number} of 6/", $this->get_widget_output() );
}
}
/**
* Provides dataset that controls output of `should_display_widget`
*/
public function should_display_widget_data_provider() {
return array(
array(
array(
'woocommerce_task_list_complete' => 'yes',
'woocommerce_task_list_hidden' => 'no',
),
),
array(
array(
'woocommerce_task_list_complete' => 'no',
'woocommerce_task_list_hidden' => 'yes',
),
),
);
}
}

View File

@ -163,6 +163,7 @@ importers:
jest-puppeteer: ^4.4.0
ndb: ^1.1.5
node-stream-zip: ^1.13.6
puppeteer: 2.1.1
readline-sync: ^1.4.10
request: ^2.88.2
semver: ^7.3.2
@ -172,7 +173,7 @@ importers:
'@jest/test-sequencer': 25.5.4
'@slack/web-api': 6.5.1
'@woocommerce/api': link:../api
'@wordpress/e2e-test-utils': 4.16.1_jest@25.5.4
'@wordpress/e2e-test-utils': 4.16.1_jest@25.5.4+puppeteer@2.1.1
'@wordpress/jest-preset-default': 7.1.3_@babel+core@7.12.9+jest@25.5.4
app-root-path: 3.0.0
commander: 4.1.1
@ -180,8 +181,9 @@ importers:
jest: 25.5.4
jest-circus: 25.1.0
jest-each: 25.5.0
jest-puppeteer: 4.4.0
jest-puppeteer: 4.4.0_puppeteer@2.1.1
node-stream-zip: 1.15.0
puppeteer: 2.1.1
readline-sync: 1.4.10
request: 2.88.2
sprintf-js: 1.1.2
@ -5346,7 +5348,7 @@ packages:
- react-native
dev: false
/@wordpress/e2e-test-utils/4.16.1_jest@25.5.4:
/@wordpress/e2e-test-utils/4.16.1_jest@25.5.4+puppeteer@2.1.1:
resolution: {integrity: sha512-Dpsq5m0VSvjIhro2MjACSzkOkOf1jGEryzgEMW1ikbT6YI+motspHfGtisKXgYhZJOnjV4PwuEg+9lPVnd971g==}
engines: {node: '>=8'}
peerDependencies:
@ -5359,6 +5361,7 @@ packages:
jest: 25.5.4
lodash: 4.17.21
node-fetch: 2.6.5
puppeteer: 2.1.1
transitivePeerDependencies:
- react-native
dev: false
@ -13271,13 +13274,14 @@ packages:
jest-resolve: 27.3.1
dev: true
/jest-puppeteer/4.4.0:
/jest-puppeteer/4.4.0_puppeteer@2.1.1:
resolution: {integrity: sha512-ZaiCTlPZ07B9HW0erAWNX6cyzBqbXMM7d2ugai4epBDKpKvRDpItlRQC6XjERoJELKZsPziFGS0OhhUvTvQAXA==}
peerDependencies:
puppeteer: '>= 1.5.0 < 3'
dependencies:
expect-puppeteer: 4.4.0
jest-environment-puppeteer: 4.4.0
puppeteer: 2.1.1
transitivePeerDependencies:
- supports-color
dev: false