Merge branch 'master' into fix/23790

This commit is contained in:
Claudio Sanches 2020-07-30 16:46:01 -03:00
commit 1cd84d6446
36 changed files with 287 additions and 140 deletions

View File

@ -14,6 +14,7 @@ contributors.html
docker-compose.yaml
Dockerfile
Gruntfile.js
lerna.json
none
package-lock.json
package.json

View File

@ -1062,6 +1062,7 @@ ul.wc_coupon_list_block {
#woocommerce-order-data {
.postbox-header,
.hndle,
.handlediv {
display: none;
@ -1412,6 +1413,10 @@ ul.wc_coupon_list_block {
.refunded-total {
color: $red;
}
.label-highlight {
font-weight: bold;
}
}
.refund-actions {
@ -1466,6 +1471,7 @@ ul.wc_coupon_list_block {
display: block !important;
}
.postbox-header,
.hndle,
.handlediv {
display: none;
@ -4347,14 +4353,13 @@ img.help_tip {
span {
display: block;
vertical-align: middle;
line-height: 24px;
}
span {
display: inline;
line-height: inherit;
vertical-align: baseline;
}
.type_box {
display: inline;
line-height: inherit;
vertical-align: baseline;
}
select {
@ -6819,6 +6824,23 @@ table.bar_chart {
}
}
.wc-wp-version-gte-55 {
#woocommerce-product-data {
.hndle {
display: block;
line-height: 24px;
.type_box {
display: inline;
line-height: inherit;
vertical-align: baseline;
}
}
}
}
/**
* Select2 colors for built-in admin color themes.
*/

View File

@ -27,7 +27,11 @@ jQuery( function( $ ) {
});
// Type box.
$( '.type_box' ).appendTo( '#woocommerce-product-data .hndle span' );
if ( $( 'body' ).hasClass( 'wc-wp-version-gte-55' ) ) {
$( '.type_box' ).appendTo( '#woocommerce-product-data .hndle' );
} else {
$( '.type_box' ).appendTo( '#woocommerce-product-data .hndle span' );
}
$( function() {
// Prevent inputs in meta box headings opening/closing contents.

View File

@ -16,7 +16,7 @@
"pelago/emogrifier": "^3.1",
"woocommerce/action-scheduler": "3.1.6",
"woocommerce/woocommerce-admin": "1.4.0-beta.2",
"woocommerce/woocommerce-blocks": "3.0.0",
"woocommerce/woocommerce-blocks": "3.1.0",
"woocommerce/woocommerce-rest-api": "1.0.11"
},
"require-dev": {

12
composer.lock generated
View File

@ -597,20 +597,20 @@
],
"description": "A modern, javascript-driven WooCommerce Admin experience.",
"homepage": "https://github.com/woocommerce/woocommerce-admin",
"time": "2020-07-28T00:28:40+00:00"
"time": "2020-07-28T15:18:55+00:00"
},
{
"name": "woocommerce/woocommerce-blocks",
"version": "v3.0.0",
"version": "v3.1.0",
"source": {
"type": "git",
"url": "https://github.com/woocommerce/woocommerce-gutenberg-products-block.git",
"reference": "cc00da60f21a7219e7e5ef5599996c68fee7b2be"
"reference": "d8fdcb4fc90c392e672b0e75bb0b7fd81dac7436"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/woocommerce/woocommerce-gutenberg-products-block/zipball/cc00da60f21a7219e7e5ef5599996c68fee7b2be",
"reference": "cc00da60f21a7219e7e5ef5599996c68fee7b2be",
"url": "https://api.github.com/repos/woocommerce/woocommerce-gutenberg-products-block/zipball/d8fdcb4fc90c392e672b0e75bb0b7fd81dac7436",
"reference": "d8fdcb4fc90c392e672b0e75bb0b7fd81dac7436",
"shasum": ""
},
"require": {
@ -644,7 +644,7 @@
"gutenberg",
"woocommerce"
],
"time": "2020-07-22T13:34:19+00:00"
"time": "2020-07-29T15:45:19+00:00"
},
{
"name": "woocommerce/woocommerce-rest-api",

View File

@ -804,9 +804,10 @@ class WC_Admin_Post_Types {
* @param int $product_id product identifier.
* @param int $variation_id optional product variation identifier.
* @param array $downloadable_files newly set files.
* @deprecated and moved to post-data class.
* @deprecated 3.3.0 and moved to post-data class.
*/
public function process_product_file_download_paths( $product_id, $variation_id, $downloadable_files ) {
wc_deprecated_function( 'WC_Admin_Post_Types::process_product_file_download_paths', '3.3', '' );
WC_Post_Data::process_product_file_download_paths( $product_id, $variation_id, $downloadable_files );
}

View File

@ -331,6 +331,11 @@ class WC_Admin {
$classes .= ' wc-wp-version-gte-53';
}
// Add WP 5.5+ compatibility class.
if ( $raw_version && version_compare( $version, '5.5', '>=' ) ) {
$classes .= ' wc-wp-version-gte-55';
}
return $classes;
}
}

View File

@ -191,6 +191,11 @@ class WC_Helper_Updater {
$locales = apply_filters( 'plugins_update_check_locales', $locales );
$locales = array_unique( $locales );
// No locales, the respone will be empty, we can return now.
if ( empty( $locales ) ) {
return array();
}
// Scan local plugins which may or may not have a subscription.
$plugins = WC_Helper::get_local_woo_plugins();
$active_woo_plugins = array_intersect( array_keys( $plugins ), get_option( 'active_plugins', array() ) );

View File

@ -395,11 +395,12 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
/**
* Search by SKU or ID for products.
*
* @deprecated Logic moved to query_filters.
* @deprecated 4.4.0 Logic moved to query_filters.
* @param string $where Where clause SQL.
* @return string
*/
public function sku_search( $where ) {
wc_deprecated_function( 'WC_Admin_List_Table_Products::sku_search', '4.4.0', 'Logic moved to query_filters.' );
return $where;
}

View File

@ -147,7 +147,7 @@ if ( wc_tax_enabled() ) {
<td class="label"><?php esc_html_e( 'Items Subtotal:', 'woocommerce' ); ?></td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $order->get_subtotal(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
<?php echo wc_price( $order->get_subtotal(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
<?php if ( 0 < $order->get_total_discount() ) : ?>
@ -155,7 +155,7 @@ if ( wc_tax_enabled() ) {
<td class="label"><?php esc_html_e( 'Coupon(s):', 'woocommerce' ); ?></td>
<td width="1%"></td>
<td class="total">-
<?php echo wc_price( $order->get_total_discount(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
<?php echo wc_price( $order->get_total_discount(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
<?php endif; ?>
@ -164,7 +164,7 @@ if ( wc_tax_enabled() ) {
<td class="label"><?php esc_html_e( 'Fees:', 'woocommerce' ); ?></td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $order->get_total_fees(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
<?php echo wc_price( $order->get_total_fees(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
<?php endif; ?>
@ -176,7 +176,7 @@ if ( wc_tax_enabled() ) {
<td class="label"><?php esc_html_e( 'Shipping:', 'woocommerce' ); ?></td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
<?php echo wc_price( $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
<?php endif; ?>
@ -189,7 +189,7 @@ if ( wc_tax_enabled() ) {
<td class="label"><?php echo esc_html( $tax_total->label ); ?>:</td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $tax_total->amount, array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
<?php echo wc_price( $tax_total->amount, array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
<?php endforeach; ?>
@ -201,7 +201,7 @@ if ( wc_tax_enabled() ) {
<td class="label"><?php esc_html_e( 'Order Total', 'woocommerce' ); ?>:</td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
<?php echo wc_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
@ -209,16 +209,31 @@ if ( wc_tax_enabled() ) {
<div class="clear"></div>
<?php if ( in_array( $order->get_status(), array( 'processing', 'completed', 'refunded' ) ) && ! empty( $order->get_date_paid() ) ) : ?>
<?php if ( in_array( $order->get_status(), array( 'processing', 'completed', 'refunded' ), true ) && ! empty( $order->get_date_paid() ) ) : ?>
<table class="wc-order-totals" style="border-top: 1px solid #999; margin-top:12px; padding-top:12px">
<tr>
<td class="label"><?php esc_html_e( 'Paid By Customer', 'woocommerce' ); ?>:</td>
<td class="<?php echo $order->get_total_refunded() ? 'label' : 'label label-highlight'; ?>"><?php esc_html_e( 'Paid', 'woocommerce' ); ?>: <br /></td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
<?php echo wc_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
<tr>
<td>
<span class="description">
<?php
if ( $order->get_payment_method_title() ) {
/* translators: 1: payment date. 2: payment method */
echo esc_html( sprintf( __( '%1$s via %2$s', 'woocommerce' ), $order->get_date_paid()->date_i18n( get_option( 'date_format' ) ), $order->get_payment_method_title() ) );
} else {
echo esc_html( $order->get_date_paid()->date_i18n( get_option( 'date_format' ) ) );
}
?>
</span>
</td>
<td colspan="2"></td>
</tr>
</table>
<div class="clear"></div>
@ -230,16 +245,16 @@ if ( wc_tax_enabled() ) {
<tr>
<td class="label refunded-total"><?php esc_html_e( 'Refunded', 'woocommerce' ); ?>:</td>
<td width="1%"></td>
<td class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?></td>
<td class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
</tr>
<?php do_action( 'woocommerce_admin_order_totals_after_refunded', $order->get_id() ); ?>
<tr>
<td class="label"><?php esc_html_e( 'Net Total', 'woocommerce' ); ?>:</td>
<td class="label label-highlight"><?php esc_html_e( 'Net Payment', 'woocommerce' ); ?>:</td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
<?php echo wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
@ -301,11 +316,11 @@ if ( wc_tax_enabled() ) {
<?php endif; ?>
<tr>
<td class="label"><?php esc_html_e( 'Amount already refunded', 'woocommerce' ); ?>:</td>
<td class="total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?></td>
<td class="total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
</tr>
<tr>
<td class="label"><?php esc_html_e( 'Total available to refund', 'woocommerce' ); ?>:</td>
<td class="total"><?php echo wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?></td>
<td class="total"><?php echo wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
</tr>
<tr>
<td class="label">
@ -386,7 +401,7 @@ if ( wc_tax_enabled() ) {
?>
<tbody data-row="<?php echo esc_attr( $row ); ?>">
<tr>
<?php echo $row; // WPCS: XSS ok. ?>
<?php echo $row; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</tr>
</tbody>
</table>
@ -426,18 +441,17 @@ if ( wc_tax_enabled() ) {
</tr>
</thead>
<?php
$rates = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name LIMIT 100" );
$rates = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name LIMIT 100" );
foreach ( $rates as $rate ) {
echo '
<tr>
<td><input type="radio" id="add_order_tax_' . absint( $rate->tax_rate_id ) . '" name="add_order_tax" value="' . absint( $rate->tax_rate_id ) . '" /></td>
<td><label for="add_order_tax_' . absint( $rate->tax_rate_id ) . '">' . WC_Tax::get_rate_label( $rate ) . '</label></td>
<td>' . ( isset( $classes_options[ $rate->tax_rate_class ] ) ? $classes_options[ $rate->tax_rate_class ] : '-' ) . '</td>
<td>' . WC_Tax::get_rate_code( $rate ) . '</td>
<td>' . WC_Tax::get_rate_percent( $rate ) . '</td>
<td><label for="add_order_tax_' . absint( $rate->tax_rate_id ) . '">' . esc_html( WC_Tax::get_rate_label( $rate ) ) . '</label></td>
<td>' . ( isset( $classes_options[ $rate->tax_rate_class ] ) ? esc_html( $classes_options[ $rate->tax_rate_class ] ) : '-' ) . '</td>
<td>' . esc_html( WC_Tax::get_rate_code( $rate ) ) . '</td>
<td>' . esc_html( WC_Tax::get_rate_percent( $rate ) ) . '</td>
</tr>
'; // WPCS: XSS ok.
';
}
?>
</table>

View File

@ -6,7 +6,7 @@
* @var int $variation_id
* @var WP_POST $variation
* @var WC_Product_Variation $variation_object
* @var array $variation_data array of variation data @deprecated.
* @var array $variation_data array of variation data @deprecated 4.4.0.
*/
defined( 'ABSPATH' ) || exit;

View File

@ -111,7 +111,7 @@ class WC_Notes_Run_Db_Update {
private static function update_needed_notice( $note_id = null ) {
$update_url = html_entity_decode(
wp_nonce_url(
add_query_arg( 'do_update_woocommerce', 'true', admin_url( 'admin.php?page=wc-settings' ) ),
add_query_arg( 'do_update_woocommerce', 'true', wc_get_current_admin_url() ? wc_get_current_admin_url() : admin_url( 'admin.php?page=wc-settings' ) ),
'wc_db_update',
'wc_db_update_nonce'
)
@ -210,7 +210,7 @@ class WC_Notes_Run_Db_Update {
add_query_arg(
'wc-hide-notice',
'update',
admin_url( 'admin.php?page=wc-settings' )
wc_get_current_admin_url() ? wc_get_current_admin_url() : admin_url( 'admin.php?page=wc-settings' )
),
'woocommerce_hide_notices_nonce',
'_wc_notice_nonce'

View File

@ -38,7 +38,7 @@ if ( ! $tab_exists ) {
self::show_messages();
do_action( 'woocommerce_settings_' . $current_tab );
do_action( 'woocommerce_settings_tabs_' . $current_tab ); // @deprecated hook. @todo remove in 4.0.
do_action( 'woocommerce_settings_tabs_' . $current_tab ); // @deprecated 3.4.0 hook.
?>
<p class="submit">
<?php if ( empty( $GLOBALS['hide_save_button'] ) ) : ?>

View File

@ -474,3 +474,23 @@ function wc_render_invalid_variation_notice( $product_object ) {
<?php
}
}
/**
* Get current admin page URL.
*
* Returns an empty string if it cannot generate a URL.
*
* @internal
* @since 4.4.0
* @return string
*/
function wc_get_current_admin_url() {
$uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$uri = preg_replace( '|^.*/wp-admin/|i', '', $uri );
if ( ! $uri ) {
return '';
}
return remove_query_arg( array( '_wpnonce', '_wc_notice_nonce', 'wc_db_update', 'wc_db_update_nonce', 'wc-hide-notice' ), admin_url( $uri ) );
}

View File

@ -454,8 +454,8 @@ class WC_Checkout {
*/
$item = apply_filters( 'woocommerce_checkout_create_order_line_item_object', new WC_Order_Item_Product(), $cart_item_key, $values, $order );
$product = $values['data'];
$item->legacy_values = $values; // @deprecated For legacy actions.
$item->legacy_cart_item_key = $cart_item_key; // @deprecated For legacy actions.
$item->legacy_values = $values; // @deprecated 4.4.0 For legacy actions.
$item->legacy_cart_item_key = $cart_item_key; // @deprecated 4.4.0 For legacy actions.
$item->set_props(
array(
'quantity' => $values['quantity'],
@ -502,8 +502,8 @@ class WC_Checkout {
public function create_order_fee_lines( &$order, $cart ) {
foreach ( $cart->get_fees() as $fee_key => $fee ) {
$item = new WC_Order_Item_Fee();
$item->legacy_fee = $fee; // @deprecated For legacy actions.
$item->legacy_fee_key = $fee_key; // @deprecated For legacy actions.
$item->legacy_fee = $fee; // @deprecated 4.4.0 For legacy actions.
$item->legacy_fee_key = $fee_key; // @deprecated 4.4.0 For legacy actions.
$item->set_props(
array(
'name' => $fee->name,
@ -541,7 +541,7 @@ class WC_Checkout {
if ( isset( $chosen_shipping_methods[ $package_key ], $package['rates'][ $chosen_shipping_methods[ $package_key ] ] ) ) {
$shipping_rate = $package['rates'][ $chosen_shipping_methods[ $package_key ] ];
$item = new WC_Order_Item_Shipping();
$item->legacy_package_key = $package_key; // @deprecated For legacy actions.
$item->legacy_package_key = $package_key; // @deprecated 4.4.0 For legacy actions.
$item->set_props(
array(
'method_title' => $shipping_rate->label,

View File

@ -191,10 +191,12 @@ class WC_Download_Handler {
/**
* Count download.
*
* @deprecated unknown
* @deprecated 4.4.0
* @param array $download_data Download data.
*/
public static function count_download( $download_data ) {}
public static function count_download( $download_data ) {
wc_deprecated_function( 'WC_Download_Handler::count_download', '4.4.0', '' );
}
/**
* Download a file - hook into init function.
@ -214,7 +216,14 @@ class WC_Download_Handler {
}
$filename = apply_filters( 'woocommerce_file_download_filename', $filename, $product_id );
$file_download_method = apply_filters( 'woocommerce_file_download_method', get_option( 'woocommerce_file_download_method', 'force' ), $product_id );
/**
* Filter download method.
*
* @param string $method Download method.
* @param int $product_id Product ID.
* @param string $file_path URL to file.
*/
$file_download_method = apply_filters( 'woocommerce_file_download_method', get_option( 'woocommerce_file_download_method', 'force' ), $product_id, $file_path );
// Add action to prevent issues in IE.
add_action( 'nocache_headers', array( __CLASS__, 'ie_nocache_headers_fix' ) );

View File

@ -136,11 +136,12 @@ class WC_Order_Item_Coupon extends WC_Order_Item {
/**
* OffsetGet for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @deprecated 4.4.0
* @param string $offset Offset.
* @return mixed
*/
public function offsetGet( $offset ) {
wc_deprecated_function( 'WC_Order_Item_Coupon::offsetGet', '4.4.0', '' );
if ( 'discount_amount' === $offset ) {
$offset = 'discount';
} elseif ( 'discount_amount_tax' === $offset ) {
@ -152,11 +153,12 @@ class WC_Order_Item_Coupon extends WC_Order_Item {
/**
* OffsetSet for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @deprecated 4.4.0
* @param string $offset Offset.
* @param mixed $value Value.
*/
public function offsetSet( $offset, $value ) {
wc_deprecated_function( 'WC_Order_Item_Coupon::offsetSet', '4.4.0', '' );
if ( 'discount_amount' === $offset ) {
$offset = 'discount';
} elseif ( 'discount_amount_tax' === $offset ) {

View File

@ -290,7 +290,6 @@ class WC_Order_Item_Fee extends WC_Order_Item {
/**
* OffsetGet for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @param string $offset Offset.
* @return mixed
*/
@ -308,11 +307,12 @@ class WC_Order_Item_Fee extends WC_Order_Item {
/**
* OffsetSet for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @deprecated 4.4.0
* @param string $offset Offset.
* @param mixed $value Value.
*/
public function offsetSet( $offset, $value ) {
wc_deprecated_function( 'WC_Order_Item_Fee::offsetSet', '4.4.0', '' );
if ( 'line_total' === $offset ) {
$offset = 'total';
} elseif ( 'line_tax' === $offset ) {

View File

@ -425,7 +425,6 @@ class WC_Order_Item_Product extends WC_Order_Item {
/**
* OffsetGet for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @param string $offset Offset.
* @return mixed
*/
@ -449,11 +448,12 @@ class WC_Order_Item_Product extends WC_Order_Item {
/**
* OffsetSet for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @deprecated 4.4.0
* @param string $offset Offset.
* @param mixed $value Value.
*/
public function offsetSet( $offset, $value ) {
wc_deprecated_function( 'WC_Order_Item_Product::offsetSet', '4.4.0', '' );
if ( 'line_subtotal' === $offset ) {
$offset = 'subtotal';
} elseif ( 'line_subtotal_tax' === $offset ) {

View File

@ -276,7 +276,6 @@ class WC_Order_Item_Shipping extends WC_Order_Item {
/**
* Offset get: for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @param string $offset Key.
* @return mixed
*/
@ -290,11 +289,12 @@ class WC_Order_Item_Shipping extends WC_Order_Item {
/**
* Offset set: for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @deprecated 4.4.0
* @param string $offset Key.
* @param mixed $value Value to set.
*/
public function offsetSet( $offset, $value ) {
wc_deprecated_function( 'WC_Order_Item_Shipping::offsetSet', '4.4.0', '' );
if ( 'cost' === $offset ) {
$offset = 'total';
}

View File

@ -244,7 +244,6 @@ class WC_Order_Item_Tax extends WC_Order_Item {
/**
* O for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @param string $offset Offset.
* @return mixed
*/
@ -260,11 +259,12 @@ class WC_Order_Item_Tax extends WC_Order_Item {
/**
* OffsetSet for ArrayAccess/Backwards compatibility.
*
* @deprecated Add deprecation notices in future release.
* @deprecated 4.4.0
* @param string $offset Offset.
* @param mixed $value Value.
*/
public function offsetSet( $offset, $value ) {
wc_deprecated_function( 'WC_Order_Item_Tax::offsetSet', '4.4.0', '' );
if ( 'tax_amount' === $offset ) {
$offset = 'tax_total';
} elseif ( 'shipping_tax_amount' === $offset ) {

View File

@ -1411,8 +1411,7 @@ class WC_Order extends WC_Abstract_Order {
$needs_address = false;
foreach ( $this->get_shipping_methods() as $shipping_method ) {
// Remove any instance IDs after ":".
$shipping_method_id = current( explode( ':', $shipping_method['method_id'] ) );
$shipping_method_id = $shipping_method->get_method_id();
if ( ! in_array( $shipping_method_id, $hide, true ) ) {
$needs_address = true;

View File

@ -368,8 +368,9 @@ class WC_Query {
}
/**
* When the request is filtering by attributes via layered nav plugin we need to adjust the total posts count
* to account for variable products having stock in some variations but not in others.
* When we are listing products and the request is filtering by attributes via layered nav plugin
* we need to adjust the total posts count to account for variable products having stock
* in some variations but not in others.
* We do that by just checking if each product is visible.
*
* We also cache the post visibility so that it isn't checked again when displaying the posts list.
@ -385,18 +386,22 @@ class WC_Query {
return $count;
}
$count = 0;
foreach ( $posts as $post ) {
$id = is_object( $post ) ? $post->ID : $post;
$product = wc_get_product( $id );
if ( is_object( $post ) && 'product' !== $post->post_type ) {
continue;
}
$product_id = is_object( $post ) ? $post->ID : $post;
$product = wc_get_product( $product_id );
if ( ! is_object( $product ) ) {
continue;
}
if ( $product->is_visible() ) {
wc_set_loop_product_visibility( $id, true );
$count++;
wc_set_loop_product_visibility( $product_id, true );
} else {
wc_set_loop_product_visibility( $id, false );
wc_set_loop_product_visibility( $product_id, false );
$count--;
}
}

View File

@ -216,7 +216,7 @@ class WC_Structured_Data {
if ( '' !== $product->get_price() ) {
// Assume prices will be valid until the end of next year, unless on sale and there is an end date.
$price_valid_until = date( 'Y-12-31', time() + YEAR_IN_SECONDS );
$price_valid_until = gmdate( 'Y-12-31', time() + YEAR_IN_SECONDS );
if ( $product->is_type( 'variable' ) ) {
$lowest = $product->get_variation_price( 'min', false );
@ -243,7 +243,7 @@ class WC_Structured_Data {
}
} else {
if ( $product->is_on_sale() && $product->get_date_on_sale_to() ) {
$price_valid_until = date( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() );
$price_valid_until = gmdate( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() );
}
$markup_offer = array(
'@type' => 'Offer',
@ -459,7 +459,7 @@ class WC_Structured_Data {
continue;
}
$product = $order->get_product_from_item( $item );
$product = $item->get_product();
$product_exists = is_object( $product );
$is_visible = $product_exists && $product->is_visible();
@ -472,12 +472,12 @@ class WC_Structured_Data {
'priceCurrency' => $order->get_currency(),
'eligibleQuantity' => array(
'@type' => 'QuantitativeValue',
'value' => apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ),
'value' => apply_filters( 'woocommerce_email_order_item_quantity', $item->get_quantity(), $item ),
),
),
'itemOffered' => array(
'@type' => 'Product',
'name' => apply_filters( 'woocommerce_order_item_name', $item['name'], $item, $is_visible ),
'name' => apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, $is_visible ),
'sku' => $product_exists ? $product->get_sku() : '',
'image' => $product_exists ? wp_get_attachment_image_url( $product->get_image_id() ) : '',
'url' => $is_visible ? get_permalink( $product->get_id() ) : get_home_url(),

View File

@ -655,7 +655,7 @@ final class WooCommerce {
/**
* Legacy image sizes.
*
* @deprecated These sizes will be removed in 4.0.
* @deprecated 3.3.0 These sizes will be removed in 4.6.0.
*/
add_image_size( 'shop_catalog', $thumbnail['width'], $thumbnail['height'], $thumbnail['crop'] );
add_image_size( 'shop_single', $single['width'], $single['height'], $single['crop'] );

View File

@ -312,11 +312,12 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
/**
* Get a product (either product or variation).
* @deprecated Add deprecation notices in future release. Replaced with $item->get_product()
* @deprecated 4.4.0
* @param object $item
* @return WC_Product|bool
*/
public function get_product_from_item( $item ) {
wc_deprecated_function( 'WC_Abstract_Legacy_Order::get_product_from_item', '4.4.0', '$item->get_product()' );
if ( is_callable( array( $item, 'get_product' ) ) ) {
$product = $item->get_product();
} else {
@ -461,7 +462,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* has_meta function for order items. This is different to the WC_Data
* version and should be removed in future versions.
*
* @deprecated
* @deprecated 3.0
*
* @param int $order_item_id
*

View File

@ -274,14 +274,14 @@ class WC_Legacy_API {
/**
* Rest API Init.
*
* @deprecated since 3.7.0 - REST API clases autoload.
* @deprecated 3.7.0 - REST API clases autoload.
*/
public function rest_api_init() {}
/**
* Include REST API classes.
*
* @deprecated since 3.7.0 - REST API clases autoload.
* @deprecated 3.7.0 - REST API clases autoload.
*/
public function rest_api_includes() {
$this->rest_api_init();
@ -289,9 +289,10 @@ class WC_Legacy_API {
/**
* Register REST API routes.
*
* @deprecated since 3.7.0 - Not used.
* @deprecated 3.7.0
*/
public function register_rest_routes() {
wc_deprecated_function( 'WC_Legacy_API::register_rest_routes', '3.7.0', '' );
$this->register_wp_admin_settings();
}
}

View File

@ -326,7 +326,7 @@ abstract class WC_Legacy_Cart {
/**
* Function to apply discounts to a product and get the discounted price (before tax is applied).
*
* @deprecated Calculation and coupon logic is handled in WC_Cart_Totals.
* @deprecated 3.2.0 Calculation and coupon logic is handled in WC_Cart_Totals.
* @param mixed $values Cart item.
* @param mixed $price Price of item.
* @param bool $add_totals Legacy.
@ -377,17 +377,18 @@ abstract class WC_Legacy_Cart {
/**
* Coupons enabled function. Filterable.
*
* @deprecated 2.5.0 in favor to wc_coupons_enabled()
* @deprecated 2.5.0
* @return bool
*/
public function coupons_enabled() {
wc_deprecated_function( 'WC_Legacy_Cart::coupons_enabled', '2.5.0', 'wc_coupons_enabled' );
return wc_coupons_enabled();
}
/**
* Gets the total (product) discount amount - these are applied before tax.
*
* @deprecated Order discounts (after tax) removed in 2.3 so multiple methods for discounts are no longer required.
* @deprecated 2.3.0 Order discounts (after tax) removed in 2.3 so multiple methods for discounts are no longer required.
* @return mixed formatted price or false if there are none.
*/
public function get_discounts_before_tax() {
@ -403,7 +404,7 @@ abstract class WC_Legacy_Cart {
/**
* Get the total of all order discounts (after tax discounts).
*
* @deprecated Order discounts (after tax) removed in 2.3.
* @deprecated 2.3.0 Order discounts (after tax) removed in 2.3.
* @return int
*/
public function get_order_discount_total() {
@ -414,7 +415,7 @@ abstract class WC_Legacy_Cart {
/**
* Function to apply cart discounts after tax.
*
* @deprecated Coupons can not be applied after tax.
* @deprecated 2.3.0 Coupons can not be applied after tax.
* @param $values
* @param $price
*/
@ -425,7 +426,7 @@ abstract class WC_Legacy_Cart {
/**
* Function to apply product discounts after tax.
*
* @deprecated Coupons can not be applied after tax.
* @deprecated 2.3.0 Coupons can not be applied after tax.
*
* @param $values
* @param $price
@ -437,7 +438,7 @@ abstract class WC_Legacy_Cart {
/**
* Gets the order discount amount - these are applied after tax.
*
* @deprecated Coupons can not be applied after tax.
* @deprecated 2.3.0 Coupons can not be applied after tax.
*/
public function get_discounts_after_tax() {
wc_deprecated_function( 'get_discounts_after_tax', '2.3' );

View File

@ -78,7 +78,7 @@ class WC_Shipping_Legacy_Flat_Rate extends WC_Shipping_Method {
$this->tax_status = $this->get_option( 'tax_status' );
$this->cost = $this->get_option( 'cost' );
$this->type = $this->get_option( 'type', 'class' );
$this->options = $this->get_option( 'options', false ); // @deprecated in 2.4.0
$this->options = $this->get_option( 'options', false ); // @deprecated 2.4.0
}
/**

View File

@ -885,8 +885,7 @@ function woocommerce_track_product_view() {
}
/**
* @since 2.3
* @deprecated has no replacement
* @deprecated 2.3 has no replacement
*/
function woocommerce_compile_less_styles() {
wc_deprecated_function( 'woocommerce_compile_less_styles', '2.3' );
@ -895,7 +894,7 @@ function woocommerce_compile_less_styles() {
/**
* woocommerce_calc_shipping was an option used to determine if shipping was enabled prior to version 2.6.0. This has since been replaced with wc_shipping_enabled() function and
* the woocommerce_ship_to_countries setting.
* @since 2.6.0
* @deprecated 2.6.0
* @return string
*/
function woocommerce_calc_shipping_backwards_compatibility( $value ) {

View File

@ -822,7 +822,7 @@ function wc_update_total_sales_counts( $order_id ) {
if ( $product_id ) {
$data_store = WC_Data_Store::load( 'product' );
$data_store->update_product_sales( $product_id, absint( $item['qty'] ), 'increase' );
$data_store->update_product_sales( $product_id, absint( $item->get_quantity() ), 'increase' );
}
}
}

48
package-lock.json generated
View File

@ -7663,9 +7663,9 @@
}
},
"@types/json-schema": {
"version": "7.0.4",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.4.tgz",
"integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==",
"version": "7.0.5",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.5.tgz",
"integrity": "sha512-7+2BITlgjgDhH0vvwZU/HZJVyk+2XUlvxXe8dFMedNX/aMkaOq++rMAFXc0tM7ij15QaWlbdQASBR9dihi+bDQ==",
"dev": true
},
"@types/mime-types": {
@ -7764,21 +7764,21 @@
"dev": true
},
"@typescript-eslint/experimental-utils": {
"version": "2.26.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.26.0.tgz",
"integrity": "sha512-RELVoH5EYd+JlGprEyojUv9HeKcZqF7nZUGSblyAw1FwOGNnmQIU8kxJ69fttQvEwCsX5D6ECJT8GTozxrDKVQ==",
"version": "2.34.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.34.0.tgz",
"integrity": "sha512-eS6FTkq+wuMJ+sgtuNTtcqavWXqsflWcfBnlYhg/nS4aZ1leewkXGbvBhaapn1q6qf4M71bsR1tez5JTRMuqwA==",
"dev": true,
"requires": {
"@types/json-schema": "^7.0.3",
"@typescript-eslint/typescript-estree": "2.26.0",
"@typescript-eslint/typescript-estree": "2.34.0",
"eslint-scope": "^5.0.0",
"eslint-utils": "^2.0.0"
},
"dependencies": {
"eslint-utils": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.0.0.tgz",
"integrity": "sha512-0HCPuJv+7Wv1bACm8y5/ECVfYdfsAm9xmVb7saeFlxjPYALefjhbYoCkBjPdPzGH8wWyTpAez82Fh3VKYEZ8OA==",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz",
"integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==",
"dev": true,
"requires": {
"eslint-visitor-keys": "^1.1.0"
@ -7787,9 +7787,9 @@
}
},
"@typescript-eslint/typescript-estree": {
"version": "2.26.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.26.0.tgz",
"integrity": "sha512-3x4SyZCLB4zsKsjuhxDLeVJN6W29VwBnYpCsZ7vIdPel9ZqLfIZJgJXO47MNUkurGpQuIBALdPQKtsSnWpE1Yg==",
"version": "2.34.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz",
"integrity": "sha512-OMAr+nJWKdlVM9LOqCqh3pQQPwxHAN7Du8DR6dmwCrAmxtiXQnhHJ6tBNtf+cggqfo51SG/FCwnKhXCIM7hnVg==",
"dev": true,
"requires": {
"debug": "^4.1.1",
@ -7797,7 +7797,7 @@
"glob": "^7.1.6",
"is-glob": "^4.0.1",
"lodash": "^4.17.15",
"semver": "^6.3.0",
"semver": "^7.3.2",
"tsutils": "^3.17.1"
},
"dependencies": {
@ -7825,9 +7825,9 @@
}
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
"version": "4.17.19",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==",
"dev": true
},
"ms": {
@ -7837,9 +7837,9 @@
"dev": true
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"version": "7.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz",
"integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==",
"dev": true
}
}
@ -8025,7 +8025,7 @@
"dev": true,
"requires": {
"@wordpress/e2e-test-utils": "^4.6.0",
"@wordpress/jest-preset-default": "^5.4.0",
"@wordpress/jest-preset-default": "^6.2.0",
"app-root-path": "^3.0.0",
"jest": "^25.1.0",
"jest-puppeteer": "^4.4.0",
@ -14328,9 +14328,9 @@
}
},
"eslint-plugin-jest": {
"version": "23.8.2",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.8.2.tgz",
"integrity": "sha512-xwbnvOsotSV27MtAe7s8uGWOori0nUsrXh2f1EnpmXua8sDfY6VZhHAhHg2sqK7HBNycRQExF074XSZ7DvfoFg==",
"version": "23.19.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.19.0.tgz",
"integrity": "sha512-l5PLflALqnODl8Yy0H5hDs18aKJS1KTf66VZGXRpIhmbLbPLaTuMB2P+65fBpkdseSpnTVcIlBYvTvJSBi/itg==",
"dev": true,
"requires": {
"@typescript-eslint/experimental-utils": "^2.5.0"

View File

@ -45,7 +45,7 @@
"deasync": "0.1.20",
"eslint": "6.8.0",
"eslint-config-wpcalypso": "5.0.0",
"eslint-plugin-jest": "23.8.2",
"eslint-plugin-jest": "23.19.0",
"github-contributors-list": "https://github.com/woocommerce/github-contributors-list/tarball/master",
"grunt": "1.1.0",
"grunt-contrib-clean": "2.0.0",

View File

@ -222,33 +222,35 @@ class WC_Tests_Order_Item_Product extends WC_Unit_Test_Case {
// Test line_subtotal.
$this->assertTrue( isset( $item['line_subtotal'] ) );
$item['line_subtotal'] = 50;
$item->set_subtotal( 50 );
$this->assertEquals( 50, $item->get_subtotal() );
$this->assertEquals( $item->get_subtotal(), $item['line_subtotal'] );
// Test line_subtotal_tax.
$this->assertTrue( isset( $item['line_subtotal_tax'] ) );
$item['line_subtotal_tax'] = 5;
$item->set_subtotal_tax( 5 );
$this->assertEquals( 5, $item->get_subtotal_tax() );
$this->assertEquals( $item->get_subtotal_tax(), $item['line_subtotal_tax'] );
// Test line_total.
$this->assertTrue( isset( $item['line_total'] ) );
$item['line_total'] = 55;
$item->set_total( 55 );
$this->assertEquals( 55, $item->get_total() );
$this->assertEquals( $item->get_total(), $item['line_total'] );
// Test line_tax.
$this->assertTrue( isset( $item['line_tax'] ) );
$item['line_tax'] = 5;
$item->set_total_tax( 5 );
$this->assertEquals( 5, $item->get_total_tax() );
$this->assertEquals( $item->get_total_tax(), $item['line_tax'] );
// Test line_tax_data.
$this->assertTrue( isset( $item['line_tax_data'] ) );
$item['line_tax_data'] = array(
'total' => array( 5 ),
'subtotal' => array( 5 ),
$item->set_taxes(
array(
'total' => array( 5 ),
'subtotal' => array( 5 ),
)
);
$this->assertEquals(
array(
@ -261,26 +263,21 @@ class WC_Tests_Order_Item_Product extends WC_Unit_Test_Case {
// Test qty.
$this->assertTrue( isset( $item['qty'] ) );
$item['qty'] = 150;
$item->set_quantity( 150 );
$this->assertEquals( 150, $item->get_quantity() );
$this->assertEquals( $item->get_quantity(), $item['qty'] );
// Test item_meta_array.
$this->assertTrue( isset( $item['item_meta_array'] ) );
$item['item_meta_array'] = array(
0 => (object) array(
'key' => 'test',
'value' => 'val',
),
);
$item->update_meta_data( 'test', 'val', 0 );
$this->assertInstanceOf( 'WC_Meta_Data', current( $item->get_meta_data() ) );
$this->assertEquals( current( $item->get_meta_data() ), $item['item_meta_array'][''] );
unset( $item['item_meta_array'] );
$this->assertEquals( array(), $item->get_meta_data() );
// Test default.
$this->assertFalse( isset( $item['foo'] ) );
$item['foo'] = 'bar';
$this->assertFalse( $item->meta_exists( 'foo' ) );
$item->add_meta_data( 'foo', 'bar' );
$this->assertEquals( 'bar', $item->get_meta( 'foo' ) );
}
}

View File

@ -441,12 +441,13 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
/**
* Setup for a test for adjust_posts.
*
* @param bool $with_nav_filtering_data Should WC_Query::get_layered_nav_chosen_attributes return filtering data?.
* @param bool $use_objects If true, get_current_posts will return objects with an ID property; if false, it will returns the ids.
* @param bool $with_nav_filtering_data Should WC_Query::get_layered_nav_chosen_attributes return filtering data?.
* @param bool $use_objects If true, get_current_posts will return objects with an ID property; if false, it will returns the ids.
* @param string $post_type The value of the 'post_type' property for the objects generated when $use_objects is true.
*
* @return array An array where the first element is the instance of WC_Query, and the second is an array of sample products created.
*/
private function setup_adjust_posts_test( $with_nav_filtering_data, $use_objects ) {
private function setup_adjust_posts_test( $with_nav_filtering_data, $use_objects, $post_type = 'product' ) {
update_option( 'woocommerce_hide_out_of_stock_items', 'yes' );
if ( $with_nav_filtering_data ) {
@ -460,7 +461,10 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
for ( $i = 0; $i < 5; $i++ ) {
$product = WC_Helper_Product::create_simple_product();
array_push( $products, $product );
$post = $use_objects ? (object) array( 'ID' => $product->get_id() ) : $product->get_id();
$post = $use_objects ? (object) array(
'ID' => $product->get_id(),
'post_type' => $post_type,
) : $product->get_id();
array_push( $posts, $post );
}
@ -495,8 +499,8 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
$products[1]->set_stock_status( 'outofstock' );
$products[1]->save();
$this->assertEquals( 3, $sut->adjust_posts_count( 34 ) );
$this->assertEquals( 3, wc_get_loop_prop( 'total' ) );
$this->assertEquals( 32, $sut->adjust_posts_count( 34 ) );
$this->assertEquals( 32, wc_get_loop_prop( 'total' ) );
$this->assertEquals( false, wc_get_loop_product_visibility( $products[0]->get_id() ) );
$this->assertEquals( false, wc_get_loop_product_visibility( $products[1]->get_id() ) );
foreach ( array_slice( $products, 2 ) as $product ) {
@ -517,4 +521,16 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
$this->assertEquals( 34, $sut->adjust_posts_count( 34 ) );
}
/**
* @testdox adjust_posts should return the input unmodified if the posts do not represent products.
*/
public function test_adjust_posts_count_when_the_posts_are_not_products() {
list( $sut, $products ) = $this->setup_adjust_posts_test( true, true, 'page' );
$products[0]->set_stock_status( 'outofstock' );
$products[0]->save();
$this->assertEquals( 34, $sut->adjust_posts_count( 34 ) );
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Unit tests for the WC_Admin_Functions_Test class
*
* @package WooCommerce\Tests\Admin
*/
/**
* Class WC_Admin_Functions_Test_Test
*/
class WC_Admin_Functions_Test extends \WC_Unit_Test_Case {
/**
* Load up the importer classes since they aren't loaded by default.
*/
public function setUp() {
parent::setUp();
$bootstrap = \WC_Unit_Tests_Bootstrap::instance();
require_once $bootstrap->plugin_dir . '/includes/admin/wc-admin-functions.php';
}
/**
* Test wc_get_current_admin_url() function.
*/
public function test_wc_get_current_admin_url() {
// Since REQUEST_URI is empty on unit tests it should return an empty string.
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
$this->assertEquals( '', wc_get_current_admin_url() );
}
// Test with REQUEST_URI.
$default_uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$_SERVER['REQUEST_URI'] = '/wp-admin/admin.php?page=wc-admin&foo=bar';
$this->assertEquals( admin_url( 'admin.php?page=wc-admin&foo=bar' ), wc_get_current_admin_url() );
// Test if nonce gets removed.
$_SERVER['REQUEST_URI'] = '/wp-admin/admin.php?page=wc-admin&_wpnonce=xxxxxxxxxxxx';
$this->assertEquals( admin_url( 'admin.php?page=wc-admin' ), wc_get_current_admin_url() );
// Restore REQUEST_URI.
$_SERVER['REQUEST_URI'] = $default_uri;
}
}