Merge branch 'master' into fix/23606

This commit is contained in:
Gerhard Potgieter 2019-05-10 11:12:54 +02:00 committed by GitHub
commit 902cc1f0b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
102 changed files with 4701 additions and 4921 deletions

View File

@ -66,34 +66,3 @@ p.woocommerce-actions,
.woocommerce-about-text {
margin-bottom: 1em !important;
}
div.woocommerce-legacy-shipping-notice,
div.woocommerce-no-shipping-methods-notice {
overflow: hidden;
padding: 1px 12px;
p {
position: relative;
z-index: 1;
line-height: 1.5em;
margin: 12px 0;
&.main {
font-size: 1.1em;
}
}
&::before {
content: "\e01b";
font-family: "WooCommerce";
text-align: center;
line-height: 1;
color: #f7f1f6;
display: block;
width: 1em;
font-size: 20em;
top: 36px;
right: 12px;
position: absolute;
}
}

View File

@ -18,7 +18,7 @@ body {
.select2-container {
text-align: left;
width: 100%;
width: auto;
}
.hidden {
display: none;

View File

@ -138,7 +138,7 @@ jQuery(function( $ ) {
var groupby = $( this ) .data( 'groupby' );
var index_type = $( this ).data( 'index_type' );
var export_format = $( this ).data( 'export' );
var csv_data = 'data:text/csv;charset=utf-8,\uFEFF';
var csv_data = '';
var s, series_data, d;
if ( 'table' === export_format ) {
@ -243,8 +243,9 @@ jQuery(function( $ ) {
} );
}
csv_data = 'data:text/csv;charset=utf-8,\uFEFF' + encodeURIComponent( csv_data );
// Set data as href and return
$( this ).attr( 'href', encodeURI( csv_data ) );
$( this ).attr( 'href', csv_data );
return true;
});
});

View File

@ -161,12 +161,28 @@
lastRow = $( this ).find( 'tbody tr:last' ),
firstRow = $( this ).find( 'tbody tr:first' );
table.find( '.wc-item-reorder-nav .wc-move-disabled' ).removeClass( 'wc-move-disabled' ).attr( { 'tabindex': '0', 'aria-hidden': 'false' } );
firstRow.find( '.wc-item-reorder-nav .wc-move-up' ).addClass( 'wc-move-disabled' ).attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
lastRow.find( '.wc-item-reorder-nav .wc-move-down' ).addClass( 'wc-move-disabled' ).attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
table.find( '.wc-item-reorder-nav .wc-move-disabled' ).removeClass( 'wc-move-disabled' )
.attr( { 'tabindex': '0', 'aria-hidden': 'false' } );
firstRow.find( '.wc-item-reorder-nav .wc-move-up' ).addClass( 'wc-move-disabled' )
.attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
lastRow.find( '.wc-item-reorder-nav .wc-move-down' ).addClass( 'wc-move-disabled' )
.attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
} );
$( '.wc-item-reorder-nav').closest( 'table' ).trigger( 'updateMoveButtons' );
$( '.submit button' ).on( 'click', function() {
if (
$( 'select#woocommerce_allowed_countries' ).val() === 'specific' &&
! $( '[name="woocommerce_specific_allowed_countries[]"]' ).val()
) {
if ( window.confirm( woocommerce_settings_params.i18n_no_specific_countries_selected ) ) {
return true;
}
return false;
}
} );
});
})( jQuery, woocommerce_settings_params, wp );

View File

@ -543,6 +543,16 @@ return array(
),
),
),
'RS' => array(
'currency_code' => 'RSD',
'currency_pos' => 'right_space',
'thousand_sep' => '.',
'decimal_sep' => ',',
'num_decimals' => 2,
'weight_unit' => 'kg',
'dimension_unit' => 'cm',
'tax_rates' => array(),
),
'TH' => array(
'currency_code' => 'THB',
'currency_pos' => 'left',

View File

@ -1077,6 +1077,7 @@ return array(
'VS' => __( 'Vaslui', 'woocommerce' ),
'VN' => __( 'Vrancea', 'woocommerce' ),
),
'RS' => array(),
'SG' => array(),
'SK' => array(),
'SI' => array(),

View File

@ -66,7 +66,7 @@ class WC_Admin_Help {
'<h2>' . __( 'Found a bug?', 'woocommerce' ) . '</h2>' .
/* translators: 1: GitHub issues URL 2: GitHub contribution guide URL 3: System status report URL */
'<p>' . sprintf( __( 'If you find a bug within WooCommerce core you can create a ticket via <a href="%1$s">Github issues</a>. Ensure you read the <a href="%2$s">contribution guide</a> prior to submitting your report. To help us solve your issue, please be as descriptive as possible and include your <a href="%3$s">system status report</a>.', 'woocommerce' ), 'https://github.com/woocommerce/woocommerce/issues?state=open', 'https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md', admin_url( 'admin.php?page=wc-status' ) ) . '</p>' .
'<p><a href="https://github.com/woocommerce/woocommerce/issues?state=open" class="button button-primary">' . __( 'Report a bug', 'woocommerce' ) . '</a> <a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button">' . __( 'System status', 'woocommerce' ) . '</a></p>',
'<p><a href="https://github.com/woocommerce/woocommerce/issues/new?template=Bug_report.md" class="button button-primary">' . __( 'Report a bug', 'woocommerce' ) . '</a> <a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button">' . __( 'System status', 'woocommerce' ) . '</a></p>',
)
);

View File

@ -135,10 +135,13 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
wp_enqueue_script( 'woocommerce_settings', WC()->plugin_url() . '/assets/js/admin/settings' . $suffix . '.js', array( 'jquery', 'wp-util', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'selectWoo' ), WC()->version, true );
wp_localize_script(
'woocommerce_settings', 'woocommerce_settings_params', array(
'woocommerce_settings',
'woocommerce_settings_params',
array(
'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'woocommerce' ),
'i18n_moved_up' => __( 'Item moved up', 'woocommerce' ),
'i18n_moved_down' => __( 'Item moved down', 'woocommerce' ),
'i18n_no_specific_countries_selected' => __( 'Selecting no country to sell to prevents from completing the checkout. Continue anyway?', 'woocommerce' ),
)
);

View File

@ -30,6 +30,9 @@ class WC_Admin {
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
add_action( 'wp_ajax_setup_wizard_check_jetpack', array( $this, 'setup_wizard_check_jetpack' ) );
add_action( 'init', array( 'WC_Site_Tracking', 'init' ) );
// Disable WXR export of schedule action posts.
add_filter( 'action_scheduler_post_type_args', array( $this, 'disable_webhook_post_export' ) );
}
/**
@ -69,8 +72,8 @@ class WC_Admin {
}
// Setup/welcome.
if ( ! empty( $_GET['page'] ) ) {
switch ( $_GET['page'] ) {
if ( ! empty( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
switch ( $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
case 'wc-setup':
include_once dirname( __FILE__ ) . '/class-wc-admin-setup-wizard.php';
break;
@ -251,7 +254,7 @@ class WC_Admin {
$wc_pages = array_diff( $wc_pages, array( 'profile', 'user-edit' ) );
// Check to make sure we're on a WooCommerce admin page.
if ( isset( $current_screen->id ) && apply_filters( 'woocommerce_display_admin_footer_text', in_array( $current_screen->id, $wc_pages ) ) ) {
if ( isset( $current_screen->id ) && apply_filters( 'woocommerce_display_admin_footer_text', in_array( $current_screen->id, $wc_pages, true ) ) ) {
// Change the footer text.
if ( ! get_option( 'woocommerce_admin_footer_text_rated' ) ) {
$footer_text = sprintf(
@ -288,6 +291,20 @@ class WC_Admin {
)
);
}
/**
* Disable WXR export of scheduled action posts.
*
* @since 3.6.2
*
* @param array $args Scehduled action post type registration args.
*
* @return array
*/
public function disable_webhook_post_export( $args ) {
$args['can_export'] = false;
return $args;
}
}
return new WC_Admin();

View File

@ -1,22 +1,34 @@
<?php
/**
* Admin View: Notice - Legacy Shipping.
*
* @package WooCommerce\Admin\Notices
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div id="message" class="updated woocommerce-message woocommerce-legacy-shipping-notice">
<a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'legacy_shipping' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php _e( 'Dismiss', 'woocommerce' ); ?></a>
<div id="message" class="updated woocommerce-message">
<a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'legacy_shipping' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>">
<?php esc_html_e( 'Dismiss', 'woocommerce' ); ?>
</a>
<p class="main"><strong><?php _e( 'New:', 'woocommerce' ); ?> <?php _e( 'Shipping zones', 'woocommerce' ); ?></strong> &#8211; <?php _e( 'a group of regions that can be assigned different shipping methods and rates.', 'woocommerce' ); ?></p>
<p><?php _e( 'Legacy shipping methods (flat rate, international flat rate, local pickup and delivery, and free shipping) are deprecated but will continue to work as normal for now. <b><em>They will be removed in future versions of WooCommerce</em></b>. We recommend disabling these and setting up new rates within shipping zones as soon as possible.', 'woocommerce' ); ?></p>
<p class="main">
<strong><?php esc_html_e( 'New:', 'woocommerce' ); ?> <?php esc_html_e( 'Shipping zones', 'woocommerce' ); ?></strong> &#8211; <?php esc_html_e( 'a group of regions that can be assigned different shipping methods and rates.', 'woocommerce' ); ?>
</p>
<p>
<?php esc_html_e( 'Legacy shipping methods (flat rate, international flat rate, local pickup and delivery, and free shipping) are deprecated but will continue to work as normal for now. <b><em>They will be removed in future versions of WooCommerce</em></b>. We recommend disabling these and setting up new rates within shipping zones as soon as possible.', 'woocommerce' ); ?>
</p>
<p class="submit">
<?php if ( empty( $_GET['page'] ) || empty( $_GET['tab'] ) || 'wc-settings' !== $_GET['page'] || 'shipping' !== $_GET['tab'] ) : ?>
<a class="button-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); ?>"><?php _e( 'Setup shipping zones', 'woocommerce' ); ?></a>
<a class="button-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); ?>">
<?php esc_html_e( 'Setup shipping zones', 'woocommerce' ); ?>
</a>
<?php endif; ?>
<a class="button-secondary" href="https://docs.woocommerce.com/document/setting-up-shipping-zones/"><?php _e( 'Learn more about shipping zones', 'woocommerce' ); ?></a>
<a class="button-secondary" href="https://docs.woocommerce.com/document/setting-up-shipping-zones/">
<?php esc_html_e( 'Learn more about shipping zones', 'woocommerce' ); ?>
</a>
</p>
</div>

View File

@ -1,21 +1,37 @@
<?php
/**
* Admin View: Notice - No Shipping methods.
*
* @package WooCommerce\Admin\Notices
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div id="message" class="updated woocommerce-message woocommerce-no-shipping-methods-notice">
<a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'no_shipping_methods' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php _e( 'Dismiss', 'woocommerce' ); ?></a>
<div id="message" class="updated woocommerce-message">
<a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'no_shipping_methods' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>">
<?php esc_html_e( 'Dismiss', 'woocommerce' ); ?>
</a>
<p class="main"><strong><?php _e( 'Add shipping methods &amp; zones', 'woocommerce' ); ?></strong></p>
<p><?php _e( 'Shipping is currently enabled, but you have not added any shipping methods to your shipping zones.', 'woocommerce' ); ?></p>
<p><?php _e( 'Customers will not be able to purchase physical goods from your store until a shipping method is available.', 'woocommerce' ); ?></p>
<p class="main">
<strong>
<?php esc_html_e( 'Add shipping methods &amp; zones', 'woocommerce' ); ?>
</strong>
</p>
<p>
<?php esc_html_e( 'Shipping is currently enabled, but you have not added any shipping methods to your shipping zones.', 'woocommerce' ); ?>
</p>
<p>
<?php esc_html_e( 'Customers will not be able to purchase physical goods from your store until a shipping method is available.', 'woocommerce' ); ?>
</p>
<p class="submit">
<a class="button-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); ?>"><?php _e( 'Setup shipping zones', 'woocommerce' ); ?></a>
<a class="button-secondary" href="https://docs.woocommerce.com/document/setting-up-shipping-zones/"><?php _e( 'Learn more about shipping zones', 'woocommerce' ); ?></a>
<a class="button-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); ?>">
<?php esc_html_e( 'Setup shipping zones', 'woocommerce' ); ?>
</a>
<a class="button-secondary" href="https://docs.woocommerce.com/document/setting-up-shipping-zones/">
<?php esc_html_e( 'Learn more about shipping zones', 'woocommerce' ); ?>
</a>
</p>
</div>

View File

@ -878,8 +878,8 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
$version_latest = $data['Version'];
// Find latest version.
if ( isset( $available_updates[ $plugin ]->update->new_version ) ) {
$version_latest = $available_updates[ $plugin ]->update->new_version;
if ( isset( $this->available_updates[ $plugin ]->update->new_version ) ) {
$version_latest = $this->available_updates[ $plugin ]->update->new_version;
}
return array(

View File

@ -1176,7 +1176,7 @@ class WC_Checkout {
if ( is_user_logged_in() ) {
// Load customer object, but keep it cached to avoid reloading it multiple times.
if ( is_null( $this->logged_in_customer ) ) {
$this->logged_in_customer = new WC_Customer( get_current_user_id() );
$this->logged_in_customer = new WC_Customer( get_current_user_id(), true );
}
$customer_object = $this->logged_in_customer;
}

View File

@ -501,6 +501,7 @@ class WC_Countries {
'PL' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
'PT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
'SK' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
'RS' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
'SI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
'ES' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}",
'SE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
@ -1103,6 +1104,12 @@ class WC_Countries {
'required' => true,
),
),
'RS' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'SG' => array(
'state' => array(
'required' => false,

View File

@ -961,7 +961,7 @@ class WC_Form_Handler {
try {
$creds = array(
'user_login' => trim( wp_unslash( $_POST['username'] ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
'user_password' => wp_unslash( $_POST['password'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
'user_password' => $_POST['password'], // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
'remember' => isset( $_POST['rememberme'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
);

View File

@ -38,7 +38,7 @@ class WC_Webhook extends WC_Legacy_Webhook {
'event' => '',
'failure_count' => 0,
'user_id' => 0,
'api_version' => 2,
'api_version' => 3,
'pending_delivery' => false,
);

View File

@ -20,7 +20,7 @@ final class WooCommerce {
*
* @var string
*/
public $version = '3.6.0';
public $version = '3.7.0';
/**
* The single instance of the class.
@ -152,6 +152,7 @@ final class WooCommerce {
*/
public function __construct() {
$this->define_constants();
$this->define_tables();
$this->includes();
$this->init_hooks();
}
@ -184,7 +185,6 @@ final class WooCommerce {
add_action( 'init', array( $this, 'init' ), 0 );
add_action( 'init', array( 'WC_Shortcodes', 'init' ) );
add_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) );
add_action( 'init', array( $this, 'wpdb_table_fix' ), 0 );
add_action( 'init', array( $this, 'add_image_sizes' ) );
add_action( 'switch_blog', array( $this, 'wpdb_table_fix' ), 0 );
add_action( 'activated_plugin', array( $this, 'activated_plugin' ) );
@ -230,6 +230,25 @@ final class WooCommerce {
$this->define( 'WC_TEMPLATE_DEBUG_MODE', false );
}
/**
* Register custom tables within $wpdb object.
*/
private function define_tables() {
global $wpdb;
// List of tables without prefixes.
$tables = array(
'payment_tokenmeta' => 'woocommerce_payment_tokenmeta',
'order_itemmeta' => 'woocommerce_order_itemmeta',
'wc_product_meta_lookup' => 'wc_product_meta_lookup',
);
foreach ( $tables as $name => $table ) {
$wpdb->$name = $wpdb->prefix . $table;
$wpdb->tables[] = $table;
}
}
/**
* Define constant if not already set.
*
@ -710,16 +729,7 @@ final class WooCommerce {
* Set tablenames inside WPDB object.
*/
public function wpdb_table_fix() {
global $wpdb;
$wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta';
$wpdb->tables[] = 'woocommerce_payment_tokenmeta';
$wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta';
$wpdb->tables[] = 'woocommerce_order_itemmeta';
$wpdb->wc_product_meta_lookup = $wpdb->prefix . 'wc_product_meta_lookup';
$wpdb->tables[] = 'wc_product_meta_lookup';
$this->define_tables();
}
/**

View File

@ -50,6 +50,7 @@ class WC_Admin_Setup_Wizard_Tracking {
public function add_footer_scripts() {
wp_print_scripts();
WC_Site_Tracking::add_tracking_function();
wc_print_js();
}
/**

View File

@ -705,7 +705,7 @@ function wc_query_string_form_fields( $values = null, $exclude = array(), $curre
$values = array();
if ( ! empty( $url_parts['query'] ) ) {
// This is to preserve full-stops and spaces in the query string when ran through parse_str.
// This is to preserve full-stops, pluses and spaces in the query string when ran through parse_str.
$replace_chars = array(
'.' => '{dot}',
'+' => '{plus}',
@ -717,9 +717,11 @@ function wc_query_string_form_fields( $values = null, $exclude = array(), $curre
// Parse the string.
parse_str( $query_string, $parsed_query_string );
// Convert the full-stops back and add to values array.
// Convert the full-stops, pluses and spaces back and add to values array.
foreach ( $parsed_query_string as $key => $value ) {
$values[ str_replace( array_values( $replace_chars ), array_keys( $replace_chars ), $key ) ] = $value;
$new_key = str_replace( array_values( $replace_chars ), array_keys( $replace_chars ), $key );
$new_value = str_replace( array_values( $replace_chars ), array_keys( $replace_chars ), $value );
$values[ $new_key ] = $new_value;
}
}
}

View File

@ -23,7 +23,7 @@ function wc_change_get_terms_defaults( $defaults, $taxonomies ) {
if ( is_array( $taxonomies ) && 1 < count( $taxonomies ) ) {
return $defaults;
}
$taxonomy = is_array( $taxonomies ) ? $taxonomies[0] : $taxonomies;
$taxonomy = is_array( $taxonomies ) ? (string) current( $taxonomies ) : $taxonomies;
$orderby = 'name';
if ( taxonomy_is_product_attribute( $taxonomy ) ) {

3997
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -56,7 +56,7 @@
"grunt-wp-i18n": "1.0.3",
"husky": "2.2.0",
"istanbul": "1.0.0-alpha.2",
"lint-staged": "8.1.5",
"lint-staged": "8.1.6",
"mocha": "6.1.4",
"node-sass": "4.12.0",
"prettier": "github:automattic/calypso-prettier#c56b4251",

View File

@ -2,7 +2,7 @@
Contributors: automattic, mikejolley, jameskoster, claudiosanches, claudiulodro, kloon, rodrigosprimo, jshreve, coderkevin
Tags: ecommerce, e-commerce, store, sales, sell, shop, cart, checkout, downloadable, downloads, payments, paypal, storefront, stripe, woo commerce, woo
Requires at least: 4.7
Tested up to: 5.1
Tested up to: 5.2
Stable tag: 3.6.0
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
@ -60,7 +60,7 @@ There are also extensions available to add [delivery and shipping options](https
= Design your store with themes and blocks =
WooCommerce store design starts with a theme of your choice. There are hundreds of free and paid themes available, including [Storefront](https://woocommerce.com/storefront/?utm_source=wp%20org%20repo%20listing&utm_content=3.6) by Automattic -- it's free to all stores and you can choose to have it installed for you during the hguided setup.
WooCommerce store design starts with a theme of your choice. There are hundreds of free and paid themes available, including [Storefront](https://woocommerce.com/storefront/?utm_source=wp%20org%20repo%20listing&utm_content=3.6) by Automattic -- it's free to all stores and you can choose to have it installed for you during the guided setup.
Storefront offers deep WooCommerce integration and prioritizes speed and uptime. You can add your brand and define your style by customizing Storefront yourself or adding one of several industry-themed [Storefront child themes](https://woocommerce.com/product-category/themes/storefront-child-theme-themes/?utm_source=wp%20org%20repo%20listing&utm_content=3.6).
@ -104,7 +104,7 @@ There are 80+ [WooCommerce Meetups](https://woocommerce.com/woocommerce/meetups/
If youre interested in contributing to WooCommerce weve got more than 350 contributors, and theres always room for more. Head to the [WooCommerce GitHub Repository](https://github.com/woocommerce/woocommerce?utm_source=wp%20org%20repo%20listing&utm_content=3.6) to find out how you can pitch in.
WooCommerce is currently 100% translated into 24 languages, including Danish, Ukranian, and Persian. If youre interested in helping to localize WooCommerce by adding your local language, visit [translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/woocommerce?utm_source=wp%20org%20repo%20listing&utm_content=3.6).
WooCommerce is currently 100% translated into 24 languages, including Danish, Ukrainian, and Persian. If youre interested in helping to localize WooCommerce by adding your local language, visit [translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/woocommerce?utm_source=wp%20org%20repo%20listing&utm_content=3.6).
== Frequently Asked Questions ==
@ -154,7 +154,7 @@ Visit the [WooCommerce server requirements documentation](https://docs.woocommer
Automatic installation is the easiest option -- WordPress will handles the file transfer, and you wont need to leave your web browser. To do an automatic install of WooCommerce, log in to your WordPress dashboard, navigate to the Plugins menu, and click “Add New.”
In the search field type “WooCommerce,” then click “Search Plugins.” Once youve found us, you can view details about it such as the point release, rating, and description. Most importantly of course, you can install it by! Clicki “Install Now,” and WordPress will take it from there.
In the search field type “WooCommerce,” then click “Search Plugins.” Once youve found us, you can view details about it such as the point release, rating, and description. Most importantly of course, you can install it by! Click “Install Now,” and WordPress will take it from there.
= Manual installation =

View File

@ -75,9 +75,19 @@ class WC_Mock_WC_Data_Store extends WC_Data_Store_WP implements WC_Object_Data_S
$content_id = $object->get_id();
if ( 'user' === $this->meta_type ) {
wp_update_user( array( 'ID' => $customer_id, 'user_email' => $object->get_content() ) );
wp_update_user(
array(
'ID' => $customer_id,
'user_email' => $object->get_content(),
)
);
} else {
wp_update_post( array( 'ID' => $content_id, 'post_title' => $object->get_content() ) );
wp_update_post(
array(
'ID' => $content_id,
'post_title' => $object->get_content(),
)
);
}
}
@ -132,7 +142,7 @@ class WC_Mock_WC_Data extends WC_Data {
$this->set_object_read( true );
}
$this->data_store = new WC_Mock_WC_Data_Store;
$this->data_store = new WC_Mock_WC_Data_Store();
if ( $this->get_id() > 0 ) {
$this->data_store->read( $this );

View File

@ -19,14 +19,18 @@ class WC_Helper_Coupon {
*/
public static function create_coupon( $coupon_code = 'dummycoupon', $meta = array() ) {
// Insert post
$coupon_id = wp_insert_post( array(
$coupon_id = wp_insert_post(
array(
'post_title' => $coupon_code,
'post_type' => 'shop_coupon',
'post_status' => 'publish',
'post_excerpt' => 'This is a dummy coupon',
) );
)
);
$meta = wp_parse_args( $meta, array(
$meta = wp_parse_args(
$meta,
array(
'discount_type' => 'fixed_cart',
'coupon_amount' => '1',
'individual_use' => 'no',
@ -44,7 +48,8 @@ class WC_Helper_Coupon {
'maximum_amount' => '',
'customer_email' => array(),
'usage_count' => '0',
) );
)
);
// Update meta.
foreach ( $meta as $key => $value ) {

View File

@ -32,7 +32,7 @@ class WC_Helper_Customer {
'calculated_shipping' => false,
);
WC_Helper_Customer::set_customer_details( $customer_data );
self::set_customer_details( $customer_data );
$customer = new WC_Customer( 0, true );
@ -70,7 +70,7 @@ class WC_Helper_Customer {
* @return array
*/
public static function get_expected_store_location() {
return array( "GB", "", "", "" );
return array( 'GB', '', '', '' );
}
/**

View File

@ -58,12 +58,14 @@ class WC_Helper_Order {
// Add order products
$item = new WC_Order_Item_Product();
$item->set_props( array(
$item->set_props(
array(
'product' => $product,
'quantity' => 4,
'subtotal' => wc_get_price_excluding_tax( $product, array( 'qty' => 4 ) ),
'total' => wc_get_price_excluding_tax( $product, array( 'qty' => 4 ) ),
) );
)
);
$item->save();
$order->add_item( $item );
@ -84,12 +86,14 @@ class WC_Helper_Order {
$shipping_taxes = WC_Tax::calc_shipping_tax( '10', WC_Tax::get_shipping_tax_rates() );
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate' );
$item = new WC_Order_Item_Shipping();
$item->set_props( array(
$item->set_props(
array(
'method_title' => $rate->label,
'method_id' => $rate->id,
'total' => wc_format_decimal( $rate->cost ),
'taxes' => $rate->taxes,
) );
)
);
foreach ( $rate->get_meta_data() as $key => $value ) {
$item->add_meta_data( $key, $value, true );
}

View File

@ -428,7 +428,8 @@ abstract class WP_HTTP_TestCase extends WP_UnitTestCase {
// phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_file_put_contents
file_put_contents(
self::$cache_dir . '/' . self::$cache_group, serialize( self::$cache )
self::$cache_dir . '/' . self::$cache_group,
serialize( self::$cache )
);
}
}

View File

@ -45,14 +45,17 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
* @since 2.6.0
*/
public function test_wc_get_account_menu_items() {
$this->assertEquals( array(
$this->assertEquals(
array(
'dashboard' => 'Dashboard',
'orders' => 'Orders',
'downloads' => 'Downloads',
'edit-address' => 'Addresses',
'edit-account' => 'Account details',
'customer-logout' => 'Logout',
), wc_get_account_menu_items() );
),
wc_get_account_menu_items()
);
}
/**
@ -79,13 +82,16 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
* @since 2.6.0
*/
public function test_wc_get_account_orders_columns() {
$this->assertEquals( array(
$this->assertEquals(
array(
'order-number' => 'Order',
'order-date' => 'Date',
'order-status' => 'Status',
'order-total' => 'Total',
'order-actions' => 'Actions',
), wc_get_account_orders_columns() );
),
wc_get_account_orders_columns()
);
}
/**
@ -94,12 +100,15 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
* @since 2.6.0
*/
public function test_wc_get_account_downloads_columns() {
$this->assertEquals( array(
$this->assertEquals(
array(
'download-file' => 'Download',
'download-remaining' => 'Downloads remaining',
'download-expires' => 'Expires',
'download-product' => 'Product',
), wc_get_account_downloads_columns() );
),
wc_get_account_downloads_columns()
);
}
/**
@ -108,11 +117,14 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
* @since 3.3.0
*/
public function test_wc_get_account_payment_methods_columns() {
$this->assertEquals( array(
$this->assertEquals(
array(
'method' => 'Method',
'expires' => 'Expires',
'actions' => '&nbsp;',
), wc_get_account_payment_methods_columns() );
),
wc_get_account_payment_methods_columns()
);
}
/**
@ -121,10 +133,13 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
* @since 3.3.0
*/
public function test_wc_get_account_payment_methods_types() {
$this->assertEquals( array(
$this->assertEquals(
array(
'cc' => 'Credit card',
'echeck' => 'eCheck',
), wc_get_account_payment_methods_types() );
),
wc_get_account_payment_methods_types()
);
}
/**
@ -135,7 +150,8 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
public function test_wc_get_account_orders_actions() {
$order = WC_Helper_Order::create_order();
$this->assertEquals( array(
$this->assertEquals(
array(
'view' => array(
'url' => $order->get_view_order_url(),
'name' => 'View',
@ -148,7 +164,9 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => 'Cancel',
),
), wc_get_account_orders_actions( $order->get_id() ) );
),
wc_get_account_orders_actions( $order->get_id() )
);
$order->delete( true );
}
@ -187,7 +205,8 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
$delete_url = wc_get_endpoint_url( 'delete-payment-method', $token->get_id() );
$delete_url = wp_nonce_url( $delete_url, 'delete-payment-method-' . $token->get_id() );
$this->assertEquals( array(
$this->assertEquals(
array(
'cc' => array(
array(
'method' => array(
@ -205,7 +224,9 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
),
),
),
), wc_get_account_saved_payment_methods_list( array(), $customer->get_id() ) );
),
wc_get_account_saved_payment_methods_list( array(), $customer->get_id() )
);
$customer->delete( true );
$token->delete( true );
@ -226,13 +247,16 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
$token->set_expiry_year( '2020' );
$token->save();
$this->assertEquals( array(
$this->assertEquals(
array(
'method' => array(
'last4' => '1234',
'brand' => 'Mastercard',
),
'expires' => '12/20',
), wc_get_account_saved_payment_methods_list_item_cc( array(), $token ) );
),
wc_get_account_saved_payment_methods_list_item_cc( array(), $token )
);
$token->delete( true );
}
@ -249,12 +273,15 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
$token->set_last4( '1234' );
$token->save();
$this->assertEquals( array(
$this->assertEquals(
array(
'method' => array(
'last4' => '1234',
'brand' => 'eCheck',
),
), wc_get_account_saved_payment_methods_list_item_echeck( array(), $token ) );
),
wc_get_account_saved_payment_methods_list_item_echeck( array(), $token )
);
$token->delete( true );
}

View File

@ -36,7 +36,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
$order->save();
$report = new WC_Admin_Report();
$data = $report->get_order_report_data( array(
$data = $report->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
@ -44,7 +45,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
'name' => 'total_orders',
),
),
) );
)
);
$this->assertEquals( 1, $data->total_orders, 'Expected to see one completed order in the report.' );
WC_Admin_Report::maybe_update_transients();
@ -71,7 +73,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
$order->save();
$report = new WC_Admin_Report();
$data = $report->get_order_report_data( array(
$data = $report->get_order_report_data(
array(
'data' => array(
'_billing_first_name' => array(
'type' => 'meta',
@ -79,7 +82,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
'name' => 'customer_name',
),
),
) );
)
);
$this->assertEquals( $order->get_billing_first_name(), $data->customer_name );
}
@ -89,12 +93,15 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
*/
public function test_get_order_report_data_for_parent_meta() {
$order = WC_Helper_Order::create_order();
$refund = wc_create_refund( array(
$refund = wc_create_refund(
array(
'order_id' => $order->get_id(),
) );
)
);
$report = new WC_Admin_Report();
$data = $report->get_order_report_data( array(
$data = $report->get_order_report_data(
array(
'data' => array(
'_order_total' => array(
'type' => 'parent_meta',
@ -102,7 +109,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
'name' => 'total_refund',
),
),
) );
)
);
$this->assertEquals( $order->get_total(), $data->total_refund );
}
@ -116,7 +124,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
$order->save();
$report = new WC_Admin_Report();
$data = $report->get_order_report_data( array(
$data = $report->get_order_report_data(
array(
'data' => array(
'post_status' => array(
'type' => 'post_data',
@ -124,7 +133,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
'name' => 'post_status',
),
),
) );
)
);
$this->assertEquals( 'wc-completed', $data->post_status );
}
@ -139,7 +149,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
$order->save();
$report = new WC_Admin_Report();
$data = $report->get_order_report_data( array(
$data = $report->get_order_report_data(
array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
@ -147,7 +158,8 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
'name' => 'name',
),
),
) );
)
);
$this->assertEquals( $product->get_name(), $data->name );
}

View File

@ -15,9 +15,11 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
public function setUp() {
parent::setUp();
$this->endpoint = new WC_REST_Coupons_Controller();
$this->user = $this->factory->user->create( array(
$this->user = $this->factory->user->create(
array(
'role' => 'administrator',
) );
)
);
}
/**
@ -47,7 +49,8 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( 2, count( $coupons ) );
$this->assertContains( array(
$this->assertContains(
array(
'id' => $coupon_1->get_id(),
'code' => 'dummycoupon-1',
'amount' => '1.00',
@ -87,7 +90,9 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
),
),
),
), $coupons );
),
$coupons
);
}
/**
@ -112,7 +117,8 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
$data = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => $coupon->get_id(),
'code' => 'dummycoupon-1',
'amount' => '1.00',
@ -140,7 +146,9 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
'email_restrictions' => array(),
'used_by' => array(),
'meta_data' => array(),
), $data );
),
$data
);
}
/**
@ -171,18 +179,21 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
public function test_create_coupon() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons' );
$request->set_body_params( array(
$request->set_body_params(
array(
'code' => 'test',
'amount' => '5.00',
'discount_type' => 'fixed_product',
'description' => 'Test',
'usage_limit' => 10,
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertEquals( 201, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => $data['id'],
'code' => 'test',
'amount' => '5.00',
@ -210,7 +221,9 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
'email_restrictions' => array(),
'used_by' => array(),
'meta_data' => array(),
), $data );
),
$data
);
}
/**
@ -222,10 +235,12 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
// test no code...
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons' );
$request->set_body_params( array(
$request->set_body_params(
array(
'amount' => '5.00',
'discount_type' => 'fixed_product',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -241,11 +256,13 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
// test no code...
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons' );
$request->set_body_params( array(
$request->set_body_params(
array(
'code' => 'fail',
'amount' => '5.00',
'discount_type' => 'fixed_product',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -268,10 +285,12 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
$this->assertEquals( '1.00', $data['amount'] );
$request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() );
$request->set_body_params( array(
$request->set_body_params(
array(
'amount' => '10.00',
'description' => 'New description',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -288,11 +307,13 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/0' );
$request->set_body_params( array(
$request->set_body_params(
array(
'code' => 'tester',
'amount' => '10.00',
'description' => 'New description',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -309,10 +330,12 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
$post = get_post( $coupon->get_id() );
$request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() );
$request->set_body_params( array(
$request->set_body_params(
array(
'amount' => '10.00',
'description' => 'New description',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 401, $response->get_status() );
@ -370,7 +393,8 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
$coupon_4 = WC_Helper_Coupon::create_coupon( 'dummycoupon-4' );
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons/batch' );
$request->set_body_params( array(
$request->set_body_params(
array(
'update' => array(
array(
'id' => $coupon_1->get_id(),
@ -387,7 +411,8 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
'amount' => '11.00',
),
),
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();

View File

@ -14,9 +14,11 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
public function setUp() {
parent::setUp();
$this->endpoint = new WC_REST_Payment_Gateways_Controller();
$this->user = $this->factory->user->create( array(
$this->user = $this->factory->user->create(
array(
'role' => 'administrator',
) );
)
);
}
/**
@ -42,7 +44,8 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
$gateways = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'cheque',
'title' => 'Check payments',
'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.',
@ -53,10 +56,13 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
'method_supports' => array(
'products',
),
'settings' => array_diff_key( $this->get_settings( 'WC_Gateway_Cheque' ), array(
'settings' => array_diff_key(
$this->get_settings( 'WC_Gateway_Cheque' ),
array(
'enabled' => false,
'description' => false,
) ),
)
),
'_links' => array(
'self' => array(
array(
@ -69,7 +75,9 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
),
),
),
), $gateways );
),
$gateways
);
}
/**
@ -95,7 +103,8 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
$paypal = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => 'paypal',
'title' => 'PayPal',
'description' => "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.",
@ -107,11 +116,16 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
'products',
'refunds',
),
'settings' => array_diff_key( $this->get_settings( 'WC_Gateway_Paypal' ), array(
'settings' => array_diff_key(
$this->get_settings( 'WC_Gateway_Paypal' ),
array(
'enabled' => false,
'description' => false,
) ),
), $paypal );
)
),
),
$paypal
);
}
/**
@ -154,11 +168,13 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
// test updating single setting
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'email' => 'woo@woo.local',
),
) );
)
);
$response = $this->server->dispatch( $request );
$paypal = $response->get_data();
@ -169,12 +185,14 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
// test updating multiple settings
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'testmode' => 'yes',
'title' => 'PayPal - New Title',
),
) );
)
);
$response = $this->server->dispatch( $request );
$paypal = $response->get_data();
@ -185,10 +203,12 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
// Test other parameters, and recheck settings
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'enabled' => false,
'order' => 2,
) );
)
);
$response = $this->server->dispatch( $request );
$paypal = $response->get_data();
@ -200,20 +220,24 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
// test bogus
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'paymentaction' => 'afasfasf',
),
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 400, $response->get_status() );
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'paymentaction' => 'authorization',
),
) );
)
);
$response = $this->server->dispatch( $request );
$paypal = $response->get_data();
$this->assertEquals( 'authorization', $paypal['settings']['paymentaction']['value'] );
@ -227,12 +251,14 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
public function test_update_payment_gateway_without_permission() {
wp_set_current_user( 0 );
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'testmode' => 'yes',
'title' => 'PayPal - New Title',
),
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 401, $response->get_status() );
}
@ -245,9 +271,11 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
public function test_update_payment_gateway_invalid_id() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/totally_fake_method' );
$request->set_body_params( array(
$request->set_body_params(
array(
'enabled' => true,
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 404, $response->get_status() );
}

View File

@ -80,7 +80,8 @@ class WC_Tests_API_Product_Reviews extends WC_REST_Unit_Test_Case {
),
),
),
), $product_reviews
),
$product_reviews
);
}
@ -134,7 +135,8 @@ class WC_Tests_API_Product_Reviews extends WC_REST_Unit_Test_Case {
'rating' => 0,
'verified' => false,
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
), $data
),
$data
);
}
@ -198,7 +200,8 @@ class WC_Tests_API_Product_Reviews extends WC_REST_Unit_Test_Case {
'rating' => 5,
'verified' => false,
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
), $data
),
$data
);
}

View File

@ -52,7 +52,8 @@ class WC_Tests_API_Reports_Coupons_Totals extends WC_REST_Unit_Test_Case {
FROM $wpdb->postmeta
WHERE meta_key = 'discount_type'
AND meta_value = %s
", $slug
",
$slug
)
);

View File

@ -15,9 +15,11 @@ class Settings extends WC_REST_Unit_Test_Case {
parent::setUp();
$this->endpoint = new WC_REST_Setting_Options_Controller();
WC_Helper_Settings::register();
$this->user = $this->factory->user->create( array(
$this->user = $this->factory->user->create(
array(
'role' => 'administrator',
) );
)
);
}
/**
@ -45,7 +47,8 @@ class Settings extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'test',
'label' => 'Test extension',
'parent_id' => '',
@ -58,9 +61,12 @@ class Settings extends WC_REST_Unit_Test_Case {
),
),
),
), $data );
),
$data
);
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'sub-test',
'label' => 'Sub test',
'parent_id' => 'test',
@ -73,7 +79,9 @@ class Settings extends WC_REST_Unit_Test_Case {
),
),
),
), $data );
),
$data
);
}
/**
@ -201,9 +209,11 @@ class Settings extends WC_REST_Unit_Test_Case {
// test updating shop display setting
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'both',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -211,9 +221,11 @@ class Settings extends WC_REST_Unit_Test_Case {
$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'subcategories',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -221,9 +233,11 @@ class Settings extends WC_REST_Unit_Test_Case {
$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => '',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -246,14 +260,16 @@ class Settings extends WC_REST_Unit_Test_Case {
// test setting both at once
$request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' );
$request->set_body_params( array(
$request->set_body_params(
array(
'update' => array(
array(
'id' => 'woocommerce_shop_page_display',
'value' => 'both',
),
),
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -262,14 +278,16 @@ class Settings extends WC_REST_Unit_Test_Case {
// test updating one, but making sure the other value stays the same
$request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' );
$request->set_body_params( array(
$request->set_body_params(
array(
'update' => array(
array(
'id' => 'woocommerce_shop_page_display',
'value' => 'subcategories',
),
),
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertEquals( 'subcategories', $data['update'][0]['value'] );
@ -374,9 +392,11 @@ class Settings extends WC_REST_Unit_Test_Case {
wp_set_current_user( 0 );
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'subcategories',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 401, $response->get_status() );
}
@ -391,14 +411,16 @@ class Settings extends WC_REST_Unit_Test_Case {
wp_set_current_user( 0 );
$request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' );
$request->set_body_params( array(
$request->set_body_params(
array(
'update' => array(
array(
'id' => 'woocommerce_shop_page_display',
'value' => 'subcategories',
),
),
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 401, $response->get_status() );
}
@ -413,9 +435,11 @@ class Settings extends WC_REST_Unit_Test_Case {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/test/invalid' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'test',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 404, $response->get_status() );
}
@ -432,7 +456,8 @@ class Settings extends WC_REST_Unit_Test_Case {
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products' ) );
$data = $response->get_data();
$this->assertTrue( is_array( $data ) );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'woocommerce_downloads_require_login',
'label' => 'Access restriction',
'description' => 'Downloads require login',
@ -452,7 +477,9 @@ class Settings extends WC_REST_Unit_Test_Case {
),
),
),
), $data );
),
$data
);
// test get single
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products/woocommerce_dimension_unit' ) );
@ -462,9 +489,11 @@ class Settings extends WC_REST_Unit_Test_Case {
// test update
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_dimension_unit' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'yd',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -485,7 +514,8 @@ class Settings extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'recipient',
'label' => 'Recipient(s)',
'description' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
@ -505,13 +535,16 @@ class Settings extends WC_REST_Unit_Test_Case {
),
),
),
), $settings );
),
$settings
);
// test get single
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order/subject' ) );
$setting = $response->get_data();
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => 'subject',
'label' => 'Subject',
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
@ -520,17 +553,22 @@ class Settings extends WC_REST_Unit_Test_Case {
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
'value' => '',
'group_id' => 'email_new_order',
), $setting );
),
$setting
);
// test update
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_new_order', 'subject' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'This is my subject',
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => 'subject',
'label' => 'Subject',
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
@ -539,7 +577,9 @@ class Settings extends WC_REST_Unit_Test_Case {
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
'value' => 'This is my subject',
'group_id' => 'email_new_order',
), $setting );
),
$setting
);
// test updating another subject and making sure it works with a "similar" id
$request = new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
@ -550,9 +590,11 @@ class Settings extends WC_REST_Unit_Test_Case {
// test update
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'This is my new subject',
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
@ -575,25 +617,31 @@ class Settings extends WC_REST_Unit_Test_Case {
// test bogus value
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'not_yes_or_no',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 400, $response->get_status() );
// test yes
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'yes',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
// test no
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'no',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
}
@ -608,17 +656,21 @@ class Settings extends WC_REST_Unit_Test_Case {
// not a valid option
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'billing2',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 400, $response->get_status() );
// valid
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'billing',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
}
@ -636,9 +688,11 @@ class Settings extends WC_REST_Unit_Test_Case {
$this->assertEmpty( $setting['value'] );
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => array( 'AX', 'DZ', 'MMM' ),
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] );
@ -658,17 +712,21 @@ class Settings extends WC_REST_Unit_Test_Case {
// invalid
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'pounds', // invalid, should be lbs
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 400, $response->get_status() );
// valid
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'lbs', // invalid, should be lbs
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( 'lbs', $setting['value'] );
@ -706,18 +764,22 @@ class Settings extends WC_REST_Unit_Test_Case {
$old_value = $setting['value'];
$new_value = $old_value . ' ' . rand( 1000, 9999 );
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $new_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $new_value, $setting['value'] );
// Put the original value back
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $old_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $old_value, $setting['value'] );
@ -738,18 +800,22 @@ class Settings extends WC_REST_Unit_Test_Case {
$old_value = $setting['value'];
$new_value = $old_value . ' ' . rand( 1000, 9999 );
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $new_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $new_value, $setting['value'] );
// Put the original value back
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $old_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $old_value, $setting['value'] );
@ -770,18 +836,22 @@ class Settings extends WC_REST_Unit_Test_Case {
$old_value = $setting['value'];
$new_value = $old_value . ' ' . rand( 1000, 9999 );
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $new_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $new_value, $setting['value'] );
// Put the original value back
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $old_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $old_value, $setting['value'] );
@ -802,18 +872,22 @@ class Settings extends WC_REST_Unit_Test_Case {
$old_value = $setting['value'];
$new_value = $old_value . ' ' . rand( 1000, 9999 );
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $new_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $new_value, $setting['value'] );
// Put the original value back
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $old_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $old_value, $setting['value'] );

View File

@ -14,9 +14,11 @@ class Shipping_Methods extends WC_REST_Unit_Test_Case {
public function setUp() {
parent::setUp();
$this->endpoint = new WC_REST_Shipping_Methods_Controller();
$this->user = $this->factory->user->create( array(
$this->user = $this->factory->user->create(
array(
'role' => 'administrator',
) );
)
);
}
/**
@ -42,7 +44,8 @@ class Shipping_Methods extends WC_REST_Unit_Test_Case {
$methods = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'free_shipping',
'title' => 'Free shipping',
'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.',
@ -58,7 +61,9 @@ class Shipping_Methods extends WC_REST_Unit_Test_Case {
),
),
),
), $methods );
),
$methods
);
}
/**
@ -84,11 +89,14 @@ class Shipping_Methods extends WC_REST_Unit_Test_Case {
$method = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => 'local_pickup',
'title' => 'Local pickup',
'description' => 'Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.',
), $method );
),
$method
);
}
/**

View File

@ -99,7 +99,8 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
// Create a zone and make sure it's in the response
@ -132,7 +133,8 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -222,7 +224,8 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -288,7 +291,8 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -391,7 +395,8 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -418,7 +423,9 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
// Create a zone
$zone = $this->create_shipping_zone(
'Zone 1', 0, array(
'Zone 1',
0,
array(
array(
'code' => 'US',
'type' => 'country',
@ -449,7 +456,8 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -552,7 +560,8 @@ class WC_Tests_API_Shipping_Zones extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}

View File

@ -15,9 +15,11 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
public function setUp() {
parent::setUp();
$this->endpoint = new WC_REST_Coupons_Controller();
$this->user = $this->factory->user->create( array(
$this->user = $this->factory->user->create(
array(
'role' => 'administrator',
) );
)
);
}
/**
@ -47,7 +49,8 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( 2, count( $coupons ) );
$this->assertContains( array(
$this->assertContains(
array(
'id' => $coupon_1->get_id(),
'code' => 'dummycoupon-1',
'amount' => '1.00',
@ -87,7 +90,9 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $coupons );
),
$coupons
);
}
/**
@ -112,7 +117,8 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
$data = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => $coupon->get_id(),
'code' => 'dummycoupon-1',
'amount' => '1.00',
@ -140,7 +146,9 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
'email_restrictions' => array(),
'used_by' => array(),
'meta_data' => array(),
), $data );
),
$data
);
}
/**
@ -171,18 +179,21 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
public function test_create_coupon() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
$request->set_body_params( array(
$request->set_body_params(
array(
'code' => 'test',
'amount' => '5.00',
'discount_type' => 'fixed_product',
'description' => 'Test',
'usage_limit' => 10,
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertEquals( 201, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => $data['id'],
'code' => 'test',
'amount' => '5.00',
@ -210,7 +221,9 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
'email_restrictions' => array(),
'used_by' => array(),
'meta_data' => array(),
), $data );
),
$data
);
}
/**
@ -222,10 +235,12 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
// test no code...
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
$request->set_body_params( array(
$request->set_body_params(
array(
'amount' => '5.00',
'discount_type' => 'fixed_product',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -241,11 +256,13 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
// test no code...
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
$request->set_body_params( array(
$request->set_body_params(
array(
'code' => 'fail',
'amount' => '5.00',
'discount_type' => 'fixed_product',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -268,10 +285,12 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
$this->assertEquals( '1.00', $data['amount'] );
$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() );
$request->set_body_params( array(
$request->set_body_params(
array(
'amount' => '10.00',
'description' => 'New description',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -288,11 +307,13 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/0' );
$request->set_body_params( array(
$request->set_body_params(
array(
'code' => 'tester',
'amount' => '10.00',
'description' => 'New description',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -309,10 +330,12 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
$post = get_post( $coupon->get_id() );
$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() );
$request->set_body_params( array(
$request->set_body_params(
array(
'amount' => '10.00',
'description' => 'New description',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 401, $response->get_status() );
@ -370,7 +393,8 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
$coupon_4 = WC_Helper_Coupon::create_coupon( 'dummycoupon-4' );
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons/batch' );
$request->set_body_params( array(
$request->set_body_params(
array(
'update' => array(
array(
'id' => $coupon_1->get_id(),
@ -387,7 +411,8 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
'amount' => '11.00',
),
),
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();

View File

@ -41,16 +41,19 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
WC_Helper_Customer::create_customer( 'test2', 'test2', 'test2@woo.local' );
$request = new WP_REST_Request( 'GET', '/wc/v2/customers' );
$request->set_query_params( array(
$request->set_query_params(
array(
'orderby' => 'id',
) );
)
);
$response = $this->server->dispatch( $request );
$customers = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( 2, count( $customers ) );
$this->assertContains( array(
$this->assertContains(
array(
'id' => $customer_1->get_id(),
'date_created' => wc_rest_prepare_date_response( $customer_1->get_date_created(), false ),
'date_created_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_created() ),
@ -102,7 +105,9 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $customers );
),
$customers
);
}
/**
@ -126,16 +131,19 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
// Test just the basics first..
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
$request->set_body_params( array(
$request->set_body_params(
array(
'username' => 'create_customer_test',
'password' => 'test123',
'email' => 'create_customer_test@woo.local',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertEquals( 201, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => $data['id'],
'date_created' => $data['date_created'],
'date_created_gmt' => $data['date_created_gmt'],
@ -175,11 +183,14 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
'orders_count' => 0,
'total_spent' => '0.00',
'avatar_url' => $data['avatar_url'],
), $data );
),
$data
);
// Test extra data
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
$request->set_body_params( array(
$request->set_body_params(
array(
'username' => 'create_customer_test2',
'password' => 'test123',
'email' => 'create_customer_test2@woo.local',
@ -193,12 +204,14 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
'state' => 'CA',
'country' => 'US',
),
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertEquals( 201, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => $data['id'],
'date_created' => $data['date_created'],
'date_created_gmt' => $data['date_created_gmt'],
@ -238,15 +251,19 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
'orders_count' => 0,
'total_spent' => '0.00',
'avatar_url' => $data['avatar_url'],
), $data );
),
$data
);
// Test without required field
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
$request->set_body_params( array(
$request->set_body_params(
array(
'username' => 'create_customer_test3',
'first_name' => 'Test',
'last_name' => 'McTestFace',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -261,11 +278,13 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
public function test_create_customer_without_permission() {
wp_set_current_user( 0 );
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
$request->set_body_params( array(
$request->set_body_params(
array(
'username' => 'create_customer_test_without_permission',
'password' => 'test123',
'email' => 'create_customer_test_without_permission@woo.local',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 401, $response->get_status() );
}
@ -281,7 +300,8 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) );
$data = $response->get_data();
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => $data['id'],
'date_created' => $data['date_created'],
'date_created_gmt' => $data['date_created_gmt'],
@ -321,7 +341,9 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
'orders_count' => 0,
'total_spent' => '0.00',
'avatar_url' => $data['avatar_url'],
), $data );
),
$data
);
}
/**
@ -362,10 +384,12 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
$this->assertEquals( 'update_customer_test@woo.local', $data['email'] );
$request = new WP_REST_Request( 'PUT', '/wc/v2/customers/' . $customer->get_id() );
$request->set_body_params( array(
$request->set_body_params(
array(
'email' => 'updated_email@woo.local',
'first_name' => 'UpdatedTest',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -452,7 +476,8 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
$customer_4 = WC_Helper_Customer::create_customer( 'test_batch_customer4', 'test123', 'test_batch_customer4@woo.local' );
$request = new WP_REST_Request( 'POST', '/wc/v2/customers/batch' );
$request->set_body_params( array(
$request->set_body_params(
array(
'update' => array(
array(
'id' => $customer_1->get_id(),
@ -470,7 +495,8 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
'email' => 'newuser@woo.local',
),
),
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();

View File

@ -121,9 +121,11 @@ class WC_Tests_API_Orders_V2 extends WC_REST_Unit_Test_Case {
public function test_get_item_refund_id() {
wp_set_current_user( $this->user );
$order = WC_Helper_Order::create_order();
$refund = wc_create_refund( array(
$refund = wc_create_refund(
array(
'order_id' => $order->get_id(),
) );
)
);
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $refund->get_id() ) );
$this->assertEquals( 404, $response->get_status() );
}
@ -273,7 +275,7 @@ class WC_Tests_API_Orders_V2 extends WC_REST_Unit_Test_Case {
$request->set_body_params(
array(
'payment_method' => 'bacs',
'payment_method_title' => '<h1>Sanitize this too <script>alert(1);</script></h1>'
'payment_method_title' => '<h1>Sanitize this too <script>alert(1);</script></h1>',
)
);
$response = $this->server->dispatch( $request );

View File

@ -14,9 +14,11 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
public function setUp() {
parent::setUp();
$this->endpoint = new WC_REST_Payment_Gateways_Controller();
$this->user = $this->factory->user->create( array(
$this->user = $this->factory->user->create(
array(
'role' => 'administrator',
) );
)
);
}
/**
@ -42,7 +44,8 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
$gateways = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'cheque',
'title' => 'Check payments',
'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.',
@ -50,10 +53,13 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
'enabled' => false,
'method_title' => 'Check payments',
'method_description' => 'Take payments in person via checks. This offline gateway can also be useful to test purchases.',
'settings' => array_diff_key( $this->get_settings( 'WC_Gateway_Cheque' ), array(
'settings' => array_diff_key(
$this->get_settings( 'WC_Gateway_Cheque' ),
array(
'enabled' => false,
'description' => false,
) ),
)
),
'_links' => array(
'self' => array(
array(
@ -66,7 +72,9 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $gateways );
),
$gateways
);
}
/**
@ -92,7 +100,8 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
$paypal = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => 'paypal',
'title' => 'PayPal',
'description' => "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.",
@ -100,11 +109,16 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
'enabled' => false,
'method_title' => 'PayPal',
'method_description' => 'PayPal Standard redirects customers to PayPal to enter their payment information.',
'settings' => array_diff_key( $this->get_settings( 'WC_Gateway_Paypal' ), array(
'settings' => array_diff_key(
$this->get_settings( 'WC_Gateway_Paypal' ),
array(
'enabled' => false,
'description' => false,
) ),
), $paypal );
)
),
),
$paypal
);
}
/**
@ -147,11 +161,13 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
// test updating single setting
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'email' => 'woo@woo.local',
),
) );
)
);
$response = $this->server->dispatch( $request );
$paypal = $response->get_data();
@ -162,12 +178,14 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
// test updating multiple settings
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'testmode' => 'yes',
'title' => 'PayPal - New Title',
),
) );
)
);
$response = $this->server->dispatch( $request );
$paypal = $response->get_data();
@ -178,10 +196,12 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
// Test other parameters, and recheck settings
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'enabled' => false,
'order' => 2,
) );
)
);
$response = $this->server->dispatch( $request );
$paypal = $response->get_data();
@ -193,20 +213,24 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
// test bogus
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'paymentaction' => 'afasfasf',
),
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 400, $response->get_status() );
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'paymentaction' => 'authorization',
),
) );
)
);
$response = $this->server->dispatch( $request );
$paypal = $response->get_data();
$this->assertEquals( 'authorization', $paypal['settings']['paymentaction']['value'] );
@ -220,12 +244,14 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
public function test_update_payment_gateway_without_permission() {
wp_set_current_user( 0 );
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
$request->set_body_params( array(
$request->set_body_params(
array(
'settings' => array(
'testmode' => 'yes',
'title' => 'PayPal - New Title',
),
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 401, $response->get_status() );
}
@ -238,9 +264,11 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
public function test_update_payment_gateway_invalid_id() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/totally_fake_method' );
$request->set_body_params( array(
$request->set_body_params(
array(
'enabled' => true,
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 404, $response->get_status() );
}

View File

@ -80,7 +80,8 @@ class WC_Tests_API_Product_Reviews_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $product_reviews
),
$product_reviews
);
}
@ -134,7 +135,8 @@ class WC_Tests_API_Product_Reviews_V2 extends WC_REST_Unit_Test_Case {
'rating' => 0,
'verified' => false,
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
), $data
),
$data
);
}
@ -198,7 +200,8 @@ class WC_Tests_API_Product_Reviews_V2 extends WC_REST_Unit_Test_Case {
'rating' => 5,
'verified' => false,
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
), $data
),
$data
);
}

View File

@ -15,9 +15,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
parent::setUp();
$this->endpoint = new WC_REST_Setting_Options_Controller();
WC_Helper_Settings::register();
$this->user = $this->factory->user->create( array(
$this->user = $this->factory->user->create(
array(
'role' => 'administrator',
) );
)
);
}
/**
@ -45,7 +47,8 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'test',
'label' => 'Test extension',
'parent_id' => '',
@ -58,9 +61,12 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data );
),
$data
);
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'sub-test',
'label' => 'Sub test',
'parent_id' => 'test',
@ -73,7 +79,9 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data );
),
$data
);
}
/**
@ -200,9 +208,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
// test updating shop display setting
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'both',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -210,9 +220,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'subcategories',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -220,9 +232,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => '',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -245,14 +259,16 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
// test setting both at once
$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
$request->set_body_params( array(
$request->set_body_params(
array(
'update' => array(
array(
'id' => 'woocommerce_shop_page_display',
'value' => 'both',
),
),
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -261,14 +277,16 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
// test updating one, but making sure the other value stays the same
$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
$request->set_body_params( array(
$request->set_body_params(
array(
'update' => array(
array(
'id' => 'woocommerce_shop_page_display',
'value' => 'subcategories',
),
),
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertEquals( 'subcategories', $data['update'][0]['value'] );
@ -373,9 +391,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
wp_set_current_user( 0 );
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'subcategories',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 401, $response->get_status() );
}
@ -390,14 +410,16 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
wp_set_current_user( 0 );
$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
$request->set_body_params( array(
$request->set_body_params(
array(
'update' => array(
array(
'id' => 'woocommerce_shop_page_display',
'value' => 'subcategories',
),
),
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 401, $response->get_status() );
}
@ -412,9 +434,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/test/invalid' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'test',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 404, $response->get_status() );
}
@ -431,7 +455,8 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products' ) );
$data = $response->get_data();
$this->assertTrue( is_array( $data ) );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'woocommerce_downloads_require_login',
'label' => 'Access restriction',
'description' => 'Downloads require login',
@ -451,7 +476,9 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data );
),
$data
);
// test get single
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products/woocommerce_dimension_unit' ) );
@ -461,9 +488,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
// test update
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_dimension_unit' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'yd',
) );
)
);
$response = $this->server->dispatch( $request );
$data = $response->get_data();
@ -484,7 +513,8 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'recipient',
'label' => 'Recipient(s)',
'description' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
@ -504,13 +534,16 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $settings );
),
$settings
);
// test get single
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order/subject' ) );
$setting = $response->get_data();
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => 'subject',
'label' => 'Subject',
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
@ -518,17 +551,22 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
'default' => '',
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
'value' => '',
), $setting );
),
$setting
);
// test update
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_new_order', 'subject' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'This is my subject',
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => 'subject',
'label' => 'Subject',
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
@ -536,7 +574,9 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
'default' => '',
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
'value' => 'This is my subject',
), $setting );
),
$setting
);
// test updating another subject and making sure it works with a "similar" id
$request = new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
@ -547,9 +587,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
// test update
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'This is my new subject',
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
@ -572,25 +614,31 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
// test bogus value
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'not_yes_or_no',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 400, $response->get_status() );
// test yes
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'yes',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
// test no
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'no',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
}
@ -605,17 +653,21 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
// not a valid option
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'billing2',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 400, $response->get_status() );
// valid
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'billing',
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
}
@ -633,9 +685,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$this->assertEmpty( $setting['value'] );
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => array( 'AX', 'DZ', 'MMM' ),
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] );
@ -655,17 +709,21 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
// invalid
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'pounds', // invalid, should be lbs
) );
)
);
$response = $this->server->dispatch( $request );
$this->assertEquals( 400, $response->get_status() );
// valid
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => 'lbs', // invalid, should be lbs
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( 'lbs', $setting['value'] );
@ -703,18 +761,22 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$old_value = $setting['value'];
$new_value = $old_value . ' ' . rand( 1000, 9999 );
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $new_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $new_value, $setting['value'] );
// Put the original value back
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $old_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $old_value, $setting['value'] );
@ -735,18 +797,22 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$old_value = $setting['value'];
$new_value = $old_value . ' ' . rand( 1000, 9999 );
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $new_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $new_value, $setting['value'] );
// Put the original value back
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $old_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $old_value, $setting['value'] );
@ -767,18 +833,22 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$old_value = $setting['value'];
$new_value = $old_value . ' ' . rand( 1000, 9999 );
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $new_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $new_value, $setting['value'] );
// Put the original value back
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $old_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $old_value, $setting['value'] );
@ -799,18 +869,22 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
$old_value = $setting['value'];
$new_value = $old_value . ' ' . rand( 1000, 9999 );
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $new_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $new_value, $setting['value'] );
// Put the original value back
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
$request->set_body_params( array(
$request->set_body_params(
array(
'value' => $old_value,
) );
)
);
$response = $this->server->dispatch( $request );
$setting = $response->get_data();
$this->assertEquals( $old_value, $setting['value'] );

View File

@ -14,9 +14,11 @@ class Shipping_Methods_V2 extends WC_REST_Unit_Test_Case {
public function setUp() {
parent::setUp();
$this->endpoint = new WC_REST_Shipping_Methods_Controller();
$this->user = $this->factory->user->create( array(
$this->user = $this->factory->user->create(
array(
'role' => 'administrator',
) );
)
);
}
/**
@ -42,7 +44,8 @@ class Shipping_Methods_V2 extends WC_REST_Unit_Test_Case {
$methods = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertContains( array(
$this->assertContains(
array(
'id' => 'free_shipping',
'title' => 'Free shipping',
'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.',
@ -58,7 +61,9 @@ class Shipping_Methods_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $methods );
),
$methods
);
}
/**
@ -84,11 +89,14 @@ class Shipping_Methods_V2 extends WC_REST_Unit_Test_Case {
$method = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( array(
$this->assertEquals(
array(
'id' => 'local_pickup',
'title' => 'Local pickup',
'description' => 'Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.',
), $method );
),
$method
);
}
/**

View File

@ -96,7 +96,8 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
// Create a zone and make sure it's in the response
@ -129,7 +130,8 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -215,7 +217,8 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -279,7 +282,8 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -377,7 +381,8 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -402,7 +407,9 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case {
// Create a zone
$zone = $this->create_shipping_zone(
'Zone 1', 0, array(
'Zone 1',
0,
array(
array(
'code' => 'US',
'type' => 'country',
@ -433,7 +440,8 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}
@ -534,7 +542,8 @@ class WC_Tests_API_Shipping_Zones_V2 extends WC_REST_Unit_Test_Case {
),
),
),
), $data
),
$data
);
}

View File

@ -41,7 +41,7 @@ class WC_Tests_WC_Cart_Fees extends WC_Unit_Test_Case {
'name' => 'newfee2',
'amount' => 10,
'tax_class' => 'Reduced rate',
'taxable' => true
'taxable' => true,
),
);
$cart_fees->set_fees( $args );

View File

@ -235,11 +235,14 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
update_post_meta( $product->get_id(), '_regular_price', '10' );
// Create coupon
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon', array(
$coupon = WC_Helper_Coupon::create_coupon(
'dummycoupon',
array(
'discount_type' => 'percent',
'coupon_amount' => '5',
'limit_usage_to_x_items' => 1,
) );
)
);
// We need this to have the calculate_totals() method calculate totals.
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
@ -265,11 +268,14 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
update_post_meta( $product->get_id(), '_regular_price', '10' );
// Create coupon
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon', array(
$coupon = WC_Helper_Coupon::create_coupon(
'dummycoupon',
array(
'discount_type' => __FUNCTION__,
'coupon_amount' => '5',
'limit_usage_to_x_items' => 1,
) );
)
);
// Add 4 products and coupon to cart.
WC()->cart->add_to_cart( $product->get_id(), 4 );

View File

@ -94,7 +94,9 @@ class WC_Tests_Coupon_Data extends WC_Unit_Test_Case {
public function test_read_manual_coupon() {
$code = 'manual_coupon_' . time();
$coupon = new WC_Coupon( $code );
$coupon->read_manual_coupon( $code, array(
$coupon->read_manual_coupon(
$code,
array(
'id' => true,
'type' => 'fixed_cart',
'amount' => 0,
@ -111,7 +113,8 @@ class WC_Tests_Coupon_Data extends WC_Unit_Test_Case {
'minimum_amount' => '',
'maximum_amount' => 100,
'customer_email' => '',
) );
)
);
$this->assertEquals( $code, $coupon->get_code() );
$this->assertTrue( $coupon->get_individual_use() );
$this->assertEquals( 100, $coupon->get_maximum_amount() );
@ -132,7 +135,9 @@ class WC_Tests_Coupon_Data extends WC_Unit_Test_Case {
$this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, $legacy_keys );
$code = 'bc_manual_coupon_' . time();
$coupon = new WC_Coupon( $code );
$coupon->read_manual_coupon( $code, array(
$coupon->read_manual_coupon(
$code,
array(
'id' => true,
'type' => 'fixed_cart',
'amount' => 0,
@ -149,7 +154,8 @@ class WC_Tests_Coupon_Data extends WC_Unit_Test_Case {
'minimum_amount' => '',
'maximum_amount' => 100,
'customer_email' => '',
) );
)
);
$this->assertEquals( $code, $coupon->get_code() );
$this->assertTrue( $coupon->get_individual_use() );
$this->assertFalse( $coupon->get_free_shipping() );

View File

@ -75,7 +75,7 @@ class WC_Tests_Data_Store extends WC_Unit_Test_Case {
* @since 3.0.0
*/
function load_dummy_store() {
include_once( dirname( dirname( dirname( __FILE__ ) ) ) . '/framework/class-wc-dummy-data-store.php' );
include_once dirname( dirname( dirname( __FILE__ ) ) ) . '/framework/class-wc-dummy-data-store.php';
add_filter( 'woocommerce_data_stores', array( $this, 'add_dummy_data_store' ) );
}

View File

@ -119,7 +119,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
* Tests that the meta data cache is not shared among instances.
*/
function test_get_meta_data_shared_bug() {
$object = new WC_Order;
$object = new WC_Order();
$object->add_meta_data( 'test_meta_key', 'val1', true );
$object->add_meta_data( 'test_multi_meta_key', 'val2' );
$object->add_meta_data( 'test_multi_meta_key', 'val3' );
@ -138,7 +138,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
* Tests the cache invalidation after an order is saved
*/
function test_get_meta_data_cache_invalidation() {
$object = new WC_Order;
$object = new WC_Order();
$object->add_meta_data( 'test_meta_key', 'val1', true );
$object->add_meta_data( 'test_multi_meta_key', 'val2' );
$object->add_meta_data( 'test_multi_meta_key', 'val3' );
@ -155,7 +155,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
}
function test_get_meta_data_cache_invalidation_array_to_scalar() {
$object = new WC_Order;
$object = new WC_Order();
$object->add_meta_data( 'test_meta_key', array( 'val1' ), true );
$object->add_meta_data( 'test_multi_meta_key', 'val2' );
$object->add_meta_data( 'test_multi_meta_key', 'val3' );
@ -241,11 +241,16 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
$object = new WC_Mock_WC_Data( $object_id );
$metadata = array();
$raw_metadata = $wpdb->get_results( $wpdb->prepare( "
$raw_metadata = $wpdb->get_results(
$wpdb->prepare(
"
SELECT meta_id, meta_key, meta_value
FROM {$wpdb->prefix}postmeta
WHERE post_id = %d ORDER BY meta_id
", $object_id ) );
",
$object_id
)
);
foreach ( $raw_metadata as $meta ) {
$metadata[] = (object) array(
@ -291,11 +296,16 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
$this->assertEquals( 'val1', $object->get_meta( 'test_meta_key' ) );
$metadata = array();
$meta_id = $wpdb->get_var( $wpdb->prepare( "
$meta_id = $wpdb->get_var(
$wpdb->prepare(
"
SELECT meta_id
FROM {$wpdb->prefix}postmeta
WHERE post_id = %d LIMIT 1
", $object_id ) );
",
$object_id
)
);
$object->update_meta_data( 'test_meta_key', 'updated_value', $meta_id );
$this->assertEquals( 'updated_value', $object->get_meta( 'test_meta_key' ) );
@ -330,11 +340,16 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
$object->save_meta_data();
$object = new WC_Mock_WC_Data( $object_id );
$raw_metadata = $wpdb->get_results( $wpdb->prepare( "
$raw_metadata = $wpdb->get_results(
$wpdb->prepare(
"
SELECT meta_id, meta_key, meta_value
FROM {$wpdb->prefix}postmeta
WHERE post_id = %d ORDER BY meta_id
", $object_id ) );
",
$object_id
)
);
$object->delete_meta_data( 'test_meta_key' );
$object->update_meta_data( 'test_meta_key_2', 'updated_value', $raw_metadata[1]->meta_id );
@ -365,7 +380,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
* data before a save.
*/
function test_add_meta_data_overwrite_before_save() {
$object = new WC_Mock_WC_Data;
$object = new WC_Mock_WC_Data();
$object->add_meta_data( 'test_field_0', 'another field', true );
$object->add_meta_data( 'test_field_1', 'another field', true );
$object->add_meta_data( 'test_field_2', 'val1', true );
@ -504,7 +519,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
'prop3' => 'value3',
);
$object = new WC_Mock_WC_Data;
$object = new WC_Mock_WC_Data();
$object->set_data( $data );
$object->set_changes( $changes );
$object->apply_changes();
@ -537,7 +552,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
),
);
$object = new WC_Mock_WC_Data;
$object = new WC_Mock_WC_Data();
$object->set_data( $data );
$object->set_changes( $changes );
$object->apply_changes();

View File

@ -119,7 +119,7 @@ class WC_Tests_CRUD_Meta_Data extends WC_Unit_Test_Case {
*/
function test_get_meta_data_after_update_post_meta() {
// Create an object.
$object = new WC_Product;
$object = new WC_Product();
$object->save();
// Update a meta value.
@ -138,7 +138,7 @@ class WC_Tests_CRUD_Meta_Data extends WC_Unit_Test_Case {
*/
function test_strings_in_meta() {
// Create objects.
$object = new WC_Product;
$object = new WC_Product();
$object_to_store = new stdClass();
$object_to_store->prop1 = 'prop_value';
$object_to_store->prop2 = 'prop_value_with_\\\"quotes"';

View File

@ -207,7 +207,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
'is_paying_customer' => true,
);
$customer = new WC_Customer;
$customer = new WC_Customer();
foreach ( $setters as $method => $value ) {
$customer->{"set_{$method}"}( $value );

View File

@ -137,9 +137,11 @@ class WC_Tests_Customer_Download_Log extends WC_Unit_Test_Case {
// Make sure download log was recorded properly.
$data_store = WC_Data_Store::load( 'customer-download-log' );
$download_logs = $data_store->get_download_logs( array(
$download_logs = $data_store->get_download_logs(
array(
'permission_id' => $download_1->get_id(),
) );
)
);
$this->assertEquals( 1, count( $download_logs ), 'After single download, permission should have one download log in database.' );

View File

@ -1339,11 +1339,13 @@ class WC_Tests_Discounts extends WC_Unit_Test_Case {
public function test_free_shipping_coupon_no_products() {
$discounts = new WC_Discounts();
$coupon = WC_Helper_Coupon::create_coupon( 'freeshipping' );
$coupon->set_props( array(
$coupon->set_props(
array(
'discount_type' => 'percent',
'amount' => '',
'free_shipping' => 'yes',
));
)
);
$discounts->apply_coupon( $coupon );
@ -1373,11 +1375,13 @@ class WC_Tests_Discounts extends WC_Unit_Test_Case {
WC()->cart->add_to_cart( $product2->get_id(), 1 );
$coupon = WC_Helper_Coupon::create_coupon( 'test' );
$coupon->set_props( array(
$coupon->set_props(
array(
'code' => 'test',
'discount_type' => 'percent',
'amount' => '20',
) );
)
);
$discounts->set_items_from_cart( WC()->cart );
$discounts->apply_coupon( $coupon );
@ -1410,19 +1414,23 @@ class WC_Tests_Discounts extends WC_Unit_Test_Case {
$product_sale->save();
$coupon_percent = new WC_Coupon();
$coupon_percent->set_props( array(
$coupon_percent->set_props(
array(
'amount' => 10,
'discount_type' => 'percent',
'exclude_sale_items' => false,
) );
)
);
$coupon_percent->save();
$coupon_percent_no_sale = new WC_Coupon();
$coupon_percent_no_sale->set_props( array(
$coupon_percent_no_sale->set_props(
array(
'amount' => 10,
'discount_type' => 'percent',
'exclude_sale_items' => true,
) );
)
);
$coupon_percent_no_sale->save();
WC()->cart->empty_cart();
@ -1467,19 +1475,23 @@ class WC_Tests_Discounts extends WC_Unit_Test_Case {
$product_sale->save();
$coupon_cart = new WC_Coupon();
$coupon_cart->set_props( array(
$coupon_cart->set_props(
array(
'amount' => 5,
'discount_type' => 'fixed_cart',
'exclude_sale_items' => false,
) );
)
);
$coupon_cart->save();
$coupon_cart_no_sale = new WC_Coupon();
$coupon_cart_no_sale->set_props( array(
$coupon_cart_no_sale->set_props(
array(
'amount' => 5,
'discount_type' => 'fixed_cart',
'exclude_sale_items' => true,
) );
)
);
$coupon_cart_no_sale->save();
WC()->cart->empty_cart();
@ -1518,19 +1530,23 @@ class WC_Tests_Discounts extends WC_Unit_Test_Case {
$product_sale->save();
$coupon_product = new WC_Coupon();
$coupon_product->set_props( array(
$coupon_product->set_props(
array(
'amount' => 5,
'discount_type' => 'fixed_product',
'exclude_sale_items' => false,
) );
)
);
$coupon_product->save();
$coupon_product_no_sale = new WC_Coupon();
$coupon_product_no_sale->set_props( array(
$coupon_product_no_sale->set_props(
array(
'amount' => 5,
'discount_type' => 'fixed_product',
'exclude_sale_items' => true,
) );
)
);
$coupon_product_no_sale->save();
WC()->cart->empty_cart();

View File

@ -241,12 +241,14 @@ class WC_Tests_Paypal_Gateway_Request extends WC_Unit_Test_Case {
$qty = 1;
$item = new WC_Order_Item_Product();
$item->set_props( array(
$item->set_props(
array(
'product' => $product,
'quantity' => $qty,
'subtotal' => wc_get_price_excluding_tax( $product, array( 'qty' => $qty ) ),
'total' => wc_get_price_excluding_tax( $product, array( 'qty' => $qty ) ),
) );
)
);
$item->save();
$order->add_item( $item );

View File

@ -33,7 +33,7 @@ class WC_Tests_Integrations extends WC_Unit_Test_Case {
$this->assertEquals( array(), $integrations->integrations );
$this->assertEquals( array(), $integrations->get_integrations() );
require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-dummy-integration.php' );
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-dummy-integration.php';
add_filter( 'woocommerce_integrations', array( $this, 'add_dummy_integration' ) );
$integrations = new WC_Integrations();

View File

@ -18,12 +18,14 @@ class WC_Tests_Libraries_Background_Process extends WC_Unit_Test_Case {
* @return void
*/
public function test_is_queue_empty() {
require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wc-mock-background-process.php' );
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wc-mock-background-process.php';
$queue = new WC_Mock_Background_Process();
$this->assertEquals( true, $queue->is_queue_empty() );
$queue->push_to_queue( array(
$queue->push_to_queue(
array(
'mock_key' => 'mock_value',
) );
)
);
$queue->save();
$this->assertEquals( false, $queue->is_queue_empty() );
}
@ -34,7 +36,7 @@ class WC_Tests_Libraries_Background_Process extends WC_Unit_Test_Case {
* @return void
*/
public function test_schedule_cron_healthcheck() {
require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wc-mock-background-process.php' );
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wc-mock-background-process.php';
$queue = new WC_Mock_Background_Process();
$this->assertArrayHasKey( 'wp_' . get_current_blog_id() . '_wc_mock_background_process_cron_interval', $queue->schedule_cron_healthcheck( array() ) );
}
@ -42,7 +44,7 @@ class WC_Tests_Libraries_Background_Process extends WC_Unit_Test_Case {
* Test prefix & action against identifier.
*/
public function test_identifier() {
require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wc-mock-background-process.php' );
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wc-mock-background-process.php';
$queue = new WC_Mock_Background_Process();
$this->assertEquals( 'wp_' . get_current_blog_id() . '_wc_mock_background_process', $queue->get_identifier() );
}
@ -53,11 +55,13 @@ class WC_Tests_Libraries_Background_Process extends WC_Unit_Test_Case {
* @return void
*/
public function test_get_batch() {
require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wc-mock-background-process.php' );
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-wc-mock-background-process.php';
$queue = new WC_Mock_Background_Process();
$queue->push_to_queue( array(
$queue->push_to_queue(
array(
'mock_key' => 'mock_value',
) );
)
);
$queue->save();
$this->assertNotEmpty( $queue->get_batch() );
}

View File

@ -114,10 +114,12 @@ class WC_Tests_Log_Handler_Email extends WC_Unit_Test_Case {
public function test_multiple_recipients() {
$mailer = tests_retrieve_phpmailer_instance();
$handler = new WC_Log_Handler_Email( array(
$handler = new WC_Log_Handler_Email(
array(
'first@test.com',
'Second Recipient <second@test.com>',
) );
)
);
$handler->handle( time(), 'emergency', '', array() );
$handler->send_log_email();

View File

@ -47,10 +47,15 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
public function test_legacy_format() {
$handler = new WC_Log_Handler_File( array( 'threshold' => 'debug' ) );
$handler->handle( time(), 'info', 'this is a message', array(
$handler->handle(
time(),
'info',
'this is a message',
array(
'source' => 'unit-tests',
'_legacy' => true,
) );
)
);
$this->assertStringMatchesFormat( '%d-%d-%d @ %d:%d:%d - %s', $this->read_content( 'unit-tests' ) );
$this->assertStringEndsWith( ' - this is a message' . PHP_EOL, $this->read_content( 'unit-tests' ) );

View File

@ -25,10 +25,12 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
$this->greaterThanOrEqual( $time ),
$this->equalTo( 'notice' ),
$this->equalTo( 'this is a message' ),
$this->equalTo( array(
$this->equalTo(
array(
'source' => 'unit-tests',
'_legacy' => true,
) )
)
)
);
$log = new WC_Logger( array( $handler ), 'debug' );

View File

@ -146,10 +146,12 @@ class WC_Tests_Order_Item_Product extends WC_Unit_Test_Case {
$variation_product = new WC_Product_Variation();
$variation_product->set_name( 'Test Variation' );
$variation_product->set_parent_id( $parent_product->get_id() );
$variation_product->set_attributes( array(
$variation_product->set_attributes(
array(
'color' => 'Green',
'size' => 'Large',
) );
)
);
$variation_product->save();
$product_item = new WC_Order_Item_Product();

View File

@ -22,10 +22,12 @@ class WC_Tests_Order_Item_Functions extends WC_Unit_Test_Case {
$order = new WC_Order();
$item_1 = new WC_Order_Item_Product();
$item_1->set_props( array(
$item_1->set_props(
array(
'product' => WC_Helper_Product::create_simple_product(),
'quantity' => 4,
) );
)
);
$order->add_item( $item_1 );
$order->save();

View File

@ -13,7 +13,7 @@ class WC_Tests_Order_Item_Coupon extends WC_Unit_Test_Case {
* @since 3.2.0
*/
public function test_setters_getters() {
$coupon = new WC_Order_Item_Coupon;
$coupon = new WC_Order_Item_Coupon();
$coupon->set_name( 'testcoupon' );
$this->assertTrue( 'testcoupon' === $coupon->get_name() && $coupon->get_name() === $coupon->get_code() );

View File

@ -14,17 +14,17 @@ class WC_Tests_Order_Item_Tax extends WC_Unit_Test_Case {
*/
function test_set_get_tax_totals() {
$item = new WC_Order_Item_Tax;
$item = new WC_Order_Item_Tax();
$this->assertEquals( 0, $item->get_tax_total() );
$item->set_tax_total( "1.50" );
$this->assertEquals( "1.50", $item->get_tax_total() );
$item->set_tax_total( '1.50' );
$this->assertEquals( '1.50', $item->get_tax_total() );
$item->set_tax_total( "" );
$item->set_tax_total( '' );
$this->assertEquals( 0, $item->get_tax_total() );
$item->set_tax_total( 10.99 );
$this->assertEquals( "10.99", $item->get_tax_total() );
$this->assertEquals( '10.99', $item->get_tax_total() );
}
/**
@ -34,16 +34,16 @@ class WC_Tests_Order_Item_Tax extends WC_Unit_Test_Case {
*/
function test_set_get_shipping_tax_totals() {
$item = new WC_Order_Item_Tax;
$item = new WC_Order_Item_Tax();
$this->assertEquals( 0, $item->get_shipping_tax_total() );
$item->set_shipping_tax_total( "1.50" );
$this->assertEquals( "1.50", $item->get_shipping_tax_total() );
$item->set_shipping_tax_total( '1.50' );
$this->assertEquals( '1.50', $item->get_shipping_tax_total() );
$item->set_shipping_tax_total( "" );
$item->set_shipping_tax_total( '' );
$this->assertEquals( 0, $item->get_shipping_tax_total() );
$item->set_shipping_tax_total( 10.99 );
$this->assertEquals( "10.99", $item->get_shipping_tax_total() );
$this->assertEquals( '10.99', $item->get_shipping_tax_total() );
}
}

View File

@ -21,7 +21,8 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
public function test_wc_get_order_statuses() {
$order_statuses = apply_filters(
'wc_order_statuses', array(
'wc_order_statuses',
array(
'wc-pending' => _x( 'Pending payment', 'Order status', 'woocommerce' ),
'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
'wc-on-hold' => _x( 'On hold', 'Order status', 'woocommerce' ),

View File

@ -39,12 +39,14 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$coupon2->set_discount_type( 'percent' );
$coupon2->save();
$order = wc_create_order( array(
$order = wc_create_order(
array(
'status' => 'pending',
'customer_id' => 1,
'customer_note' => '',
'total' => '',
) );
)
);
// Add order products
$product_item = new WC_Order_Item_Product();
@ -52,39 +54,51 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$coupon_item_2 = new WC_Order_Item_Coupon();
if ( get_option( 'woocommerce_prices_include_tax', 'no' ) === 'yes' && get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ) {
$product_item->set_props( array(
$product_item->set_props(
array(
'product' => $product,
'quantity' => 1,
'subtotal' => 909.09, // Ex tax.
'total' => 726.36,
) );
$coupon_item_1->set_props( array(
)
);
$coupon_item_1->set_props(
array(
'code' => 'test-coupon-1',
'discount' => 0.91,
'discount_tax' => 0.09,
) );
$coupon_item_2->set_props( array(
)
);
$coupon_item_2->set_props(
array(
'code' => 'this-is-a-virtal-coupon',
'discount' => 181.82,
'discount_tax' => 18.18,
) );
)
);
} else {
$product_item->set_props( array(
$product_item->set_props(
array(
'product' => $product,
'quantity' => 1,
'subtotal' => 1000, // Ex tax.
'total' => 799,
) );
$coupon_item_1->set_props( array(
)
);
$coupon_item_1->set_props(
array(
'code' => 'test-coupon-1',
'discount' => 1,
'discount_tax' => get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ? 0.1 : 0,
) );
$coupon_item_2->set_props( array(
)
);
$coupon_item_2->set_props(
array(
'code' => 'this-is-a-virtal-coupon',
'discount' => 200,
'discount_tax' => get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ? 20 : 0,
) );
)
);
}
$product_item->save();
@ -99,7 +113,8 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$this->objects['coupons'][] = $coupon2;
$this->objects['products'][] = $product;
$this->objects['order'] = $order;
$this->objects['tax_rate_ids'][] = WC_Tax::_insert_tax_rate( array(
$this->objects['tax_rate_ids'][] = WC_Tax::_insert_tax_rate(
array(
'tax_rate_country' => '',
'tax_rate_state' => '',
'tax_rate' => '10.0000',
@ -109,7 +124,8 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
'tax_rate_shipping' => '1',
'tax_rate_order' => '1',
'tax_rate_class' => '',
) );
)
);
$order->calculate_totals( true );
$order->save();

View File

@ -80,32 +80,40 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
$order->save();
// Check WC_DateTime support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_created' => $order->get_date_created(),
) );
)
);
$orders = $query->get_orders();
$this->assertEquals( 1, count( $orders ) );
// Check date support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_created' => $now_date,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_created', $past );
$this->assertEquals( 0, count( $query->get_orders() ) );
// Check timestamp support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_created' => $order->get_date_created()->getTimestamp(),
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_created', $future_stamp );
$this->assertEquals( 0, count( $query->get_orders() ) );
// Check comparison support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_created' => '>' . $past,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_created', '<' . $past );
$this->assertEquals( 0, count( $query->get_orders() ) );
@ -113,18 +121,22 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
$this->assertEquals( 1, count( $query->get_orders() ) );
// Check timestamp comparison support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_created' => '<' . $future_stamp,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_created', '<' . $past_stamp );
$this->assertEquals( 0, count( $query->get_orders() ) );
$query->set( 'date_created', '>=' . $now_stamp );
// Check date range support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_created' => $past . '...' . $future,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_created', $past . '...' . $now_date );
$this->assertEquals( 1, count( $query->get_orders() ) );
@ -132,9 +144,11 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
$this->assertEquals( 0, count( $query->get_orders() ) );
// Check timestamp range support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_created' => $past_stamp . '...' . $future_stamp,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_created', $now_stamp . '...' . $future_stamp );
$this->assertEquals( 1, count( $query->get_orders() ) );
@ -161,32 +175,40 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
$order->save();
// Check WC_DateTime support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_completed' => $order->get_date_completed(),
) );
)
);
$orders = $query->get_orders();
$this->assertEquals( 1, count( $orders ) );
// Check date support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_completed' => $now_date,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_completed', $past );
$this->assertEquals( 0, count( $query->get_orders() ) );
// Check timestamp support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_completed' => $order->get_date_completed()->getTimestamp(),
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_completed', $future_stamp );
$this->assertEquals( 0, count( $query->get_orders() ) );
// Check comparison support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_completed' => '>' . $past,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_completed', '<' . $past );
$this->assertEquals( 0, count( $query->get_orders() ) );
@ -194,18 +216,22 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
$this->assertEquals( 1, count( $query->get_orders() ) );
// Check timestamp comparison support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_completed' => '<' . $future_stamp,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_completed', '<' . $past_stamp );
$this->assertEquals( 0, count( $query->get_orders() ) );
$query->set( 'date_completed', '>=' . $now_stamp );
// Check date range support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_completed' => $past . '...' . $future,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_completed', $now_date . '...' . $future );
$this->assertEquals( 1, count( $query->get_orders() ) );
@ -213,9 +239,11 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
$this->assertEquals( 0, count( $query->get_orders() ) );
// Check timestamp range support.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'date_completed' => $past_stamp . '...' . $future_stamp,
) );
)
);
$this->assertEquals( 1, count( $query->get_orders() ) );
$query->set( 'date_completed', $now_stamp . '...' . $future_stamp );
$this->assertEquals( 1, count( $query->get_orders() ) );
@ -229,19 +257,23 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
* @since 3.1
*/
public function test_order_query_key_mapping() {
$user_id = wp_insert_user( array(
$user_id = wp_insert_user(
array(
'user_login' => 'testname',
'user_pass' => 'testpass',
'user_email' => 'email@testmail.com',
) );
)
);
$order = new WC_Order();
$order->set_customer_id( $user_id );
$order->save();
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'customer_id' => $user_id,
) );
)
);
$results = $query->get_orders();
$this->assertEquals( 1, count( $results ) );
@ -249,18 +281,22 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
public function test_order_query_search_by_customers() {
$user_email_1 = 'email@testmail.com';
$user_id_1 = wp_insert_user( array(
$user_id_1 = wp_insert_user(
array(
'user_login' => 'testname',
'user_pass' => 'testpass',
'user_email' => $user_email_1,
) );
)
);
$user_email_2 = 'email2@testmail.com';
$user_id_2 = wp_insert_user( array(
$user_id_2 = wp_insert_user(
array(
'user_login' => 'testname2',
'user_pass' => 'testpass2',
'user_email' => $user_email_2,
) );
)
);
$order1 = new WC_Order();
$order1->set_customer_id( $user_id_1 );
@ -275,30 +311,38 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
$order3->save();
// Searching for both users IDs should return all orders.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'customer' => array( $user_id_1, $user_id_2 ),
) );
)
);
$results = $query->get_orders();
$this->assertEquals( 3, count( $results ) );
// Searching for user 1 email and user 2 ID should return all orders.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'customer' => array( $user_email_1, $user_id_2 ),
) );
)
);
$results = $query->get_orders();
$this->assertEquals( 3, count( $results ) );
// Searching for orders that match the first user email AND ID should return only a single order
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'customer' => array( array( $user_email_1, $user_id_1 ) ),
) );
)
);
$results = $query->get_orders();
$this->assertEquals( 1, count( $results ) );
// Searching for orders that match the first user email AND the second user ID should return no orders.
$query = new WC_Order_Query( array(
$query = new WC_Order_Query(
array(
'customer' => array( array( $user_email_1, $user_id_2 ) ),
) );
)
);
$results = $query->get_orders();
$this->assertEquals( 0, count( $results ) );
}

View File

@ -19,11 +19,11 @@ class WC_Tests_Product_Variation extends WC_Unit_Test_Case {
*/
public function test_is_sold_individually() {
// Create a variable product with sold individually.
$product = new WC_Product_Variable;
$product = new WC_Product_Variable();
$product->set_sold_individually( true );
$product->save();
$variation = new WC_Product_Variation;
$variation = new WC_Product_Variation();
$variation->set_parent_id( $product->get_id() );
$variation->save();
@ -35,11 +35,11 @@ class WC_Tests_Product_Variation extends WC_Unit_Test_Case {
* Check get_tax_class against different parent child scenarios
*/
public function test_get_tax_class() {
$product = new WC_Product_Variable;
$product = new WC_Product_Variable();
$product->set_tax_class( 'standard' );
$product->save();
$variation = new WC_Product_Variation;
$variation = new WC_Product_Variation();
$variation->set_parent_id( $product->get_id() );
$variation->set_tax_class( 'parent' );
$variation->save();

View File

@ -25,45 +25,63 @@ class WC_Tests_Setup_Functions extends WC_Unit_Test_Case {
// non-admin user
$this->user_id = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
wp_set_current_user( $this->user_id );
$this->assertEquals( gateways( $setup_wizard ), array(
$this->assertEquals(
gateways( $setup_wizard ),
array(
'paypal' => false,
) );
)
);
// set admin user
$this->user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
wp_set_current_user( $this->user_id );
update_option( 'woocommerce_default_country', 'US' );
$this->assertEquals( gateways( $setup_wizard ), array(
$this->assertEquals(
gateways( $setup_wizard ),
array(
'stripe' => true,
'ppec_paypal' => true,
) );
)
);
update_option( 'woocommerce_default_country', 'CN' );
$this->assertEquals( gateways( $setup_wizard ), array(
$this->assertEquals(
gateways( $setup_wizard ),
array(
'ppec_paypal' => true,
) );
)
);
update_option( 'woocommerce_default_country', 'SE' );
$this->assertEquals( gateways( $setup_wizard ), array(
$this->assertEquals(
gateways( $setup_wizard ),
array(
'klarna_checkout' => true,
'ppec_paypal' => true,
'stripe' => false,
) );
)
);
update_option( 'woocommerce_default_country', 'DE' );
$this->assertEquals( gateways( $setup_wizard ), array(
$this->assertEquals(
gateways( $setup_wizard ),
array(
'klarna_payments' => true,
'ppec_paypal' => true,
'stripe' => false,
) );
)
);
update_option( 'woocommerce_default_country', 'GB' );
update_option( 'woocommerce_sell_in_person', 'yes' );
$this->assertEquals( gateways( $setup_wizard ), array(
$this->assertEquals(
gateways( $setup_wizard ),
array(
'square' => true,
'ppec_paypal' => true,
'stripe' => false,
) );
)
);
}
}

View File

@ -34,10 +34,12 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
);
$this->assertEquals( $expected, $shortcode->get_attributes() );
$shortcode2 = new WC_Shortcode_Products( array(
$shortcode2 = new WC_Shortcode_Products(
array(
'orderby' => 'id',
'order' => 'DESC',
) );
)
);
$expected2 = array(
'limit' => '-1',
'columns' => '4',
@ -85,10 +87,12 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected, $shortcode->get_query_args() );
// products shortcode with attributes.
$shortcode2 = new WC_Shortcode_Products( array(
$shortcode2 = new WC_Shortcode_Products(
array(
'orderby' => 'ID',
'order' => 'DESC',
) );
)
);
$expected2 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -103,10 +107,12 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
);
$this->assertEquals( $expected2, $shortcode2->get_query_args() );
$shortcode3 = new WC_Shortcode_Products( array(
$shortcode3 = new WC_Shortcode_Products(
array(
'ids' => '1,2,3',
'skus' => 'foo,bar',
) );
)
);
$expected3 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -129,14 +135,17 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected3, $shortcode3->get_query_args() );
// product_category shortcode.
$shortcode4 = new WC_Shortcode_Products( array(
$shortcode4 = new WC_Shortcode_Products(
array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'title',
'order' => 'ASC',
'category' => 'clothing',
'operator' => 'IN',
), 'product_category' );
),
'product_category'
);
$expected4 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -160,14 +169,17 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected4, $shortcode4->get_query_args() );
// product_category shortcode using category ids.
$shortcode4_id = new WC_Shortcode_Products( array(
$shortcode4_id = new WC_Shortcode_Products(
array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'title',
'order' => 'ASC',
'category' => '123',
'operator' => 'IN',
), 'product_category' );
),
'product_category'
);
$expected4_id = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -191,14 +203,17 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected4_id, $shortcode4_id->get_query_args() );
// recent_products shortcode.
$shortcode5 = new WC_Shortcode_Products( array(
$shortcode5 = new WC_Shortcode_Products(
array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'date',
'order' => 'DESC',
'category' => '',
'operator' => 'IN',
), 'recent_products' );
),
'recent_products'
);
$expected5 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -215,10 +230,13 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected5, $shortcode5->get_query_args() );
// product shortcode.
$shortcode6 = new WC_Shortcode_Products( array(
$shortcode6 = new WC_Shortcode_Products(
array(
'ids' => '1',
'per_page' => '1',
), 'product' );
),
'product'
);
$expected6 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -236,14 +254,17 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected6, $shortcode6->get_query_args() );
// sale_products shortcode.
$shortcode7 = new WC_Shortcode_Products( array(
$shortcode7 = new WC_Shortcode_Products(
array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'title',
'order' => 'ASC',
'category' => '',
'operator' => 'IN',
), 'sale_products' );
),
'sale_products'
);
$expected7 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -261,12 +282,15 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected7, $shortcode7->get_query_args() );
// best_selling_products shortcode.
$shortcode8 = new WC_Shortcode_Products( array(
$shortcode8 = new WC_Shortcode_Products(
array(
'per_page' => '12',
'columns' => '4',
'category' => '',
'operator' => 'IN',
), 'best_selling_products' );
),
'best_selling_products'
);
$expected8 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -284,14 +308,17 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected8, $shortcode8->get_query_args() );
// top_rated_products shortcode.
$shortcode9 = new WC_Shortcode_Products( array(
$shortcode9 = new WC_Shortcode_Products(
array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'title',
'order' => 'ASC',
'category' => '',
'operator' => 'IN',
), 'top_rated_products' );
),
'top_rated_products'
);
$expected9 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -308,7 +335,8 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected9, $shortcode9->get_query_args() );
// featured_products shortcode.
$shortcode10 = new WC_Shortcode_Products( array(
$shortcode10 = new WC_Shortcode_Products(
array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'date',
@ -316,7 +344,8 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'category' => '',
'operator' => 'IN',
'visibility' => 'featured',
) );
)
);
$expected10 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -326,7 +355,9 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'order' => 'DESC',
'posts_per_page' => 12,
'meta_query' => $meta_query,
'tax_query' => array_merge( $tax_query, array(
'tax_query' => array_merge(
$tax_query,
array(
array(
'taxonomy' => 'product_visibility',
'terms' => 'featured',
@ -334,21 +365,25 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'operator' => 'IN',
'include_children' => false,
),
) ),
)
),
'fields' => 'ids',
);
$this->assertEquals( $expected10, $shortcode10->get_query_args() );
// product_attribute shortcode.
$shortcode11 = new WC_Shortcode_Products( array(
$shortcode11 = new WC_Shortcode_Products(
array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'title',
'order' => 'asc',
'attribute' => 'color',
'filter' => 'black',
), 'product_attribute' );
),
'product_attribute'
);
$expected11 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -358,28 +393,34 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'order' => 'ASC',
'posts_per_page' => 12,
'meta_query' => $meta_query,
'tax_query' => array_merge( $tax_query, array(
'tax_query' => array_merge(
$tax_query,
array(
array(
'taxonomy' => 'pa_color',
'terms' => array( 'black' ),
'field' => 'slug',
'operator' => 'IN',
),
) ),
)
),
'fields' => 'ids',
);
$this->assertEquals( $expected11, $shortcode11->get_query_args() );
// product_attribute shortcode using term ids.
$shortcode11_id = new WC_Shortcode_Products( array(
$shortcode11_id = new WC_Shortcode_Products(
array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'title',
'order' => 'asc',
'attribute' => 'color',
'terms' => '123',
), 'product_attribute' );
),
'product_attribute'
);
$expected11_id = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -389,23 +430,28 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'order' => 'ASC',
'posts_per_page' => 12,
'meta_query' => $meta_query,
'tax_query' => array_merge( $tax_query, array(
'tax_query' => array_merge(
$tax_query,
array(
array(
'taxonomy' => 'pa_color',
'terms' => array( 123 ),
'field' => 'term_id',
'operator' => 'IN',
),
) ),
)
),
'fields' => 'ids',
);
$this->assertEquals( $expected11_id, $shortcode11_id->get_query_args() );
// Check for visibility shortcode.
$shortcode12 = new WC_Shortcode_Products( array(
$shortcode12 = new WC_Shortcode_Products(
array(
'visibility' => 'hidden',
) );
)
);
$expected12 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -429,9 +475,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected12, $shortcode12->get_query_args() );
$shortcode13 = new WC_Shortcode_Products( array(
$shortcode13 = new WC_Shortcode_Products(
array(
'visibility' => 'catalog',
) );
)
);
$expected13 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -462,9 +510,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected13, $shortcode13->get_query_args() );
$shortcode14 = new WC_Shortcode_Products( array(
$shortcode14 = new WC_Shortcode_Products(
array(
'visibility' => 'search',
) );
)
);
$expected14 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -496,10 +546,12 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$this->assertEquals( $expected14, $shortcode14->get_query_args() );
// products shortcode -- select multiple categories using AND operator.
$shortcode15 = new WC_Shortcode_Products( array(
$shortcode15 = new WC_Shortcode_Products(
array(
'category' => 'cat1,cat2',
'cat_operator' => 'AND',
) );
)
);
$expected15 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -509,7 +561,9 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'order' => 'ASC',
'posts_per_page' => -1,
'meta_query' => $meta_query,
'tax_query' => array_merge( $tax_query, array(
'tax_query' => array_merge(
$tax_query,
array(
array(
'taxonomy' => 'product_cat',
'terms' => array( 'cat1', 'cat2' ),
@ -517,17 +571,20 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'operator' => 'AND',
'include_children' => false,
),
) ),
)
),
'fields' => 'ids',
);
$this->assertEquals( $expected15, $shortcode15->get_query_args() );
// products shortcode -- exclude multiple categories using NOT IN operator.
$shortcode16 = new WC_Shortcode_Products( array(
$shortcode16 = new WC_Shortcode_Products(
array(
'category' => 'cat1,cat2',
'cat_operator' => 'NOT IN',
) );
)
);
$expected16 = array(
'post_type' => 'product',
'post_status' => 'publish',
@ -537,7 +594,9 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'order' => 'ASC',
'posts_per_page' => -1,
'meta_query' => $meta_query,
'tax_query' => array_merge( $tax_query, array(
'tax_query' => array_merge(
$tax_query,
array(
array(
'taxonomy' => 'product_cat',
'terms' => array( 'cat1', 'cat2' ),
@ -545,7 +604,8 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'operator' => 'NOT IN',
'include_children' => true,
),
) ),
)
),
'fields' => 'ids',
);
@ -579,9 +639,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$shortcode = new WC_Shortcode_Products();
$this->assertFalse( $shortcode->set_product_as_visible( false ) );
$shortcode2 = new WC_Shortcode_Products( array(
$shortcode2 = new WC_Shortcode_Products(
array(
'visibility' => 'hidden',
) );
)
);
$this->assertTrue( $shortcode2->set_product_as_visible( false ) );
}
@ -598,9 +660,14 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'groupby' => "$wpdb->posts.ID",
);
$this->assertEquals( $expected, WC_Shortcode_Products::order_by_rating_post_clauses( array(
$this->assertEquals(
$expected,
WC_Shortcode_Products::order_by_rating_post_clauses(
array(
'where' => '',
'join' => '',
) ) );
)
)
);
}
}

View File

@ -28,7 +28,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
$tax_rates = WC_Tax::get_rates();
$this->assertSame(
$tax_rates, array(
$tax_rates,
array(
$tax_rate_id => array(
'rate' => 20.0,
'label' => 'VAT',
@ -56,7 +57,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
$tax_rates = WC_Tax::get_rates();
$this->assertSame(
$tax_rates, array(
$tax_rates,
array(
$tax_rate_catch_all_id => array(
'rate' => 0.0,
'label' => 'VAT',
@ -89,14 +91,16 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
$tax_rates = WC_Tax::get_shipping_tax_rates();
$this->assertEquals(
$tax_rates, array(
$tax_rates,
array(
$tax_rate_id => array(
'rate' => '20.0000',
'label' => 'VAT',
'shipping' => 'yes',
'compound' => 'no',
),
), print_r( $tax_rates, true )
),
print_r( $tax_rates, true )
);
}
@ -121,7 +125,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
$tax_rates = WC_Tax::get_base_tax_rates();
$this->assertEquals(
$tax_rates, array(
$tax_rates,
array(
$tax_rate_id => array(
'rate' => '20.0000',
'label' => 'VAT',
@ -161,7 +166,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
);
$this->assertEquals(
$tax_rates, array(
$tax_rates,
array(
$tax_rate_id => array(
'rate' => '20.0000',
'label' => 'VAT',
@ -201,7 +207,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
);
$this->assertEquals(
$tax_rates, array(
$tax_rates,
array(
$tax_rate_id => array(
'rate' => '20.0000',
'label' => 'VAT',
@ -296,7 +303,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
// prices exclusive of tax
$calced_tax = WC_Tax::calc_tax( '100', $tax_rates, false, false );
$this->assertEquals(
$calced_tax, array(
$calced_tax,
array(
$tax_rate_1_id => '5.0000',
$tax_rate_2_id => '8.925',
)

View File

@ -124,22 +124,22 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
public function test_wc_query_string_form_fields() {
$actual_html = wc_query_string_form_fields( '?test=1', array(), '', true );
$expected_html = '<input type="hidden" name="test" value="1" />';
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
$this->assertEquals( $expected_html, $actual_html );
$actual_html = wc_query_string_form_fields( '?test=1&test2=something', array(), '', true );
$expected_html = '<input type="hidden" name="test" value="1" /><input type="hidden" name="test2" value="something" />';
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
$this->assertEquals( $expected_html, $actual_html );
$actual_html = wc_query_string_form_fields( '?test.something=something', array(), '', true );
$expected_html = '<input type="hidden" name="test.something" value="something" />';
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
$actual_html = wc_query_string_form_fields( '?test.something=something.else', array(), '', true );
$expected_html = '<input type="hidden" name="test.something" value="something.else" />';
$this->assertEquals( $expected_html, $actual_html );
$actual_html = wc_query_string_form_fields( '?test+something=something', array(), '', true );
$expected_html = '<input type="hidden" name="test+something" value="something" />';
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
$actual_html = wc_query_string_form_fields( '?test+something=something+else', array(), '', true );
$expected_html = '<input type="hidden" name="test+something" value="something+else" />';
$this->assertEquals( $expected_html, $actual_html );
$actual_html = wc_query_string_form_fields( '?test%20something=something', array(), '', true );
$expected_html = '<input type="hidden" name="test%20something" value="something" />';
$this->assertEquals( $expected_html, $actual_html, var_export( $actual_html, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
$actual_html = wc_query_string_form_fields( '?test%20something=something%20else', array(), '', true );
$expected_html = '<input type="hidden" name="test%20something" value="something%20else" />';
$this->assertEquals( $expected_html, $actual_html );
}
}

View File

@ -19,26 +19,32 @@ class WC_Tests_User_Functions extends WC_Unit_Test_Case {
public function test_wc_modify_editable_roles() {
$password = wp_generate_password();
$admin_id = wp_insert_user( array(
$admin_id = wp_insert_user(
array(
'user_login' => 'test_admin',
'user_pass' => $password,
'user_email' => 'admin@example.com',
'role' => 'administrator',
) );
)
);
$editor_id = wp_insert_user( array(
$editor_id = wp_insert_user(
array(
'user_login' => 'test_editor',
'user_pass' => $password,
'user_email' => 'editor@example.com',
'role' => 'editor',
) );
)
);
$manager_id = wp_insert_user( array(
$manager_id = wp_insert_user(
array(
'user_login' => 'test_manager',
'user_pass' => $password,
'user_email' => 'manager@example.com',
'role' => 'shop_manager',
) );
)
);
// Admins should be able to edit anyone.
wp_set_current_user( $admin_id );
@ -70,33 +76,41 @@ class WC_Tests_User_Functions extends WC_Unit_Test_Case {
public function test_wc_modify_map_meta_cap() {
$password = wp_generate_password();
$admin_id = wp_insert_user( array(
$admin_id = wp_insert_user(
array(
'user_login' => 'test_admin',
'user_pass' => $password,
'user_email' => 'admin@example.com',
'role' => 'administrator',
) );
)
);
$editor_id = wp_insert_user( array(
$editor_id = wp_insert_user(
array(
'user_login' => 'test_editor',
'user_pass' => $password,
'user_email' => 'editor@example.com',
'role' => 'editor',
) );
)
);
$manager_id = wp_insert_user( array(
$manager_id = wp_insert_user(
array(
'user_login' => 'test_manager',
'user_pass' => $password,
'user_email' => 'manager@example.com',
'role' => 'shop_manager',
) );
)
);
$customer_id = wp_insert_user( array(
$customer_id = wp_insert_user(
array(
'user_login' => 'test_customer',
'user_pass' => $password,
'user_email' => 'customer@example.com',
'role' => 'customer',
) );
)
);
// Admins should be able to edit or promote anyone.
wp_set_current_user( $admin_id );
@ -123,20 +137,24 @@ class WC_Tests_User_Functions extends WC_Unit_Test_Case {
public function test_wc_shop_manager_has_capability() {
$password = wp_generate_password();
$manager_id = wp_insert_user( array(
$manager_id = wp_insert_user(
array(
'user_login' => 'test_manager',
'user_pass' => $password,
'user_email' => 'manager@example.com',
'role' => 'shop_manager',
) );
)
);
$manager = new WP_User( $manager_id );
$editor_id = wp_insert_user( array(
$editor_id = wp_insert_user(
array(
'user_login' => 'test_editor',
'user_pass' => $password,
'user_email' => 'editor@example.com',
'role' => 'editor',
) );
)
);
$editor = new WP_User( $editor_id );
// Test capabilities translation is working correctly and only gives shop managers capabilities.

View File

@ -164,7 +164,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
$token = WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
$token->save();
$product = new WC_Product_Variation;
$product = new WC_Product_Variation();
$product->save();
$this->assertEquals( 1, did_action( 'woocommerce_payment_token_created' ) );

View File

@ -23,10 +23,10 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
if ( ! class_exists( 'WC_Plugin_Updates' ) ) {
$bootstrap = WC_Unit_Tests_Bootstrap::instance();
include_once( $bootstrap->plugin_dir . '/includes/admin/plugin-updates/class-wc-plugin-updates.php' );
include_once $bootstrap->plugin_dir . '/includes/admin/plugin-updates/class-wc-plugin-updates.php';
}
$this->updates = new WC_Plugin_Updates;
$this->updates = new WC_Plugin_Updates();
$this->plugins = array();
add_filter( 'woocommerce_get_plugins_with_header', array( $this, 'populate_untested_plugins' ), 10, 2 );