Merge branch 'master' into fix/23606
This commit is contained in:
commit
902cc1f0b0
|
@ -66,34 +66,3 @@ p.woocommerce-actions,
|
||||||
.woocommerce-about-text {
|
.woocommerce-about-text {
|
||||||
margin-bottom: 1em !important;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ body {
|
||||||
|
|
||||||
.select2-container {
|
.select2-container {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
width: 100%;
|
width: auto;
|
||||||
}
|
}
|
||||||
.hidden {
|
.hidden {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
|
@ -138,7 +138,7 @@ jQuery(function( $ ) {
|
||||||
var groupby = $( this ) .data( 'groupby' );
|
var groupby = $( this ) .data( 'groupby' );
|
||||||
var index_type = $( this ).data( 'index_type' );
|
var index_type = $( this ).data( 'index_type' );
|
||||||
var export_format = $( this ).data( 'export' );
|
var export_format = $( this ).data( 'export' );
|
||||||
var csv_data = 'data:text/csv;charset=utf-8,\uFEFF';
|
var csv_data = '';
|
||||||
var s, series_data, d;
|
var s, series_data, d;
|
||||||
|
|
||||||
if ( 'table' === export_format ) {
|
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
|
// Set data as href and return
|
||||||
$( this ).attr( 'href', encodeURI( csv_data ) );
|
$( this ).attr( 'href', csv_data );
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -161,12 +161,28 @@
|
||||||
lastRow = $( this ).find( 'tbody tr:last' ),
|
lastRow = $( this ).find( 'tbody tr:last' ),
|
||||||
firstRow = $( this ).find( 'tbody tr:first' );
|
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' } );
|
table.find( '.wc-item-reorder-nav .wc-move-disabled' ).removeClass( 'wc-move-disabled' )
|
||||||
firstRow.find( '.wc-item-reorder-nav .wc-move-up' ).addClass( 'wc-move-disabled' ).attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
|
.attr( { 'tabindex': '0', 'aria-hidden': 'false' } );
|
||||||
lastRow.find( '.wc-item-reorder-nav .wc-move-down' ).addClass( 'wc-move-disabled' ).attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
|
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' );
|
$( '.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 );
|
})( jQuery, woocommerce_settings_params, wp );
|
||||||
|
|
|
@ -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(
|
'TH' => array(
|
||||||
'currency_code' => 'THB',
|
'currency_code' => 'THB',
|
||||||
'currency_pos' => 'left',
|
'currency_pos' => 'left',
|
||||||
|
|
|
@ -1077,6 +1077,7 @@ return array(
|
||||||
'VS' => __( 'Vaslui', 'woocommerce' ),
|
'VS' => __( 'Vaslui', 'woocommerce' ),
|
||||||
'VN' => __( 'Vrancea', 'woocommerce' ),
|
'VN' => __( 'Vrancea', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
|
'RS' => array(),
|
||||||
'SG' => array(),
|
'SG' => array(),
|
||||||
'SK' => array(),
|
'SK' => array(),
|
||||||
'SI' => array(),
|
'SI' => array(),
|
||||||
|
|
|
@ -66,7 +66,7 @@ class WC_Admin_Help {
|
||||||
'<h2>' . __( 'Found a bug?', 'woocommerce' ) . '</h2>' .
|
'<h2>' . __( 'Found a bug?', 'woocommerce' ) . '</h2>' .
|
||||||
/* translators: 1: GitHub issues URL 2: GitHub contribution guide URL 3: System status report URL */
|
/* 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>' . 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>',
|
||||||
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -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_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(
|
wp_localize_script(
|
||||||
'woocommerce_settings', 'woocommerce_settings_params', array(
|
'woocommerce_settings',
|
||||||
'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'woocommerce' ),
|
'woocommerce_settings_params',
|
||||||
'i18n_moved_up' => __( 'Item moved up', 'woocommerce' ),
|
array(
|
||||||
'i18n_moved_down' => __( 'Item moved down', 'woocommerce' ),
|
'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' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -391,7 +394,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
|
||||||
selected( $option_value, (string) $key );
|
selected( $option_value, (string) $key );
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
><?php echo esc_html( $val ); ?></option>
|
><?php echo esc_html( $val ); ?></option>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
@ -494,7 +497,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! isset( $value['checkboxgroup'] ) || 'end' === $value['checkboxgroup'] ) {
|
if ( ! isset( $value['checkboxgroup'] ) || 'end' === $value['checkboxgroup'] ) {
|
||||||
?>
|
?>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -30,6 +30,9 @@ class WC_Admin {
|
||||||
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
|
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( 'wp_ajax_setup_wizard_check_jetpack', array( $this, 'setup_wizard_check_jetpack' ) );
|
||||||
add_action( 'init', array( 'WC_Site_Tracking', 'init' ) );
|
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.
|
// Setup/welcome.
|
||||||
if ( ! empty( $_GET['page'] ) ) {
|
if ( ! empty( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
|
||||||
switch ( $_GET['page'] ) {
|
switch ( $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
|
||||||
case 'wc-setup':
|
case 'wc-setup':
|
||||||
include_once dirname( __FILE__ ) . '/class-wc-admin-setup-wizard.php';
|
include_once dirname( __FILE__ ) . '/class-wc-admin-setup-wizard.php';
|
||||||
break;
|
break;
|
||||||
|
@ -251,7 +254,7 @@ class WC_Admin {
|
||||||
$wc_pages = array_diff( $wc_pages, array( 'profile', 'user-edit' ) );
|
$wc_pages = array_diff( $wc_pages, array( 'profile', 'user-edit' ) );
|
||||||
|
|
||||||
// Check to make sure we're on a WooCommerce admin page.
|
// 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.
|
// Change the footer text.
|
||||||
if ( ! get_option( 'woocommerce_admin_footer_text_rated' ) ) {
|
if ( ! get_option( 'woocommerce_admin_footer_text_rated' ) ) {
|
||||||
$footer_text = sprintf(
|
$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();
|
return new WC_Admin();
|
||||||
|
|
|
@ -1,22 +1,34 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Admin View: Notice - Legacy Shipping.
|
* Admin View: Notice - Legacy Shipping.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\Admin\Notices
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<div id="message" class="updated woocommerce-message woocommerce-legacy-shipping-notice">
|
<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 _e( 'Dismiss', 'woocommerce' ); ?></a>
|
<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> – <?php _e( 'a group of regions that can be assigned different shipping methods and rates.', 'woocommerce' ); ?></p>
|
<p class="main">
|
||||||
<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>
|
<strong><?php esc_html_e( 'New:', 'woocommerce' ); ?> <?php esc_html_e( 'Shipping zones', 'woocommerce' ); ?></strong> – <?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">
|
<p class="submit">
|
||||||
<?php if ( empty( $_GET['page'] ) || empty( $_GET['tab'] ) || 'wc-settings' !== $_GET['page'] || 'shipping' !== $_GET['tab'] ) : ?>
|
<?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; ?>
|
<?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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,21 +1,37 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Admin View: Notice - No Shipping methods.
|
* Admin View: Notice - No Shipping methods.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\Admin\Notices
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<div id="message" class="updated woocommerce-message woocommerce-no-shipping-methods-notice">
|
<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 _e( 'Dismiss', 'woocommerce' ); ?></a>
|
<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 & zones', 'woocommerce' ); ?></strong></p>
|
<p class="main">
|
||||||
<p><?php _e( 'Shipping is currently enabled, but you have not added any shipping methods to your shipping zones.', 'woocommerce' ); ?></p>
|
<strong>
|
||||||
<p><?php _e( 'Customers will not be able to purchase physical goods from your store until a shipping method is available.', 'woocommerce' ); ?></p>
|
<?php esc_html_e( 'Add shipping methods & 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">
|
<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-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); ?>">
|
||||||
<a class="button-secondary" href="https://docs.woocommerce.com/document/setting-up-shipping-zones/"><?php _e( 'Learn more about shipping zones', 'woocommerce' ); ?></a>
|
<?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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -878,8 +878,8 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
|
||||||
$version_latest = $data['Version'];
|
$version_latest = $data['Version'];
|
||||||
|
|
||||||
// Find latest version.
|
// Find latest version.
|
||||||
if ( isset( $available_updates[ $plugin ]->update->new_version ) ) {
|
if ( isset( $this->available_updates[ $plugin ]->update->new_version ) ) {
|
||||||
$version_latest = $available_updates[ $plugin ]->update->new_version;
|
$version_latest = $this->available_updates[ $plugin ]->update->new_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
|
|
@ -1176,7 +1176,7 @@ class WC_Checkout {
|
||||||
if ( is_user_logged_in() ) {
|
if ( is_user_logged_in() ) {
|
||||||
// Load customer object, but keep it cached to avoid reloading it multiple times.
|
// Load customer object, but keep it cached to avoid reloading it multiple times.
|
||||||
if ( is_null( $this->logged_in_customer ) ) {
|
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;
|
$customer_object = $this->logged_in_customer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -501,6 +501,7 @@ class WC_Countries {
|
||||||
'PL' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
'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}",
|
'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}",
|
'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}",
|
'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}",
|
'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}",
|
'SE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
||||||
|
@ -1103,6 +1104,12 @@ class WC_Countries {
|
||||||
'required' => true,
|
'required' => true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
'RS' => array(
|
||||||
|
'state' => array(
|
||||||
|
'required' => false,
|
||||||
|
'hidden' => true,
|
||||||
|
),
|
||||||
|
),
|
||||||
'SG' => array(
|
'SG' => array(
|
||||||
'state' => array(
|
'state' => array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
|
|
|
@ -961,7 +961,7 @@ class WC_Form_Handler {
|
||||||
try {
|
try {
|
||||||
$creds = array(
|
$creds = array(
|
||||||
'user_login' => trim( wp_unslash( $_POST['username'] ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
'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
|
'remember' => isset( $_POST['rememberme'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class WC_Webhook extends WC_Legacy_Webhook {
|
||||||
'event' => '',
|
'event' => '',
|
||||||
'failure_count' => 0,
|
'failure_count' => 0,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
'api_version' => 2,
|
'api_version' => 3,
|
||||||
'pending_delivery' => false,
|
'pending_delivery' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ final class WooCommerce {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $version = '3.6.0';
|
public $version = '3.7.0';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The single instance of the class.
|
* The single instance of the class.
|
||||||
|
@ -152,6 +152,7 @@ final class WooCommerce {
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->define_constants();
|
$this->define_constants();
|
||||||
|
$this->define_tables();
|
||||||
$this->includes();
|
$this->includes();
|
||||||
$this->init_hooks();
|
$this->init_hooks();
|
||||||
}
|
}
|
||||||
|
@ -184,7 +185,6 @@ final class WooCommerce {
|
||||||
add_action( 'init', array( $this, 'init' ), 0 );
|
add_action( 'init', array( $this, 'init' ), 0 );
|
||||||
add_action( 'init', array( 'WC_Shortcodes', 'init' ) );
|
add_action( 'init', array( 'WC_Shortcodes', 'init' ) );
|
||||||
add_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) );
|
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( 'init', array( $this, 'add_image_sizes' ) );
|
||||||
add_action( 'switch_blog', array( $this, 'wpdb_table_fix' ), 0 );
|
add_action( 'switch_blog', array( $this, 'wpdb_table_fix' ), 0 );
|
||||||
add_action( 'activated_plugin', array( $this, 'activated_plugin' ) );
|
add_action( 'activated_plugin', array( $this, 'activated_plugin' ) );
|
||||||
|
@ -230,6 +230,25 @@ final class WooCommerce {
|
||||||
$this->define( 'WC_TEMPLATE_DEBUG_MODE', false );
|
$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.
|
* Define constant if not already set.
|
||||||
*
|
*
|
||||||
|
@ -710,16 +729,7 @@ final class WooCommerce {
|
||||||
* Set tablenames inside WPDB object.
|
* Set tablenames inside WPDB object.
|
||||||
*/
|
*/
|
||||||
public function wpdb_table_fix() {
|
public function wpdb_table_fix() {
|
||||||
global $wpdb;
|
$this->define_tables();
|
||||||
|
|
||||||
$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';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -50,6 +50,7 @@ class WC_Admin_Setup_Wizard_Tracking {
|
||||||
public function add_footer_scripts() {
|
public function add_footer_scripts() {
|
||||||
wp_print_scripts();
|
wp_print_scripts();
|
||||||
WC_Site_Tracking::add_tracking_function();
|
WC_Site_Tracking::add_tracking_function();
|
||||||
|
wc_print_js();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -705,7 +705,7 @@ function wc_query_string_form_fields( $values = null, $exclude = array(), $curre
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
if ( ! empty( $url_parts['query'] ) ) {
|
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(
|
$replace_chars = array(
|
||||||
'.' => '{dot}',
|
'.' => '{dot}',
|
||||||
'+' => '{plus}',
|
'+' => '{plus}',
|
||||||
|
@ -717,9 +717,11 @@ function wc_query_string_form_fields( $values = null, $exclude = array(), $curre
|
||||||
// Parse the string.
|
// Parse the string.
|
||||||
parse_str( $query_string, $parsed_query_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 ) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ function wc_change_get_terms_defaults( $defaults, $taxonomies ) {
|
||||||
if ( is_array( $taxonomies ) && 1 < count( $taxonomies ) ) {
|
if ( is_array( $taxonomies ) && 1 < count( $taxonomies ) ) {
|
||||||
return $defaults;
|
return $defaults;
|
||||||
}
|
}
|
||||||
$taxonomy = is_array( $taxonomies ) ? $taxonomies[0] : $taxonomies;
|
$taxonomy = is_array( $taxonomies ) ? (string) current( $taxonomies ) : $taxonomies;
|
||||||
$orderby = 'name';
|
$orderby = 'name';
|
||||||
|
|
||||||
if ( taxonomy_is_product_attribute( $taxonomy ) ) {
|
if ( taxonomy_is_product_attribute( $taxonomy ) ) {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -56,7 +56,7 @@
|
||||||
"grunt-wp-i18n": "1.0.3",
|
"grunt-wp-i18n": "1.0.3",
|
||||||
"husky": "2.2.0",
|
"husky": "2.2.0",
|
||||||
"istanbul": "1.0.0-alpha.2",
|
"istanbul": "1.0.0-alpha.2",
|
||||||
"lint-staged": "8.1.5",
|
"lint-staged": "8.1.6",
|
||||||
"mocha": "6.1.4",
|
"mocha": "6.1.4",
|
||||||
"node-sass": "4.12.0",
|
"node-sass": "4.12.0",
|
||||||
"prettier": "github:automattic/calypso-prettier#c56b4251",
|
"prettier": "github:automattic/calypso-prettier#c56b4251",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Contributors: automattic, mikejolley, jameskoster, claudiosanches, claudiulodro, kloon, rodrigosprimo, jshreve, coderkevin
|
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
|
Tags: ecommerce, e-commerce, store, sales, sell, shop, cart, checkout, downloadable, downloads, payments, paypal, storefront, stripe, woo commerce, woo
|
||||||
Requires at least: 4.7
|
Requires at least: 4.7
|
||||||
Tested up to: 5.1
|
Tested up to: 5.2
|
||||||
Stable tag: 3.6.0
|
Stable tag: 3.6.0
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
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 =
|
= 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).
|
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 you’re interested in contributing to WooCommerce we’ve got more than 350 contributors, and there’s 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.
|
If you’re interested in contributing to WooCommerce we’ve got more than 350 contributors, and there’s 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 you’re 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 you’re 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 ==
|
== 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 won’t 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.”
|
Automatic installation is the easiest option -- WordPress will handles the file transfer, and you won’t 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 you’ve 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 you’ve 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 =
|
= Manual installation =
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,10 @@ class WC_API_Unit_Test_Case extends WC_Unit_Test_Case {
|
||||||
* Assert the given response is an API error with a specific code and status.
|
* Assert the given response is an API error with a specific code and status.
|
||||||
*
|
*
|
||||||
* @since 2.2
|
* @since 2.2
|
||||||
* @param string $code error code, e.g. `woocommerce_api_user_cannot_read_orders_count`
|
* @param string $code error code, e.g. `woocommerce_api_user_cannot_read_orders_count`
|
||||||
* @param int|null $status HTTP status code associated with error, e.g. 400
|
* @param int|null $status HTTP status code associated with error, e.g. 400
|
||||||
* @param WP_Error $response
|
* @param WP_Error $response
|
||||||
* @param string $message optional message to render when assertion fails
|
* @param string $message optional message to render when assertion fails
|
||||||
*/
|
*/
|
||||||
public function assertHasAPIError( $code, $status = null, $response, $message = '' ) {
|
public function assertHasAPIError( $code, $status = null, $response, $message = '' ) {
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
class WC_Mock_WC_Data_Store extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface {
|
class WC_Mock_WC_Data_Store extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface {
|
||||||
|
|
||||||
protected $meta_type = 'post';
|
protected $meta_type = 'post';
|
||||||
protected $object_id_field_for_meta = '';
|
protected $object_id_field_for_meta = '';
|
||||||
protected $internal_meta_keys = array();
|
protected $internal_meta_keys = array();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
@ -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();
|
$content_id = $object->get_id();
|
||||||
|
|
||||||
if ( 'user' === $this->meta_type ) {
|
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 {
|
} 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->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 ) {
|
if ( $this->get_id() > 0 ) {
|
||||||
$this->data_store->read( $this );
|
$this->data_store->read( $this );
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WC_REST_Unit_Test_Case extends WC_Unit_Test_Case {
|
||||||
do_action( 'rest_api_init' );
|
do_action( 'rest_api_init' );
|
||||||
|
|
||||||
// Reset payment gateways.
|
// Reset payment gateways.
|
||||||
$gateways = WC_Payment_Gateways::instance();
|
$gateways = WC_Payment_Gateways::instance();
|
||||||
$gateways->payment_gateways = array();
|
$gateways->payment_gateways = array();
|
||||||
$gateways->init();
|
$gateways->init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,32 +19,37 @@ class WC_Helper_Coupon {
|
||||||
*/
|
*/
|
||||||
public static function create_coupon( $coupon_code = 'dummycoupon', $meta = array() ) {
|
public static function create_coupon( $coupon_code = 'dummycoupon', $meta = array() ) {
|
||||||
// Insert post
|
// Insert post
|
||||||
$coupon_id = wp_insert_post( array(
|
$coupon_id = wp_insert_post(
|
||||||
'post_title' => $coupon_code,
|
array(
|
||||||
'post_type' => 'shop_coupon',
|
'post_title' => $coupon_code,
|
||||||
'post_status' => 'publish',
|
'post_type' => 'shop_coupon',
|
||||||
'post_excerpt' => 'This is a dummy coupon',
|
'post_status' => 'publish',
|
||||||
) );
|
'post_excerpt' => 'This is a dummy coupon',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$meta = wp_parse_args( $meta, array(
|
$meta = wp_parse_args(
|
||||||
'discount_type' => 'fixed_cart',
|
$meta,
|
||||||
'coupon_amount' => '1',
|
array(
|
||||||
'individual_use' => 'no',
|
'discount_type' => 'fixed_cart',
|
||||||
'product_ids' => '',
|
'coupon_amount' => '1',
|
||||||
'exclude_product_ids' => '',
|
'individual_use' => 'no',
|
||||||
'usage_limit' => '',
|
'product_ids' => '',
|
||||||
'usage_limit_per_user' => '',
|
'exclude_product_ids' => '',
|
||||||
'limit_usage_to_x_items' => '',
|
'usage_limit' => '',
|
||||||
'expiry_date' => '',
|
'usage_limit_per_user' => '',
|
||||||
'free_shipping' => 'no',
|
'limit_usage_to_x_items' => '',
|
||||||
'exclude_sale_items' => 'no',
|
'expiry_date' => '',
|
||||||
'product_categories' => array(),
|
'free_shipping' => 'no',
|
||||||
'exclude_product_categories' => array(),
|
'exclude_sale_items' => 'no',
|
||||||
'minimum_amount' => '',
|
'product_categories' => array(),
|
||||||
'maximum_amount' => '',
|
'exclude_product_categories' => array(),
|
||||||
'customer_email' => array(),
|
'minimum_amount' => '',
|
||||||
'usage_count' => '0',
|
'maximum_amount' => '',
|
||||||
) );
|
'customer_email' => array(),
|
||||||
|
'usage_count' => '0',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Update meta.
|
// Update meta.
|
||||||
foreach ( $meta as $key => $value ) {
|
foreach ( $meta as $key => $value ) {
|
||||||
|
|
|
@ -14,25 +14,25 @@ class WC_Helper_Customer {
|
||||||
*/
|
*/
|
||||||
public static function create_mock_customer() {
|
public static function create_mock_customer() {
|
||||||
$customer_data = array(
|
$customer_data = array(
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
'date_modified' => null,
|
'date_modified' => null,
|
||||||
'country' => 'US',
|
'country' => 'US',
|
||||||
'state' => 'PA',
|
'state' => 'PA',
|
||||||
'postcode' => '19123',
|
'postcode' => '19123',
|
||||||
'city' => 'Philadelphia',
|
'city' => 'Philadelphia',
|
||||||
'address' => '123 South Street',
|
'address' => '123 South Street',
|
||||||
'address_2' => 'Apt 1',
|
'address_2' => 'Apt 1',
|
||||||
'shipping_country' => 'US',
|
'shipping_country' => 'US',
|
||||||
'shipping_state' => 'PA',
|
'shipping_state' => 'PA',
|
||||||
'shipping_postcode' => '19123',
|
'shipping_postcode' => '19123',
|
||||||
'shipping_city' => 'Philadelphia',
|
'shipping_city' => 'Philadelphia',
|
||||||
'shipping_address' => '123 South Street',
|
'shipping_address' => '123 South Street',
|
||||||
'shipping_address_2' => 'Apt 1',
|
'shipping_address_2' => 'Apt 1',
|
||||||
'is_vat_exempt' => false,
|
'is_vat_exempt' => false,
|
||||||
'calculated_shipping' => false,
|
'calculated_shipping' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
WC_Helper_Customer::set_customer_details( $customer_data );
|
self::set_customer_details( $customer_data );
|
||||||
|
|
||||||
$customer = new WC_Customer( 0, true );
|
$customer = new WC_Customer( 0, true );
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class WC_Helper_Customer {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function get_expected_store_location() {
|
public static function get_expected_store_location() {
|
||||||
return array( "GB", "", "", "" );
|
return array( 'GB', '', '', '' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -54,16 +54,18 @@ class WC_Helper_Order {
|
||||||
);
|
);
|
||||||
|
|
||||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Required, else wc_create_order throws an exception
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Required, else wc_create_order throws an exception
|
||||||
$order = wc_create_order( $order_data );
|
$order = wc_create_order( $order_data );
|
||||||
|
|
||||||
// Add order products
|
// Add order products
|
||||||
$item = new WC_Order_Item_Product();
|
$item = new WC_Order_Item_Product();
|
||||||
$item->set_props( array(
|
$item->set_props(
|
||||||
'product' => $product,
|
array(
|
||||||
'quantity' => 4,
|
'product' => $product,
|
||||||
'subtotal' => wc_get_price_excluding_tax( $product, array( 'qty' => 4 ) ),
|
'quantity' => 4,
|
||||||
'total' => wc_get_price_excluding_tax( $product, array( 'qty' => 4 ) ),
|
'subtotal' => wc_get_price_excluding_tax( $product, array( 'qty' => 4 ) ),
|
||||||
) );
|
'total' => wc_get_price_excluding_tax( $product, array( 'qty' => 4 ) ),
|
||||||
|
)
|
||||||
|
);
|
||||||
$item->save();
|
$item->save();
|
||||||
$order->add_item( $item );
|
$order->add_item( $item );
|
||||||
|
|
||||||
|
@ -82,14 +84,16 @@ class WC_Helper_Order {
|
||||||
|
|
||||||
// Add shipping costs
|
// Add shipping costs
|
||||||
$shipping_taxes = WC_Tax::calc_shipping_tax( '10', WC_Tax::get_shipping_tax_rates() );
|
$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' );
|
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate' );
|
||||||
$item = new WC_Order_Item_Shipping();
|
$item = new WC_Order_Item_Shipping();
|
||||||
$item->set_props( array(
|
$item->set_props(
|
||||||
'method_title' => $rate->label,
|
array(
|
||||||
'method_id' => $rate->id,
|
'method_title' => $rate->label,
|
||||||
'total' => wc_format_decimal( $rate->cost ),
|
'method_id' => $rate->id,
|
||||||
'taxes' => $rate->taxes,
|
'total' => wc_format_decimal( $rate->cost ),
|
||||||
) );
|
'taxes' => $rate->taxes,
|
||||||
|
)
|
||||||
|
);
|
||||||
foreach ( $rate->get_meta_data() as $key => $value ) {
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
||||||
$item->add_meta_data( $key, $value, true );
|
$item->add_meta_data( $key, $value, true );
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,8 +90,8 @@ class WC_Helper_Product {
|
||||||
$product = new WC_Product_Grouped();
|
$product = new WC_Product_Grouped();
|
||||||
$product->set_props(
|
$product->set_props(
|
||||||
array(
|
array(
|
||||||
'name' => 'Dummy Grouped Product',
|
'name' => 'Dummy Grouped Product',
|
||||||
'sku' => 'DUMMY GROUPED SKU',
|
'sku' => 'DUMMY GROUPED SKU',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$product->set_children( array( $simple_product_1->get_id(), $simple_product_2->get_id() ) );
|
$product->set_children( array( $simple_product_1->get_id(), $simple_product_2->get_id() ) );
|
||||||
|
@ -235,7 +235,7 @@ class WC_Helper_Product {
|
||||||
$result = term_exists( $term, $attribute->slug );
|
$result = term_exists( $term, $attribute->slug );
|
||||||
|
|
||||||
if ( ! $result ) {
|
if ( ! $result ) {
|
||||||
$result = wp_insert_term( $term, $attribute->slug );
|
$result = wp_insert_term( $term, $attribute->slug );
|
||||||
$return['term_ids'][] = $result['term_id'];
|
$return['term_ids'][] = $result['term_id'];
|
||||||
} else {
|
} else {
|
||||||
$return['term_ids'][] = $result['term_id'];
|
$return['term_ids'][] = $result['term_id'];
|
||||||
|
|
|
@ -40,13 +40,13 @@ class WC_Helper_Settings {
|
||||||
'option_key' => '',
|
'option_key' => '',
|
||||||
);
|
);
|
||||||
$groups[] = array(
|
$groups[] = array(
|
||||||
'id' => 'coupon-data',
|
'id' => 'coupon-data',
|
||||||
'label' => 'Coupon data',
|
'label' => 'Coupon data',
|
||||||
'option_key' => '',
|
'option_key' => '',
|
||||||
);
|
);
|
||||||
$groups[] = array(
|
$groups[] = array(
|
||||||
'id' => 'invalid',
|
'id' => 'invalid',
|
||||||
'option_key' => '',
|
'option_key' => '',
|
||||||
);
|
);
|
||||||
return $groups;
|
return $groups;
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ abstract class WP_HTTP_TestCase extends WP_UnitTestCase {
|
||||||
public function http_request_listner( $preempt, $request, $url ) {
|
public function http_request_listner( $preempt, $request, $url ) {
|
||||||
|
|
||||||
$this->http_requests[] = array(
|
$this->http_requests[] = array(
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'request' => $request,
|
'request' => $request,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ abstract class WP_HTTP_TestCase extends WP_UnitTestCase {
|
||||||
*
|
*
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*
|
*
|
||||||
* @param array $request The request.
|
* @param array $request The request.
|
||||||
* @param string $url The URL the request is for.
|
* @param string $url The URL the request is for.
|
||||||
*
|
*
|
||||||
* @return string|false The cache key for the request. False if not caching.
|
* @return string|false The cache key for the request. False if not caching.
|
||||||
|
@ -315,7 +315,7 @@ abstract class WP_HTTP_TestCase extends WP_UnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$cache[ $cache_key ] = $response;
|
self::$cache[ $cache_key ] = $response;
|
||||||
self::$cache_changed = true;
|
self::$cache_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -428,7 +428,8 @@ abstract class WP_HTTP_TestCase extends WP_UnitTestCase {
|
||||||
|
|
||||||
// phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_file_put_contents
|
// phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_file_put_contents
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
self::$cache_dir . '/' . self::$cache_group, serialize( self::$cache )
|
self::$cache_dir . '/' . self::$cache_group,
|
||||||
|
serialize( self::$cache )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,14 +45,17 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_get_account_menu_items() {
|
public function test_wc_get_account_menu_items() {
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'dashboard' => 'Dashboard',
|
array(
|
||||||
'orders' => 'Orders',
|
'dashboard' => 'Dashboard',
|
||||||
'downloads' => 'Downloads',
|
'orders' => 'Orders',
|
||||||
'edit-address' => 'Addresses',
|
'downloads' => 'Downloads',
|
||||||
'edit-account' => 'Account details',
|
'edit-address' => 'Addresses',
|
||||||
'customer-logout' => 'Logout',
|
'edit-account' => 'Account details',
|
||||||
), wc_get_account_menu_items() );
|
'customer-logout' => 'Logout',
|
||||||
|
),
|
||||||
|
wc_get_account_menu_items()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,13 +82,16 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_get_account_orders_columns() {
|
public function test_wc_get_account_orders_columns() {
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'order-number' => 'Order',
|
array(
|
||||||
'order-date' => 'Date',
|
'order-number' => 'Order',
|
||||||
'order-status' => 'Status',
|
'order-date' => 'Date',
|
||||||
'order-total' => 'Total',
|
'order-status' => 'Status',
|
||||||
'order-actions' => 'Actions',
|
'order-total' => 'Total',
|
||||||
), wc_get_account_orders_columns() );
|
'order-actions' => 'Actions',
|
||||||
|
),
|
||||||
|
wc_get_account_orders_columns()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,12 +100,15 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_get_account_downloads_columns() {
|
public function test_wc_get_account_downloads_columns() {
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'download-file' => 'Download',
|
array(
|
||||||
'download-remaining' => 'Downloads remaining',
|
'download-file' => 'Download',
|
||||||
'download-expires' => 'Expires',
|
'download-remaining' => 'Downloads remaining',
|
||||||
'download-product' => 'Product',
|
'download-expires' => 'Expires',
|
||||||
), wc_get_account_downloads_columns() );
|
'download-product' => 'Product',
|
||||||
|
),
|
||||||
|
wc_get_account_downloads_columns()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,11 +117,14 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
|
||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_get_account_payment_methods_columns() {
|
public function test_wc_get_account_payment_methods_columns() {
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'method' => 'Method',
|
array(
|
||||||
'expires' => 'Expires',
|
'method' => 'Method',
|
||||||
'actions' => ' ',
|
'expires' => 'Expires',
|
||||||
), wc_get_account_payment_methods_columns() );
|
'actions' => ' ',
|
||||||
|
),
|
||||||
|
wc_get_account_payment_methods_columns()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,10 +133,13 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
|
||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_get_account_payment_methods_types() {
|
public function test_wc_get_account_payment_methods_types() {
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'cc' => 'Credit card',
|
array(
|
||||||
'echeck' => 'eCheck',
|
'cc' => 'Credit card',
|
||||||
), wc_get_account_payment_methods_types() );
|
'echeck' => 'eCheck',
|
||||||
|
),
|
||||||
|
wc_get_account_payment_methods_types()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,20 +150,23 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
|
||||||
public function test_wc_get_account_orders_actions() {
|
public function test_wc_get_account_orders_actions() {
|
||||||
$order = WC_Helper_Order::create_order();
|
$order = WC_Helper_Order::create_order();
|
||||||
|
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'view' => array(
|
array(
|
||||||
'url' => $order->get_view_order_url(),
|
'view' => array(
|
||||||
'name' => 'View',
|
'url' => $order->get_view_order_url(),
|
||||||
|
'name' => 'View',
|
||||||
|
),
|
||||||
|
'pay' => array(
|
||||||
|
'url' => $order->get_checkout_payment_url(),
|
||||||
|
'name' => 'Pay',
|
||||||
|
),
|
||||||
|
'cancel' => array(
|
||||||
|
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
|
||||||
|
'name' => 'Cancel',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
'pay' => array(
|
wc_get_account_orders_actions( $order->get_id() )
|
||||||
'url' => $order->get_checkout_payment_url(),
|
);
|
||||||
'name' => 'Pay',
|
|
||||||
),
|
|
||||||
'cancel' => array(
|
|
||||||
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
|
|
||||||
'name' => 'Cancel',
|
|
||||||
),
|
|
||||||
), wc_get_account_orders_actions( $order->get_id() ) );
|
|
||||||
|
|
||||||
$order->delete( true );
|
$order->delete( true );
|
||||||
}
|
}
|
||||||
|
@ -187,25 +205,28 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
|
||||||
$delete_url = wc_get_endpoint_url( 'delete-payment-method', $token->get_id() );
|
$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() );
|
$delete_url = wp_nonce_url( $delete_url, 'delete-payment-method-' . $token->get_id() );
|
||||||
|
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'cc' => array(
|
array(
|
||||||
array(
|
'cc' => array(
|
||||||
'method' => array(
|
array(
|
||||||
'gateway' => 'bacs',
|
'method' => array(
|
||||||
'last4' => '1234',
|
'gateway' => 'bacs',
|
||||||
'brand' => 'Mastercard',
|
'last4' => '1234',
|
||||||
),
|
'brand' => 'Mastercard',
|
||||||
'expires' => '12/20',
|
),
|
||||||
'is_default' => true,
|
'expires' => '12/20',
|
||||||
'actions' => array(
|
'is_default' => true,
|
||||||
'delete' => array(
|
'actions' => array(
|
||||||
'url' => $delete_url,
|
'delete' => array(
|
||||||
'name' => 'Delete',
|
'url' => $delete_url,
|
||||||
|
'name' => 'Delete',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), 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 );
|
$customer->delete( true );
|
||||||
$token->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->set_expiry_year( '2020' );
|
||||||
$token->save();
|
$token->save();
|
||||||
|
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'method' => array(
|
array(
|
||||||
'last4' => '1234',
|
'method' => array(
|
||||||
'brand' => 'Mastercard',
|
'last4' => '1234',
|
||||||
|
'brand' => 'Mastercard',
|
||||||
|
),
|
||||||
|
'expires' => '12/20',
|
||||||
),
|
),
|
||||||
'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 );
|
$token->delete( true );
|
||||||
}
|
}
|
||||||
|
@ -249,12 +273,15 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
|
||||||
$token->set_last4( '1234' );
|
$token->set_last4( '1234' );
|
||||||
$token->save();
|
$token->save();
|
||||||
|
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'method' => array(
|
array(
|
||||||
'last4' => '1234',
|
'method' => array(
|
||||||
'brand' => 'eCheck',
|
'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 );
|
$token->delete( true );
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,20 +31,22 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
|
||||||
* Test: get_order_report_data
|
* Test: get_order_report_data
|
||||||
*/
|
*/
|
||||||
public function test_get_order_report_data() {
|
public function test_get_order_report_data() {
|
||||||
$order = WC_Helper_Order::create_order();
|
$order = WC_Helper_Order::create_order();
|
||||||
$order->set_status( 'completed' );
|
$order->set_status( 'completed' );
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
$report = new WC_Admin_Report();
|
$report = new WC_Admin_Report();
|
||||||
$data = $report->get_order_report_data( array(
|
$data = $report->get_order_report_data(
|
||||||
'data' => array(
|
array(
|
||||||
'ID' => array(
|
'data' => array(
|
||||||
'type' => 'post_data',
|
'ID' => array(
|
||||||
'function' => 'COUNT',
|
'type' => 'post_data',
|
||||||
'name' => 'total_orders',
|
'function' => 'COUNT',
|
||||||
|
'name' => 'total_orders',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
|
|
||||||
$this->assertEquals( 1, $data->total_orders, 'Expected to see one completed order in the report.' );
|
$this->assertEquals( 1, $data->total_orders, 'Expected to see one completed order in the report.' );
|
||||||
WC_Admin_Report::maybe_update_transients();
|
WC_Admin_Report::maybe_update_transients();
|
||||||
|
@ -66,20 +68,22 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
|
||||||
* Test: get_order_report_data
|
* Test: get_order_report_data
|
||||||
*/
|
*/
|
||||||
public function test_get_order_report_data_for_post_meta() {
|
public function test_get_order_report_data_for_post_meta() {
|
||||||
$order = WC_Helper_Order::create_order();
|
$order = WC_Helper_Order::create_order();
|
||||||
$order->set_status( 'completed' );
|
$order->set_status( 'completed' );
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
$report = new WC_Admin_Report();
|
$report = new WC_Admin_Report();
|
||||||
$data = $report->get_order_report_data( array(
|
$data = $report->get_order_report_data(
|
||||||
'data' => array(
|
array(
|
||||||
'_billing_first_name' => array(
|
'data' => array(
|
||||||
'type' => 'meta',
|
'_billing_first_name' => array(
|
||||||
'function' => null,
|
'type' => 'meta',
|
||||||
'name' => 'customer_name',
|
'function' => null,
|
||||||
|
'name' => 'customer_name',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
|
|
||||||
$this->assertEquals( $order->get_billing_first_name(), $data->customer_name );
|
$this->assertEquals( $order->get_billing_first_name(), $data->customer_name );
|
||||||
}
|
}
|
||||||
|
@ -89,20 +93,24 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_get_order_report_data_for_parent_meta() {
|
public function test_get_order_report_data_for_parent_meta() {
|
||||||
$order = WC_Helper_Order::create_order();
|
$order = WC_Helper_Order::create_order();
|
||||||
$refund = wc_create_refund( array(
|
$refund = wc_create_refund(
|
||||||
'order_id' => $order->get_id(),
|
array(
|
||||||
) );
|
'order_id' => $order->get_id(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$report = new WC_Admin_Report();
|
$report = new WC_Admin_Report();
|
||||||
$data = $report->get_order_report_data( array(
|
$data = $report->get_order_report_data(
|
||||||
'data' => array(
|
array(
|
||||||
'_order_total' => array(
|
'data' => array(
|
||||||
'type' => 'parent_meta',
|
'_order_total' => array(
|
||||||
'function' => '',
|
'type' => 'parent_meta',
|
||||||
'name' => 'total_refund',
|
'function' => '',
|
||||||
|
'name' => 'total_refund',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
|
|
||||||
$this->assertEquals( $order->get_total(), $data->total_refund );
|
$this->assertEquals( $order->get_total(), $data->total_refund );
|
||||||
}
|
}
|
||||||
|
@ -111,20 +119,22 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
|
||||||
* Test: get_order_report_data
|
* Test: get_order_report_data
|
||||||
*/
|
*/
|
||||||
public function test_get_order_report_data_for_post_data() {
|
public function test_get_order_report_data_for_post_data() {
|
||||||
$order = WC_Helper_Order::create_order();
|
$order = WC_Helper_Order::create_order();
|
||||||
$order->set_status( 'completed' );
|
$order->set_status( 'completed' );
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
$report = new WC_Admin_Report();
|
$report = new WC_Admin_Report();
|
||||||
$data = $report->get_order_report_data( array(
|
$data = $report->get_order_report_data(
|
||||||
'data' => array(
|
array(
|
||||||
'post_status' => array(
|
'data' => array(
|
||||||
'type' => 'post_data',
|
'post_status' => array(
|
||||||
'function' => null,
|
'type' => 'post_data',
|
||||||
'name' => 'post_status',
|
'function' => null,
|
||||||
|
'name' => 'post_status',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
|
|
||||||
$this->assertEquals( 'wc-completed', $data->post_status );
|
$this->assertEquals( 'wc-completed', $data->post_status );
|
||||||
}
|
}
|
||||||
|
@ -139,15 +149,17 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case {
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
$report = new WC_Admin_Report();
|
$report = new WC_Admin_Report();
|
||||||
$data = $report->get_order_report_data( array(
|
$data = $report->get_order_report_data(
|
||||||
'data' => array(
|
array(
|
||||||
'order_item_name' => array(
|
'data' => array(
|
||||||
'type' => 'order_item',
|
'order_item_name' => array(
|
||||||
'function' => null,
|
'type' => 'order_item',
|
||||||
'name' => 'name',
|
'function' => null,
|
||||||
|
'name' => 'name',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
|
|
||||||
$this->assertEquals( $product->get_name(), $data->name );
|
$this->assertEquals( $product->get_name(), $data->name );
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,11 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->endpoint = new WC_REST_Coupons_Controller();
|
$this->endpoint = new WC_REST_Coupons_Controller();
|
||||||
$this->user = $this->factory->user->create( array(
|
$this->user = $this->factory->user->create(
|
||||||
'role' => 'administrator',
|
array(
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,51 +45,54 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
$coupon_2 = WC_Helper_Coupon::create_coupon( 'dummycoupon-2' );
|
$coupon_2 = WC_Helper_Coupon::create_coupon( 'dummycoupon-2' );
|
||||||
|
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons' ) );
|
||||||
$coupons = $response->get_data();
|
$coupons = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( 2, count( $coupons ) );
|
$this->assertEquals( 2, count( $coupons ) );
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => $coupon_1->get_id(),
|
array(
|
||||||
'code' => 'dummycoupon-1',
|
'id' => $coupon_1->get_id(),
|
||||||
'amount' => '1.00',
|
'code' => 'dummycoupon-1',
|
||||||
'date_created' => wc_rest_prepare_date_response( $post_1->post_date_gmt, false ),
|
'amount' => '1.00',
|
||||||
'date_created_gmt' => wc_rest_prepare_date_response( $post_1->post_date_gmt ),
|
'date_created' => wc_rest_prepare_date_response( $post_1->post_date_gmt, false ),
|
||||||
'date_modified' => wc_rest_prepare_date_response( $post_1->post_modified_gmt, false ),
|
'date_created_gmt' => wc_rest_prepare_date_response( $post_1->post_date_gmt ),
|
||||||
'date_modified_gmt' => wc_rest_prepare_date_response( $post_1->post_modified_gmt ),
|
'date_modified' => wc_rest_prepare_date_response( $post_1->post_modified_gmt, false ),
|
||||||
'discount_type' => 'fixed_cart',
|
'date_modified_gmt' => wc_rest_prepare_date_response( $post_1->post_modified_gmt ),
|
||||||
'description' => 'This is a dummy coupon',
|
'discount_type' => 'fixed_cart',
|
||||||
'date_expires' => '',
|
'description' => 'This is a dummy coupon',
|
||||||
'date_expires_gmt' => '',
|
'date_expires' => '',
|
||||||
'usage_count' => 0,
|
'date_expires_gmt' => '',
|
||||||
'individual_use' => false,
|
'usage_count' => 0,
|
||||||
'product_ids' => array(),
|
'individual_use' => false,
|
||||||
'excluded_product_ids' => array(),
|
'product_ids' => array(),
|
||||||
'usage_limit' => '',
|
'excluded_product_ids' => array(),
|
||||||
'usage_limit_per_user' => '',
|
'usage_limit' => '',
|
||||||
'limit_usage_to_x_items' => null,
|
'usage_limit_per_user' => '',
|
||||||
'free_shipping' => false,
|
'limit_usage_to_x_items' => null,
|
||||||
'product_categories' => array(),
|
'free_shipping' => false,
|
||||||
'excluded_product_categories' => array(),
|
'product_categories' => array(),
|
||||||
'exclude_sale_items' => false,
|
'excluded_product_categories' => array(),
|
||||||
'minimum_amount' => '0.00',
|
'exclude_sale_items' => false,
|
||||||
'maximum_amount' => '0.00',
|
'minimum_amount' => '0.00',
|
||||||
'email_restrictions' => array(),
|
'maximum_amount' => '0.00',
|
||||||
'used_by' => array(),
|
'email_restrictions' => array(),
|
||||||
'meta_data' => array(),
|
'used_by' => array(),
|
||||||
'_links' => array(
|
'meta_data' => array(),
|
||||||
'self' => array(
|
'_links' => array(
|
||||||
array(
|
'self' => array(
|
||||||
'href' => rest_url( '/wc/v3/coupons/' . $coupon_1->get_id() ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v3/coupons/' . $coupon_1->get_id() ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'collection' => array(
|
||||||
'collection' => array(
|
array(
|
||||||
array(
|
'href' => rest_url( '/wc/v3/coupons' ),
|
||||||
'href' => rest_url( '/wc/v3/coupons' ),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $coupons );
|
$coupons
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,35 +117,38 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => $coupon->get_id(),
|
array(
|
||||||
'code' => 'dummycoupon-1',
|
'id' => $coupon->get_id(),
|
||||||
'amount' => '1.00',
|
'code' => 'dummycoupon-1',
|
||||||
'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt, false ),
|
'amount' => '1.00',
|
||||||
'date_created_gmt' => wc_rest_prepare_date_response( $post->post_date_gmt ),
|
'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt, false ),
|
||||||
'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt, false ),
|
'date_created_gmt' => wc_rest_prepare_date_response( $post->post_date_gmt ),
|
||||||
'date_modified_gmt' => wc_rest_prepare_date_response( $post->post_modified_gmt ),
|
'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt, false ),
|
||||||
'discount_type' => 'fixed_cart',
|
'date_modified_gmt' => wc_rest_prepare_date_response( $post->post_modified_gmt ),
|
||||||
'description' => 'This is a dummy coupon',
|
'discount_type' => 'fixed_cart',
|
||||||
'date_expires' => null,
|
'description' => 'This is a dummy coupon',
|
||||||
'date_expires_gmt' => null,
|
'date_expires' => null,
|
||||||
'usage_count' => 0,
|
'date_expires_gmt' => null,
|
||||||
'individual_use' => false,
|
'usage_count' => 0,
|
||||||
'product_ids' => array(),
|
'individual_use' => false,
|
||||||
'excluded_product_ids' => array(),
|
'product_ids' => array(),
|
||||||
'usage_limit' => null,
|
'excluded_product_ids' => array(),
|
||||||
'usage_limit_per_user' => null,
|
'usage_limit' => null,
|
||||||
'limit_usage_to_x_items' => null,
|
'usage_limit_per_user' => null,
|
||||||
'free_shipping' => false,
|
'limit_usage_to_x_items' => null,
|
||||||
'product_categories' => array(),
|
'free_shipping' => false,
|
||||||
'excluded_product_categories' => array(),
|
'product_categories' => array(),
|
||||||
'exclude_sale_items' => false,
|
'excluded_product_categories' => array(),
|
||||||
'minimum_amount' => '0.00',
|
'exclude_sale_items' => false,
|
||||||
'maximum_amount' => '0.00',
|
'minimum_amount' => '0.00',
|
||||||
'email_restrictions' => array(),
|
'maximum_amount' => '0.00',
|
||||||
'used_by' => array(),
|
'email_restrictions' => array(),
|
||||||
'meta_data' => array(),
|
'used_by' => array(),
|
||||||
), $data );
|
'meta_data' => array(),
|
||||||
|
),
|
||||||
|
$data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,46 +179,51 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
public function test_create_coupon() {
|
public function test_create_coupon() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'code' => 'test',
|
array(
|
||||||
'amount' => '5.00',
|
'code' => 'test',
|
||||||
'discount_type' => 'fixed_product',
|
'amount' => '5.00',
|
||||||
'description' => 'Test',
|
'discount_type' => 'fixed_product',
|
||||||
'usage_limit' => 10,
|
'description' => 'Test',
|
||||||
) );
|
'usage_limit' => 10,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 201, $response->get_status() );
|
$this->assertEquals( 201, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => $data['id'],
|
array(
|
||||||
'code' => 'test',
|
'id' => $data['id'],
|
||||||
'amount' => '5.00',
|
'code' => 'test',
|
||||||
'date_created' => $data['date_created'],
|
'amount' => '5.00',
|
||||||
'date_created_gmt' => $data['date_created_gmt'],
|
'date_created' => $data['date_created'],
|
||||||
'date_modified' => $data['date_modified'],
|
'date_created_gmt' => $data['date_created_gmt'],
|
||||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
'date_modified' => $data['date_modified'],
|
||||||
'discount_type' => 'fixed_product',
|
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||||
'description' => 'Test',
|
'discount_type' => 'fixed_product',
|
||||||
'date_expires' => null,
|
'description' => 'Test',
|
||||||
'date_expires_gmt' => null,
|
'date_expires' => null,
|
||||||
'usage_count' => 0,
|
'date_expires_gmt' => null,
|
||||||
'individual_use' => false,
|
'usage_count' => 0,
|
||||||
'product_ids' => array(),
|
'individual_use' => false,
|
||||||
'excluded_product_ids' => array(),
|
'product_ids' => array(),
|
||||||
'usage_limit' => 10,
|
'excluded_product_ids' => array(),
|
||||||
'usage_limit_per_user' => null,
|
'usage_limit' => 10,
|
||||||
'limit_usage_to_x_items' => null,
|
'usage_limit_per_user' => null,
|
||||||
'free_shipping' => false,
|
'limit_usage_to_x_items' => null,
|
||||||
'product_categories' => array(),
|
'free_shipping' => false,
|
||||||
'excluded_product_categories' => array(),
|
'product_categories' => array(),
|
||||||
'exclude_sale_items' => false,
|
'excluded_product_categories' => array(),
|
||||||
'minimum_amount' => '0.00',
|
'exclude_sale_items' => false,
|
||||||
'maximum_amount' => '0.00',
|
'minimum_amount' => '0.00',
|
||||||
'email_restrictions' => array(),
|
'maximum_amount' => '0.00',
|
||||||
'used_by' => array(),
|
'email_restrictions' => array(),
|
||||||
'meta_data' => array(),
|
'used_by' => array(),
|
||||||
), $data );
|
'meta_data' => array(),
|
||||||
|
),
|
||||||
|
$data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -222,12 +235,14 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test no code...
|
// test no code...
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'amount' => '5.00',
|
array(
|
||||||
'discount_type' => 'fixed_product',
|
'amount' => '5.00',
|
||||||
) );
|
'discount_type' => 'fixed_product',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -241,13 +256,15 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test no code...
|
// test no code...
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'code' => 'fail',
|
array(
|
||||||
'amount' => '5.00',
|
'code' => 'fail',
|
||||||
'discount_type' => 'fixed_product',
|
'amount' => '5.00',
|
||||||
) );
|
'discount_type' => 'fixed_product',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -258,8 +275,8 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_update_coupon() {
|
public function test_update_coupon() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
||||||
$post = get_post( $coupon->get_id() );
|
$post = get_post( $coupon->get_id() );
|
||||||
|
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/' . $coupon->get_id() ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/' . $coupon->get_id() ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
@ -268,12 +285,14 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEquals( '1.00', $data['amount'] );
|
$this->assertEquals( '1.00', $data['amount'] );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'amount' => '10.00',
|
array(
|
||||||
'description' => 'New description',
|
'amount' => '10.00',
|
||||||
) );
|
'description' => 'New description',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( '10.00', $data['amount'] );
|
$this->assertEquals( '10.00', $data['amount'] );
|
||||||
$this->assertEquals( 'New description', $data['description'] );
|
$this->assertEquals( 'New description', $data['description'] );
|
||||||
|
@ -288,13 +307,15 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/0' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/0' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'code' => 'tester',
|
array(
|
||||||
'amount' => '10.00',
|
'code' => 'tester',
|
||||||
'description' => 'New description',
|
'amount' => '10.00',
|
||||||
) );
|
'description' => 'New description',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -305,14 +326,16 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_update_coupon_without_permission() {
|
public function test_update_coupon_without_permission() {
|
||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
||||||
$post = get_post( $coupon->get_id() );
|
$post = get_post( $coupon->get_id() );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'amount' => '10.00',
|
array(
|
||||||
'description' => 'New description',
|
'amount' => '10.00',
|
||||||
) );
|
'description' => 'New description',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
|
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
|
@ -324,7 +347,7 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_delete_coupon() {
|
public function test_delete_coupon() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
||||||
$request = new WP_REST_Request( 'DELETE', '/wc/v3/coupons/' . $coupon->get_id() );
|
$request = new WP_REST_Request( 'DELETE', '/wc/v3/coupons/' . $coupon->get_id() );
|
||||||
$request->set_param( 'force', true );
|
$request->set_param( 'force', true );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
|
@ -364,32 +387,34 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
public function test_batch_coupon() {
|
public function test_batch_coupon() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$coupon_1 = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
$coupon_1 = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
||||||
$coupon_2 = WC_Helper_Coupon::create_coupon( 'dummycoupon-2' );
|
$coupon_2 = WC_Helper_Coupon::create_coupon( 'dummycoupon-2' );
|
||||||
$coupon_3 = WC_Helper_Coupon::create_coupon( 'dummycoupon-3' );
|
$coupon_3 = WC_Helper_Coupon::create_coupon( 'dummycoupon-3' );
|
||||||
$coupon_4 = WC_Helper_Coupon::create_coupon( 'dummycoupon-4' );
|
$coupon_4 = WC_Helper_Coupon::create_coupon( 'dummycoupon-4' );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons/batch' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/coupons/batch' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'update' => array(
|
array(
|
||||||
array(
|
'update' => array(
|
||||||
'id' => $coupon_1->get_id(),
|
array(
|
||||||
'amount' => '5.15',
|
'id' => $coupon_1->get_id(),
|
||||||
|
'amount' => '5.15',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'delete' => array(
|
||||||
'delete' => array(
|
$coupon_2->get_id(),
|
||||||
$coupon_2->get_id(),
|
$coupon_3->get_id(),
|
||||||
$coupon_3->get_id(),
|
|
||||||
),
|
|
||||||
'create' => array(
|
|
||||||
array(
|
|
||||||
'code' => 'new-coupon',
|
|
||||||
'amount' => '11.00',
|
|
||||||
),
|
),
|
||||||
),
|
'create' => array(
|
||||||
) );
|
array(
|
||||||
|
'code' => 'new-coupon',
|
||||||
|
'amount' => '11.00',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( '5.15', $data['update'][0]['amount'] );
|
$this->assertEquals( '5.15', $data['update'][0]['amount'] );
|
||||||
$this->assertEquals( '11.00', $data['create'][0]['amount'] );
|
$this->assertEquals( '11.00', $data['create'][0]['amount'] );
|
||||||
|
@ -397,9 +422,9 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEquals( $coupon_2->get_id(), $data['delete'][0]['id'] );
|
$this->assertEquals( $coupon_2->get_id(), $data['delete'][0]['id'] );
|
||||||
$this->assertEquals( $coupon_3->get_id(), $data['delete'][1]['id'] );
|
$this->assertEquals( $coupon_3->get_id(), $data['delete'][1]['id'] );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'GET', '/wc/v3/coupons' );
|
$request = new WP_REST_Request( 'GET', '/wc/v3/coupons' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 3, count( $data ) );
|
$this->assertEquals( 3, count( $data ) );
|
||||||
}
|
}
|
||||||
|
@ -410,9 +435,9 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_coupon_schema() {
|
public function test_coupon_schema() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/coupons' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/coupons' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
|
|
||||||
$this->assertEquals( 27, count( $properties ) );
|
$this->assertEquals( 27, count( $properties ) );
|
||||||
|
|
|
@ -14,9 +14,11 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->endpoint = new WC_REST_Payment_Gateways_Controller();
|
$this->endpoint = new WC_REST_Payment_Gateways_Controller();
|
||||||
$this->user = $this->factory->user->create( array(
|
$this->user = $this->factory->user->create(
|
||||||
'role' => 'administrator',
|
array(
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,34 +44,40 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
$gateways = $response->get_data();
|
$gateways = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'cheque',
|
array(
|
||||||
'title' => 'Check payments',
|
'id' => 'cheque',
|
||||||
'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.',
|
'title' => 'Check payments',
|
||||||
'order' => '',
|
'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.',
|
||||||
'enabled' => false,
|
'order' => '',
|
||||||
'method_title' => 'Check payments',
|
'enabled' => false,
|
||||||
'method_description' => 'Take payments in person via checks. This offline gateway can also be useful to test purchases.',
|
'method_title' => 'Check payments',
|
||||||
'method_supports' => array(
|
'method_description' => 'Take payments in person via checks. This offline gateway can also be useful to test purchases.',
|
||||||
'products',
|
'method_supports' => array(
|
||||||
),
|
'products',
|
||||||
'settings' => array_diff_key( $this->get_settings( 'WC_Gateway_Cheque' ), array(
|
|
||||||
'enabled' => false,
|
|
||||||
'description' => false,
|
|
||||||
) ),
|
|
||||||
'_links' => array(
|
|
||||||
'self' => array(
|
|
||||||
array(
|
|
||||||
'href' => rest_url( '/wc/v3/payment_gateways/cheque' ),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'collection' => array(
|
'settings' => array_diff_key(
|
||||||
|
$this->get_settings( 'WC_Gateway_Cheque' ),
|
||||||
array(
|
array(
|
||||||
'href' => rest_url( '/wc/v3/payment_gateways' ),
|
'enabled' => false,
|
||||||
|
'description' => false,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'_links' => array(
|
||||||
|
'self' => array(
|
||||||
|
array(
|
||||||
|
'href' => rest_url( '/wc/v3/payment_gateways/cheque' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'collection' => array(
|
||||||
|
array(
|
||||||
|
'href' => rest_url( '/wc/v3/payment_gateways' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $gateways );
|
$gateways
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,23 +103,29 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => 'paypal',
|
array(
|
||||||
'title' => 'PayPal',
|
'id' => 'paypal',
|
||||||
'description' => "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.",
|
'title' => 'PayPal',
|
||||||
'order' => '',
|
'description' => "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.",
|
||||||
'enabled' => false,
|
'order' => '',
|
||||||
'method_title' => 'PayPal',
|
'enabled' => false,
|
||||||
'method_description' => 'PayPal Standard redirects customers to PayPal to enter their payment information.',
|
'method_title' => 'PayPal',
|
||||||
'method_supports' => array(
|
'method_description' => 'PayPal Standard redirects customers to PayPal to enter their payment information.',
|
||||||
'products',
|
'method_supports' => array(
|
||||||
'refunds',
|
'products',
|
||||||
|
'refunds',
|
||||||
|
),
|
||||||
|
'settings' => array_diff_key(
|
||||||
|
$this->get_settings( 'WC_Gateway_Paypal' ),
|
||||||
|
array(
|
||||||
|
'enabled' => false,
|
||||||
|
'description' => false,
|
||||||
|
)
|
||||||
|
),
|
||||||
),
|
),
|
||||||
'settings' => array_diff_key( $this->get_settings( 'WC_Gateway_Paypal' ), array(
|
$paypal
|
||||||
'enabled' => false,
|
);
|
||||||
'description' => false,
|
|
||||||
) ),
|
|
||||||
), $paypal );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,11 +168,13 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test updating single setting
|
// test updating single setting
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'email' => 'woo@woo.local',
|
'settings' => array(
|
||||||
),
|
'email' => 'woo@woo.local',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
|
|
||||||
|
@ -169,12 +185,14 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test updating multiple settings
|
// test updating multiple settings
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'testmode' => 'yes',
|
'settings' => array(
|
||||||
'title' => 'PayPal - New Title',
|
'testmode' => 'yes',
|
||||||
),
|
'title' => 'PayPal - New Title',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
|
|
||||||
|
@ -185,10 +203,12 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// Test other parameters, and recheck settings
|
// Test other parameters, and recheck settings
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'enabled' => false,
|
array(
|
||||||
'order' => 2,
|
'enabled' => false,
|
||||||
) );
|
'order' => 2,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
|
|
||||||
|
@ -200,20 +220,24 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test bogus
|
// test bogus
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'paymentaction' => 'afasfasf',
|
'settings' => array(
|
||||||
),
|
'paymentaction' => 'afasfasf',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'paymentaction' => 'authorization',
|
'settings' => array(
|
||||||
),
|
'paymentaction' => 'authorization',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
$this->assertEquals( 'authorization', $paypal['settings']['paymentaction']['value'] );
|
$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() {
|
public function test_update_payment_gateway_without_permission() {
|
||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'testmode' => 'yes',
|
'settings' => array(
|
||||||
'title' => 'PayPal - New Title',
|
'testmode' => 'yes',
|
||||||
),
|
'title' => 'PayPal - New Title',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -244,10 +270,12 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_update_payment_gateway_invalid_id() {
|
public function test_update_payment_gateway_invalid_id() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/totally_fake_method' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/totally_fake_method' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'enabled' => true,
|
array(
|
||||||
) );
|
'enabled' => true,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 404, $response->get_status() );
|
$this->assertEquals( 404, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -260,9 +288,9 @@ class Payment_Gateways extends WC_REST_Unit_Test_Case {
|
||||||
public function test_payment_gateway_schema() {
|
public function test_payment_gateway_schema() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/payment_gateways' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/payment_gateways' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
|
|
||||||
$this->assertEquals( 9, count( $properties ) );
|
$this->assertEquals( 9, count( $properties ) );
|
||||||
|
|
|
@ -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,
|
'rating' => 0,
|
||||||
'verified' => false,
|
'verified' => false,
|
||||||
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
|
'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,
|
'rating' => 5,
|
||||||
'verified' => false,
|
'verified' => false,
|
||||||
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
|
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
|
||||||
), $data
|
),
|
||||||
|
$data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,8 @@ class WC_Tests_API_Reports_Coupons_Totals extends WC_REST_Unit_Test_Case {
|
||||||
FROM $wpdb->postmeta
|
FROM $wpdb->postmeta
|
||||||
WHERE meta_key = 'discount_type'
|
WHERE meta_key = 'discount_type'
|
||||||
AND meta_value = %s
|
AND meta_value = %s
|
||||||
", $slug
|
",
|
||||||
|
$slug
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,11 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->endpoint = new WC_REST_Setting_Options_Controller();
|
$this->endpoint = new WC_REST_Setting_Options_Controller();
|
||||||
WC_Helper_Settings::register();
|
WC_Helper_Settings::register();
|
||||||
$this->user = $this->factory->user->create( array(
|
$this->user = $this->factory->user->create(
|
||||||
'role' => 'administrator',
|
array(
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,39 +43,45 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'test',
|
array(
|
||||||
'label' => 'Test extension',
|
'id' => 'test',
|
||||||
'parent_id' => '',
|
'label' => 'Test extension',
|
||||||
'description' => 'My awesome test settings.',
|
'parent_id' => '',
|
||||||
'sub_groups' => array( 'sub-test' ),
|
'description' => 'My awesome test settings.',
|
||||||
'_links' => array(
|
'sub_groups' => array( 'sub-test' ),
|
||||||
'options' => array(
|
'_links' => array(
|
||||||
array(
|
'options' => array(
|
||||||
'href' => rest_url( '/wc/v3/settings/test' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v3/settings/test' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $data );
|
$data
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'sub-test',
|
array(
|
||||||
'label' => 'Sub test',
|
'id' => 'sub-test',
|
||||||
'parent_id' => 'test',
|
'label' => 'Sub test',
|
||||||
'description' => '',
|
'parent_id' => 'test',
|
||||||
'sub_groups' => array(),
|
'description' => '',
|
||||||
'_links' => array(
|
'sub_groups' => array(),
|
||||||
'options' => array(
|
'_links' => array(
|
||||||
array(
|
'options' => array(
|
||||||
'href' => rest_url( '/wc/v3/settings/sub-test' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v3/settings/sub-test' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $data );
|
$data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,9 +119,9 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
public function test_get_group_schema() {
|
public function test_get_group_schema() {
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/settings' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/settings' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
$this->assertEquals( 5, count( $properties ) );
|
$this->assertEquals( 5, count( $properties ) );
|
||||||
$this->assertArrayHasKey( 'id', $properties );
|
$this->assertArrayHasKey( 'id', $properties );
|
||||||
|
@ -129,9 +137,9 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
public function test_get_setting_schema() {
|
public function test_get_setting_schema() {
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/settings/test/woocommerce_shop_page_display' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/settings/test/woocommerce_shop_page_display' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
$this->assertEquals( 10, count( $properties ) );
|
$this->assertEquals( 10, count( $properties ) );
|
||||||
$this->assertArrayHasKey( 'id', $properties );
|
$this->assertArrayHasKey( 'id', $properties );
|
||||||
|
@ -168,7 +176,7 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test getting a valid group with settings attached to it
|
// test getting a valid group with settings attached to it
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( 1, count( $data ) );
|
$this->assertEquals( 1, count( $data ) );
|
||||||
$this->assertEquals( 'woocommerce_shop_page_display', $data[0]['id'] );
|
$this->assertEquals( 'woocommerce_shop_page_display', $data[0]['id'] );
|
||||||
$this->assertEmpty( $data[0]['value'] );
|
$this->assertEmpty( $data[0]['value'] );
|
||||||
|
@ -196,36 +204,42 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test defaults first
|
// test defaults first
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( '', $data['value'] );
|
$this->assertEquals( '', $data['value'] );
|
||||||
|
|
||||||
// test updating shop display setting
|
// test updating shop display setting
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', '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(
|
||||||
'value' => 'both',
|
array(
|
||||||
) );
|
'value' => 'both',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'both', $data['value'] );
|
$this->assertEquals( 'both', $data['value'] );
|
||||||
$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
|
$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 = 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(
|
||||||
'value' => 'subcategories',
|
array(
|
||||||
) );
|
'value' => 'subcategories',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'subcategories', $data['value'] );
|
$this->assertEquals( 'subcategories', $data['value'] );
|
||||||
$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
|
$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 = 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(
|
||||||
'value' => '',
|
array(
|
||||||
) );
|
'value' => '',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( '', $data['value'] );
|
$this->assertEquals( '', $data['value'] );
|
||||||
$this->assertEquals( '', get_option( 'woocommerce_shop_page_display' ) );
|
$this->assertEquals( '', get_option( 'woocommerce_shop_page_display' ) );
|
||||||
|
@ -241,37 +255,41 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test defaults first
|
// test defaults first
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( '', $data[0]['value'] );
|
$this->assertEquals( '', $data[0]['value'] );
|
||||||
|
|
||||||
// test setting both at once
|
// test setting both at once
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'update' => array(
|
array(
|
||||||
array(
|
'update' => array(
|
||||||
'id' => 'woocommerce_shop_page_display',
|
array(
|
||||||
'value' => 'both',
|
'id' => 'woocommerce_shop_page_display',
|
||||||
|
'value' => 'both',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'both', $data['update'][0]['value'] );
|
$this->assertEquals( 'both', $data['update'][0]['value'] );
|
||||||
$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
|
$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
|
||||||
|
|
||||||
// test updating one, but making sure the other value stays the same
|
// test updating one, but making sure the other value stays the same
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'update' => array(
|
array(
|
||||||
array(
|
'update' => array(
|
||||||
'id' => 'woocommerce_shop_page_display',
|
array(
|
||||||
'value' => 'subcategories',
|
'id' => 'woocommerce_shop_page_display',
|
||||||
|
'value' => 'subcategories',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( 'subcategories', $data['update'][0]['value'] );
|
$this->assertEquals( 'subcategories', $data['update'][0]['value'] );
|
||||||
$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
|
$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
|
||||||
}
|
}
|
||||||
|
@ -286,17 +304,17 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test getting an invalid setting from a group that does not exist
|
// test getting an invalid setting from a group that does not exist
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/not-real/woocommerce_shop_page_display' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/not-real/woocommerce_shop_page_display' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( 404, $response->get_status() );
|
$this->assertEquals( 404, $response->get_status() );
|
||||||
|
|
||||||
// test getting an invalid setting from a group that does exist
|
// test getting an invalid setting from a group that does exist
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/invalid/invalid' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/invalid/invalid' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( 404, $response->get_status() );
|
$this->assertEquals( 404, $response->get_status() );
|
||||||
|
|
||||||
// test getting a valid setting
|
// test getting a valid setting
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
|
@ -374,9 +392,11 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', '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(
|
||||||
'value' => 'subcategories',
|
array(
|
||||||
) );
|
'value' => 'subcategories',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -391,14 +411,16 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' );
|
$request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'update' => array(
|
array(
|
||||||
array(
|
'update' => array(
|
||||||
'id' => 'woocommerce_shop_page_display',
|
array(
|
||||||
'value' => 'subcategories',
|
'id' => 'woocommerce_shop_page_display',
|
||||||
|
'value' => 'subcategories',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -413,9 +435,11 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/test/invalid' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/test/invalid' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => 'test',
|
array(
|
||||||
) );
|
'value' => 'test',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 404, $response->get_status() );
|
$this->assertEquals( 404, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -430,43 +454,48 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// Make sure the group is properly registered
|
// Make sure the group is properly registered
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertTrue( is_array( $data ) );
|
$this->assertTrue( is_array( $data ) );
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'woocommerce_downloads_require_login',
|
array(
|
||||||
'label' => 'Access restriction',
|
'id' => 'woocommerce_downloads_require_login',
|
||||||
'description' => 'Downloads require login',
|
'label' => 'Access restriction',
|
||||||
'type' => 'checkbox',
|
'description' => 'Downloads require login',
|
||||||
'default' => 'no',
|
'type' => 'checkbox',
|
||||||
'tip' => 'This setting does not apply to guest purchases.',
|
'default' => 'no',
|
||||||
'value' => 'no',
|
'tip' => 'This setting does not apply to guest purchases.',
|
||||||
'_links' => array(
|
'value' => 'no',
|
||||||
'self' => array(
|
'_links' => array(
|
||||||
array(
|
'self' => array(
|
||||||
'href' => rest_url( '/wc/v3/settings/products/woocommerce_downloads_require_login' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v3/settings/products/woocommerce_downloads_require_login' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'collection' => array(
|
||||||
'collection' => array(
|
array(
|
||||||
array(
|
'href' => rest_url( '/wc/v3/settings/products' ),
|
||||||
'href' => rest_url( '/wc/v3/settings/products' ),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $data );
|
$data
|
||||||
|
);
|
||||||
|
|
||||||
// test get single
|
// test get single
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products/woocommerce_dimension_unit' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products/woocommerce_dimension_unit' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'cm', $data['default'] );
|
$this->assertEquals( 'cm', $data['default'] );
|
||||||
|
|
||||||
// test update
|
// test update
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_dimension_unit' ) );
|
$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(
|
||||||
'value' => 'yd',
|
array(
|
||||||
) );
|
'value' => 'yd',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'yd', $data['value'] );
|
$this->assertEquals( 'yd', $data['value'] );
|
||||||
$this->assertEquals( 'yd', get_option( 'woocommerce_dimension_unit' ) );
|
$this->assertEquals( 'yd', get_option( 'woocommerce_dimension_unit' ) );
|
||||||
|
@ -485,64 +514,75 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'recipient',
|
array(
|
||||||
'label' => 'Recipient(s)',
|
'id' => 'recipient',
|
||||||
'description' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
|
'label' => 'Recipient(s)',
|
||||||
'type' => 'text',
|
'description' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
|
||||||
'default' => '',
|
'type' => 'text',
|
||||||
'tip' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
|
'default' => '',
|
||||||
'value' => '',
|
'tip' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
|
||||||
'_links' => array(
|
'value' => '',
|
||||||
'self' => array(
|
'_links' => array(
|
||||||
array(
|
'self' => array(
|
||||||
'href' => rest_url( '/wc/v3/settings/email_new_order/recipient' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v3/settings/email_new_order/recipient' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'collection' => array(
|
||||||
'collection' => array(
|
array(
|
||||||
array(
|
'href' => rest_url( '/wc/v3/settings/email_new_order' ),
|
||||||
'href' => rest_url( '/wc/v3/settings/email_new_order' ),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $settings );
|
$settings
|
||||||
|
);
|
||||||
|
|
||||||
// test get single
|
// test get single
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order/subject' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order/subject' ) );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => 'subject',
|
array(
|
||||||
'label' => 'Subject',
|
'id' => 'subject',
|
||||||
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
'label' => 'Subject',
|
||||||
'type' => 'text',
|
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
||||||
'default' => '',
|
'type' => 'text',
|
||||||
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
'default' => '',
|
||||||
'value' => '',
|
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
||||||
'group_id' => 'email_new_order',
|
'value' => '',
|
||||||
), $setting );
|
'group_id' => 'email_new_order',
|
||||||
|
),
|
||||||
|
$setting
|
||||||
|
);
|
||||||
|
|
||||||
// test update
|
// test update
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_new_order', 'subject' ) );
|
$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(
|
||||||
'value' => 'This is my subject',
|
array(
|
||||||
) );
|
'value' => 'This is my subject',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => 'subject',
|
array(
|
||||||
'label' => 'Subject',
|
'id' => 'subject',
|
||||||
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
'label' => 'Subject',
|
||||||
'type' => 'text',
|
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
||||||
'default' => '',
|
'type' => 'text',
|
||||||
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
'default' => '',
|
||||||
'value' => 'This is my subject',
|
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
||||||
'group_id' => 'email_new_order',
|
'value' => 'This is my subject',
|
||||||
), $setting );
|
'group_id' => 'email_new_order',
|
||||||
|
),
|
||||||
|
$setting
|
||||||
|
);
|
||||||
|
|
||||||
// test updating another subject and making sure it works with a "similar" id
|
// 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' ) );
|
$request = new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
|
|
||||||
|
@ -550,9 +590,11 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test update
|
// test update
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
|
$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(
|
||||||
'value' => 'This is my new subject',
|
array(
|
||||||
) );
|
'value' => 'This is my new subject',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
|
|
||||||
|
@ -575,25 +617,31 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test bogus value
|
// test bogus value
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
|
$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(
|
||||||
'value' => 'not_yes_or_no',
|
array(
|
||||||
) );
|
'value' => 'not_yes_or_no',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
|
||||||
// test yes
|
// test yes
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
|
$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(
|
||||||
'value' => 'yes',
|
array(
|
||||||
) );
|
'value' => 'yes',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
// test no
|
// test no
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
|
$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(
|
||||||
'value' => 'no',
|
array(
|
||||||
) );
|
'value' => 'no',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -608,17 +656,21 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// not a valid option
|
// not a valid option
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
|
$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(
|
||||||
'value' => 'billing2',
|
array(
|
||||||
) );
|
'value' => 'billing2',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
|
||||||
// valid
|
// valid
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
|
$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(
|
||||||
'value' => 'billing',
|
array(
|
||||||
) );
|
'value' => 'billing',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -636,9 +688,11 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEmpty( $setting['value'] );
|
$this->assertEmpty( $setting['value'] );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) );
|
$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(
|
||||||
'value' => array( 'AX', 'DZ', 'MMM' ),
|
array(
|
||||||
) );
|
'value' => array( 'AX', 'DZ', 'MMM' ),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] );
|
$this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] );
|
||||||
|
@ -658,17 +712,21 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// invalid
|
// invalid
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
|
$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(
|
||||||
'value' => 'pounds', // invalid, should be lbs
|
array(
|
||||||
) );
|
'value' => 'pounds', // invalid, should be lbs
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
|
||||||
// valid
|
// valid
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
|
$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(
|
||||||
'value' => 'lbs', // invalid, should be lbs
|
array(
|
||||||
) );
|
'value' => 'lbs', // invalid, should be lbs
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( 'lbs', $setting['value'] );
|
$this->assertEquals( 'lbs', $setting['value'] );
|
||||||
|
@ -705,19 +763,23 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
// Repalce the old value with something uniquely new
|
// Repalce the old value with something uniquely new
|
||||||
$old_value = $setting['value'];
|
$old_value = $setting['value'];
|
||||||
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $new_value,
|
array(
|
||||||
) );
|
'value' => $new_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $new_value, $setting['value'] );
|
$this->assertEquals( $new_value, $setting['value'] );
|
||||||
|
|
||||||
// Put the original value back
|
// Put the original value back
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $old_value,
|
array(
|
||||||
) );
|
'value' => $old_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $old_value, $setting['value'] );
|
$this->assertEquals( $old_value, $setting['value'] );
|
||||||
|
@ -737,19 +799,23 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
// Repalce the old value with something uniquely new
|
// Repalce the old value with something uniquely new
|
||||||
$old_value = $setting['value'];
|
$old_value = $setting['value'];
|
||||||
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $new_value,
|
array(
|
||||||
) );
|
'value' => $new_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $new_value, $setting['value'] );
|
$this->assertEquals( $new_value, $setting['value'] );
|
||||||
|
|
||||||
// Put the original value back
|
// Put the original value back
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $old_value,
|
array(
|
||||||
) );
|
'value' => $old_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $old_value, $setting['value'] );
|
$this->assertEquals( $old_value, $setting['value'] );
|
||||||
|
@ -769,19 +835,23 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
// Repalce the old value with something uniquely new
|
// Repalce the old value with something uniquely new
|
||||||
$old_value = $setting['value'];
|
$old_value = $setting['value'];
|
||||||
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $new_value,
|
array(
|
||||||
) );
|
'value' => $new_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $new_value, $setting['value'] );
|
$this->assertEquals( $new_value, $setting['value'] );
|
||||||
|
|
||||||
// Put the original value back
|
// Put the original value back
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $old_value,
|
array(
|
||||||
) );
|
'value' => $old_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $old_value, $setting['value'] );
|
$this->assertEquals( $old_value, $setting['value'] );
|
||||||
|
@ -801,19 +871,23 @@ class Settings extends WC_REST_Unit_Test_Case {
|
||||||
// Repalce the old value with something uniquely new
|
// Repalce the old value with something uniquely new
|
||||||
$old_value = $setting['value'];
|
$old_value = $setting['value'];
|
||||||
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $new_value,
|
array(
|
||||||
) );
|
'value' => $new_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $new_value, $setting['value'] );
|
$this->assertEquals( $new_value, $setting['value'] );
|
||||||
|
|
||||||
// Put the original value back
|
// Put the original value back
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $old_value,
|
array(
|
||||||
) );
|
'value' => $old_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $old_value, $setting['value'] );
|
$this->assertEquals( $old_value, $setting['value'] );
|
||||||
|
|
|
@ -14,9 +14,11 @@ class Shipping_Methods extends WC_REST_Unit_Test_Case {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->endpoint = new WC_REST_Shipping_Methods_Controller();
|
$this->endpoint = new WC_REST_Shipping_Methods_Controller();
|
||||||
$this->user = $this->factory->user->create( array(
|
$this->user = $this->factory->user->create(
|
||||||
'role' => 'administrator',
|
array(
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,26 +41,29 @@ class Shipping_Methods extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods' ) );
|
||||||
$methods = $response->get_data();
|
$methods = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'free_shipping',
|
array(
|
||||||
'title' => 'Free shipping',
|
'id' => 'free_shipping',
|
||||||
'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.',
|
'title' => 'Free shipping',
|
||||||
'_links' => array(
|
'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.',
|
||||||
'self' => array(
|
'_links' => array(
|
||||||
array(
|
'self' => array(
|
||||||
'href' => rest_url( '/wc/v3/shipping_methods/free_shipping' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v3/shipping_methods/free_shipping' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'collection' => array(
|
||||||
'collection' => array(
|
array(
|
||||||
array(
|
'href' => rest_url( '/wc/v3/shipping_methods' ),
|
||||||
'href' => rest_url( '/wc/v3/shipping_methods' ),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $methods );
|
$methods
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,11 +89,14 @@ class Shipping_Methods extends WC_REST_Unit_Test_Case {
|
||||||
$method = $response->get_data();
|
$method = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => 'local_pickup',
|
array(
|
||||||
'title' => 'Local pickup',
|
'id' => '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.',
|
'title' => 'Local pickup',
|
||||||
), $method );
|
'description' => 'Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.',
|
||||||
|
),
|
||||||
|
$method
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,9 +130,9 @@ class Shipping_Methods extends WC_REST_Unit_Test_Case {
|
||||||
public function test_shipping_method_schema() {
|
public function test_shipping_method_schema() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/shipping_methods' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v3/shipping_methods' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
|
|
||||||
$this->assertEquals( 3, count( $properties ) );
|
$this->assertEquals( 3, count( $properties ) );
|
||||||
|
|
|
@ -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
|
// 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
|
// Create a zone
|
||||||
$zone = $this->create_shipping_zone(
|
$zone = $this->create_shipping_zone(
|
||||||
'Zone 1', 0, array(
|
'Zone 1',
|
||||||
|
0,
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'code' => 'US',
|
'code' => 'US',
|
||||||
'type' => 'country',
|
'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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,14 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
* Setup test coupon data.
|
* Setup test coupon data.
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->endpoint = new WC_REST_Coupons_Controller();
|
$this->endpoint = new WC_REST_Coupons_Controller();
|
||||||
$this->user = $this->factory->user->create( array(
|
$this->user = $this->factory->user->create(
|
||||||
'role' => 'administrator',
|
array(
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,51 +45,54 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$coupon_2 = WC_Helper_Coupon::create_coupon( 'dummycoupon-2' );
|
$coupon_2 = WC_Helper_Coupon::create_coupon( 'dummycoupon-2' );
|
||||||
|
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons' ) );
|
||||||
$coupons = $response->get_data();
|
$coupons = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( 2, count( $coupons ) );
|
$this->assertEquals( 2, count( $coupons ) );
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => $coupon_1->get_id(),
|
array(
|
||||||
'code' => 'dummycoupon-1',
|
'id' => $coupon_1->get_id(),
|
||||||
'amount' => '1.00',
|
'code' => 'dummycoupon-1',
|
||||||
'date_created' => wc_rest_prepare_date_response( $post_1->post_date_gmt, false ),
|
'amount' => '1.00',
|
||||||
'date_created_gmt' => wc_rest_prepare_date_response( $post_1->post_date_gmt ),
|
'date_created' => wc_rest_prepare_date_response( $post_1->post_date_gmt, false ),
|
||||||
'date_modified' => wc_rest_prepare_date_response( $post_1->post_modified_gmt, false ),
|
'date_created_gmt' => wc_rest_prepare_date_response( $post_1->post_date_gmt ),
|
||||||
'date_modified_gmt' => wc_rest_prepare_date_response( $post_1->post_modified_gmt ),
|
'date_modified' => wc_rest_prepare_date_response( $post_1->post_modified_gmt, false ),
|
||||||
'discount_type' => 'fixed_cart',
|
'date_modified_gmt' => wc_rest_prepare_date_response( $post_1->post_modified_gmt ),
|
||||||
'description' => 'This is a dummy coupon',
|
'discount_type' => 'fixed_cart',
|
||||||
'date_expires' => '',
|
'description' => 'This is a dummy coupon',
|
||||||
'date_expires_gmt' => '',
|
'date_expires' => '',
|
||||||
'usage_count' => 0,
|
'date_expires_gmt' => '',
|
||||||
'individual_use' => false,
|
'usage_count' => 0,
|
||||||
'product_ids' => array(),
|
'individual_use' => false,
|
||||||
'excluded_product_ids' => array(),
|
'product_ids' => array(),
|
||||||
'usage_limit' => '',
|
'excluded_product_ids' => array(),
|
||||||
'usage_limit_per_user' => '',
|
'usage_limit' => '',
|
||||||
'limit_usage_to_x_items' => null,
|
'usage_limit_per_user' => '',
|
||||||
'free_shipping' => false,
|
'limit_usage_to_x_items' => null,
|
||||||
'product_categories' => array(),
|
'free_shipping' => false,
|
||||||
'excluded_product_categories' => array(),
|
'product_categories' => array(),
|
||||||
'exclude_sale_items' => false,
|
'excluded_product_categories' => array(),
|
||||||
'minimum_amount' => '0.00',
|
'exclude_sale_items' => false,
|
||||||
'maximum_amount' => '0.00',
|
'minimum_amount' => '0.00',
|
||||||
'email_restrictions' => array(),
|
'maximum_amount' => '0.00',
|
||||||
'used_by' => array(),
|
'email_restrictions' => array(),
|
||||||
'meta_data' => array(),
|
'used_by' => array(),
|
||||||
'_links' => array(
|
'meta_data' => array(),
|
||||||
'self' => array(
|
'_links' => array(
|
||||||
array(
|
'self' => array(
|
||||||
'href' => rest_url( '/wc/v2/coupons/' . $coupon_1->get_id() ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/coupons/' . $coupon_1->get_id() ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'collection' => array(
|
||||||
'collection' => array(
|
array(
|
||||||
array(
|
'href' => rest_url( '/wc/v2/coupons' ),
|
||||||
'href' => rest_url( '/wc/v2/coupons' ),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $coupons );
|
$coupons
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,35 +117,38 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => $coupon->get_id(),
|
array(
|
||||||
'code' => 'dummycoupon-1',
|
'id' => $coupon->get_id(),
|
||||||
'amount' => '1.00',
|
'code' => 'dummycoupon-1',
|
||||||
'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt, false ),
|
'amount' => '1.00',
|
||||||
'date_created_gmt' => wc_rest_prepare_date_response( $post->post_date_gmt ),
|
'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt, false ),
|
||||||
'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt, false ),
|
'date_created_gmt' => wc_rest_prepare_date_response( $post->post_date_gmt ),
|
||||||
'date_modified_gmt' => wc_rest_prepare_date_response( $post->post_modified_gmt ),
|
'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt, false ),
|
||||||
'discount_type' => 'fixed_cart',
|
'date_modified_gmt' => wc_rest_prepare_date_response( $post->post_modified_gmt ),
|
||||||
'description' => 'This is a dummy coupon',
|
'discount_type' => 'fixed_cart',
|
||||||
'date_expires' => null,
|
'description' => 'This is a dummy coupon',
|
||||||
'date_expires_gmt' => null,
|
'date_expires' => null,
|
||||||
'usage_count' => 0,
|
'date_expires_gmt' => null,
|
||||||
'individual_use' => false,
|
'usage_count' => 0,
|
||||||
'product_ids' => array(),
|
'individual_use' => false,
|
||||||
'excluded_product_ids' => array(),
|
'product_ids' => array(),
|
||||||
'usage_limit' => null,
|
'excluded_product_ids' => array(),
|
||||||
'usage_limit_per_user' => null,
|
'usage_limit' => null,
|
||||||
'limit_usage_to_x_items' => null,
|
'usage_limit_per_user' => null,
|
||||||
'free_shipping' => false,
|
'limit_usage_to_x_items' => null,
|
||||||
'product_categories' => array(),
|
'free_shipping' => false,
|
||||||
'excluded_product_categories' => array(),
|
'product_categories' => array(),
|
||||||
'exclude_sale_items' => false,
|
'excluded_product_categories' => array(),
|
||||||
'minimum_amount' => '0.00',
|
'exclude_sale_items' => false,
|
||||||
'maximum_amount' => '0.00',
|
'minimum_amount' => '0.00',
|
||||||
'email_restrictions' => array(),
|
'maximum_amount' => '0.00',
|
||||||
'used_by' => array(),
|
'email_restrictions' => array(),
|
||||||
'meta_data' => array(),
|
'used_by' => array(),
|
||||||
), $data );
|
'meta_data' => array(),
|
||||||
|
),
|
||||||
|
$data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,46 +179,51 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
public function test_create_coupon() {
|
public function test_create_coupon() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'code' => 'test',
|
array(
|
||||||
'amount' => '5.00',
|
'code' => 'test',
|
||||||
'discount_type' => 'fixed_product',
|
'amount' => '5.00',
|
||||||
'description' => 'Test',
|
'discount_type' => 'fixed_product',
|
||||||
'usage_limit' => 10,
|
'description' => 'Test',
|
||||||
) );
|
'usage_limit' => 10,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 201, $response->get_status() );
|
$this->assertEquals( 201, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => $data['id'],
|
array(
|
||||||
'code' => 'test',
|
'id' => $data['id'],
|
||||||
'amount' => '5.00',
|
'code' => 'test',
|
||||||
'date_created' => $data['date_created'],
|
'amount' => '5.00',
|
||||||
'date_created_gmt' => $data['date_created_gmt'],
|
'date_created' => $data['date_created'],
|
||||||
'date_modified' => $data['date_modified'],
|
'date_created_gmt' => $data['date_created_gmt'],
|
||||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
'date_modified' => $data['date_modified'],
|
||||||
'discount_type' => 'fixed_product',
|
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||||
'description' => 'Test',
|
'discount_type' => 'fixed_product',
|
||||||
'date_expires' => null,
|
'description' => 'Test',
|
||||||
'date_expires_gmt' => null,
|
'date_expires' => null,
|
||||||
'usage_count' => 0,
|
'date_expires_gmt' => null,
|
||||||
'individual_use' => false,
|
'usage_count' => 0,
|
||||||
'product_ids' => array(),
|
'individual_use' => false,
|
||||||
'excluded_product_ids' => array(),
|
'product_ids' => array(),
|
||||||
'usage_limit' => 10,
|
'excluded_product_ids' => array(),
|
||||||
'usage_limit_per_user' => null,
|
'usage_limit' => 10,
|
||||||
'limit_usage_to_x_items' => null,
|
'usage_limit_per_user' => null,
|
||||||
'free_shipping' => false,
|
'limit_usage_to_x_items' => null,
|
||||||
'product_categories' => array(),
|
'free_shipping' => false,
|
||||||
'excluded_product_categories' => array(),
|
'product_categories' => array(),
|
||||||
'exclude_sale_items' => false,
|
'excluded_product_categories' => array(),
|
||||||
'minimum_amount' => '0.00',
|
'exclude_sale_items' => false,
|
||||||
'maximum_amount' => '0.00',
|
'minimum_amount' => '0.00',
|
||||||
'email_restrictions' => array(),
|
'maximum_amount' => '0.00',
|
||||||
'used_by' => array(),
|
'email_restrictions' => array(),
|
||||||
'meta_data' => array(),
|
'used_by' => array(),
|
||||||
), $data );
|
'meta_data' => array(),
|
||||||
|
),
|
||||||
|
$data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -222,12 +235,14 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test no code...
|
// test no code...
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'amount' => '5.00',
|
array(
|
||||||
'discount_type' => 'fixed_product',
|
'amount' => '5.00',
|
||||||
) );
|
'discount_type' => 'fixed_product',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -241,13 +256,15 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test no code...
|
// test no code...
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'code' => 'fail',
|
array(
|
||||||
'amount' => '5.00',
|
'code' => 'fail',
|
||||||
'discount_type' => 'fixed_product',
|
'amount' => '5.00',
|
||||||
) );
|
'discount_type' => 'fixed_product',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -258,8 +275,8 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_update_coupon() {
|
public function test_update_coupon() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
||||||
$post = get_post( $coupon->get_id() );
|
$post = get_post( $coupon->get_id() );
|
||||||
|
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/' . $coupon->get_id() ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/' . $coupon->get_id() ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
@ -268,12 +285,14 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEquals( '1.00', $data['amount'] );
|
$this->assertEquals( '1.00', $data['amount'] );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'amount' => '10.00',
|
array(
|
||||||
'description' => 'New description',
|
'amount' => '10.00',
|
||||||
) );
|
'description' => 'New description',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( '10.00', $data['amount'] );
|
$this->assertEquals( '10.00', $data['amount'] );
|
||||||
$this->assertEquals( 'New description', $data['description'] );
|
$this->assertEquals( 'New description', $data['description'] );
|
||||||
|
@ -288,13 +307,15 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/0' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/0' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'code' => 'tester',
|
array(
|
||||||
'amount' => '10.00',
|
'code' => 'tester',
|
||||||
'description' => 'New description',
|
'amount' => '10.00',
|
||||||
) );
|
'description' => 'New description',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -305,14 +326,16 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_update_coupon_without_permission() {
|
public function test_update_coupon_without_permission() {
|
||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
||||||
$post = get_post( $coupon->get_id() );
|
$post = get_post( $coupon->get_id() );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'amount' => '10.00',
|
array(
|
||||||
'description' => 'New description',
|
'amount' => '10.00',
|
||||||
) );
|
'description' => 'New description',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
|
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
|
@ -324,7 +347,7 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_delete_coupon() {
|
public function test_delete_coupon() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
||||||
$request = new WP_REST_Request( 'DELETE', '/wc/v2/coupons/' . $coupon->get_id() );
|
$request = new WP_REST_Request( 'DELETE', '/wc/v2/coupons/' . $coupon->get_id() );
|
||||||
$request->set_param( 'force', true );
|
$request->set_param( 'force', true );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
|
@ -364,32 +387,34 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
public function test_batch_coupon() {
|
public function test_batch_coupon() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$coupon_1 = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
$coupon_1 = WC_Helper_Coupon::create_coupon( 'dummycoupon-1' );
|
||||||
$coupon_2 = WC_Helper_Coupon::create_coupon( 'dummycoupon-2' );
|
$coupon_2 = WC_Helper_Coupon::create_coupon( 'dummycoupon-2' );
|
||||||
$coupon_3 = WC_Helper_Coupon::create_coupon( 'dummycoupon-3' );
|
$coupon_3 = WC_Helper_Coupon::create_coupon( 'dummycoupon-3' );
|
||||||
$coupon_4 = WC_Helper_Coupon::create_coupon( 'dummycoupon-4' );
|
$coupon_4 = WC_Helper_Coupon::create_coupon( 'dummycoupon-4' );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons/batch' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/coupons/batch' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'update' => array(
|
array(
|
||||||
array(
|
'update' => array(
|
||||||
'id' => $coupon_1->get_id(),
|
array(
|
||||||
'amount' => '5.15',
|
'id' => $coupon_1->get_id(),
|
||||||
|
'amount' => '5.15',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'delete' => array(
|
||||||
'delete' => array(
|
$coupon_2->get_id(),
|
||||||
$coupon_2->get_id(),
|
$coupon_3->get_id(),
|
||||||
$coupon_3->get_id(),
|
|
||||||
),
|
|
||||||
'create' => array(
|
|
||||||
array(
|
|
||||||
'code' => 'new-coupon',
|
|
||||||
'amount' => '11.00',
|
|
||||||
),
|
),
|
||||||
),
|
'create' => array(
|
||||||
) );
|
array(
|
||||||
|
'code' => 'new-coupon',
|
||||||
|
'amount' => '11.00',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( '5.15', $data['update'][0]['amount'] );
|
$this->assertEquals( '5.15', $data['update'][0]['amount'] );
|
||||||
$this->assertEquals( '11.00', $data['create'][0]['amount'] );
|
$this->assertEquals( '11.00', $data['create'][0]['amount'] );
|
||||||
|
@ -397,9 +422,9 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEquals( $coupon_2->get_id(), $data['delete'][0]['id'] );
|
$this->assertEquals( $coupon_2->get_id(), $data['delete'][0]['id'] );
|
||||||
$this->assertEquals( $coupon_3->get_id(), $data['delete'][1]['id'] );
|
$this->assertEquals( $coupon_3->get_id(), $data['delete'][1]['id'] );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'GET', '/wc/v2/coupons' );
|
$request = new WP_REST_Request( 'GET', '/wc/v2/coupons' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 3, count( $data ) );
|
$this->assertEquals( 3, count( $data ) );
|
||||||
}
|
}
|
||||||
|
@ -410,9 +435,9 @@ class WC_Tests_API_Coupons_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_coupon_schema() {
|
public function test_coupon_schema() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/coupons' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/coupons' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
|
|
||||||
$this->assertEquals( 27, count( $properties ) );
|
$this->assertEquals( 27, count( $properties ) );
|
||||||
|
|
|
@ -41,68 +41,73 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
WC_Helper_Customer::create_customer( 'test2', 'test2', 'test2@woo.local' );
|
WC_Helper_Customer::create_customer( 'test2', 'test2', 'test2@woo.local' );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'GET', '/wc/v2/customers' );
|
$request = new WP_REST_Request( 'GET', '/wc/v2/customers' );
|
||||||
$request->set_query_params( array(
|
$request->set_query_params(
|
||||||
'orderby' => 'id',
|
array(
|
||||||
) );
|
'orderby' => 'id',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$customers = $response->get_data();
|
$customers = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( 2, count( $customers ) );
|
$this->assertEquals( 2, count( $customers ) );
|
||||||
|
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => $customer_1->get_id(),
|
array(
|
||||||
'date_created' => wc_rest_prepare_date_response( $customer_1->get_date_created(), false ),
|
'id' => $customer_1->get_id(),
|
||||||
'date_created_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_created() ),
|
'date_created' => wc_rest_prepare_date_response( $customer_1->get_date_created(), false ),
|
||||||
'date_modified' => wc_rest_prepare_date_response( $customer_1->get_date_modified(), false ),
|
'date_created_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_created() ),
|
||||||
'date_modified_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_modified() ),
|
'date_modified' => wc_rest_prepare_date_response( $customer_1->get_date_modified(), false ),
|
||||||
'email' => 'test@woo.local',
|
'date_modified_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_modified() ),
|
||||||
'first_name' => 'Justin',
|
'email' => 'test@woo.local',
|
||||||
'last_name' => '',
|
'first_name' => 'Justin',
|
||||||
'role' => 'customer',
|
'last_name' => '',
|
||||||
'username' => 'testcustomer',
|
'role' => 'customer',
|
||||||
'billing' => array(
|
'username' => 'testcustomer',
|
||||||
'first_name' => '',
|
'billing' => array(
|
||||||
'last_name' => '',
|
'first_name' => '',
|
||||||
'company' => '',
|
'last_name' => '',
|
||||||
'address_1' => '123 South Street',
|
'company' => '',
|
||||||
'address_2' => 'Apt 1',
|
'address_1' => '123 South Street',
|
||||||
'city' => 'Philadelphia',
|
'address_2' => 'Apt 1',
|
||||||
'state' => 'PA',
|
'city' => 'Philadelphia',
|
||||||
'postcode' => '19123',
|
'state' => 'PA',
|
||||||
'country' => 'US',
|
'postcode' => '19123',
|
||||||
'email' => '',
|
'country' => 'US',
|
||||||
'phone' => '',
|
'email' => '',
|
||||||
),
|
'phone' => '',
|
||||||
'shipping' => array(
|
|
||||||
'first_name' => '',
|
|
||||||
'last_name' => '',
|
|
||||||
'company' => '',
|
|
||||||
'address_1' => '123 South Street',
|
|
||||||
'address_2' => 'Apt 1',
|
|
||||||
'city' => 'Philadelphia',
|
|
||||||
'state' => 'PA',
|
|
||||||
'postcode' => '19123',
|
|
||||||
'country' => 'US',
|
|
||||||
),
|
|
||||||
'is_paying_customer' => false,
|
|
||||||
'orders_count' => 0,
|
|
||||||
'total_spent' => '0.00',
|
|
||||||
'avatar_url' => $customer_1->get_avatar_url(),
|
|
||||||
'meta_data' => array(),
|
|
||||||
'_links' => array(
|
|
||||||
'self' => array(
|
|
||||||
array(
|
|
||||||
'href' => rest_url( '/wc/v2/customers/' . $customer_1->get_id() . '' ),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'collection' => array(
|
'shipping' => array(
|
||||||
array(
|
'first_name' => '',
|
||||||
'href' => rest_url( '/wc/v2/customers' ),
|
'last_name' => '',
|
||||||
|
'company' => '',
|
||||||
|
'address_1' => '123 South Street',
|
||||||
|
'address_2' => 'Apt 1',
|
||||||
|
'city' => 'Philadelphia',
|
||||||
|
'state' => 'PA',
|
||||||
|
'postcode' => '19123',
|
||||||
|
'country' => 'US',
|
||||||
|
),
|
||||||
|
'is_paying_customer' => false,
|
||||||
|
'orders_count' => 0,
|
||||||
|
'total_spent' => '0.00',
|
||||||
|
'avatar_url' => $customer_1->get_avatar_url(),
|
||||||
|
'meta_data' => array(),
|
||||||
|
'_links' => array(
|
||||||
|
'self' => array(
|
||||||
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/customers/' . $customer_1->get_id() . '' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'collection' => array(
|
||||||
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/customers' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $customers );
|
$customers
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,129 +131,141 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// Test just the basics first..
|
// Test just the basics first..
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'username' => 'create_customer_test',
|
array(
|
||||||
'password' => 'test123',
|
'username' => 'create_customer_test',
|
||||||
'email' => 'create_customer_test@woo.local',
|
'password' => 'test123',
|
||||||
) );
|
'email' => 'create_customer_test@woo.local',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 201, $response->get_status() );
|
$this->assertEquals( 201, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => $data['id'],
|
array(
|
||||||
'date_created' => $data['date_created'],
|
'id' => $data['id'],
|
||||||
'date_created_gmt' => $data['date_created_gmt'],
|
'date_created' => $data['date_created'],
|
||||||
'date_modified' => $data['date_modified'],
|
'date_created_gmt' => $data['date_created_gmt'],
|
||||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
'date_modified' => $data['date_modified'],
|
||||||
'email' => 'create_customer_test@woo.local',
|
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||||
'first_name' => '',
|
'email' => 'create_customer_test@woo.local',
|
||||||
'last_name' => '',
|
'first_name' => '',
|
||||||
'role' => 'customer',
|
'last_name' => '',
|
||||||
'username' => 'create_customer_test',
|
'role' => 'customer',
|
||||||
'billing' => array(
|
'username' => 'create_customer_test',
|
||||||
'first_name' => '',
|
'billing' => array(
|
||||||
'last_name' => '',
|
'first_name' => '',
|
||||||
'company' => '',
|
'last_name' => '',
|
||||||
'address_1' => '',
|
'company' => '',
|
||||||
'address_2' => '',
|
'address_1' => '',
|
||||||
'city' => '',
|
'address_2' => '',
|
||||||
'state' => '',
|
'city' => '',
|
||||||
'postcode' => '',
|
'state' => '',
|
||||||
'country' => '',
|
'postcode' => '',
|
||||||
'email' => '',
|
'country' => '',
|
||||||
'phone' => '',
|
'email' => '',
|
||||||
|
'phone' => '',
|
||||||
|
),
|
||||||
|
'shipping' => array(
|
||||||
|
'first_name' => '',
|
||||||
|
'last_name' => '',
|
||||||
|
'company' => '',
|
||||||
|
'address_1' => '',
|
||||||
|
'address_2' => '',
|
||||||
|
'city' => '',
|
||||||
|
'state' => '',
|
||||||
|
'postcode' => '',
|
||||||
|
'country' => '',
|
||||||
|
),
|
||||||
|
'is_paying_customer' => false,
|
||||||
|
'meta_data' => array(),
|
||||||
|
'orders_count' => 0,
|
||||||
|
'total_spent' => '0.00',
|
||||||
|
'avatar_url' => $data['avatar_url'],
|
||||||
),
|
),
|
||||||
'shipping' => array(
|
$data
|
||||||
'first_name' => '',
|
);
|
||||||
'last_name' => '',
|
|
||||||
'company' => '',
|
|
||||||
'address_1' => '',
|
|
||||||
'address_2' => '',
|
|
||||||
'city' => '',
|
|
||||||
'state' => '',
|
|
||||||
'postcode' => '',
|
|
||||||
'country' => '',
|
|
||||||
),
|
|
||||||
'is_paying_customer' => false,
|
|
||||||
'meta_data' => array(),
|
|
||||||
'orders_count' => 0,
|
|
||||||
'total_spent' => '0.00',
|
|
||||||
'avatar_url' => $data['avatar_url'],
|
|
||||||
), $data );
|
|
||||||
|
|
||||||
// Test extra data
|
// Test extra data
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'username' => 'create_customer_test2',
|
array(
|
||||||
'password' => 'test123',
|
'username' => 'create_customer_test2',
|
||||||
'email' => 'create_customer_test2@woo.local',
|
'password' => 'test123',
|
||||||
'first_name' => 'Test',
|
'email' => 'create_customer_test2@woo.local',
|
||||||
'last_name' => 'McTestFace',
|
'first_name' => 'Test',
|
||||||
'billing' => array(
|
'last_name' => 'McTestFace',
|
||||||
'country' => 'US',
|
'billing' => array(
|
||||||
'state' => 'WA',
|
'country' => 'US',
|
||||||
),
|
'state' => 'WA',
|
||||||
'shipping' => array(
|
),
|
||||||
'state' => 'CA',
|
'shipping' => array(
|
||||||
'country' => 'US',
|
'state' => 'CA',
|
||||||
),
|
'country' => 'US',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 201, $response->get_status() );
|
$this->assertEquals( 201, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => $data['id'],
|
array(
|
||||||
'date_created' => $data['date_created'],
|
'id' => $data['id'],
|
||||||
'date_created_gmt' => $data['date_created_gmt'],
|
'date_created' => $data['date_created'],
|
||||||
'date_modified' => $data['date_modified'],
|
'date_created_gmt' => $data['date_created_gmt'],
|
||||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
'date_modified' => $data['date_modified'],
|
||||||
'email' => 'create_customer_test2@woo.local',
|
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||||
'first_name' => 'Test',
|
'email' => 'create_customer_test2@woo.local',
|
||||||
'last_name' => 'McTestFace',
|
'first_name' => 'Test',
|
||||||
'role' => 'customer',
|
'last_name' => 'McTestFace',
|
||||||
'username' => 'create_customer_test2',
|
'role' => 'customer',
|
||||||
'billing' => array(
|
'username' => 'create_customer_test2',
|
||||||
'first_name' => '',
|
'billing' => array(
|
||||||
'last_name' => '',
|
'first_name' => '',
|
||||||
'company' => '',
|
'last_name' => '',
|
||||||
'address_1' => '',
|
'company' => '',
|
||||||
'address_2' => '',
|
'address_1' => '',
|
||||||
'city' => '',
|
'address_2' => '',
|
||||||
'state' => 'WA',
|
'city' => '',
|
||||||
'postcode' => '',
|
'state' => 'WA',
|
||||||
'country' => 'US',
|
'postcode' => '',
|
||||||
'email' => '',
|
'country' => 'US',
|
||||||
'phone' => '',
|
'email' => '',
|
||||||
|
'phone' => '',
|
||||||
|
),
|
||||||
|
'shipping' => array(
|
||||||
|
'first_name' => '',
|
||||||
|
'last_name' => '',
|
||||||
|
'company' => '',
|
||||||
|
'address_1' => '',
|
||||||
|
'address_2' => '',
|
||||||
|
'city' => '',
|
||||||
|
'state' => 'CA',
|
||||||
|
'postcode' => '',
|
||||||
|
'country' => 'US',
|
||||||
|
),
|
||||||
|
'is_paying_customer' => false,
|
||||||
|
'meta_data' => array(),
|
||||||
|
'orders_count' => 0,
|
||||||
|
'total_spent' => '0.00',
|
||||||
|
'avatar_url' => $data['avatar_url'],
|
||||||
),
|
),
|
||||||
'shipping' => array(
|
$data
|
||||||
'first_name' => '',
|
);
|
||||||
'last_name' => '',
|
|
||||||
'company' => '',
|
|
||||||
'address_1' => '',
|
|
||||||
'address_2' => '',
|
|
||||||
'city' => '',
|
|
||||||
'state' => 'CA',
|
|
||||||
'postcode' => '',
|
|
||||||
'country' => 'US',
|
|
||||||
),
|
|
||||||
'is_paying_customer' => false,
|
|
||||||
'meta_data' => array(),
|
|
||||||
'orders_count' => 0,
|
|
||||||
'total_spent' => '0.00',
|
|
||||||
'avatar_url' => $data['avatar_url'],
|
|
||||||
), $data );
|
|
||||||
|
|
||||||
// Test without required field
|
// Test without required field
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'username' => 'create_customer_test3',
|
array(
|
||||||
'first_name' => 'Test',
|
'username' => 'create_customer_test3',
|
||||||
'last_name' => 'McTestFace',
|
'first_name' => 'Test',
|
||||||
) );
|
'last_name' => 'McTestFace',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -261,11 +278,13 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
public function test_create_customer_without_permission() {
|
public function test_create_customer_without_permission() {
|
||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'username' => 'create_customer_test_without_permission',
|
array(
|
||||||
'password' => 'test123',
|
'username' => 'create_customer_test_without_permission',
|
||||||
'email' => 'create_customer_test_without_permission@woo.local',
|
'password' => 'test123',
|
||||||
) );
|
'email' => 'create_customer_test_without_permission@woo.local',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -279,49 +298,52 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( 1 );
|
wp_set_current_user( 1 );
|
||||||
$customer = WC_Helper_Customer::create_customer( 'get_customer_test', 'test123', 'get_customer_test@woo.local' );
|
$customer = WC_Helper_Customer::create_customer( 'get_customer_test', 'test123', 'get_customer_test@woo.local' );
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => $data['id'],
|
array(
|
||||||
'date_created' => $data['date_created'],
|
'id' => $data['id'],
|
||||||
'date_created_gmt' => $data['date_created_gmt'],
|
'date_created' => $data['date_created'],
|
||||||
'date_modified' => $data['date_modified'],
|
'date_created_gmt' => $data['date_created_gmt'],
|
||||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
'date_modified' => $data['date_modified'],
|
||||||
'email' => 'get_customer_test@woo.local',
|
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||||
'first_name' => 'Justin',
|
'email' => 'get_customer_test@woo.local',
|
||||||
'billing' => array(
|
'first_name' => 'Justin',
|
||||||
'first_name' => '',
|
'billing' => array(
|
||||||
'last_name' => '',
|
'first_name' => '',
|
||||||
'company' => '',
|
'last_name' => '',
|
||||||
'address_1' => '123 South Street',
|
'company' => '',
|
||||||
'address_2' => 'Apt 1',
|
'address_1' => '123 South Street',
|
||||||
'city' => 'Philadelphia',
|
'address_2' => 'Apt 1',
|
||||||
'state' => 'PA',
|
'city' => 'Philadelphia',
|
||||||
'postcode' => '19123',
|
'state' => 'PA',
|
||||||
'country' => 'US',
|
'postcode' => '19123',
|
||||||
'email' => '',
|
'country' => 'US',
|
||||||
'phone' => '',
|
'email' => '',
|
||||||
|
'phone' => '',
|
||||||
|
),
|
||||||
|
'shipping' => array(
|
||||||
|
'first_name' => '',
|
||||||
|
'last_name' => '',
|
||||||
|
'company' => '',
|
||||||
|
'address_1' => '123 South Street',
|
||||||
|
'address_2' => 'Apt 1',
|
||||||
|
'city' => 'Philadelphia',
|
||||||
|
'state' => 'PA',
|
||||||
|
'postcode' => '19123',
|
||||||
|
'country' => 'US',
|
||||||
|
),
|
||||||
|
'is_paying_customer' => false,
|
||||||
|
'meta_data' => array(),
|
||||||
|
'last_name' => '',
|
||||||
|
'role' => 'customer',
|
||||||
|
'username' => 'get_customer_test',
|
||||||
|
'orders_count' => 0,
|
||||||
|
'total_spent' => '0.00',
|
||||||
|
'avatar_url' => $data['avatar_url'],
|
||||||
),
|
),
|
||||||
'shipping' => array(
|
$data
|
||||||
'first_name' => '',
|
);
|
||||||
'last_name' => '',
|
|
||||||
'company' => '',
|
|
||||||
'address_1' => '123 South Street',
|
|
||||||
'address_2' => 'Apt 1',
|
|
||||||
'city' => 'Philadelphia',
|
|
||||||
'state' => 'PA',
|
|
||||||
'postcode' => '19123',
|
|
||||||
'country' => 'US',
|
|
||||||
),
|
|
||||||
'is_paying_customer' => false,
|
|
||||||
'meta_data' => array(),
|
|
||||||
'last_name' => '',
|
|
||||||
'role' => 'customer',
|
|
||||||
'username' => 'get_customer_test',
|
|
||||||
'orders_count' => 0,
|
|
||||||
'total_spent' => '0.00',
|
|
||||||
'avatar_url' => $data['avatar_url'],
|
|
||||||
), $data );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -362,10 +384,12 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEquals( 'update_customer_test@woo.local', $data['email'] );
|
$this->assertEquals( 'update_customer_test@woo.local', $data['email'] );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/customers/' . $customer->get_id() );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/customers/' . $customer->get_id() );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'email' => 'updated_email@woo.local',
|
array(
|
||||||
'first_name' => 'UpdatedTest',
|
'email' => 'updated_email@woo.local',
|
||||||
) );
|
'first_name' => 'UpdatedTest',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
@ -418,7 +442,7 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_delete_customer_invalid_id() {
|
public function test_delete_customer_invalid_id() {
|
||||||
wp_set_current_user( 1 );
|
wp_set_current_user( 1 );
|
||||||
$request = new WP_REST_Request( 'DELETE', '/wc/v2/customers/0' );
|
$request = new WP_REST_Request( 'DELETE', '/wc/v2/customers/0' );
|
||||||
$request->set_param( 'force', true );
|
$request->set_param( 'force', true );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
@ -452,27 +476,29 @@ 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' );
|
$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 = new WP_REST_Request( 'POST', '/wc/v2/customers/batch' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'update' => array(
|
array(
|
||||||
array(
|
'update' => array(
|
||||||
'id' => $customer_1->get_id(),
|
array(
|
||||||
'last_name' => 'McTest',
|
'id' => $customer_1->get_id(),
|
||||||
|
'last_name' => 'McTest',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'delete' => array(
|
||||||
'delete' => array(
|
$customer_2->get_id(),
|
||||||
$customer_2->get_id(),
|
$customer_3->get_id(),
|
||||||
$customer_3->get_id(),
|
|
||||||
),
|
|
||||||
'create' => array(
|
|
||||||
array(
|
|
||||||
'username' => 'newuser',
|
|
||||||
'password' => 'test123',
|
|
||||||
'email' => 'newuser@woo.local',
|
|
||||||
),
|
),
|
||||||
),
|
'create' => array(
|
||||||
) );
|
array(
|
||||||
|
'username' => 'newuser',
|
||||||
|
'password' => 'test123',
|
||||||
|
'email' => 'newuser@woo.local',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'McTest', $data['update'][0]['last_name'] );
|
$this->assertEquals( 'McTest', $data['update'][0]['last_name'] );
|
||||||
$this->assertEquals( 'newuser', $data['create'][0]['username'] );
|
$this->assertEquals( 'newuser', $data['create'][0]['username'] );
|
||||||
|
@ -480,9 +506,9 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEquals( $customer_2->get_id(), $data['delete'][0]['id'] );
|
$this->assertEquals( $customer_2->get_id(), $data['delete'][0]['id'] );
|
||||||
$this->assertEquals( $customer_3->get_id(), $data['delete'][1]['id'] );
|
$this->assertEquals( $customer_3->get_id(), $data['delete'][1]['id'] );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'GET', '/wc/v2/customers' );
|
$request = new WP_REST_Request( 'GET', '/wc/v2/customers' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 3, count( $data ) );
|
$this->assertEquals( 3, count( $data ) );
|
||||||
}
|
}
|
||||||
|
@ -494,9 +520,9 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_customer_schema() {
|
public function test_customer_schema() {
|
||||||
wp_set_current_user( 1 );
|
wp_set_current_user( 1 );
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/customers' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/customers' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
|
|
||||||
$this->assertEquals( 18, count( $properties ) );
|
$this->assertEquals( 18, count( $properties ) );
|
||||||
|
|
|
@ -120,10 +120,12 @@ class WC_Tests_API_Orders_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_get_item_refund_id() {
|
public function test_get_item_refund_id() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$order = WC_Helper_Order::create_order();
|
$order = WC_Helper_Order::create_order();
|
||||||
$refund = wc_create_refund( array(
|
$refund = wc_create_refund(
|
||||||
'order_id' => $order->get_id(),
|
array(
|
||||||
) );
|
'order_id' => $order->get_id(),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $refund->get_id() ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $refund->get_id() ) );
|
||||||
$this->assertEquals( 404, $response->get_status() );
|
$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(
|
$request->set_body_params(
|
||||||
array(
|
array(
|
||||||
'payment_method' => 'bacs',
|
'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 );
|
$response = $this->server->dispatch( $request );
|
||||||
|
|
|
@ -14,9 +14,11 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->endpoint = new WC_REST_Payment_Gateways_Controller();
|
$this->endpoint = new WC_REST_Payment_Gateways_Controller();
|
||||||
$this->user = $this->factory->user->create( array(
|
$this->user = $this->factory->user->create(
|
||||||
'role' => 'administrator',
|
array(
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,31 +44,37 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$gateways = $response->get_data();
|
$gateways = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'cheque',
|
array(
|
||||||
'title' => 'Check payments',
|
'id' => 'cheque',
|
||||||
'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.',
|
'title' => 'Check payments',
|
||||||
'order' => '',
|
'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.',
|
||||||
'enabled' => false,
|
'order' => '',
|
||||||
'method_title' => 'Check payments',
|
'enabled' => false,
|
||||||
'method_description' => 'Take payments in person via checks. This offline gateway can also be useful to test purchases.',
|
'method_title' => 'Check payments',
|
||||||
'settings' => array_diff_key( $this->get_settings( 'WC_Gateway_Cheque' ), array(
|
'method_description' => 'Take payments in person via checks. This offline gateway can also be useful to test purchases.',
|
||||||
'enabled' => false,
|
'settings' => array_diff_key(
|
||||||
'description' => false,
|
$this->get_settings( 'WC_Gateway_Cheque' ),
|
||||||
) ),
|
|
||||||
'_links' => array(
|
|
||||||
'self' => array(
|
|
||||||
array(
|
array(
|
||||||
'href' => rest_url( '/wc/v2/payment_gateways/cheque' ),
|
'enabled' => false,
|
||||||
),
|
'description' => false,
|
||||||
|
)
|
||||||
),
|
),
|
||||||
'collection' => array(
|
'_links' => array(
|
||||||
array(
|
'self' => array(
|
||||||
'href' => rest_url( '/wc/v2/payment_gateways' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/payment_gateways/cheque' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'collection' => array(
|
||||||
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/payment_gateways' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $gateways );
|
$gateways
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,19 +100,25 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => 'paypal',
|
array(
|
||||||
'title' => 'PayPal',
|
'id' => 'paypal',
|
||||||
'description' => "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.",
|
'title' => 'PayPal',
|
||||||
'order' => '',
|
'description' => "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.",
|
||||||
'enabled' => false,
|
'order' => '',
|
||||||
'method_title' => 'PayPal',
|
'enabled' => false,
|
||||||
'method_description' => 'PayPal Standard redirects customers to PayPal to enter their payment information.',
|
'method_title' => 'PayPal',
|
||||||
'settings' => array_diff_key( $this->get_settings( 'WC_Gateway_Paypal' ), array(
|
'method_description' => 'PayPal Standard redirects customers to PayPal to enter their payment information.',
|
||||||
'enabled' => false,
|
'settings' => array_diff_key(
|
||||||
'description' => false,
|
$this->get_settings( 'WC_Gateway_Paypal' ),
|
||||||
) ),
|
array(
|
||||||
), $paypal );
|
'enabled' => false,
|
||||||
|
'description' => false,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
$paypal
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,11 +161,13 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test updating single setting
|
// test updating single setting
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'email' => 'woo@woo.local',
|
'settings' => array(
|
||||||
),
|
'email' => 'woo@woo.local',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
|
|
||||||
|
@ -162,12 +178,14 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test updating multiple settings
|
// test updating multiple settings
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'testmode' => 'yes',
|
'settings' => array(
|
||||||
'title' => 'PayPal - New Title',
|
'testmode' => 'yes',
|
||||||
),
|
'title' => 'PayPal - New Title',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
|
|
||||||
|
@ -178,10 +196,12 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// Test other parameters, and recheck settings
|
// Test other parameters, and recheck settings
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'enabled' => false,
|
array(
|
||||||
'order' => 2,
|
'enabled' => false,
|
||||||
) );
|
'order' => 2,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
|
|
||||||
|
@ -193,20 +213,24 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test bogus
|
// test bogus
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'paymentaction' => 'afasfasf',
|
'settings' => array(
|
||||||
),
|
'paymentaction' => 'afasfasf',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'paymentaction' => 'authorization',
|
'settings' => array(
|
||||||
),
|
'paymentaction' => 'authorization',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$paypal = $response->get_data();
|
$paypal = $response->get_data();
|
||||||
$this->assertEquals( 'authorization', $paypal['settings']['paymentaction']['value'] );
|
$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() {
|
public function test_update_payment_gateway_without_permission() {
|
||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/paypal' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'settings' => array(
|
array(
|
||||||
'testmode' => 'yes',
|
'settings' => array(
|
||||||
'title' => 'PayPal - New Title',
|
'testmode' => 'yes',
|
||||||
),
|
'title' => 'PayPal - New Title',
|
||||||
) );
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -237,10 +263,12 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_update_payment_gateway_invalid_id() {
|
public function test_update_payment_gateway_invalid_id() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/totally_fake_method' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/payment_gateways/totally_fake_method' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'enabled' => true,
|
array(
|
||||||
) );
|
'enabled' => true,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 404, $response->get_status() );
|
$this->assertEquals( 404, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -253,9 +281,9 @@ class Payment_Gateways_V2 extends WC_REST_Unit_Test_Case {
|
||||||
public function test_payment_gateway_schema() {
|
public function test_payment_gateway_schema() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/payment_gateways' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/payment_gateways' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
|
|
||||||
$this->assertEquals( 8, count( $properties ) );
|
$this->assertEquals( 8, count( $properties ) );
|
||||||
|
|
|
@ -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,
|
'rating' => 0,
|
||||||
'verified' => false,
|
'verified' => false,
|
||||||
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
|
'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,
|
'rating' => 5,
|
||||||
'verified' => false,
|
'verified' => false,
|
||||||
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
|
'reviewer_avatar_urls' => $data['reviewer_avatar_urls'],
|
||||||
), $data
|
),
|
||||||
|
$data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->endpoint = new WC_REST_Setting_Options_Controller();
|
$this->endpoint = new WC_REST_Setting_Options_Controller();
|
||||||
WC_Helper_Settings::register();
|
WC_Helper_Settings::register();
|
||||||
$this->user = $this->factory->user->create( array(
|
$this->user = $this->factory->user->create(
|
||||||
'role' => 'administrator',
|
array(
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,39 +43,45 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'test',
|
array(
|
||||||
'label' => 'Test extension',
|
'id' => 'test',
|
||||||
'parent_id' => '',
|
'label' => 'Test extension',
|
||||||
'description' => 'My awesome test settings.',
|
'parent_id' => '',
|
||||||
'sub_groups' => array( 'sub-test' ),
|
'description' => 'My awesome test settings.',
|
||||||
'_links' => array(
|
'sub_groups' => array( 'sub-test' ),
|
||||||
'options' => array(
|
'_links' => array(
|
||||||
array(
|
'options' => array(
|
||||||
'href' => rest_url( '/wc/v2/settings/test' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/settings/test' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $data );
|
$data
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'sub-test',
|
array(
|
||||||
'label' => 'Sub test',
|
'id' => 'sub-test',
|
||||||
'parent_id' => 'test',
|
'label' => 'Sub test',
|
||||||
'description' => '',
|
'parent_id' => 'test',
|
||||||
'sub_groups' => array(),
|
'description' => '',
|
||||||
'_links' => array(
|
'sub_groups' => array(),
|
||||||
'options' => array(
|
'_links' => array(
|
||||||
array(
|
'options' => array(
|
||||||
'href' => rest_url( '/wc/v2/settings/sub-test' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/settings/sub-test' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $data );
|
$data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,9 +119,9 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_get_group_schema() {
|
public function test_get_group_schema() {
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/settings' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/settings' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
$this->assertEquals( 5, count( $properties ) );
|
$this->assertEquals( 5, count( $properties ) );
|
||||||
$this->assertArrayHasKey( 'id', $properties );
|
$this->assertArrayHasKey( 'id', $properties );
|
||||||
|
@ -129,9 +137,9 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_get_setting_schema() {
|
public function test_get_setting_schema() {
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/settings/test/woocommerce_shop_page_display' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/settings/test/woocommerce_shop_page_display' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
$this->assertEquals( 9, count( $properties ) );
|
$this->assertEquals( 9, count( $properties ) );
|
||||||
$this->assertArrayHasKey( 'id', $properties );
|
$this->assertArrayHasKey( 'id', $properties );
|
||||||
|
@ -167,7 +175,7 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test getting a valid group with settings attached to it
|
// test getting a valid group with settings attached to it
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( 1, count( $data ) );
|
$this->assertEquals( 1, count( $data ) );
|
||||||
$this->assertEquals( 'woocommerce_shop_page_display', $data[0]['id'] );
|
$this->assertEquals( 'woocommerce_shop_page_display', $data[0]['id'] );
|
||||||
$this->assertEmpty( $data[0]['value'] );
|
$this->assertEmpty( $data[0]['value'] );
|
||||||
|
@ -195,36 +203,42 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test defaults first
|
// test defaults first
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( '', $data['value'] );
|
$this->assertEquals( '', $data['value'] );
|
||||||
|
|
||||||
// test updating shop display setting
|
// test updating shop display setting
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', '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(
|
||||||
'value' => 'both',
|
array(
|
||||||
) );
|
'value' => 'both',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'both', $data['value'] );
|
$this->assertEquals( 'both', $data['value'] );
|
||||||
$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
|
$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 = 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(
|
||||||
'value' => 'subcategories',
|
array(
|
||||||
) );
|
'value' => 'subcategories',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'subcategories', $data['value'] );
|
$this->assertEquals( 'subcategories', $data['value'] );
|
||||||
$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
|
$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 = 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(
|
||||||
'value' => '',
|
array(
|
||||||
) );
|
'value' => '',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( '', $data['value'] );
|
$this->assertEquals( '', $data['value'] );
|
||||||
$this->assertEquals( '', get_option( 'woocommerce_shop_page_display' ) );
|
$this->assertEquals( '', get_option( 'woocommerce_shop_page_display' ) );
|
||||||
|
@ -240,37 +254,41 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test defaults first
|
// test defaults first
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( '', $data[0]['value'] );
|
$this->assertEquals( '', $data[0]['value'] );
|
||||||
|
|
||||||
// test setting both at once
|
// test setting both at once
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'update' => array(
|
array(
|
||||||
array(
|
'update' => array(
|
||||||
'id' => 'woocommerce_shop_page_display',
|
array(
|
||||||
'value' => 'both',
|
'id' => 'woocommerce_shop_page_display',
|
||||||
|
'value' => 'both',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'both', $data['update'][0]['value'] );
|
$this->assertEquals( 'both', $data['update'][0]['value'] );
|
||||||
$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
|
$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
|
||||||
|
|
||||||
// test updating one, but making sure the other value stays the same
|
// test updating one, but making sure the other value stays the same
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'update' => array(
|
array(
|
||||||
array(
|
'update' => array(
|
||||||
'id' => 'woocommerce_shop_page_display',
|
array(
|
||||||
'value' => 'subcategories',
|
'id' => 'woocommerce_shop_page_display',
|
||||||
|
'value' => 'subcategories',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( 'subcategories', $data['update'][0]['value'] );
|
$this->assertEquals( 'subcategories', $data['update'][0]['value'] );
|
||||||
$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
|
$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
|
||||||
}
|
}
|
||||||
|
@ -285,17 +303,17 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test getting an invalid setting from a group that does not exist
|
// test getting an invalid setting from a group that does not exist
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/not-real/woocommerce_shop_page_display' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/not-real/woocommerce_shop_page_display' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( 404, $response->get_status() );
|
$this->assertEquals( 404, $response->get_status() );
|
||||||
|
|
||||||
// test getting an invalid setting from a group that does exist
|
// test getting an invalid setting from a group that does exist
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/invalid/invalid' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/invalid/invalid' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertEquals( 404, $response->get_status() );
|
$this->assertEquals( 404, $response->get_status() );
|
||||||
|
|
||||||
// test getting a valid setting
|
// test getting a valid setting
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
|
@ -373,9 +391,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', '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(
|
||||||
'value' => 'subcategories',
|
array(
|
||||||
) );
|
'value' => 'subcategories',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$this->assertEquals( 401, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -390,14 +410,16 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
|
$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'update' => array(
|
array(
|
||||||
array(
|
'update' => array(
|
||||||
'id' => 'woocommerce_shop_page_display',
|
array(
|
||||||
'value' => 'subcategories',
|
'id' => 'woocommerce_shop_page_display',
|
||||||
|
'value' => 'subcategories',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
) );
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 401, $response->get_status() );
|
$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 );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/test/invalid' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/test/invalid' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => 'test',
|
array(
|
||||||
) );
|
'value' => 'test',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 404, $response->get_status() );
|
$this->assertEquals( 404, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -429,43 +453,48 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// Make sure the group is properly registered
|
// Make sure the group is properly registered
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$this->assertTrue( is_array( $data ) );
|
$this->assertTrue( is_array( $data ) );
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'woocommerce_downloads_require_login',
|
array(
|
||||||
'label' => 'Access restriction',
|
'id' => 'woocommerce_downloads_require_login',
|
||||||
'description' => 'Downloads require login',
|
'label' => 'Access restriction',
|
||||||
'type' => 'checkbox',
|
'description' => 'Downloads require login',
|
||||||
'default' => 'no',
|
'type' => 'checkbox',
|
||||||
'tip' => 'This setting does not apply to guest purchases.',
|
'default' => 'no',
|
||||||
'value' => 'no',
|
'tip' => 'This setting does not apply to guest purchases.',
|
||||||
'_links' => array(
|
'value' => 'no',
|
||||||
'self' => array(
|
'_links' => array(
|
||||||
array(
|
'self' => array(
|
||||||
'href' => rest_url( '/wc/v2/settings/products/woocommerce_downloads_require_login' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/settings/products/woocommerce_downloads_require_login' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'collection' => array(
|
||||||
'collection' => array(
|
array(
|
||||||
array(
|
'href' => rest_url( '/wc/v2/settings/products' ),
|
||||||
'href' => rest_url( '/wc/v2/settings/products' ),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $data );
|
$data
|
||||||
|
);
|
||||||
|
|
||||||
// test get single
|
// test get single
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products/woocommerce_dimension_unit' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products/woocommerce_dimension_unit' ) );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'cm', $data['default'] );
|
$this->assertEquals( 'cm', $data['default'] );
|
||||||
|
|
||||||
// test update
|
// test update
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_dimension_unit' ) );
|
$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(
|
||||||
'value' => 'yd',
|
array(
|
||||||
) );
|
'value' => 'yd',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 'yd', $data['value'] );
|
$this->assertEquals( 'yd', $data['value'] );
|
||||||
$this->assertEquals( 'yd', get_option( 'woocommerce_dimension_unit' ) );
|
$this->assertEquals( 'yd', get_option( 'woocommerce_dimension_unit' ) );
|
||||||
|
@ -484,62 +513,73 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'recipient',
|
array(
|
||||||
'label' => 'Recipient(s)',
|
'id' => 'recipient',
|
||||||
'description' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
|
'label' => 'Recipient(s)',
|
||||||
'type' => 'text',
|
'description' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
|
||||||
'default' => '',
|
'type' => 'text',
|
||||||
'tip' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
|
'default' => '',
|
||||||
'value' => '',
|
'tip' => 'Enter recipients (comma separated) for this email. Defaults to <code>admin@example.org</code>.',
|
||||||
'_links' => array(
|
'value' => '',
|
||||||
'self' => array(
|
'_links' => array(
|
||||||
array(
|
'self' => array(
|
||||||
'href' => rest_url( '/wc/v2/settings/email_new_order/recipient' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/settings/email_new_order/recipient' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'collection' => array(
|
||||||
'collection' => array(
|
array(
|
||||||
array(
|
'href' => rest_url( '/wc/v2/settings/email_new_order' ),
|
||||||
'href' => rest_url( '/wc/v2/settings/email_new_order' ),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $settings );
|
$settings
|
||||||
|
);
|
||||||
|
|
||||||
// test get single
|
// test get single
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order/subject' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order/subject' ) );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => 'subject',
|
array(
|
||||||
'label' => 'Subject',
|
'id' => 'subject',
|
||||||
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
'label' => 'Subject',
|
||||||
'type' => 'text',
|
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
||||||
'default' => '',
|
'type' => 'text',
|
||||||
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
'default' => '',
|
||||||
'value' => '',
|
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
||||||
), $setting );
|
'value' => '',
|
||||||
|
),
|
||||||
|
$setting
|
||||||
|
);
|
||||||
|
|
||||||
// test update
|
// test update
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_new_order', 'subject' ) );
|
$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(
|
||||||
'value' => 'This is my subject',
|
array(
|
||||||
) );
|
'value' => 'This is my subject',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => 'subject',
|
array(
|
||||||
'label' => 'Subject',
|
'id' => 'subject',
|
||||||
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
'label' => 'Subject',
|
||||||
'type' => 'text',
|
'description' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
||||||
'default' => '',
|
'type' => 'text',
|
||||||
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
'default' => '',
|
||||||
'value' => 'This is my subject',
|
'tip' => 'Available placeholders: <code>{site_title}, {order_date}, {order_number}</code>',
|
||||||
), $setting );
|
'value' => 'This is my subject',
|
||||||
|
),
|
||||||
|
$setting
|
||||||
|
);
|
||||||
|
|
||||||
// test updating another subject and making sure it works with a "similar" id
|
// 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' ) );
|
$request = new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
|
|
||||||
|
@ -547,9 +587,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test update
|
// test update
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
|
$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(
|
||||||
'value' => 'This is my new subject',
|
array(
|
||||||
) );
|
'value' => 'This is my new subject',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
|
|
||||||
|
@ -572,25 +614,31 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// test bogus value
|
// test bogus value
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
|
$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(
|
||||||
'value' => 'not_yes_or_no',
|
array(
|
||||||
) );
|
'value' => 'not_yes_or_no',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
|
||||||
// test yes
|
// test yes
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
|
$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(
|
||||||
'value' => 'yes',
|
array(
|
||||||
) );
|
'value' => 'yes',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
|
||||||
// test no
|
// test no
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
|
$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(
|
||||||
'value' => 'no',
|
array(
|
||||||
) );
|
'value' => 'no',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -605,17 +653,21 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// not a valid option
|
// not a valid option
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
|
$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(
|
||||||
'value' => 'billing2',
|
array(
|
||||||
) );
|
'value' => 'billing2',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
|
||||||
// valid
|
// valid
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
|
$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(
|
||||||
'value' => 'billing',
|
array(
|
||||||
) );
|
'value' => 'billing',
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
}
|
}
|
||||||
|
@ -633,9 +685,11 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEmpty( $setting['value'] );
|
$this->assertEmpty( $setting['value'] );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) );
|
$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(
|
||||||
'value' => array( 'AX', 'DZ', 'MMM' ),
|
array(
|
||||||
) );
|
'value' => array( 'AX', 'DZ', 'MMM' ),
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] );
|
$this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] );
|
||||||
|
@ -655,17 +709,21 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
|
|
||||||
// invalid
|
// invalid
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
|
$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(
|
||||||
'value' => 'pounds', // invalid, should be lbs
|
array(
|
||||||
) );
|
'value' => 'pounds', // invalid, should be lbs
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$this->assertEquals( 400, $response->get_status() );
|
$this->assertEquals( 400, $response->get_status() );
|
||||||
|
|
||||||
// valid
|
// valid
|
||||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
|
$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(
|
||||||
'value' => 'lbs', // invalid, should be lbs
|
array(
|
||||||
) );
|
'value' => 'lbs', // invalid, should be lbs
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( 'lbs', $setting['value'] );
|
$this->assertEquals( 'lbs', $setting['value'] );
|
||||||
|
@ -702,19 +760,23 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
// Repalce the old value with something uniquely new
|
// Repalce the old value with something uniquely new
|
||||||
$old_value = $setting['value'];
|
$old_value = $setting['value'];
|
||||||
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $new_value,
|
array(
|
||||||
) );
|
'value' => $new_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $new_value, $setting['value'] );
|
$this->assertEquals( $new_value, $setting['value'] );
|
||||||
|
|
||||||
// Put the original value back
|
// Put the original value back
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $old_value,
|
array(
|
||||||
) );
|
'value' => $old_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $old_value, $setting['value'] );
|
$this->assertEquals( $old_value, $setting['value'] );
|
||||||
|
@ -734,19 +796,23 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
// Repalce the old value with something uniquely new
|
// Repalce the old value with something uniquely new
|
||||||
$old_value = $setting['value'];
|
$old_value = $setting['value'];
|
||||||
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $new_value,
|
array(
|
||||||
) );
|
'value' => $new_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $new_value, $setting['value'] );
|
$this->assertEquals( $new_value, $setting['value'] );
|
||||||
|
|
||||||
// Put the original value back
|
// Put the original value back
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $old_value,
|
array(
|
||||||
) );
|
'value' => $old_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $old_value, $setting['value'] );
|
$this->assertEquals( $old_value, $setting['value'] );
|
||||||
|
@ -766,19 +832,23 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
// Repalce the old value with something uniquely new
|
// Repalce the old value with something uniquely new
|
||||||
$old_value = $setting['value'];
|
$old_value = $setting['value'];
|
||||||
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $new_value,
|
array(
|
||||||
) );
|
'value' => $new_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $new_value, $setting['value'] );
|
$this->assertEquals( $new_value, $setting['value'] );
|
||||||
|
|
||||||
// Put the original value back
|
// Put the original value back
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $old_value,
|
array(
|
||||||
) );
|
'value' => $old_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $old_value, $setting['value'] );
|
$this->assertEquals( $old_value, $setting['value'] );
|
||||||
|
@ -798,19 +868,23 @@ class Settings_V2 extends WC_REST_Unit_Test_Case {
|
||||||
// Repalce the old value with something uniquely new
|
// Repalce the old value with something uniquely new
|
||||||
$old_value = $setting['value'];
|
$old_value = $setting['value'];
|
||||||
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
$new_value = $old_value . ' ' . rand( 1000, 9999 );
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $new_value,
|
array(
|
||||||
) );
|
'value' => $new_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $new_value, $setting['value'] );
|
$this->assertEquals( $new_value, $setting['value'] );
|
||||||
|
|
||||||
// Put the original value back
|
// Put the original value back
|
||||||
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
|
$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
|
||||||
$request->set_body_params( array(
|
$request->set_body_params(
|
||||||
'value' => $old_value,
|
array(
|
||||||
) );
|
'value' => $old_value,
|
||||||
|
)
|
||||||
|
);
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$setting = $response->get_data();
|
$setting = $response->get_data();
|
||||||
$this->assertEquals( $old_value, $setting['value'] );
|
$this->assertEquals( $old_value, $setting['value'] );
|
||||||
|
|
|
@ -14,9 +14,11 @@ class Shipping_Methods_V2 extends WC_REST_Unit_Test_Case {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->endpoint = new WC_REST_Shipping_Methods_Controller();
|
$this->endpoint = new WC_REST_Shipping_Methods_Controller();
|
||||||
$this->user = $this->factory->user->create( array(
|
$this->user = $this->factory->user->create(
|
||||||
'role' => 'administrator',
|
array(
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +28,7 @@ class Shipping_Methods_V2 extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_register_routes() {
|
public function test_register_routes() {
|
||||||
$routes = $this->server->get_routes();
|
$routes = $this->server->get_routes();
|
||||||
$this->assertArrayHasKey( '/wc/v2/shipping_methods', $routes );
|
$this->assertArrayHasKey( '/wc/v2/shipping_methods', $routes );
|
||||||
$this->assertArrayHasKey( '/wc/v2/shipping_methods/(?P<id>[\w-]+)', $routes );
|
$this->assertArrayHasKey( '/wc/v2/shipping_methods/(?P<id>[\w-]+)', $routes );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,26 +41,29 @@ class Shipping_Methods_V2 extends WC_REST_Unit_Test_Case {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods' ) );
|
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods' ) );
|
||||||
$methods = $response->get_data();
|
$methods = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertContains( array(
|
$this->assertContains(
|
||||||
'id' => 'free_shipping',
|
array(
|
||||||
'title' => 'Free shipping',
|
'id' => 'free_shipping',
|
||||||
'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.',
|
'title' => 'Free shipping',
|
||||||
'_links' => array(
|
'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.',
|
||||||
'self' => array(
|
'_links' => array(
|
||||||
array(
|
'self' => array(
|
||||||
'href' => rest_url( '/wc/v2/shipping_methods/free_shipping' ),
|
array(
|
||||||
|
'href' => rest_url( '/wc/v2/shipping_methods/free_shipping' ),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
'collection' => array(
|
||||||
'collection' => array(
|
array(
|
||||||
array(
|
'href' => rest_url( '/wc/v2/shipping_methods' ),
|
||||||
'href' => rest_url( '/wc/v2/shipping_methods' ),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), $methods );
|
$methods
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,11 +89,14 @@ class Shipping_Methods_V2 extends WC_REST_Unit_Test_Case {
|
||||||
$method = $response->get_data();
|
$method = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( array(
|
$this->assertEquals(
|
||||||
'id' => 'local_pickup',
|
array(
|
||||||
'title' => 'Local pickup',
|
'id' => '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.',
|
'title' => 'Local pickup',
|
||||||
), $method );
|
'description' => 'Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.',
|
||||||
|
),
|
||||||
|
$method
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,9 +130,9 @@ class Shipping_Methods_V2 extends WC_REST_Unit_Test_Case {
|
||||||
public function test_shipping_method_schema() {
|
public function test_shipping_method_schema() {
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
|
|
||||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/shipping_methods' );
|
$request = new WP_REST_Request( 'OPTIONS', '/wc/v2/shipping_methods' );
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
|
|
||||||
$this->assertEquals( 3, count( $properties ) );
|
$this->assertEquals( 3, count( $properties ) );
|
||||||
|
|
|
@ -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
|
// 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
|
// Create a zone
|
||||||
$zone = $this->create_shipping_zone(
|
$zone = $this->create_shipping_zone(
|
||||||
'Zone 1', 0, array(
|
'Zone 1',
|
||||||
|
0,
|
||||||
|
array(
|
||||||
array(
|
array(
|
||||||
'code' => 'US',
|
'code' => 'US',
|
||||||
'type' => 'country',
|
'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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class WC_Tests_API_Products_Attributes_Controller extends WC_REST_Unit_Test_Case
|
||||||
wp_set_current_user( $this->user );
|
wp_set_current_user( $this->user );
|
||||||
$request = new WP_REST_Request( 'GET', $this->endpoint . '/products/attributes' );
|
$request = new WP_REST_Request( 'GET', $this->endpoint . '/products/attributes' );
|
||||||
|
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$response_attributes = $response->get_data();
|
$response_attributes = $response->get_data();
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( 2, count( $response_attributes ) );
|
$this->assertEquals( 2, count( $response_attributes ) );
|
||||||
|
@ -96,7 +96,7 @@ class WC_Tests_API_Products_Attributes_Controller extends WC_REST_Unit_Test_Case
|
||||||
wp_set_current_user( $this->contributor );
|
wp_set_current_user( $this->contributor );
|
||||||
$request = new WP_REST_Request( 'GET', $this->endpoint . '/products/attributes/' . $this->attr_size['attribute_id'] );
|
$request = new WP_REST_Request( 'GET', $this->endpoint . '/products/attributes/' . $this->attr_size['attribute_id'] );
|
||||||
|
|
||||||
$response = $this->server->dispatch( $request );
|
$response = $this->server->dispatch( $request );
|
||||||
$attribute = $response->get_data();
|
$attribute = $response->get_data();
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( $this->attr_size['attribute_id'], $attribute['id'] );
|
$this->assertEquals( $this->attr_size['attribute_id'], $attribute['id'] );
|
||||||
|
|
|
@ -125,7 +125,7 @@ class WC_Tests_Attributes_Functions extends WC_Unit_Test_Case {
|
||||||
'is_variation' => 0,
|
'is_variation' => 0,
|
||||||
'is_taxonomy' => 1,
|
'is_taxonomy' => 1,
|
||||||
);
|
);
|
||||||
$local_before = isset( $product_meta_before_update['Test Local Attribute'] ) ? $product_meta_before_update['Test Local Attribute'] : $product_meta_before_update['test-local-attribute'];
|
$local_before = isset( $product_meta_before_update['Test Local Attribute'] ) ? $product_meta_before_update['Test Local Attribute'] : $product_meta_before_update['test-local-attribute'];
|
||||||
$this->assertEquals( $expected_local_attribute_data, $local_before );
|
$this->assertEquals( $expected_local_attribute_data, $local_before );
|
||||||
$this->assertEquals( $expected_global_attribute_data, $product_meta_before_update['pa_test'] );
|
$this->assertEquals( $expected_global_attribute_data, $product_meta_before_update['pa_test'] );
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ class WC_Tests_WC_Cart_Fees extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
// Test add_fee.
|
// Test add_fee.
|
||||||
$args = array(
|
$args = array(
|
||||||
'name' => 'testfee',
|
'name' => 'testfee',
|
||||||
'amount' => 10,
|
'amount' => 10,
|
||||||
);
|
);
|
||||||
$cart_fees->add_fee( $args );
|
$cart_fees->add_fee( $args );
|
||||||
$applied_fees = $cart_fees->get_fees();
|
$applied_fees = $cart_fees->get_fees();
|
||||||
|
@ -34,14 +34,14 @@ class WC_Tests_WC_Cart_Fees extends WC_Unit_Test_Case {
|
||||||
// Test set_fees.
|
// Test set_fees.
|
||||||
$args = array(
|
$args = array(
|
||||||
array(
|
array(
|
||||||
'name' => 'newfee',
|
'name' => 'newfee',
|
||||||
'amount' => -5,
|
'amount' => -5,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'name' => 'newfee2',
|
'name' => 'newfee2',
|
||||||
'amount' => 10,
|
'amount' => 10,
|
||||||
'tax_class' => 'Reduced rate',
|
'tax_class' => 'Reduced rate',
|
||||||
'taxable' => true
|
'taxable' => true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$cart_fees->set_fees( $args );
|
$cart_fees->set_fees( $args );
|
||||||
|
|
|
@ -109,7 +109,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
||||||
update_option( 'woocommerce_calc_taxes', 'yes' );
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
||||||
update_option( 'woocommerce_tax_round_at_subtotal', 'yes' );
|
update_option( 'woocommerce_tax_round_at_subtotal', 'yes' );
|
||||||
|
|
||||||
$tax_rate = array(
|
$tax_rate = array(
|
||||||
'tax_rate_country' => '',
|
'tax_rate_country' => '',
|
||||||
'tax_rate_state' => '',
|
'tax_rate_state' => '',
|
||||||
'tax_rate' => '23.0000',
|
'tax_rate' => '23.0000',
|
||||||
|
@ -122,7 +122,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
||||||
);
|
);
|
||||||
$tax_rate_23 = WC_Tax::_insert_tax_rate( $tax_rate );
|
$tax_rate_23 = WC_Tax::_insert_tax_rate( $tax_rate );
|
||||||
|
|
||||||
$tax_rate = array(
|
$tax_rate = array(
|
||||||
'tax_rate_country' => '',
|
'tax_rate_country' => '',
|
||||||
'tax_rate_state' => '',
|
'tax_rate_state' => '',
|
||||||
'tax_rate' => '5.0000',
|
'tax_rate' => '5.0000',
|
||||||
|
@ -196,7 +196,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_cart_get_discounted_price_issue_10963() {
|
public function test_cart_get_discounted_price_issue_10963() {
|
||||||
// Create dummy coupon - fixed cart, 1 value
|
// Create dummy coupon - fixed cart, 1 value
|
||||||
$coupon = WC_Helper_Coupon::create_coupon();
|
$coupon = WC_Helper_Coupon::create_coupon();
|
||||||
|
|
||||||
// Add coupon
|
// Add coupon
|
||||||
WC()->cart->add_discount( $coupon->get_code() );
|
WC()->cart->add_discount( $coupon->get_code() );
|
||||||
|
@ -290,7 +290,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_cart_get_discounted_price_issue_10573() {
|
public function test_cart_get_discounted_price_issue_10573() {
|
||||||
// Create dummy coupon - fixed cart, 1 value
|
// Create dummy coupon - fixed cart, 1 value
|
||||||
$coupon = WC_Helper_Coupon::create_coupon();
|
$coupon = WC_Helper_Coupon::create_coupon();
|
||||||
|
|
||||||
// Create dummy product - price will be 10
|
// Create dummy product - price will be 10
|
||||||
$product = WC_Helper_Product::create_simple_product();
|
$product = WC_Helper_Product::create_simple_product();
|
||||||
|
@ -1580,7 +1580,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_add_individual_use_coupon_removal() {
|
public function test_add_individual_use_coupon_removal() {
|
||||||
$coupon = WC_Helper_Coupon::create_coupon();
|
$coupon = WC_Helper_Coupon::create_coupon();
|
||||||
$iu_coupon = WC_Helper_Coupon::create_coupon( 'code1' );
|
$iu_coupon = WC_Helper_Coupon::create_coupon( 'code1' );
|
||||||
$iu_coupon->set_individual_use( true );
|
$iu_coupon->set_individual_use( true );
|
||||||
$iu_coupon->save();
|
$iu_coupon->save();
|
||||||
|
@ -1649,7 +1649,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
||||||
$new_cart = clone $cart;
|
$new_cart = clone $cart;
|
||||||
|
|
||||||
// Get the properties from each object.
|
// Get the properties from each object.
|
||||||
$cart_fees = $cart->fees_api();
|
$cart_fees = $cart->fees_api();
|
||||||
$new_cart_fees = $new_cart->fees_api();
|
$new_cart_fees = $new_cart->fees_api();
|
||||||
|
|
||||||
// Ensure that cloned properties are not identical.
|
// Ensure that cloned properties are not identical.
|
||||||
|
|
|
@ -27,7 +27,7 @@ class WC_Tests_Countries extends WC_Unit_Test_Case {
|
||||||
* @since 3.6.0
|
* @since 3.6.0
|
||||||
*/
|
*/
|
||||||
public function test_get_shipping_continents() {
|
public function test_get_shipping_continents() {
|
||||||
$countries = new WC_Countries();
|
$countries = new WC_Countries();
|
||||||
$all_continents = $countries->get_continents();
|
$all_continents = $countries->get_continents();
|
||||||
|
|
||||||
update_option( 'woocommerce_ship_to_countries', 'all' );
|
update_option( 'woocommerce_ship_to_countries', 'all' );
|
||||||
|
@ -110,7 +110,7 @@ class WC_Tests_Countries extends WC_Unit_Test_Case {
|
||||||
update_option( 'woocommerce_specific_allowed_countries', array( 'US' ) );
|
update_option( 'woocommerce_specific_allowed_countries', array( 'US' ) );
|
||||||
|
|
||||||
$all_states = $countries->get_allowed_country_states();
|
$all_states = $countries->get_allowed_country_states();
|
||||||
$us_states = $all_states['US'];
|
$us_states = $all_states['US'];
|
||||||
|
|
||||||
$this->assertEquals( 'Oregon', $us_states['OR'] );
|
$this->assertEquals( 'Oregon', $us_states['OR'] );
|
||||||
$this->assertGreaterThanOrEqual( 50, count( $us_states ) );
|
$this->assertGreaterThanOrEqual( 50, count( $us_states ) );
|
||||||
|
@ -134,7 +134,7 @@ class WC_Tests_Countries extends WC_Unit_Test_Case {
|
||||||
update_option( 'woocommerce_specific_ship_to_countries', array( 'US' ) );
|
update_option( 'woocommerce_specific_ship_to_countries', array( 'US' ) );
|
||||||
|
|
||||||
$all_states = $countries->get_shipping_country_states();
|
$all_states = $countries->get_shipping_country_states();
|
||||||
$us_states = $all_states['US'];
|
$us_states = $all_states['US'];
|
||||||
|
|
||||||
$this->assertEquals( 'Oregon', $us_states['OR'] );
|
$this->assertEquals( 'Oregon', $us_states['OR'] );
|
||||||
$this->assertGreaterThanOrEqual( 50, count( $us_states ) );
|
$this->assertGreaterThanOrEqual( 50, count( $us_states ) );
|
||||||
|
|
|
@ -235,11 +235,14 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
||||||
update_post_meta( $product->get_id(), '_regular_price', '10' );
|
update_post_meta( $product->get_id(), '_regular_price', '10' );
|
||||||
|
|
||||||
// Create coupon
|
// Create coupon
|
||||||
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon', array(
|
$coupon = WC_Helper_Coupon::create_coupon(
|
||||||
'discount_type' => 'percent',
|
'dummycoupon',
|
||||||
'coupon_amount' => '5',
|
array(
|
||||||
'limit_usage_to_x_items' => 1,
|
'discount_type' => 'percent',
|
||||||
) );
|
'coupon_amount' => '5',
|
||||||
|
'limit_usage_to_x_items' => 1,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// We need this to have the calculate_totals() method calculate totals.
|
// We need this to have the calculate_totals() method calculate totals.
|
||||||
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
|
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' );
|
update_post_meta( $product->get_id(), '_regular_price', '10' );
|
||||||
|
|
||||||
// Create coupon
|
// Create coupon
|
||||||
$coupon = WC_Helper_Coupon::create_coupon( 'dummycoupon', array(
|
$coupon = WC_Helper_Coupon::create_coupon(
|
||||||
'discount_type' => __FUNCTION__,
|
'dummycoupon',
|
||||||
'coupon_amount' => '5',
|
array(
|
||||||
'limit_usage_to_x_items' => 1,
|
'discount_type' => __FUNCTION__,
|
||||||
) );
|
'coupon_amount' => '5',
|
||||||
|
'limit_usage_to_x_items' => 1,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Add 4 products and coupon to cart.
|
// Add 4 products and coupon to cart.
|
||||||
WC()->cart->add_to_cart( $product->get_id(), 4 );
|
WC()->cart->add_to_cart( $product->get_id(), 4 );
|
||||||
|
|
|
@ -94,24 +94,27 @@ class WC_Tests_Coupon_Data extends WC_Unit_Test_Case {
|
||||||
public function test_read_manual_coupon() {
|
public function test_read_manual_coupon() {
|
||||||
$code = 'manual_coupon_' . time();
|
$code = 'manual_coupon_' . time();
|
||||||
$coupon = new WC_Coupon( $code );
|
$coupon = new WC_Coupon( $code );
|
||||||
$coupon->read_manual_coupon( $code, array(
|
$coupon->read_manual_coupon(
|
||||||
'id' => true,
|
$code,
|
||||||
'type' => 'fixed_cart',
|
array(
|
||||||
'amount' => 0,
|
'id' => true,
|
||||||
'individual_use' => true,
|
'type' => 'fixed_cart',
|
||||||
'product_ids' => array(),
|
'amount' => 0,
|
||||||
'exclude_product_ids' => array(),
|
'individual_use' => true,
|
||||||
'usage_limit' => '',
|
'product_ids' => array(),
|
||||||
'usage_count' => '',
|
'exclude_product_ids' => array(),
|
||||||
'expiry_date' => '',
|
'usage_limit' => '',
|
||||||
'free_shipping' => false,
|
'usage_count' => '',
|
||||||
'product_categories' => array(),
|
'expiry_date' => '',
|
||||||
'exclude_product_categories' => array(),
|
'free_shipping' => false,
|
||||||
'exclude_sale_items' => false,
|
'product_categories' => array(),
|
||||||
'minimum_amount' => '',
|
'exclude_product_categories' => array(),
|
||||||
'maximum_amount' => 100,
|
'exclude_sale_items' => false,
|
||||||
'customer_email' => '',
|
'minimum_amount' => '',
|
||||||
) );
|
'maximum_amount' => 100,
|
||||||
|
'customer_email' => '',
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( $code, $coupon->get_code() );
|
$this->assertEquals( $code, $coupon->get_code() );
|
||||||
$this->assertTrue( $coupon->get_individual_use() );
|
$this->assertTrue( $coupon->get_individual_use() );
|
||||||
$this->assertEquals( 100, $coupon->get_maximum_amount() );
|
$this->assertEquals( 100, $coupon->get_maximum_amount() );
|
||||||
|
@ -132,24 +135,27 @@ class WC_Tests_Coupon_Data extends WC_Unit_Test_Case {
|
||||||
$this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, $legacy_keys );
|
$this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, $legacy_keys );
|
||||||
$code = 'bc_manual_coupon_' . time();
|
$code = 'bc_manual_coupon_' . time();
|
||||||
$coupon = new WC_Coupon( $code );
|
$coupon = new WC_Coupon( $code );
|
||||||
$coupon->read_manual_coupon( $code, array(
|
$coupon->read_manual_coupon(
|
||||||
'id' => true,
|
$code,
|
||||||
'type' => 'fixed_cart',
|
array(
|
||||||
'amount' => 0,
|
'id' => true,
|
||||||
'individual_use' => 'yes',
|
'type' => 'fixed_cart',
|
||||||
'product_ids' => '',
|
'amount' => 0,
|
||||||
'exclude_product_ids' => '5,6',
|
'individual_use' => 'yes',
|
||||||
'usage_limit' => '',
|
'product_ids' => '',
|
||||||
'usage_count' => '',
|
'exclude_product_ids' => '5,6',
|
||||||
'expiry_date' => '',
|
'usage_limit' => '',
|
||||||
'free_shipping' => 'no',
|
'usage_count' => '',
|
||||||
'product_categories' => array(),
|
'expiry_date' => '',
|
||||||
'exclude_product_categories' => array(),
|
'free_shipping' => 'no',
|
||||||
'exclude_sale_items' => 'no',
|
'product_categories' => array(),
|
||||||
'minimum_amount' => '',
|
'exclude_product_categories' => array(),
|
||||||
'maximum_amount' => 100,
|
'exclude_sale_items' => 'no',
|
||||||
'customer_email' => '',
|
'minimum_amount' => '',
|
||||||
) );
|
'maximum_amount' => 100,
|
||||||
|
'customer_email' => '',
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( $code, $coupon->get_code() );
|
$this->assertEquals( $code, $coupon->get_code() );
|
||||||
$this->assertTrue( $coupon->get_individual_use() );
|
$this->assertTrue( $coupon->get_individual_use() );
|
||||||
$this->assertFalse( $coupon->get_free_shipping() );
|
$this->assertFalse( $coupon->get_free_shipping() );
|
||||||
|
|
|
@ -75,7 +75,7 @@ class WC_Tests_Data_Store extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
function load_dummy_store() {
|
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' ) );
|
add_filter( 'woocommerce_data_stores', array( $this, 'add_dummy_data_store' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
/**
|
/**
|
||||||
* Restore UTC on failire.
|
* Restore UTC on failire.
|
||||||
*/
|
*/
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
// @codingStandardsIgnoreStart
|
// @codingStandardsIgnoreStart
|
||||||
date_default_timezone_set( 'UTC' );
|
date_default_timezone_set( 'UTC' );
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
@ -63,9 +63,9 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* Test: delete_meta_data_by_mid
|
* Test: delete_meta_data_by_mid
|
||||||
*/
|
*/
|
||||||
function test_delete_meta_data_by_mid() {
|
function test_delete_meta_data_by_mid() {
|
||||||
$object = $this->create_test_post();
|
$object = $this->create_test_post();
|
||||||
$object_id = $object->get_id();
|
$object_id = $object->get_id();
|
||||||
$meta_id = add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
|
$meta_id = add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
|
||||||
$object->delete_meta_data_by_mid( $meta_id );
|
$object->delete_meta_data_by_mid( $meta_id );
|
||||||
$this->assertEmpty( $object->get_meta( 'test_meta_key' ) );
|
$this->assertEmpty( $object->get_meta( 'test_meta_key' ) );
|
||||||
}
|
}
|
||||||
|
@ -74,12 +74,12 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* Test: set_props
|
* Test: set_props
|
||||||
*/
|
*/
|
||||||
function test_set_props() {
|
function test_set_props() {
|
||||||
$object = new WC_Mock_WC_Data();
|
$object = new WC_Mock_WC_Data();
|
||||||
$data_to_set = array(
|
$data_to_set = array(
|
||||||
'content' => 'I am a fish',
|
'content' => 'I am a fish',
|
||||||
'bool_value' => true,
|
'bool_value' => true,
|
||||||
);
|
);
|
||||||
$result = $object->set_props( $data_to_set );
|
$result = $object->set_props( $data_to_set );
|
||||||
$this->assertFalse( is_wp_error( $result ) );
|
$this->assertFalse( is_wp_error( $result ) );
|
||||||
$this->assertEquals( 'I am a fish', $object->get_content() );
|
$this->assertEquals( 'I am a fish', $object->get_content() );
|
||||||
$this->assertTrue( $object->get_bool_value() );
|
$this->assertTrue( $object->get_bool_value() );
|
||||||
|
@ -88,7 +88,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
'content' => 'I am also a fish',
|
'content' => 'I am also a fish',
|
||||||
'bool_value' => 'thisisinvalid',
|
'bool_value' => 'thisisinvalid',
|
||||||
);
|
);
|
||||||
$result = $object->set_props( $data_to_set );
|
$result = $object->set_props( $data_to_set );
|
||||||
$this->assertTrue( is_wp_error( $result ) );
|
$this->assertTrue( is_wp_error( $result ) );
|
||||||
$this->assertEquals( 'I am also a fish', $object->get_content() );
|
$this->assertEquals( 'I am also a fish', $object->get_content() );
|
||||||
$this->assertNotEquals( 'thisisinvalid', $object->get_bool_value() );
|
$this->assertNotEquals( 'thisisinvalid', $object->get_bool_value() );
|
||||||
|
@ -119,14 +119,14 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* Tests that the meta data cache is not shared among instances.
|
* Tests that the meta data cache is not shared among instances.
|
||||||
*/
|
*/
|
||||||
function test_get_meta_data_shared_bug() {
|
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_meta_key', 'val1', true );
|
||||||
$object->add_meta_data( 'test_multi_meta_key', 'val2' );
|
$object->add_meta_data( 'test_multi_meta_key', 'val2' );
|
||||||
$object->add_meta_data( 'test_multi_meta_key', 'val3' );
|
$object->add_meta_data( 'test_multi_meta_key', 'val3' );
|
||||||
$object->save();
|
$object->save();
|
||||||
|
|
||||||
$order = new WC_Order( $object->get_id() );
|
$order = new WC_Order( $object->get_id() );
|
||||||
$metas = $order->get_meta_data();
|
$metas = $order->get_meta_data();
|
||||||
$metas[0]->value = 'wrong value';
|
$metas[0]->value = 'wrong value';
|
||||||
|
|
||||||
$order = new WC_Order( $object->get_id() );
|
$order = new WC_Order( $object->get_id() );
|
||||||
|
@ -138,14 +138,14 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* Tests the cache invalidation after an order is saved
|
* Tests the cache invalidation after an order is saved
|
||||||
*/
|
*/
|
||||||
function test_get_meta_data_cache_invalidation() {
|
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_meta_key', 'val1', true );
|
||||||
$object->add_meta_data( 'test_multi_meta_key', 'val2' );
|
$object->add_meta_data( 'test_multi_meta_key', 'val2' );
|
||||||
$object->add_meta_data( 'test_multi_meta_key', 'val3' );
|
$object->add_meta_data( 'test_multi_meta_key', 'val3' );
|
||||||
$object->save();
|
$object->save();
|
||||||
|
|
||||||
$order = new WC_Order( $object->get_id() );
|
$order = new WC_Order( $object->get_id() );
|
||||||
$metas = $order->get_meta_data();
|
$metas = $order->get_meta_data();
|
||||||
$metas[0]->value = 'updated value';
|
$metas[0]->value = 'updated value';
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
|
@ -155,14 +155,14 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_get_meta_data_cache_invalidation_array_to_scalar() {
|
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_meta_key', array( 'val1' ), true );
|
||||||
$object->add_meta_data( 'test_multi_meta_key', 'val2' );
|
$object->add_meta_data( 'test_multi_meta_key', 'val2' );
|
||||||
$object->add_meta_data( 'test_multi_meta_key', 'val3' );
|
$object->add_meta_data( 'test_multi_meta_key', 'val3' );
|
||||||
$object->save();
|
$object->save();
|
||||||
|
|
||||||
$order = new WC_Order( $object->get_id() );
|
$order = new WC_Order( $object->get_id() );
|
||||||
$metas = $order->get_meta_data();
|
$metas = $order->get_meta_data();
|
||||||
$metas[0]->value = 'updated value';
|
$metas[0]->value = 'updated value';
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* Test getting meta by ID.
|
* Test getting meta by ID.
|
||||||
*/
|
*/
|
||||||
function test_get_meta() {
|
function test_get_meta() {
|
||||||
$object = $this->create_test_post();
|
$object = $this->create_test_post();
|
||||||
$object_id = $object->get_id();
|
$object_id = $object->get_id();
|
||||||
$object->add_meta_data( 'test_meta_key', 'val1', true );
|
$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', 'val2' );
|
||||||
|
@ -218,11 +218,11 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* Test getting meta that hasn't been set
|
* Test getting meta that hasn't been set
|
||||||
*/
|
*/
|
||||||
function test_get_meta_no_meta() {
|
function test_get_meta_no_meta() {
|
||||||
$object = $this->create_test_post();
|
$object = $this->create_test_post();
|
||||||
$object_id = $object->get_id();
|
$object_id = $object->get_id();
|
||||||
$object = new WC_Mock_WC_Data( $object_id );
|
$object = new WC_Mock_WC_Data( $object_id );
|
||||||
|
|
||||||
$single_on = $object->get_meta( 'doesnt-exist', true );
|
$single_on = $object->get_meta( 'doesnt-exist', true );
|
||||||
$single_off = $object->get_meta( 'also-doesnt-exist', false );
|
$single_off = $object->get_meta( 'also-doesnt-exist', false );
|
||||||
|
|
||||||
$this->assertEquals( '', $single_on );
|
$this->assertEquals( '', $single_on );
|
||||||
|
@ -234,18 +234,23 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
function test_set_meta_data() {
|
function test_set_meta_data() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$object = $this->create_test_post();
|
$object = $this->create_test_post();
|
||||||
$object_id = $object->get_id();
|
$object_id = $object->get_id();
|
||||||
add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
|
add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
|
||||||
add_metadata( 'post', $object_id, 'test_meta_key_2', 'val2', true );
|
add_metadata( 'post', $object_id, 'test_meta_key_2', 'val2', true );
|
||||||
$object = new WC_Mock_WC_Data( $object_id );
|
$object = new WC_Mock_WC_Data( $object_id );
|
||||||
|
|
||||||
$metadata = array();
|
$metadata = array();
|
||||||
$raw_metadata = $wpdb->get_results( $wpdb->prepare( "
|
$raw_metadata = $wpdb->get_results(
|
||||||
|
$wpdb->prepare(
|
||||||
|
"
|
||||||
SELECT meta_id, meta_key, meta_value
|
SELECT meta_id, meta_key, meta_value
|
||||||
FROM {$wpdb->prefix}postmeta
|
FROM {$wpdb->prefix}postmeta
|
||||||
WHERE post_id = %d ORDER BY meta_id
|
WHERE post_id = %d ORDER BY meta_id
|
||||||
", $object_id ) );
|
",
|
||||||
|
$object_id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
foreach ( $raw_metadata as $meta ) {
|
foreach ( $raw_metadata as $meta ) {
|
||||||
$metadata[] = (object) array(
|
$metadata[] = (object) array(
|
||||||
|
@ -270,9 +275,9 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* Test adding meta data.
|
* Test adding meta data.
|
||||||
*/
|
*/
|
||||||
function test_add_meta_data() {
|
function test_add_meta_data() {
|
||||||
$object = $this->create_test_post();
|
$object = $this->create_test_post();
|
||||||
$object_id = $object->get_id();
|
$object_id = $object->get_id();
|
||||||
$data = 'add_meta_data_' . time();
|
$data = 'add_meta_data_' . time();
|
||||||
$object->add_meta_data( 'test_new_field', $data );
|
$object->add_meta_data( 'test_new_field', $data );
|
||||||
$meta = $object->get_meta( 'test_new_field' );
|
$meta = $object->get_meta( 'test_new_field' );
|
||||||
$this->assertEquals( $data, $meta );
|
$this->assertEquals( $data, $meta );
|
||||||
|
@ -283,19 +288,24 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
function test_update_meta_data() {
|
function test_update_meta_data() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$object = $this->create_test_post();
|
$object = $this->create_test_post();
|
||||||
$object_id = $object->get_id();
|
$object_id = $object->get_id();
|
||||||
add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
|
add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
|
||||||
$object = new WC_Mock_WC_Data( $object_id );
|
$object = new WC_Mock_WC_Data( $object_id );
|
||||||
|
|
||||||
$this->assertEquals( 'val1', $object->get_meta( 'test_meta_key' ) );
|
$this->assertEquals( 'val1', $object->get_meta( 'test_meta_key' ) );
|
||||||
|
|
||||||
$metadata = array();
|
$metadata = array();
|
||||||
$meta_id = $wpdb->get_var( $wpdb->prepare( "
|
$meta_id = $wpdb->get_var(
|
||||||
|
$wpdb->prepare(
|
||||||
|
"
|
||||||
SELECT meta_id
|
SELECT meta_id
|
||||||
FROM {$wpdb->prefix}postmeta
|
FROM {$wpdb->prefix}postmeta
|
||||||
WHERE post_id = %d LIMIT 1
|
WHERE post_id = %d LIMIT 1
|
||||||
", $object_id ) );
|
",
|
||||||
|
$object_id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$object->update_meta_data( 'test_meta_key', 'updated_value', $meta_id );
|
$object->update_meta_data( 'test_meta_key', 'updated_value', $meta_id );
|
||||||
$this->assertEquals( 'updated_value', $object->get_meta( 'test_meta_key' ) );
|
$this->assertEquals( 'updated_value', $object->get_meta( 'test_meta_key' ) );
|
||||||
|
@ -305,7 +315,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* Test deleting meta.
|
* Test deleting meta.
|
||||||
*/
|
*/
|
||||||
function test_delete_meta_data() {
|
function test_delete_meta_data() {
|
||||||
$object = $this->create_test_post();
|
$object = $this->create_test_post();
|
||||||
$object_id = $object->get_id();
|
$object_id = $object->get_id();
|
||||||
add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
|
add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
|
||||||
$object = new WC_Mock_WC_Data( $object_id );
|
$object = new WC_Mock_WC_Data( $object_id );
|
||||||
|
@ -323,18 +333,23 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
function test_save_meta_data() {
|
function test_save_meta_data() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$object = $this->create_test_post();
|
$object = $this->create_test_post();
|
||||||
$object_id = $object->get_id();
|
$object_id = $object->get_id();
|
||||||
$object->add_meta_data( 'test_meta_key', 'val1', true );
|
$object->add_meta_data( 'test_meta_key', 'val1', true );
|
||||||
$object->add_meta_data( 'test_meta_key_2', 'val2', true );
|
$object->add_meta_data( 'test_meta_key_2', 'val2', true );
|
||||||
$object->save_meta_data();
|
$object->save_meta_data();
|
||||||
$object = new WC_Mock_WC_Data( $object_id );
|
$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
|
SELECT meta_id, meta_key, meta_value
|
||||||
FROM {$wpdb->prefix}postmeta
|
FROM {$wpdb->prefix}postmeta
|
||||||
WHERE post_id = %d ORDER BY meta_id
|
WHERE post_id = %d ORDER BY meta_id
|
||||||
", $object_id ) );
|
",
|
||||||
|
$object_id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$object->delete_meta_data( 'test_meta_key' );
|
$object->delete_meta_data( 'test_meta_key' );
|
||||||
$object->update_meta_data( 'test_meta_key_2', 'updated_value', $raw_metadata[1]->meta_id );
|
$object->update_meta_data( 'test_meta_key_2', 'updated_value', $raw_metadata[1]->meta_id );
|
||||||
|
@ -350,7 +365,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* Test reading/getting user meta data too.
|
* Test reading/getting user meta data too.
|
||||||
*/
|
*/
|
||||||
function test_usermeta() {
|
function test_usermeta() {
|
||||||
$object = $this->create_test_user();
|
$object = $this->create_test_user();
|
||||||
$object_id = $object->get_id();
|
$object_id = $object->get_id();
|
||||||
$object->add_meta_data( 'test_meta_key', 'val1', true );
|
$object->add_meta_data( 'test_meta_key', 'val1', true );
|
||||||
$object->add_meta_data( 'test_meta_key_2', 'val2', true );
|
$object->add_meta_data( 'test_meta_key_2', 'val2', true );
|
||||||
|
@ -365,7 +380,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
* data before a save.
|
* data before a save.
|
||||||
*/
|
*/
|
||||||
function test_add_meta_data_overwrite_before_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_0', 'another field', true );
|
||||||
$object->add_meta_data( 'test_field_1', 'another field', true );
|
$object->add_meta_data( 'test_field_1', 'another field', true );
|
||||||
$object->add_meta_data( 'test_field_2', 'val1', true );
|
$object->add_meta_data( 'test_field_2', 'val1', true );
|
||||||
|
@ -504,12 +519,12 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
||||||
'prop3' => 'value3',
|
'prop3' => 'value3',
|
||||||
);
|
);
|
||||||
|
|
||||||
$object = new WC_Mock_WC_Data;
|
$object = new WC_Mock_WC_Data();
|
||||||
$object->set_data( $data );
|
$object->set_data( $data );
|
||||||
$object->set_changes( $changes );
|
$object->set_changes( $changes );
|
||||||
$object->apply_changes();
|
$object->apply_changes();
|
||||||
|
|
||||||
$new_data = $object->get_data();
|
$new_data = $object->get_data();
|
||||||
$new_changes = $object->get_changes();
|
$new_changes = $object->get_changes();
|
||||||
|
|
||||||
$this->assertEquals( 'new_value1', $new_data['prop1'] );
|
$this->assertEquals( 'new_value1', $new_data['prop1'] );
|
||||||
|
@ -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_data( $data );
|
||||||
$object->set_changes( $changes );
|
$object->set_changes( $changes );
|
||||||
$object->apply_changes();
|
$object->apply_changes();
|
||||||
|
|
|
@ -36,7 +36,7 @@ class WC_Tests_CRUD_Meta_Data extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
function test_disappearing_item_meta() {
|
function test_disappearing_item_meta() {
|
||||||
// Setup for testing by making an item.
|
// Setup for testing by making an item.
|
||||||
$item = new WC_Order_Item_Product();
|
$item = new WC_Order_Item_Product();
|
||||||
$this->item_id = $item->save();
|
$this->item_id = $item->save();
|
||||||
|
|
||||||
$item = WC_Order_Factory::get_order_item( $this->item_id );
|
$item = WC_Order_Factory::get_order_item( $this->item_id );
|
||||||
|
@ -78,7 +78,7 @@ class WC_Tests_CRUD_Meta_Data extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
function test_disappearing_order_meta() {
|
function test_disappearing_order_meta() {
|
||||||
// Setup for testing by making an item.
|
// Setup for testing by making an item.
|
||||||
$order = new WC_Order();
|
$order = new WC_Order();
|
||||||
$this->order_id = $order->save();
|
$this->order_id = $order->save();
|
||||||
|
|
||||||
$order = wc_get_order( $this->order_id );
|
$order = wc_get_order( $this->order_id );
|
||||||
|
@ -119,7 +119,7 @@ class WC_Tests_CRUD_Meta_Data extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
function test_get_meta_data_after_update_post_meta() {
|
function test_get_meta_data_after_update_post_meta() {
|
||||||
// Create an object.
|
// Create an object.
|
||||||
$object = new WC_Product;
|
$object = new WC_Product();
|
||||||
$object->save();
|
$object->save();
|
||||||
|
|
||||||
// Update a meta value.
|
// Update a meta value.
|
||||||
|
@ -138,8 +138,8 @@ class WC_Tests_CRUD_Meta_Data extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
function test_strings_in_meta() {
|
function test_strings_in_meta() {
|
||||||
// Create objects.
|
// Create objects.
|
||||||
$object = new WC_Product;
|
$object = new WC_Product();
|
||||||
$object_to_store = new stdClass();
|
$object_to_store = new stdClass();
|
||||||
$object_to_store->prop1 = 'prop_value';
|
$object_to_store->prop1 = 'prop_value';
|
||||||
$object_to_store->prop2 = 'prop_value_with_\\\"quotes"';
|
$object_to_store->prop2 = 'prop_value_with_\\\"quotes"';
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class WC_Tests_CRUD_Meta_Data extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
// Get object and check it.
|
// Get object and check it.
|
||||||
$object = wc_get_product( $object_id );
|
$object = wc_get_product( $object_id );
|
||||||
$value = $object->get_meta( 'Test Object', true );
|
$value = $object->get_meta( 'Test Object', true );
|
||||||
|
|
||||||
$this->assertEquals( $object_to_store, $object->get_meta( 'Test Object', true ) );
|
$this->assertEquals( $object_to_store, $object->get_meta( 'Test Object', true ) );
|
||||||
$this->assertEquals( 'Test\slashes', $object->get_meta( 'Test meta with slash', true ) );
|
$this->assertEquals( 'Test\slashes', $object->get_meta( 'Test meta with slash', true ) );
|
||||||
|
|
|
@ -26,7 +26,7 @@ class WC_Tests_WC_Object_Query extends WC_Unit_Test_Case {
|
||||||
* @since 3.1.0
|
* @since 3.1.0
|
||||||
*/
|
*/
|
||||||
function test_query_with_args() {
|
function test_query_with_args() {
|
||||||
$args = array(
|
$args = array(
|
||||||
'limit' => 15,
|
'limit' => 15,
|
||||||
);
|
);
|
||||||
$query = new WC_Mock_WC_Object_Query( $args );
|
$query = new WC_Mock_WC_Object_Query( $args );
|
||||||
|
|
|
@ -29,7 +29,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_update_customer() {
|
public function test_update_customer() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$this->assertEquals( 'test@woo.local', $customer->get_email() );
|
$this->assertEquals( 'test@woo.local', $customer->get_email() );
|
||||||
$this->assertEquals( 'Apt 1', $customer->get_billing_address_2() );
|
$this->assertEquals( 'Apt 1', $customer->get_billing_address_2() );
|
||||||
|
@ -58,7 +58,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( 0, $customer->get_id() );
|
$this->assertEquals( 0, $customer->get_id() );
|
||||||
$customer->save();
|
$customer->save();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$wp_user = new WP_User( $customer->get_id() );
|
$wp_user = new WP_User( $customer->get_id() );
|
||||||
|
|
||||||
$this->assertNotEquals( 0, $customer->get_id() );
|
$this->assertNotEquals( 0, $customer->get_id() );
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_delete_customer() {
|
public function test_delete_customer() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$this->assertNotEquals( 0, $customer->get_id() );
|
$this->assertNotEquals( 0, $customer->get_id() );
|
||||||
$customer->delete();
|
$customer->delete();
|
||||||
|
@ -97,7 +97,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
$customer->set_last_name( 'Bob' );
|
$customer->set_last_name( 'Bob' );
|
||||||
$customer->set_display_name( 'Billy Bob' );
|
$customer->set_display_name( 'Billy Bob' );
|
||||||
$customer->save();
|
$customer->save();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$customer_read = new WC_Customer( $customer_id );
|
$customer_read = new WC_Customer( $customer_id );
|
||||||
|
|
||||||
$this->assertEquals( $customer_id, $customer_read->get_id() );
|
$this->assertEquals( $customer_id, $customer_read->get_id() );
|
||||||
|
@ -179,35 +179,35 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_customer_setters_and_getters() {
|
public function test_customer_setters_and_getters() {
|
||||||
$time = time();
|
$time = time();
|
||||||
$setters = array(
|
$setters = array(
|
||||||
'username' => 'test',
|
'username' => 'test',
|
||||||
'email' => 'test@woo.local',
|
'email' => 'test@woo.local',
|
||||||
'first_name' => 'Bob',
|
'first_name' => 'Bob',
|
||||||
'last_name' => 'tester',
|
'last_name' => 'tester',
|
||||||
'display_name' => 'Bob Tester',
|
'display_name' => 'Bob Tester',
|
||||||
'role' => 'customer',
|
'role' => 'customer',
|
||||||
'date_created' => $time,
|
'date_created' => $time,
|
||||||
'date_modified' => $time,
|
'date_modified' => $time,
|
||||||
'billing_postcode' => 11010,
|
'billing_postcode' => 11010,
|
||||||
'billing_city' => 'New York',
|
'billing_city' => 'New York',
|
||||||
'billing_address' => '123 Main St.',
|
'billing_address' => '123 Main St.',
|
||||||
'billing_address_1' => '123 Main St.',
|
'billing_address_1' => '123 Main St.',
|
||||||
'billing_address_2' => 'Apt 2',
|
'billing_address_2' => 'Apt 2',
|
||||||
'billing_state' => 'NY',
|
'billing_state' => 'NY',
|
||||||
'billing_country' => 'US',
|
'billing_country' => 'US',
|
||||||
'shipping_state' => 'NY',
|
'shipping_state' => 'NY',
|
||||||
'shipping_postcode' => 11011,
|
'shipping_postcode' => 11011,
|
||||||
'shipping_city' => 'New York',
|
'shipping_city' => 'New York',
|
||||||
'shipping_address' => '123 Main St.',
|
'shipping_address' => '123 Main St.',
|
||||||
'shipping_address_1' => '123 Main St.',
|
'shipping_address_1' => '123 Main St.',
|
||||||
'shipping_address_2' => 'Apt 2',
|
'shipping_address_2' => 'Apt 2',
|
||||||
'is_vat_exempt' => true,
|
'is_vat_exempt' => true,
|
||||||
'calculated_shipping' => true,
|
'calculated_shipping' => true,
|
||||||
'is_paying_customer' => true,
|
'is_paying_customer' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
$customer = new WC_Customer;
|
$customer = new WC_Customer();
|
||||||
|
|
||||||
foreach ( $setters as $method => $value ) {
|
foreach ( $setters as $method => $value ) {
|
||||||
$customer->{"set_{$method}"}( $value );
|
$customer->{"set_{$method}"}( $value );
|
||||||
|
@ -220,7 +220,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get timestamps from date_created and date_modified.
|
// Get timestamps from date_created and date_modified.
|
||||||
$getters['date_created'] = $getters['date_created']->getOffsetTimestamp();
|
$getters['date_created'] = $getters['date_created']->getOffsetTimestamp();
|
||||||
$getters['date_modified'] = $getters['date_modified']->getOffsetTimestamp();
|
$getters['date_modified'] = $getters['date_modified']->getOffsetTimestamp();
|
||||||
|
|
||||||
$this->assertEquals( $setters, $getters );
|
$this->assertEquals( $setters, $getters );
|
||||||
|
@ -231,11 +231,11 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_customer_get_last_order_info() {
|
public function test_customer_get_last_order_info() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$order = WC_Helper_Order::create_order( $customer_id );
|
$order = WC_Helper_Order::create_order( $customer_id );
|
||||||
$customer = new WC_Customer( $customer_id );
|
$customer = new WC_Customer( $customer_id );
|
||||||
$last_order = $customer->get_last_order();
|
$last_order = $customer->get_last_order();
|
||||||
$this->assertEquals( $order->get_id(), $last_order ? $last_order->get_id() : 0 );
|
$this->assertEquals( $order->get_id(), $last_order ? $last_order->get_id() : 0 );
|
||||||
$this->assertEquals( $order->get_date_created(), $last_order ? $last_order->get_date_created() : 0 );
|
$this->assertEquals( $order->get_date_created(), $last_order ? $last_order->get_date_created() : 0 );
|
||||||
$order->delete();
|
$order->delete();
|
||||||
|
@ -246,7 +246,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_customer_get_order_count_read() {
|
public function test_customer_get_order_count_read() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
WC_Helper_Order::create_order( $customer_id );
|
WC_Helper_Order::create_order( $customer_id );
|
||||||
WC_Helper_Order::create_order( $customer_id );
|
WC_Helper_Order::create_order( $customer_id );
|
||||||
|
@ -260,10 +260,10 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_customer_get_total_spent_read() {
|
public function test_customer_get_total_spent_read() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$order = WC_Helper_Order::create_order( $customer_id );
|
$order = WC_Helper_Order::create_order( $customer_id );
|
||||||
$customer = new WC_Customer( $customer_id );
|
$customer = new WC_Customer( $customer_id );
|
||||||
$this->assertEquals( 0, $customer->get_total_spent() );
|
$this->assertEquals( 0, $customer->get_total_spent() );
|
||||||
$order->update_status( 'wc-completed' );
|
$order->update_status( 'wc-completed' );
|
||||||
$customer = new WC_Customer( $customer_id );
|
$customer = new WC_Customer( $customer_id );
|
||||||
|
@ -286,9 +286,9 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_customer_get_date_created_read() {
|
public function test_customer_get_date_created_read() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$user = new WP_User( $customer_id );
|
$user = new WP_User( $customer_id );
|
||||||
$this->assertEquals( strtotime( $user->data->user_registered ), $customer->get_date_created()->getOffsetTimestamp() );
|
$this->assertEquals( strtotime( $user->data->user_registered ), $customer->get_date_created()->getOffsetTimestamp() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,9 +297,9 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_customer_get_date_modified_read() {
|
public function test_customer_get_date_modified_read() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$last = get_user_meta( $customer_id, 'last_update', true );
|
$last = get_user_meta( $customer_id, 'last_update', true );
|
||||||
sleep( 1 );
|
sleep( 1 );
|
||||||
$this->assertEquals( $last, $customer->get_date_modified()->getOffsetTimestamp() );
|
$this->assertEquals( $last, $customer->get_date_modified()->getOffsetTimestamp() );
|
||||||
$customer->set_billing_address( '1234 Some St.' );
|
$customer->set_billing_address( '1234 Some St.' );
|
||||||
|
@ -314,7 +314,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_customer_get_taxable_address() {
|
public function test_customer_get_taxable_address() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$customer->set_shipping_postcode( '11111' );
|
$customer->set_shipping_postcode( '11111' );
|
||||||
$customer->set_shipping_city( 'Test' );
|
$customer->set_shipping_city( 'Test' );
|
||||||
|
@ -348,7 +348,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_customer_get_downloadable_products() {
|
public function test_customer_get_downloadable_products() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$this->assertEquals( wc_get_customer_available_downloads( $customer_id ), $customer->get_downloadable_products() );
|
$this->assertEquals( wc_get_customer_available_downloads( $customer_id ), $customer->get_downloadable_products() );
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_customer_password() {
|
public function test_customer_password() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
|
|
||||||
$user = get_user_by( 'id', $customer_id );
|
$user = get_user_by( 'id', $customer_id );
|
||||||
|
@ -460,7 +460,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
// should still be session ID, not a created row, since we are working with guests/sessions
|
// should still be session ID, not a created row, since we are working with guests/sessions
|
||||||
$this->assertFalse( $session->get_id() > 0 );
|
$this->assertFalse( $session->get_id() > 0 );
|
||||||
$this->assertEquals( '32191' , $session->get_billing_postcode() );
|
$this->assertEquals( '32191', $session->get_billing_postcode() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -468,12 +468,12 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_get_meta() {
|
public function test_get_meta() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$meta_value = time() . '-custom-value';
|
$meta_value = time() . '-custom-value';
|
||||||
add_user_meta( $customer_id, 'test_field', $meta_value, true );
|
add_user_meta( $customer_id, 'test_field', $meta_value, true );
|
||||||
$customer = new WC_Customer( $customer_id );
|
$customer = new WC_Customer( $customer_id );
|
||||||
$fields = $customer->get_meta_data();
|
$fields = $customer->get_meta_data();
|
||||||
$this->assertEquals( $meta_value, $customer->get_meta( 'test_field' ) );
|
$this->assertEquals( $meta_value, $customer->get_meta( 'test_field' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,9 +482,9 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_set_meta() {
|
public function test_set_meta() {
|
||||||
$customer = WC_Helper_Customer::create_customer();
|
$customer = WC_Helper_Customer::create_customer();
|
||||||
$customer_id = $customer->get_id();
|
$customer_id = $customer->get_id();
|
||||||
$meta_value = time() . '-custom-value';
|
$meta_value = time() . '-custom-value';
|
||||||
$customer->add_meta_data( 'my-field', $meta_value, true );
|
$customer->add_meta_data( 'my-field', $meta_value, true );
|
||||||
$customer->save();
|
$customer->save();
|
||||||
$customer = new WC_Customer( $customer_id );
|
$customer = new WC_Customer( $customer_id );
|
||||||
|
|
|
@ -137,9 +137,11 @@ class WC_Tests_Customer_Download_Log extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
// Make sure download log was recorded properly.
|
// Make sure download log was recorded properly.
|
||||||
$data_store = WC_Data_Store::load( 'customer-download-log' );
|
$data_store = WC_Data_Store::load( 'customer-download-log' );
|
||||||
$download_logs = $data_store->get_download_logs( array(
|
$download_logs = $data_store->get_download_logs(
|
||||||
'permission_id' => $download_1->get_id(),
|
array(
|
||||||
) );
|
'permission_id' => $download_1->get_id(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertEquals( 1, count( $download_logs ), 'After single download, permission should have one download log in database.' );
|
$this->assertEquals( 1, count( $download_logs ), 'After single download, permission should have one download log in database.' );
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ class WC_Tests_Customer_Functions extends WC_Unit_Test_Case {
|
||||||
'bob@bobbobson.com',
|
'bob@bobbobson.com',
|
||||||
array(
|
array(
|
||||||
'first_name' => 'Bob',
|
'first_name' => 'Bob',
|
||||||
'last_name' => 'Bobson',
|
'last_name' => 'Bobson',
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -110,7 +110,7 @@ class WC_Tests_Customer_Functions extends WC_Unit_Test_Case {
|
||||||
'unicode@unicode.com',
|
'unicode@unicode.com',
|
||||||
array(
|
array(
|
||||||
'first_name' => 'こんにちは',
|
'first_name' => 'こんにちは',
|
||||||
'last_name' => 'こんにちは',
|
'last_name' => 'こんにちは',
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -213,21 +213,21 @@ class WC_Tests_Paypal_Gateway_Request extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( '_cart', $query_array['cmd'] );
|
$this->assertEquals( '_cart', $query_array['cmd'] );
|
||||||
|
|
||||||
$this->check_shipping_tax( $query_array, $shipping_tax_included );
|
$this->check_shipping_tax( $query_array, $shipping_tax_included );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test removing HTML tags from product title and request URL
|
|
||||||
*
|
|
||||||
* @param bool $testmode Whether to use Paypal sandbox.
|
|
||||||
*/
|
|
||||||
protected function check_product_title_containing_html( $testmode ) {
|
|
||||||
$order = WC_Helper_Order::create_order();
|
|
||||||
|
|
||||||
foreach ( $order->get_items() as $item ) {
|
/**
|
||||||
|
* Test removing HTML tags from product title and request URL
|
||||||
|
*
|
||||||
|
* @param bool $testmode Whether to use Paypal sandbox.
|
||||||
|
*/
|
||||||
|
protected function check_product_title_containing_html( $testmode ) {
|
||||||
|
$order = WC_Helper_Order::create_order();
|
||||||
|
|
||||||
|
foreach ( $order->get_items() as $item ) {
|
||||||
$order->remove_item( $item->get_id() );
|
$order->remove_item( $item->get_id() );
|
||||||
}
|
}
|
||||||
|
|
||||||
$product = new WC_Product_Simple();
|
$product = new WC_Product_Simple();
|
||||||
$product->set_props(
|
$product->set_props(
|
||||||
array(
|
array(
|
||||||
'name' => 'New Product <a href="#" style="color: red;">Link</a>',
|
'name' => 'New Product <a href="#" style="color: red;">Link</a>',
|
||||||
|
@ -235,33 +235,35 @@ class WC_Tests_Paypal_Gateway_Request extends WC_Unit_Test_Case {
|
||||||
'price' => 10,
|
'price' => 10,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$product->save();
|
$product->save();
|
||||||
$product = wc_get_product( $product->get_id() );
|
$product = wc_get_product( $product->get_id() );
|
||||||
|
|
||||||
$qty = 1;
|
$qty = 1;
|
||||||
|
|
||||||
$item = new WC_Order_Item_Product();
|
|
||||||
$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 );
|
|
||||||
$order->save();
|
|
||||||
|
|
||||||
$request_url = $this->paypal_request->get_request_url( $order, $testmode );
|
$item = new WC_Order_Item_Product();
|
||||||
|
$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();
|
||||||
|
|
||||||
$query_string = wp_parse_url( $request_url, PHP_URL_QUERY )
|
$order->add_item( $item );
|
||||||
|
$order->save();
|
||||||
|
|
||||||
|
$request_url = $this->paypal_request->get_request_url( $order, $testmode );
|
||||||
|
|
||||||
|
$query_string = wp_parse_url( $request_url, PHP_URL_QUERY )
|
||||||
? wp_parse_url( $request_url, PHP_URL_QUERY )
|
? wp_parse_url( $request_url, PHP_URL_QUERY )
|
||||||
: '';
|
: '';
|
||||||
$query_array = array();
|
$query_array = array();
|
||||||
parse_str( $query_string, $query_array );
|
parse_str( $query_string, $query_array );
|
||||||
|
|
||||||
$this->assertEquals( $query_array['item_name_1'], 'New Product Link x ' . $qty );
|
$this->assertEquals( $query_array['item_name_1'], 'New Product Link x ' . $qty );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if value is < 0, false otherwise.
|
* Return true if value is < 0, false otherwise.
|
||||||
|
@ -395,10 +397,10 @@ class WC_Tests_Paypal_Gateway_Request extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
// Test order with URL longer than limit.
|
// Test order with URL longer than limit.
|
||||||
// Many items in order -> forced to use one line item -> shipping tax included.
|
// Many items in order -> forced to use one line item -> shipping tax included.
|
||||||
$this->check_large_order( true, $testmode );
|
$this->check_large_order( true, $testmode );
|
||||||
|
|
||||||
// Test removing tags from line item name
|
// Test removing tags from line item name
|
||||||
$this->check_product_title_containing_html( $testmode );
|
$this->check_product_title_containing_html( $testmode );
|
||||||
|
|
||||||
// Test amount < 0.
|
// Test amount < 0.
|
||||||
$this->check_negative_amount( $testmode );
|
$this->check_negative_amount( $testmode );
|
||||||
|
|
|
@ -599,7 +599,7 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* This function is called by WP_HTTP_TestCase::http_request_listner().
|
* This function is called by WP_HTTP_TestCase::http_request_listner().
|
||||||
*
|
*
|
||||||
* @param array $request Request arguments.
|
* @param array $request Request arguments.
|
||||||
* @param string $url URL of the request.
|
* @param string $url URL of the request.
|
||||||
*
|
*
|
||||||
* @return array|false mocked response or false to let WP perform a regular request.
|
* @return array|false mocked response or false to let WP perform a regular request.
|
||||||
|
|
|
@ -33,7 +33,7 @@ class WC_Tests_Integrations extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( array(), $integrations->integrations );
|
$this->assertEquals( array(), $integrations->integrations );
|
||||||
$this->assertEquals( array(), $integrations->get_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' ) );
|
add_filter( 'woocommerce_integrations', array( $this, 'add_dummy_integration' ) );
|
||||||
$integrations = new WC_Integrations();
|
$integrations = new WC_Integrations();
|
||||||
|
|
|
@ -18,12 +18,14 @@ class WC_Tests_Libraries_Background_Process extends WC_Unit_Test_Case {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function test_is_queue_empty() {
|
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();
|
$queue = new WC_Mock_Background_Process();
|
||||||
$this->assertEquals( true, $queue->is_queue_empty() );
|
$this->assertEquals( true, $queue->is_queue_empty() );
|
||||||
$queue->push_to_queue( array(
|
$queue->push_to_queue(
|
||||||
'mock_key' => 'mock_value',
|
array(
|
||||||
) );
|
'mock_key' => 'mock_value',
|
||||||
|
)
|
||||||
|
);
|
||||||
$queue->save();
|
$queue->save();
|
||||||
$this->assertEquals( false, $queue->is_queue_empty() );
|
$this->assertEquals( false, $queue->is_queue_empty() );
|
||||||
}
|
}
|
||||||
|
@ -34,7 +36,7 @@ class WC_Tests_Libraries_Background_Process extends WC_Unit_Test_Case {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function test_schedule_cron_healthcheck() {
|
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();
|
$queue = new WC_Mock_Background_Process();
|
||||||
$this->assertArrayHasKey( 'wp_' . get_current_blog_id() . '_wc_mock_background_process_cron_interval', $queue->schedule_cron_healthcheck( array() ) );
|
$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.
|
* Test prefix & action against identifier.
|
||||||
*/
|
*/
|
||||||
public function test_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();
|
$queue = new WC_Mock_Background_Process();
|
||||||
$this->assertEquals( 'wp_' . get_current_blog_id() . '_wc_mock_background_process', $queue->get_identifier() );
|
$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
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function test_get_batch() {
|
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 = new WC_Mock_Background_Process();
|
||||||
$queue->push_to_queue( array(
|
$queue->push_to_queue(
|
||||||
'mock_key' => 'mock_value',
|
array(
|
||||||
) );
|
'mock_key' => 'mock_value',
|
||||||
|
)
|
||||||
|
);
|
||||||
$queue->save();
|
$queue->save();
|
||||||
$this->assertNotEmpty( $queue->get_batch() );
|
$this->assertNotEmpty( $queue->get_batch() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ class WC_Tests_Log_Handler_Email extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_handle() {
|
public function test_handle() {
|
||||||
$mailer = tests_retrieve_phpmailer_instance();
|
$mailer = tests_retrieve_phpmailer_instance();
|
||||||
$time = time();
|
$time = time();
|
||||||
$site_name = get_bloginfo( 'name' );
|
$site_name = get_bloginfo( 'name' );
|
||||||
|
|
||||||
$handler = new WC_Log_Handler_Email();
|
$handler = new WC_Log_Handler_Email();
|
||||||
|
@ -82,8 +82,8 @@ class WC_Tests_Log_Handler_Email extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_email_subject() {
|
public function test_email_subject() {
|
||||||
$mailer = tests_retrieve_phpmailer_instance();
|
$mailer = tests_retrieve_phpmailer_instance();
|
||||||
$time = time();
|
$time = time();
|
||||||
$site_name = get_bloginfo( 'name' );
|
$site_name = get_bloginfo( 'name' );
|
||||||
|
|
||||||
$handler = new WC_Log_Handler_Email( null, WC_Log_Levels::DEBUG );
|
$handler = new WC_Log_Handler_Email( null, WC_Log_Levels::DEBUG );
|
||||||
|
@ -114,10 +114,12 @@ class WC_Tests_Log_Handler_Email extends WC_Unit_Test_Case {
|
||||||
public function test_multiple_recipients() {
|
public function test_multiple_recipients() {
|
||||||
$mailer = tests_retrieve_phpmailer_instance();
|
$mailer = tests_retrieve_phpmailer_instance();
|
||||||
|
|
||||||
$handler = new WC_Log_Handler_Email( array(
|
$handler = new WC_Log_Handler_Email(
|
||||||
'first@test.com',
|
array(
|
||||||
'Second Recipient <second@test.com>',
|
'first@test.com',
|
||||||
) );
|
'Second Recipient <second@test.com>',
|
||||||
|
)
|
||||||
|
);
|
||||||
$handler->handle( time(), 'emergency', '', array() );
|
$handler->handle( time(), 'emergency', '', array() );
|
||||||
$handler->send_log_email();
|
$handler->send_log_email();
|
||||||
|
|
||||||
|
@ -141,7 +143,7 @@ class WC_Tests_Log_Handler_Email extends WC_Unit_Test_Case {
|
||||||
$handler->handle( time(), 'emergency', '', array() );
|
$handler->handle( time(), 'emergency', '', array() );
|
||||||
$handler->send_log_email();
|
$handler->send_log_email();
|
||||||
|
|
||||||
$recipient = $mailer->get_recipient( 'to' );
|
$recipient = $mailer->get_recipient( 'to' );
|
||||||
$this->assertEquals( 'user@test.com', $recipient->address );
|
$this->assertEquals( 'user@test.com', $recipient->address );
|
||||||
$this->assertEquals( 'User', $recipient->name );
|
$this->assertEquals( 'User', $recipient->name );
|
||||||
}
|
}
|
||||||
|
@ -200,7 +202,7 @@ class WC_Tests_Log_Handler_Email extends WC_Unit_Test_Case {
|
||||||
$mailer = tests_retrieve_phpmailer_instance();
|
$mailer = tests_retrieve_phpmailer_instance();
|
||||||
|
|
||||||
$handler = new WC_Log_Handler_Email();
|
$handler = new WC_Log_Handler_Email();
|
||||||
$time = time();
|
$time = time();
|
||||||
$handler->handle( $time, 'emergency', 'message 1', array() );
|
$handler->handle( $time, 'emergency', 'message 1', array() );
|
||||||
$handler->send_log_email();
|
$handler->send_log_email();
|
||||||
$handler->handle( $time, 'emergency', 'message 2', array() );
|
$handler->handle( $time, 'emergency', 'message 2', array() );
|
||||||
|
|
|
@ -47,10 +47,15 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
public function test_legacy_format() {
|
public function test_legacy_format() {
|
||||||
$handler = new WC_Log_Handler_File( array( 'threshold' => 'debug' ) );
|
$handler = new WC_Log_Handler_File( array( 'threshold' => 'debug' ) );
|
||||||
|
|
||||||
$handler->handle( time(), 'info', 'this is a message', array(
|
$handler->handle(
|
||||||
'source' => 'unit-tests',
|
time(),
|
||||||
'_legacy' => true,
|
'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->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' ) );
|
$this->assertStringEndsWith( ' - this is a message' . PHP_EOL, $this->read_content( 'unit-tests' ) );
|
||||||
|
@ -62,7 +67,7 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_clear() {
|
public function test_clear() {
|
||||||
$handler = new WC_Log_Handler_File();
|
$handler = new WC_Log_Handler_File();
|
||||||
$log_name = '_test_clear';
|
$log_name = '_test_clear';
|
||||||
$handler->handle( time(), 'debug', 'debug', array( 'source' => $log_name ) );
|
$handler->handle( time(), 'debug', 'debug', array( 'source' => $log_name ) );
|
||||||
$handler->clear( $log_name );
|
$handler->clear( $log_name );
|
||||||
|
@ -75,7 +80,7 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_remove() {
|
public function test_remove() {
|
||||||
$handler = new WC_Log_Handler_File();
|
$handler = new WC_Log_Handler_File();
|
||||||
$log_name = '_test_remove';
|
$log_name = '_test_remove';
|
||||||
$handler->handle( time(), 'debug', 'debug', array( 'source' => $log_name ) );
|
$handler->handle( time(), 'debug', 'debug', array( 'source' => $log_name ) );
|
||||||
$handler->remove( wc_get_log_file_name( $log_name ) );
|
$handler->remove( wc_get_log_file_name( $log_name ) );
|
||||||
|
@ -89,7 +94,7 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_writes_file() {
|
public function test_writes_file() {
|
||||||
$handler = new WC_Log_Handler_File();
|
$handler = new WC_Log_Handler_File();
|
||||||
$time = time();
|
$time = time();
|
||||||
|
|
||||||
$handler->handle( $time, 'debug', 'debug', array() );
|
$handler->handle( $time, 'debug', 'debug', array() );
|
||||||
$handler->handle( $time, 'info', 'info', array() );
|
$handler->handle( $time, 'info', 'info', array() );
|
||||||
|
@ -110,8 +115,8 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_log_file_source() {
|
public function test_log_file_source() {
|
||||||
$handler = new WC_Log_Handler_File();
|
$handler = new WC_Log_Handler_File();
|
||||||
$time = time();
|
$time = time();
|
||||||
$context_source = array( 'source' => 'unit-tests' );
|
$context_source = array( 'source' => 'unit-tests' );
|
||||||
|
|
||||||
$handler->handle( $time, 'debug', 'debug', $context_source );
|
$handler->handle( $time, 'debug', 'debug', $context_source );
|
||||||
|
@ -133,9 +138,9 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_multiple_handlers() {
|
public function test_multiple_handlers() {
|
||||||
$handler_a = new WC_Log_Handler_File();
|
$handler_a = new WC_Log_Handler_File();
|
||||||
$handler_b = new WC_Log_Handler_File();
|
$handler_b = new WC_Log_Handler_File();
|
||||||
$time = time();
|
$time = time();
|
||||||
$context_source = array( 'source' => 'unit-tests' );
|
$context_source = array( 'source' => 'unit-tests' );
|
||||||
|
|
||||||
// Different loggers should not conflict.
|
// Different loggers should not conflict.
|
||||||
|
@ -162,9 +167,9 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
public function test_log_rotate() {
|
public function test_log_rotate() {
|
||||||
|
|
||||||
// Handler with log size limit of 5mb
|
// Handler with log size limit of 5mb
|
||||||
$handler = new WC_Log_Handler_File( 5 * 1024 * 1024 );
|
$handler = new WC_Log_Handler_File( 5 * 1024 * 1024 );
|
||||||
$time = time();
|
$time = time();
|
||||||
$log_name = '_test_log_rotate';
|
$log_name = '_test_log_rotate';
|
||||||
$base_log_file = WC_Log_Handler_File::get_log_file_path( $log_name );
|
$base_log_file = WC_Log_Handler_File::get_log_file_path( $log_name );
|
||||||
|
|
||||||
// Create log file larger than 5mb to ensure log is rotated
|
// Create log file larger than 5mb to ensure log is rotated
|
||||||
|
@ -199,9 +204,9 @@ class WC_Tests_Log_Handler_File extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_get_log_file_path() {
|
public function test_get_log_file_path() {
|
||||||
$log_dir = trailingslashit( WC_LOG_DIR );
|
$log_dir = trailingslashit( WC_LOG_DIR );
|
||||||
$date_suffix = date( 'Y-m-d', current_time( 'timestamp', true ) );
|
$date_suffix = date( 'Y-m-d', current_time( 'timestamp', true ) );
|
||||||
$hash_name = sanitize_file_name( wp_hash( 'unit-tests' ) );
|
$hash_name = sanitize_file_name( wp_hash( 'unit-tests' ) );
|
||||||
$this->assertEquals( $log_dir . 'unit-tests-' . $date_suffix . '-' . $hash_name . '.log', WC_Log_Handler_File::get_log_file_path( 'unit-tests' ) );
|
$this->assertEquals( $log_dir . 'unit-tests-' . $date_suffix . '-' . $hash_name . '.log', WC_Log_Handler_File::get_log_file_path( 'unit-tests' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class WC_Tests_Log_Levels extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function test_get_level_severity() {
|
public function test_get_level_severity() {
|
||||||
$this->assertEquals( 0, WC_Log_Levels::get_level_severity( 'unrecognized level' ) );
|
$this->assertEquals( 0, WC_Log_Levels::get_level_severity( 'unrecognized level' ) );
|
||||||
$this->assertEquals( 100, WC_Log_Levels::get_level_severity( 'debug' ) );
|
$this->assertEquals( 100, WC_Log_Levels::get_level_severity( 'debug' ) );
|
||||||
$this->assertEquals( 200, WC_Log_Levels::get_level_severity( 'info' ) );
|
$this->assertEquals( 200, WC_Log_Levels::get_level_severity( 'info' ) );
|
||||||
$this->assertEquals( 300, WC_Log_Levels::get_level_severity( 'notice' ) );
|
$this->assertEquals( 300, WC_Log_Levels::get_level_severity( 'notice' ) );
|
||||||
|
|
|
@ -13,7 +13,7 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
* @since 2.4
|
* @since 2.4
|
||||||
*/
|
*/
|
||||||
public function test_add() {
|
public function test_add() {
|
||||||
$time = time();
|
$time = time();
|
||||||
$handler = $this
|
$handler = $this
|
||||||
->getMockBuilder( 'WC_Log_Handler_Interface' )
|
->getMockBuilder( 'WC_Log_Handler_Interface' )
|
||||||
->setMethods( array( 'handle' ) )
|
->setMethods( array( 'handle' ) )
|
||||||
|
@ -25,10 +25,12 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
$this->greaterThanOrEqual( $time ),
|
$this->greaterThanOrEqual( $time ),
|
||||||
$this->equalTo( 'notice' ),
|
$this->equalTo( 'notice' ),
|
||||||
$this->equalTo( 'this is a message' ),
|
$this->equalTo( 'this is a message' ),
|
||||||
$this->equalTo( array(
|
$this->equalTo(
|
||||||
'source' => 'unit-tests',
|
array(
|
||||||
'_legacy' => true,
|
'source' => 'unit-tests',
|
||||||
) )
|
'_legacy' => true,
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
$log = new WC_Logger( array( $handler ), 'debug' );
|
$log = new WC_Logger( array( $handler ), 'debug' );
|
||||||
|
|
||||||
|
@ -66,7 +68,7 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_log() {
|
public function test_log() {
|
||||||
$handler = $this->create_mock_handler();
|
$handler = $this->create_mock_handler();
|
||||||
$log = new WC_Logger( array( $handler ), 'debug' );
|
$log = new WC_Logger( array( $handler ), 'debug' );
|
||||||
$log->log( 'debug', 'debug message' );
|
$log->log( 'debug', 'debug message' );
|
||||||
$log->log( 'info', 'info message' );
|
$log->log( 'info', 'info message' );
|
||||||
$log->log( 'notice', 'notice message' );
|
$log->log( 'notice', 'notice message' );
|
||||||
|
@ -120,7 +122,7 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_level_methods() {
|
public function test_level_methods() {
|
||||||
$handler = $this->create_mock_handler();
|
$handler = $this->create_mock_handler();
|
||||||
$log = new WC_Logger( array( $handler ), 'debug' );
|
$log = new WC_Logger( array( $handler ), 'debug' );
|
||||||
$log->debug( 'debug message' );
|
$log->debug( 'debug message' );
|
||||||
$log->info( 'info message' );
|
$log->info( 'info message' );
|
||||||
$log->notice( 'notice message' );
|
$log->notice( 'notice message' );
|
||||||
|
@ -242,7 +244,7 @@ class WC_Tests_Logger extends WC_Unit_Test_Case {
|
||||||
* @return WC_Log_Handler mock object
|
* @return WC_Log_Handler mock object
|
||||||
*/
|
*/
|
||||||
public function create_mock_handler() {
|
public function create_mock_handler() {
|
||||||
$time = time();
|
$time = time();
|
||||||
$handler = $this
|
$handler = $this
|
||||||
->getMockBuilder( 'WC_Log_Handler_Interface' )
|
->getMockBuilder( 'WC_Log_Handler_Interface' )
|
||||||
->setMethods( array( 'handle' ) )
|
->setMethods( array( 'handle' ) )
|
||||||
|
|
|
@ -146,10 +146,12 @@ class WC_Tests_Order_Item_Product extends WC_Unit_Test_Case {
|
||||||
$variation_product = new WC_Product_Variation();
|
$variation_product = new WC_Product_Variation();
|
||||||
$variation_product->set_name( 'Test Variation' );
|
$variation_product->set_name( 'Test Variation' );
|
||||||
$variation_product->set_parent_id( $parent_product->get_id() );
|
$variation_product->set_parent_id( $parent_product->get_id() );
|
||||||
$variation_product->set_attributes( array(
|
$variation_product->set_attributes(
|
||||||
'color' => 'Green',
|
array(
|
||||||
'size' => 'Large',
|
'color' => 'Green',
|
||||||
) );
|
'size' => 'Large',
|
||||||
|
)
|
||||||
|
);
|
||||||
$variation_product->save();
|
$variation_product->save();
|
||||||
|
|
||||||
$product_item = new WC_Order_Item_Product();
|
$product_item = new WC_Order_Item_Product();
|
||||||
|
@ -158,7 +160,7 @@ class WC_Tests_Order_Item_Product extends WC_Unit_Test_Case {
|
||||||
$product_item->save();
|
$product_item->save();
|
||||||
|
|
||||||
// Test with show_all on.
|
// Test with show_all on.
|
||||||
$formatted = $product_item->get_formatted_meta_data( '_', true );
|
$formatted = $product_item->get_formatted_meta_data( '_', true );
|
||||||
$formatted_as_array = array();
|
$formatted_as_array = array();
|
||||||
foreach ( $formatted as $f ) {
|
foreach ( $formatted as $f ) {
|
||||||
$formatted_as_array[] = (array) $f;
|
$formatted_as_array[] = (array) $f;
|
||||||
|
@ -188,7 +190,7 @@ class WC_Tests_Order_Item_Product extends WC_Unit_Test_Case {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test with show_all off.
|
// Test with show_all off.
|
||||||
$formatted = $product_item->get_formatted_meta_data( '_', false );
|
$formatted = $product_item->get_formatted_meta_data( '_', false );
|
||||||
$formatted_as_array = array();
|
$formatted_as_array = array();
|
||||||
foreach ( $formatted as $f ) {
|
foreach ( $formatted as $f ) {
|
||||||
$formatted_as_array[] = (array) $f;
|
$formatted_as_array[] = (array) $f;
|
||||||
|
@ -267,7 +269,7 @@ class WC_Tests_Order_Item_Product extends WC_Unit_Test_Case {
|
||||||
$this->assertTrue( isset( $item['item_meta_array'] ) );
|
$this->assertTrue( isset( $item['item_meta_array'] ) );
|
||||||
$item['item_meta_array'] = array(
|
$item['item_meta_array'] = array(
|
||||||
0 => (object) array(
|
0 => (object) array(
|
||||||
'key' => 'test',
|
'key' => 'test',
|
||||||
'value' => 'val',
|
'value' => 'val',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -22,10 +22,12 @@ class WC_Tests_Order_Item_Functions extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$order = new WC_Order();
|
$order = new WC_Order();
|
||||||
$item_1 = new WC_Order_Item_Product();
|
$item_1 = new WC_Order_Item_Product();
|
||||||
$item_1->set_props( array(
|
$item_1->set_props(
|
||||||
'product' => WC_Helper_Product::create_simple_product(),
|
array(
|
||||||
'quantity' => 4,
|
'product' => WC_Helper_Product::create_simple_product(),
|
||||||
) );
|
'quantity' => 4,
|
||||||
|
)
|
||||||
|
);
|
||||||
$order->add_item( $item_1 );
|
$order->add_item( $item_1 );
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class WC_Tests_Order_Item_Coupon extends WC_Unit_Test_Case {
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
*/
|
*/
|
||||||
public function test_setters_getters() {
|
public function test_setters_getters() {
|
||||||
$coupon = new WC_Order_Item_Coupon;
|
$coupon = new WC_Order_Item_Coupon();
|
||||||
|
|
||||||
$coupon->set_name( 'testcoupon' );
|
$coupon->set_name( 'testcoupon' );
|
||||||
$this->assertTrue( 'testcoupon' === $coupon->get_name() && $coupon->get_name() === $coupon->get_code() );
|
$this->assertTrue( 'testcoupon' === $coupon->get_name() && $coupon->get_name() === $coupon->get_code() );
|
||||||
|
|
|
@ -14,17 +14,17 @@ class WC_Tests_Order_Item_Tax extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
function test_set_get_tax_totals() {
|
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() );
|
$this->assertEquals( 0, $item->get_tax_total() );
|
||||||
|
|
||||||
$item->set_tax_total( "1.50" );
|
$item->set_tax_total( '1.50' );
|
||||||
$this->assertEquals( "1.50", $item->get_tax_total() );
|
$this->assertEquals( '1.50', $item->get_tax_total() );
|
||||||
|
|
||||||
$item->set_tax_total( "" );
|
$item->set_tax_total( '' );
|
||||||
$this->assertEquals( 0, $item->get_tax_total() );
|
$this->assertEquals( 0, $item->get_tax_total() );
|
||||||
|
|
||||||
$item->set_tax_total( 10.99 );
|
$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() {
|
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() );
|
$this->assertEquals( 0, $item->get_shipping_tax_total() );
|
||||||
|
|
||||||
$item->set_shipping_tax_total( "1.50" );
|
$item->set_shipping_tax_total( '1.50' );
|
||||||
$this->assertEquals( "1.50", $item->get_shipping_tax_total() );
|
$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() );
|
$this->assertEquals( 0, $item->get_shipping_tax_total() );
|
||||||
|
|
||||||
$item->set_shipping_tax_total( 10.99 );
|
$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() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
|
||||||
public function test_wc_get_order_statuses() {
|
public function test_wc_get_order_statuses() {
|
||||||
|
|
||||||
$order_statuses = apply_filters(
|
$order_statuses = apply_filters(
|
||||||
'wc_order_statuses', array(
|
'wc_order_statuses',
|
||||||
|
array(
|
||||||
'wc-pending' => _x( 'Pending payment', 'Order status', 'woocommerce' ),
|
'wc-pending' => _x( 'Pending payment', 'Order status', 'woocommerce' ),
|
||||||
'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
|
'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
|
||||||
'wc-on-hold' => _x( 'On hold', 'Order status', 'woocommerce' ),
|
'wc-on-hold' => _x( 'On hold', 'Order status', 'woocommerce' ),
|
||||||
|
|
|
@ -39,12 +39,14 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
|
||||||
$coupon2->set_discount_type( 'percent' );
|
$coupon2->set_discount_type( 'percent' );
|
||||||
$coupon2->save();
|
$coupon2->save();
|
||||||
|
|
||||||
$order = wc_create_order( array(
|
$order = wc_create_order(
|
||||||
'status' => 'pending',
|
array(
|
||||||
'customer_id' => 1,
|
'status' => 'pending',
|
||||||
'customer_note' => '',
|
'customer_id' => 1,
|
||||||
'total' => '',
|
'customer_note' => '',
|
||||||
) );
|
'total' => '',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Add order products
|
// Add order products
|
||||||
$product_item = new WC_Order_Item_Product();
|
$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();
|
$coupon_item_2 = new WC_Order_Item_Coupon();
|
||||||
|
|
||||||
if ( get_option( 'woocommerce_prices_include_tax', 'no' ) === 'yes' && get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ) {
|
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(
|
||||||
'product' => $product,
|
array(
|
||||||
'quantity' => 1,
|
'product' => $product,
|
||||||
'subtotal' => 909.09, // Ex tax.
|
'quantity' => 1,
|
||||||
'total' => 726.36,
|
'subtotal' => 909.09, // Ex tax.
|
||||||
) );
|
'total' => 726.36,
|
||||||
$coupon_item_1->set_props( array(
|
)
|
||||||
'code' => 'test-coupon-1',
|
);
|
||||||
'discount' => 0.91,
|
$coupon_item_1->set_props(
|
||||||
'discount_tax' => 0.09,
|
array(
|
||||||
) );
|
'code' => 'test-coupon-1',
|
||||||
$coupon_item_2->set_props( array(
|
'discount' => 0.91,
|
||||||
'code' => 'this-is-a-virtal-coupon',
|
'discount_tax' => 0.09,
|
||||||
'discount' => 181.82,
|
)
|
||||||
'discount_tax' => 18.18,
|
);
|
||||||
) );
|
$coupon_item_2->set_props(
|
||||||
|
array(
|
||||||
|
'code' => 'this-is-a-virtal-coupon',
|
||||||
|
'discount' => 181.82,
|
||||||
|
'discount_tax' => 18.18,
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$product_item->set_props( array(
|
$product_item->set_props(
|
||||||
'product' => $product,
|
array(
|
||||||
'quantity' => 1,
|
'product' => $product,
|
||||||
'subtotal' => 1000, // Ex tax.
|
'quantity' => 1,
|
||||||
'total' => 799,
|
'subtotal' => 1000, // Ex tax.
|
||||||
) );
|
'total' => 799,
|
||||||
$coupon_item_1->set_props( array(
|
)
|
||||||
'code' => 'test-coupon-1',
|
);
|
||||||
'discount' => 1,
|
$coupon_item_1->set_props(
|
||||||
'discount_tax' => get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ? 0.1 : 0,
|
array(
|
||||||
) );
|
'code' => 'test-coupon-1',
|
||||||
$coupon_item_2->set_props( array(
|
'discount' => 1,
|
||||||
'code' => 'this-is-a-virtal-coupon',
|
'discount_tax' => get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ? 0.1 : 0,
|
||||||
'discount' => 200,
|
)
|
||||||
'discount_tax' => get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ? 20 : 0,
|
);
|
||||||
) );
|
$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();
|
$product_item->save();
|
||||||
|
@ -99,17 +113,19 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
|
||||||
$this->objects['coupons'][] = $coupon2;
|
$this->objects['coupons'][] = $coupon2;
|
||||||
$this->objects['products'][] = $product;
|
$this->objects['products'][] = $product;
|
||||||
$this->objects['order'] = $order;
|
$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(
|
||||||
'tax_rate_country' => '',
|
array(
|
||||||
'tax_rate_state' => '',
|
'tax_rate_country' => '',
|
||||||
'tax_rate' => '10.0000',
|
'tax_rate_state' => '',
|
||||||
'tax_rate_name' => 'VAT',
|
'tax_rate' => '10.0000',
|
||||||
'tax_rate_priority' => '1',
|
'tax_rate_name' => 'VAT',
|
||||||
'tax_rate_compound' => '0',
|
'tax_rate_priority' => '1',
|
||||||
'tax_rate_shipping' => '1',
|
'tax_rate_compound' => '0',
|
||||||
'tax_rate_order' => '1',
|
'tax_rate_shipping' => '1',
|
||||||
'tax_rate_class' => '',
|
'tax_rate_order' => '1',
|
||||||
) );
|
'tax_rate_class' => '',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$order->calculate_totals( true );
|
$order->calculate_totals( true );
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
|
@ -34,7 +34,7 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
|
||||||
$order2->save();
|
$order2->save();
|
||||||
|
|
||||||
// Just get some orders.
|
// Just get some orders.
|
||||||
$query = new WC_Order_Query();
|
$query = new WC_Order_Query();
|
||||||
$results = $query->get_orders();
|
$results = $query->get_orders();
|
||||||
$this->assertEquals( 2, count( $results ) );
|
$this->assertEquals( 2, count( $results ) );
|
||||||
|
|
||||||
|
@ -67,45 +67,53 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public function test_order_query_date_queries() {
|
public function test_order_query_date_queries() {
|
||||||
$now = current_time( 'mysql', true );
|
$now = current_time( 'mysql', true );
|
||||||
$now_stamp = strtotime( $now );
|
$now_stamp = strtotime( $now );
|
||||||
$now_date = date( 'Y-m-d', $now_stamp );
|
$now_date = date( 'Y-m-d', $now_stamp );
|
||||||
$past_stamp = $now_stamp - DAY_IN_SECONDS;
|
$past_stamp = $now_stamp - DAY_IN_SECONDS;
|
||||||
$past = date( 'Y-m-d', $past_stamp );
|
$past = date( 'Y-m-d', $past_stamp );
|
||||||
$future_stamp = $now_stamp + DAY_IN_SECONDS;
|
$future_stamp = $now_stamp + DAY_IN_SECONDS;
|
||||||
$future = date( 'Y-m-d', $future_stamp );
|
$future = date( 'Y-m-d', $future_stamp );
|
||||||
|
|
||||||
$order = new WC_Order();
|
$order = new WC_Order();
|
||||||
$order->set_date_completed( $now_stamp );
|
$order->set_date_completed( $now_stamp );
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
// Check WC_DateTime support.
|
// Check WC_DateTime support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_created' => $order->get_date_created(),
|
array(
|
||||||
) );
|
'date_created' => $order->get_date_created(),
|
||||||
|
)
|
||||||
|
);
|
||||||
$orders = $query->get_orders();
|
$orders = $query->get_orders();
|
||||||
$this->assertEquals( 1, count( $orders ) );
|
$this->assertEquals( 1, count( $orders ) );
|
||||||
|
|
||||||
// Check date support.
|
// Check date support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_created' => $now_date,
|
array(
|
||||||
) );
|
'date_created' => $now_date,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_created', $past );
|
$query->set( 'date_created', $past );
|
||||||
$this->assertEquals( 0, count( $query->get_orders() ) );
|
$this->assertEquals( 0, count( $query->get_orders() ) );
|
||||||
|
|
||||||
// Check timestamp support.
|
// Check timestamp support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_created' => $order->get_date_created()->getTimestamp(),
|
array(
|
||||||
) );
|
'date_created' => $order->get_date_created()->getTimestamp(),
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_created', $future_stamp );
|
$query->set( 'date_created', $future_stamp );
|
||||||
$this->assertEquals( 0, count( $query->get_orders() ) );
|
$this->assertEquals( 0, count( $query->get_orders() ) );
|
||||||
|
|
||||||
// Check comparison support.
|
// Check comparison support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_created' => '>' . $past,
|
array(
|
||||||
) );
|
'date_created' => '>' . $past,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_created', '<' . $past );
|
$query->set( 'date_created', '<' . $past );
|
||||||
$this->assertEquals( 0, count( $query->get_orders() ) );
|
$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() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
|
|
||||||
// Check timestamp comparison support.
|
// Check timestamp comparison support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_created' => '<' . $future_stamp,
|
array(
|
||||||
) );
|
'date_created' => '<' . $future_stamp,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_created', '<' . $past_stamp );
|
$query->set( 'date_created', '<' . $past_stamp );
|
||||||
$this->assertEquals( 0, count( $query->get_orders() ) );
|
$this->assertEquals( 0, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_created', '>=' . $now_stamp );
|
$query->set( 'date_created', '>=' . $now_stamp );
|
||||||
|
|
||||||
// Check date range support.
|
// Check date range support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_created' => $past . '...' . $future,
|
array(
|
||||||
) );
|
'date_created' => $past . '...' . $future,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_created', $past . '...' . $now_date );
|
$query->set( 'date_created', $past . '...' . $now_date );
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$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() ) );
|
$this->assertEquals( 0, count( $query->get_orders() ) );
|
||||||
|
|
||||||
// Check timestamp range support.
|
// Check timestamp range support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_created' => $past_stamp . '...' . $future_stamp,
|
array(
|
||||||
) );
|
'date_created' => $past_stamp . '...' . $future_stamp,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_created', $now_stamp . '...' . $future_stamp );
|
$query->set( 'date_created', $now_stamp . '...' . $future_stamp );
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
|
@ -148,45 +162,53 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public function test_order_query_meta_date_queries() {
|
public function test_order_query_meta_date_queries() {
|
||||||
$now = current_time( 'mysql', true );
|
$now = current_time( 'mysql', true );
|
||||||
$now_stamp = strtotime( $now );
|
$now_stamp = strtotime( $now );
|
||||||
$now_date = date( 'Y-m-d', $now_stamp );
|
$now_date = date( 'Y-m-d', $now_stamp );
|
||||||
$past_stamp = $now_stamp - DAY_IN_SECONDS;
|
$past_stamp = $now_stamp - DAY_IN_SECONDS;
|
||||||
$past = date( 'Y-m-d', $past_stamp );
|
$past = date( 'Y-m-d', $past_stamp );
|
||||||
$future_stamp = $now_stamp + DAY_IN_SECONDS;
|
$future_stamp = $now_stamp + DAY_IN_SECONDS;
|
||||||
$future = date( 'Y-m-d', $future_stamp );
|
$future = date( 'Y-m-d', $future_stamp );
|
||||||
|
|
||||||
$order = new WC_Order();
|
$order = new WC_Order();
|
||||||
$order->set_date_completed( $now_stamp );
|
$order->set_date_completed( $now_stamp );
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
// Check WC_DateTime support.
|
// Check WC_DateTime support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_completed' => $order->get_date_completed(),
|
array(
|
||||||
) );
|
'date_completed' => $order->get_date_completed(),
|
||||||
|
)
|
||||||
|
);
|
||||||
$orders = $query->get_orders();
|
$orders = $query->get_orders();
|
||||||
$this->assertEquals( 1, count( $orders ) );
|
$this->assertEquals( 1, count( $orders ) );
|
||||||
|
|
||||||
// Check date support.
|
// Check date support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_completed' => $now_date,
|
array(
|
||||||
) );
|
'date_completed' => $now_date,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_completed', $past );
|
$query->set( 'date_completed', $past );
|
||||||
$this->assertEquals( 0, count( $query->get_orders() ) );
|
$this->assertEquals( 0, count( $query->get_orders() ) );
|
||||||
|
|
||||||
// Check timestamp support.
|
// Check timestamp support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_completed' => $order->get_date_completed()->getTimestamp(),
|
array(
|
||||||
) );
|
'date_completed' => $order->get_date_completed()->getTimestamp(),
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_completed', $future_stamp );
|
$query->set( 'date_completed', $future_stamp );
|
||||||
$this->assertEquals( 0, count( $query->get_orders() ) );
|
$this->assertEquals( 0, count( $query->get_orders() ) );
|
||||||
|
|
||||||
// Check comparison support.
|
// Check comparison support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_completed' => '>' . $past,
|
array(
|
||||||
) );
|
'date_completed' => '>' . $past,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_completed', '<' . $past );
|
$query->set( 'date_completed', '<' . $past );
|
||||||
$this->assertEquals( 0, count( $query->get_orders() ) );
|
$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() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
|
|
||||||
// Check timestamp comparison support.
|
// Check timestamp comparison support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_completed' => '<' . $future_stamp,
|
array(
|
||||||
) );
|
'date_completed' => '<' . $future_stamp,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_completed', '<' . $past_stamp );
|
$query->set( 'date_completed', '<' . $past_stamp );
|
||||||
$this->assertEquals( 0, count( $query->get_orders() ) );
|
$this->assertEquals( 0, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_completed', '>=' . $now_stamp );
|
$query->set( 'date_completed', '>=' . $now_stamp );
|
||||||
|
|
||||||
// Check date range support.
|
// Check date range support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_completed' => $past . '...' . $future,
|
array(
|
||||||
) );
|
'date_completed' => $past . '...' . $future,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_completed', $now_date . '...' . $future );
|
$query->set( 'date_completed', $now_date . '...' . $future );
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$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() ) );
|
$this->assertEquals( 0, count( $query->get_orders() ) );
|
||||||
|
|
||||||
// Check timestamp range support.
|
// Check timestamp range support.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'date_completed' => $past_stamp . '...' . $future_stamp,
|
array(
|
||||||
) );
|
'date_completed' => $past_stamp . '...' . $future_stamp,
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$this->assertEquals( 1, count( $query->get_orders() ) );
|
||||||
$query->set( 'date_completed', $now_stamp . '...' . $future_stamp );
|
$query->set( 'date_completed', $now_stamp . '...' . $future_stamp );
|
||||||
$this->assertEquals( 1, count( $query->get_orders() ) );
|
$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
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public function test_order_query_key_mapping() {
|
public function test_order_query_key_mapping() {
|
||||||
$user_id = wp_insert_user( array(
|
$user_id = wp_insert_user(
|
||||||
'user_login' => 'testname',
|
array(
|
||||||
'user_pass' => 'testpass',
|
'user_login' => 'testname',
|
||||||
'user_email' => 'email@testmail.com',
|
'user_pass' => 'testpass',
|
||||||
) );
|
'user_email' => 'email@testmail.com',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$order = new WC_Order();
|
$order = new WC_Order();
|
||||||
$order->set_customer_id( $user_id );
|
$order->set_customer_id( $user_id );
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'customer_id' => $user_id,
|
array(
|
||||||
) );
|
'customer_id' => $user_id,
|
||||||
|
)
|
||||||
|
);
|
||||||
$results = $query->get_orders();
|
$results = $query->get_orders();
|
||||||
|
|
||||||
$this->assertEquals( 1, count( $results ) );
|
$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() {
|
public function test_order_query_search_by_customers() {
|
||||||
$user_email_1 = 'email@testmail.com';
|
$user_email_1 = 'email@testmail.com';
|
||||||
$user_id_1 = wp_insert_user( array(
|
$user_id_1 = wp_insert_user(
|
||||||
'user_login' => 'testname',
|
array(
|
||||||
'user_pass' => 'testpass',
|
'user_login' => 'testname',
|
||||||
'user_email' => $user_email_1,
|
'user_pass' => 'testpass',
|
||||||
) );
|
'user_email' => $user_email_1,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$user_email_2 = 'email2@testmail.com';
|
$user_email_2 = 'email2@testmail.com';
|
||||||
$user_id_2 = wp_insert_user( array(
|
$user_id_2 = wp_insert_user(
|
||||||
'user_login' => 'testname2',
|
array(
|
||||||
'user_pass' => 'testpass2',
|
'user_login' => 'testname2',
|
||||||
'user_email' => $user_email_2,
|
'user_pass' => 'testpass2',
|
||||||
) );
|
'user_email' => $user_email_2,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$order1 = new WC_Order();
|
$order1 = new WC_Order();
|
||||||
$order1->set_customer_id( $user_id_1 );
|
$order1->set_customer_id( $user_id_1 );
|
||||||
|
@ -275,30 +311,38 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
|
||||||
$order3->save();
|
$order3->save();
|
||||||
|
|
||||||
// Searching for both users IDs should return all orders.
|
// Searching for both users IDs should return all orders.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'customer' => array( $user_id_1, $user_id_2 ),
|
array(
|
||||||
) );
|
'customer' => array( $user_id_1, $user_id_2 ),
|
||||||
|
)
|
||||||
|
);
|
||||||
$results = $query->get_orders();
|
$results = $query->get_orders();
|
||||||
$this->assertEquals( 3, count( $results ) );
|
$this->assertEquals( 3, count( $results ) );
|
||||||
|
|
||||||
// Searching for user 1 email and user 2 ID should return all orders.
|
// Searching for user 1 email and user 2 ID should return all orders.
|
||||||
$query = new WC_Order_Query( array(
|
$query = new WC_Order_Query(
|
||||||
'customer' => array( $user_email_1, $user_id_2 ),
|
array(
|
||||||
) );
|
'customer' => array( $user_email_1, $user_id_2 ),
|
||||||
|
)
|
||||||
|
);
|
||||||
$results = $query->get_orders();
|
$results = $query->get_orders();
|
||||||
$this->assertEquals( 3, count( $results ) );
|
$this->assertEquals( 3, count( $results ) );
|
||||||
|
|
||||||
// Searching for orders that match the first user email AND ID should return only a single order
|
// 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(
|
||||||
'customer' => array( array( $user_email_1, $user_id_1 ) ),
|
array(
|
||||||
) );
|
'customer' => array( array( $user_email_1, $user_id_1 ) ),
|
||||||
|
)
|
||||||
|
);
|
||||||
$results = $query->get_orders();
|
$results = $query->get_orders();
|
||||||
$this->assertEquals( 1, count( $results ) );
|
$this->assertEquals( 1, count( $results ) );
|
||||||
|
|
||||||
// Searching for orders that match the first user email AND the second user ID should return no orders.
|
// 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(
|
||||||
'customer' => array( array( $user_email_1, $user_id_2 ) ),
|
array(
|
||||||
) );
|
'customer' => array( array( $user_email_1, $user_id_2 ) ),
|
||||||
|
)
|
||||||
|
);
|
||||||
$results = $query->get_orders();
|
$results = $query->get_orders();
|
||||||
$this->assertEquals( 0, count( $results ) );
|
$this->assertEquals( 0, count( $results ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,8 +90,8 @@ class WC_Tests_Payment_Token_CC extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_payment_token_cc_read_pulls_meta() {
|
public function test_wc_payment_token_cc_read_pulls_meta() {
|
||||||
$token = WC_Helper_Payment_Token::create_cc_token();
|
$token = WC_Helper_Payment_Token::create_cc_token();
|
||||||
$token_id = $token->get_id();
|
$token_id = $token->get_id();
|
||||||
$token_read = new WC_Payment_Token_CC( $token_id );
|
$token_read = new WC_Payment_Token_CC( $token_id );
|
||||||
$this->assertEquals( '1234', $token_read->get_last4() );
|
$this->assertEquals( '1234', $token_read->get_last4() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class WC_Tests_Payment_Token_eCheck extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_payment_token_echeck_read_pulls_meta() {
|
public function test_wc_payment_token_echeck_read_pulls_meta() {
|
||||||
$token = WC_Helper_Payment_Token::create_eCheck_token();
|
$token = WC_Helper_Payment_Token::create_eCheck_token();
|
||||||
$token_id = $token->get_id();
|
$token_id = $token->get_id();
|
||||||
|
|
||||||
$token_read = new WC_Payment_Token_ECheck( $token_id );
|
$token_read = new WC_Payment_Token_ECheck( $token_id );
|
||||||
|
|
|
@ -20,7 +20,7 @@ class WC_Tests_Payment_Token extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_wc_payment_token_token() {
|
public function test_wc_payment_token_token() {
|
||||||
$raw_token = time() . ' ' . __FUNCTION__;
|
$raw_token = time() . ' ' . __FUNCTION__;
|
||||||
$token = new WC_Payment_Token_Stub();
|
$token = new WC_Payment_Token_Stub();
|
||||||
$token->set_token( $raw_token );
|
$token->set_token( $raw_token );
|
||||||
$this->assertEquals( $raw_token, $token->get_token() );
|
$this->assertEquals( $raw_token, $token->get_token() );
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class WC_Tests_Payment_Token extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_wc_payment_token_get_data() {
|
public function test_wc_payment_token_get_data() {
|
||||||
$raw_token = time() . ' ' . __FUNCTION__;
|
$raw_token = time() . ' ' . __FUNCTION__;
|
||||||
$token = new WC_Payment_Token_Stub();
|
$token = new WC_Payment_Token_Stub();
|
||||||
$token->set_token( $raw_token );
|
$token->set_token( $raw_token );
|
||||||
$token->set_gateway_id( 'paypal' );
|
$token->set_gateway_id( 'paypal' );
|
||||||
$token->set_extra( 'woocommerce' );
|
$token->set_extra( 'woocommerce' );
|
||||||
|
@ -105,7 +105,7 @@ class WC_Tests_Payment_Token extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_payment_token_read() {
|
public function test_wc_payment_token_read() {
|
||||||
$token = WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
$token = WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
||||||
$token_id = $token->get_id();
|
$token_id = $token->get_id();
|
||||||
|
|
||||||
$token_read = new WC_Payment_Token_Stub( $token_id );
|
$token_read = new WC_Payment_Token_Stub( $token_id );
|
||||||
|
@ -150,7 +150,7 @@ class WC_Tests_Payment_Token extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_payment_token_delete() {
|
public function test_wc_payment_token_delete() {
|
||||||
$token = WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
$token = WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
||||||
$token_id = $token->get_id();
|
$token_id = $token->get_id();
|
||||||
$token->delete();
|
$token->delete();
|
||||||
$get_token = WC_Payment_Tokens::get( $token_id );
|
$get_token = WC_Payment_Tokens::get( $token_id );
|
||||||
|
@ -176,7 +176,7 @@ class WC_Tests_Payment_Token extends WC_Unit_Test_Case {
|
||||||
* @expectedDeprecated WC_Payment_Token::update
|
* @expectedDeprecated WC_Payment_Token::update
|
||||||
*/
|
*/
|
||||||
public function test_wc_payment_token_legacy() {
|
public function test_wc_payment_token_legacy() {
|
||||||
$token = WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
$token = WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
||||||
$token_id = $token->get_id();
|
$token_id = $token->get_id();
|
||||||
|
|
||||||
$token_read = new WC_Payment_Token_Stub();
|
$token_read = new WC_Payment_Token_Stub();
|
||||||
|
|
|
@ -119,8 +119,8 @@ class WC_Tests_Payment_Tokens extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
function test_wc_payment_tokens_get() {
|
function test_wc_payment_tokens_get() {
|
||||||
$token = WC_Helper_Payment_Token::create_cc_token();
|
$token = WC_Helper_Payment_Token::create_cc_token();
|
||||||
$token_id = $token->get_id();
|
$token_id = $token->get_id();
|
||||||
$get_token = WC_Payment_Tokens::get( $token_id );
|
$get_token = WC_Payment_Tokens::get( $token_id );
|
||||||
$this->assertEquals( $token->get_token(), $get_token->get_token() );
|
$this->assertEquals( $token->get_token(), $get_token->get_token() );
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ class WC_Tests_Payment_Tokens extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
function test_wc_payment_tokens_delete() {
|
function test_wc_payment_tokens_delete() {
|
||||||
$token = WC_Helper_Payment_Token::create_cc_token();
|
$token = WC_Helper_Payment_Token::create_cc_token();
|
||||||
$token_id = $token->get_id();
|
$token_id = $token->get_id();
|
||||||
|
|
||||||
WC_Payment_Tokens::delete( $token_id );
|
WC_Payment_Tokens::delete( $token_id );
|
||||||
|
@ -144,7 +144,7 @@ class WC_Tests_Payment_Tokens extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
function test_wc_payment_tokens_get_type_by_id() {
|
function test_wc_payment_tokens_get_type_by_id() {
|
||||||
$token = WC_Helper_Payment_Token::create_cc_token();
|
$token = WC_Helper_Payment_Token::create_cc_token();
|
||||||
$token_id = $token->get_id();
|
$token_id = $token->get_id();
|
||||||
$this->assertEquals( 'CC', WC_Payment_Tokens::get_token_type_by_id( $token_id ) );
|
$this->assertEquals( 'CC', WC_Payment_Tokens::get_token_type_by_id( $token_id ) );
|
||||||
}
|
}
|
||||||
|
@ -154,11 +154,11 @@ class WC_Tests_Payment_Tokens extends WC_Unit_Test_Case {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
function test_wc_payment_tokens_set_users_default() {
|
function test_wc_payment_tokens_set_users_default() {
|
||||||
$token = WC_Helper_Payment_Token::create_cc_token( $this->user_id );
|
$token = WC_Helper_Payment_Token::create_cc_token( $this->user_id );
|
||||||
$token_id = $token->get_id();
|
$token_id = $token->get_id();
|
||||||
$token->save();
|
$token->save();
|
||||||
|
|
||||||
$token2 = WC_Helper_Payment_Token::create_cc_token( $this->user_id );
|
$token2 = WC_Helper_Payment_Token::create_cc_token( $this->user_id );
|
||||||
$token_id_2 = $token2->get_id();
|
$token_id_2 = $token2->get_id();
|
||||||
$token2->save();
|
$token2->save();
|
||||||
|
|
||||||
|
|
|
@ -273,7 +273,7 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
||||||
* Test: test_get_image_should_return_product_image.
|
* Test: test_get_image_should_return_product_image.
|
||||||
*/
|
*/
|
||||||
public function test_get_image_should_return_product_image() {
|
public function test_get_image_should_return_product_image() {
|
||||||
$product = new WC_Product();
|
$product = new WC_Product();
|
||||||
$image_url = $this->set_product_image( $product );
|
$image_url = $this->set_product_image( $product );
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
@ -297,9 +297,9 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_get_image_should_return_parent_product_image() {
|
public function test_get_image_should_return_parent_product_image() {
|
||||||
$variable_product = WC_Helper_Product::create_variation_product();
|
$variable_product = WC_Helper_Product::create_variation_product();
|
||||||
$variations = $variable_product->get_children();
|
$variations = $variable_product->get_children();
|
||||||
$variation_1 = wc_get_product( $variations[0] );
|
$variation_1 = wc_get_product( $variations[0] );
|
||||||
$image_url = $this->set_product_image( $variable_product );
|
$image_url = $this->set_product_image( $variable_product );
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'<img width="186" height="144" src="' . $image_url . '" class="attachment-woocommerce_thumbnail size-woocommerce_thumbnail" alt="" />',
|
'<img width="186" height="144" src="' . $image_url . '" class="attachment-woocommerce_thumbnail size-woocommerce_thumbnail" alt="" />',
|
||||||
|
|
|
@ -12,9 +12,9 @@ class WC_Tests_Product_Factory extends WC_Unit_Test_Case {
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
function test_get_product_type() {
|
function test_get_product_type() {
|
||||||
$simple = WC_Helper_Product::create_simple_product();
|
$simple = WC_Helper_Product::create_simple_product();
|
||||||
$external = WC_Helper_Product::create_external_product();
|
$external = WC_Helper_Product::create_external_product();
|
||||||
$grouped = WC_Helper_Product::create_grouped_product();
|
$grouped = WC_Helper_Product::create_grouped_product();
|
||||||
$variable = WC_Helper_Product::create_variation_product();
|
$variable = WC_Helper_Product::create_variation_product();
|
||||||
$children = $variable->get_children();
|
$children = $variable->get_children();
|
||||||
$child_id = $children[0];
|
$child_id = $children[0];
|
||||||
|
@ -51,7 +51,7 @@ class WC_Tests_Product_Factory extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
function test_get_product() {
|
function test_get_product() {
|
||||||
$test_product = WC_Helper_Product::create_simple_product();
|
$test_product = WC_Helper_Product::create_simple_product();
|
||||||
$get_product = WC()->product_factory->get_product( $test_product->get_id() );
|
$get_product = WC()->product_factory->get_product( $test_product->get_id() );
|
||||||
$this->assertEquals( $test_product->get_data(), $get_product->get_data() );
|
$this->assertEquals( $test_product->get_data(), $get_product->get_data() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@ class WC_Tests_Product_Variation extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_is_sold_individually() {
|
public function test_is_sold_individually() {
|
||||||
// Create a variable product with 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->set_sold_individually( true );
|
||||||
$product->save();
|
$product->save();
|
||||||
|
|
||||||
$variation = new WC_Product_Variation;
|
$variation = new WC_Product_Variation();
|
||||||
$variation->set_parent_id( $product->get_id() );
|
$variation->set_parent_id( $product->get_id() );
|
||||||
$variation->save();
|
$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
|
* Check get_tax_class against different parent child scenarios
|
||||||
*/
|
*/
|
||||||
public function test_get_tax_class() {
|
public function test_get_tax_class() {
|
||||||
$product = new WC_Product_Variable;
|
$product = new WC_Product_Variable();
|
||||||
$product->set_tax_class( 'standard' );
|
$product->set_tax_class( 'standard' );
|
||||||
$product->save();
|
$product->save();
|
||||||
|
|
||||||
$variation = new WC_Product_Variation;
|
$variation = new WC_Product_Variation();
|
||||||
$variation->set_parent_id( $product->get_id() );
|
$variation->set_parent_id( $product->get_id() );
|
||||||
$variation->set_tax_class( 'parent' );
|
$variation->set_tax_class( 'parent' );
|
||||||
$variation->save();
|
$variation->save();
|
||||||
|
|
|
@ -62,7 +62,7 @@ class WC_Tests_Session_Handler extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
public function test_get_session_should_return_default_value() {
|
public function test_get_session_should_return_default_value() {
|
||||||
$default_session = array( 'session' => 'default' );
|
$default_session = array( 'session' => 'default' );
|
||||||
$session = $this->handler->get_session( 'non-existent key', $default_session );
|
$session = $this->handler->get_session( 'non-existent key', $default_session );
|
||||||
$this->assertEquals( $default_session, $session );
|
$this->assertEquals( $default_session, $session );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class WC_Tests_Session_Handler extends WC_Unit_Test_Case {
|
||||||
wp_set_current_user( 1 );
|
wp_set_current_user( 1 );
|
||||||
$this->handler->set( 'cart', 'fake cart' );
|
$this->handler->set( 'cart', 'fake cart' );
|
||||||
$this->handler->save_data();
|
$this->handler->save_data();
|
||||||
$this->session_key = $this->handler->get_customer_id();
|
$this->session_key = $this->handler->get_customer_id();
|
||||||
$this->cache_prefix = WC_Cache_Helper::get_cache_prefix( WC_SESSION_CACHE_GROUP );
|
$this->cache_prefix = WC_Cache_Helper::get_cache_prefix( WC_SESSION_CACHE_GROUP );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
||||||
'label' => $this->page->get_label(),
|
'label' => $this->page->get_label(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$actual = $settings->register_page_group( $initial );
|
$actual = $settings->register_page_group( $initial );
|
||||||
|
|
||||||
$this->assertEquals( $expected, $actual );
|
$this->assertEquals( $expected, $actual );
|
||||||
}
|
}
|
||||||
|
@ -109,11 +109,11 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
||||||
// Boolean 'desc_tip' defaulting to 'desc' value
|
// Boolean 'desc_tip' defaulting to 'desc' value
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'id' => 'setting-id',
|
'id' => 'setting-id',
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'title' => 'Setting Name',
|
'title' => 'Setting Name',
|
||||||
'desc' => 'Setting Description',
|
'desc' => 'Setting Description',
|
||||||
'desc_tip' => true,
|
'desc_tip' => true,
|
||||||
'option_key' => '',
|
'option_key' => '',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
@ -211,18 +211,18 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$settings = array(
|
$settings = array(
|
||||||
array(
|
array(
|
||||||
'id' => 'setting-1',
|
'id' => 'setting-1',
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'option_key' => '',
|
'option_key' => '',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'type' => 'no-id',
|
'type' => 'no-id',
|
||||||
'option_key' => '',
|
'option_key' => '',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'id' => 'setting-2',
|
'id' => 'setting-2',
|
||||||
'type' => 'textarea',
|
'type' => 'textarea',
|
||||||
'option_key' => '',
|
'option_key' => '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
||||||
'option_key' => 'setting-2',
|
'option_key' => 'setting-2',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$actual = $settings->register_page_settings( array() );
|
$actual = $settings->register_page_settings( array() );
|
||||||
|
|
||||||
$this->assertEquals( $expected, $actual );
|
$this->assertEquals( $expected, $actual );
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,45 +25,63 @@ class WC_Tests_Setup_Functions extends WC_Unit_Test_Case {
|
||||||
// non-admin user
|
// non-admin user
|
||||||
$this->user_id = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
|
$this->user_id = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
|
||||||
wp_set_current_user( $this->user_id );
|
wp_set_current_user( $this->user_id );
|
||||||
$this->assertEquals( gateways( $setup_wizard ), array(
|
$this->assertEquals(
|
||||||
'paypal' => false,
|
gateways( $setup_wizard ),
|
||||||
) );
|
array(
|
||||||
|
'paypal' => false,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// set admin user
|
// set admin user
|
||||||
$this->user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
|
$this->user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
|
||||||
wp_set_current_user( $this->user_id );
|
wp_set_current_user( $this->user_id );
|
||||||
|
|
||||||
update_option( 'woocommerce_default_country', 'US' );
|
update_option( 'woocommerce_default_country', 'US' );
|
||||||
$this->assertEquals( gateways( $setup_wizard ), array(
|
$this->assertEquals(
|
||||||
'stripe' => true,
|
gateways( $setup_wizard ),
|
||||||
'ppec_paypal' => true,
|
array(
|
||||||
) );
|
'stripe' => true,
|
||||||
|
'ppec_paypal' => true,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
update_option( 'woocommerce_default_country', 'CN' );
|
update_option( 'woocommerce_default_country', 'CN' );
|
||||||
$this->assertEquals( gateways( $setup_wizard ), array(
|
$this->assertEquals(
|
||||||
'ppec_paypal' => true,
|
gateways( $setup_wizard ),
|
||||||
) );
|
array(
|
||||||
|
'ppec_paypal' => true,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
update_option( 'woocommerce_default_country', 'SE' );
|
update_option( 'woocommerce_default_country', 'SE' );
|
||||||
$this->assertEquals( gateways( $setup_wizard ), array(
|
$this->assertEquals(
|
||||||
'klarna_checkout' => true,
|
gateways( $setup_wizard ),
|
||||||
'ppec_paypal' => true,
|
array(
|
||||||
'stripe' => false,
|
'klarna_checkout' => true,
|
||||||
) );
|
'ppec_paypal' => true,
|
||||||
|
'stripe' => false,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
update_option( 'woocommerce_default_country', 'DE' );
|
update_option( 'woocommerce_default_country', 'DE' );
|
||||||
$this->assertEquals( gateways( $setup_wizard ), array(
|
$this->assertEquals(
|
||||||
'klarna_payments' => true,
|
gateways( $setup_wizard ),
|
||||||
'ppec_paypal' => true,
|
array(
|
||||||
'stripe' => false,
|
'klarna_payments' => true,
|
||||||
) );
|
'ppec_paypal' => true,
|
||||||
|
'stripe' => false,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
update_option( 'woocommerce_default_country', 'GB' );
|
update_option( 'woocommerce_default_country', 'GB' );
|
||||||
update_option( 'woocommerce_sell_in_person', 'yes' );
|
update_option( 'woocommerce_sell_in_person', 'yes' );
|
||||||
$this->assertEquals( gateways( $setup_wizard ), array(
|
$this->assertEquals(
|
||||||
'square' => true,
|
gateways( $setup_wizard ),
|
||||||
'ppec_paypal' => true,
|
array(
|
||||||
'stripe' => false,
|
'square' => true,
|
||||||
) );
|
'ppec_paypal' => true,
|
||||||
}
|
'stripe' => false,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,12 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
);
|
);
|
||||||
$this->assertEquals( $expected, $shortcode->get_attributes() );
|
$this->assertEquals( $expected, $shortcode->get_attributes() );
|
||||||
|
|
||||||
$shortcode2 = new WC_Shortcode_Products( array(
|
$shortcode2 = new WC_Shortcode_Products(
|
||||||
'orderby' => 'id',
|
array(
|
||||||
'order' => 'DESC',
|
'orderby' => 'id',
|
||||||
) );
|
'order' => 'DESC',
|
||||||
|
)
|
||||||
|
);
|
||||||
$expected2 = array(
|
$expected2 = array(
|
||||||
'limit' => '-1',
|
'limit' => '-1',
|
||||||
'columns' => '4',
|
'columns' => '4',
|
||||||
|
@ -85,10 +87,12 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected, $shortcode->get_query_args() );
|
$this->assertEquals( $expected, $shortcode->get_query_args() );
|
||||||
|
|
||||||
// products shortcode with attributes.
|
// products shortcode with attributes.
|
||||||
$shortcode2 = new WC_Shortcode_Products( array(
|
$shortcode2 = new WC_Shortcode_Products(
|
||||||
'orderby' => 'ID',
|
array(
|
||||||
'order' => 'DESC',
|
'orderby' => 'ID',
|
||||||
) );
|
'order' => 'DESC',
|
||||||
|
)
|
||||||
|
);
|
||||||
$expected2 = array(
|
$expected2 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -103,11 +107,13 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
);
|
);
|
||||||
$this->assertEquals( $expected2, $shortcode2->get_query_args() );
|
$this->assertEquals( $expected2, $shortcode2->get_query_args() );
|
||||||
|
|
||||||
$shortcode3 = new WC_Shortcode_Products( array(
|
$shortcode3 = new WC_Shortcode_Products(
|
||||||
'ids' => '1,2,3',
|
array(
|
||||||
'skus' => 'foo,bar',
|
'ids' => '1,2,3',
|
||||||
) );
|
'skus' => 'foo,bar',
|
||||||
$expected3 = array(
|
)
|
||||||
|
);
|
||||||
|
$expected3 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'ignore_sticky_posts' => true,
|
'ignore_sticky_posts' => true,
|
||||||
|
@ -129,15 +135,18 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected3, $shortcode3->get_query_args() );
|
$this->assertEquals( $expected3, $shortcode3->get_query_args() );
|
||||||
|
|
||||||
// product_category shortcode.
|
// product_category shortcode.
|
||||||
$shortcode4 = new WC_Shortcode_Products( array(
|
$shortcode4 = new WC_Shortcode_Products(
|
||||||
'per_page' => '12',
|
array(
|
||||||
'columns' => '4',
|
'per_page' => '12',
|
||||||
'orderby' => 'title',
|
'columns' => '4',
|
||||||
'order' => 'ASC',
|
'orderby' => 'title',
|
||||||
'category' => 'clothing',
|
'order' => 'ASC',
|
||||||
'operator' => 'IN',
|
'category' => 'clothing',
|
||||||
), 'product_category' );
|
'operator' => 'IN',
|
||||||
$expected4 = array(
|
),
|
||||||
|
'product_category'
|
||||||
|
);
|
||||||
|
$expected4 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'ignore_sticky_posts' => true,
|
'ignore_sticky_posts' => true,
|
||||||
|
@ -160,15 +169,18 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected4, $shortcode4->get_query_args() );
|
$this->assertEquals( $expected4, $shortcode4->get_query_args() );
|
||||||
|
|
||||||
// product_category shortcode using category ids.
|
// product_category shortcode using category ids.
|
||||||
$shortcode4_id = new WC_Shortcode_Products( array(
|
$shortcode4_id = new WC_Shortcode_Products(
|
||||||
'per_page' => '12',
|
array(
|
||||||
'columns' => '4',
|
'per_page' => '12',
|
||||||
'orderby' => 'title',
|
'columns' => '4',
|
||||||
'order' => 'ASC',
|
'orderby' => 'title',
|
||||||
'category' => '123',
|
'order' => 'ASC',
|
||||||
'operator' => 'IN',
|
'category' => '123',
|
||||||
), 'product_category' );
|
'operator' => 'IN',
|
||||||
$expected4_id = array(
|
),
|
||||||
|
'product_category'
|
||||||
|
);
|
||||||
|
$expected4_id = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'ignore_sticky_posts' => true,
|
'ignore_sticky_posts' => true,
|
||||||
|
@ -191,14 +203,17 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected4_id, $shortcode4_id->get_query_args() );
|
$this->assertEquals( $expected4_id, $shortcode4_id->get_query_args() );
|
||||||
|
|
||||||
// recent_products shortcode.
|
// recent_products shortcode.
|
||||||
$shortcode5 = new WC_Shortcode_Products( array(
|
$shortcode5 = new WC_Shortcode_Products(
|
||||||
'per_page' => '12',
|
array(
|
||||||
'columns' => '4',
|
'per_page' => '12',
|
||||||
'orderby' => 'date',
|
'columns' => '4',
|
||||||
'order' => 'DESC',
|
'orderby' => 'date',
|
||||||
'category' => '',
|
'order' => 'DESC',
|
||||||
'operator' => 'IN',
|
'category' => '',
|
||||||
), 'recent_products' );
|
'operator' => 'IN',
|
||||||
|
),
|
||||||
|
'recent_products'
|
||||||
|
);
|
||||||
$expected5 = array(
|
$expected5 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -215,10 +230,13 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected5, $shortcode5->get_query_args() );
|
$this->assertEquals( $expected5, $shortcode5->get_query_args() );
|
||||||
|
|
||||||
// product shortcode.
|
// product shortcode.
|
||||||
$shortcode6 = new WC_Shortcode_Products( array(
|
$shortcode6 = new WC_Shortcode_Products(
|
||||||
'ids' => '1',
|
array(
|
||||||
'per_page' => '1',
|
'ids' => '1',
|
||||||
), 'product' );
|
'per_page' => '1',
|
||||||
|
),
|
||||||
|
'product'
|
||||||
|
);
|
||||||
$expected6 = array(
|
$expected6 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -236,14 +254,17 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected6, $shortcode6->get_query_args() );
|
$this->assertEquals( $expected6, $shortcode6->get_query_args() );
|
||||||
|
|
||||||
// sale_products shortcode.
|
// sale_products shortcode.
|
||||||
$shortcode7 = new WC_Shortcode_Products( array(
|
$shortcode7 = new WC_Shortcode_Products(
|
||||||
'per_page' => '12',
|
array(
|
||||||
'columns' => '4',
|
'per_page' => '12',
|
||||||
'orderby' => 'title',
|
'columns' => '4',
|
||||||
'order' => 'ASC',
|
'orderby' => 'title',
|
||||||
'category' => '',
|
'order' => 'ASC',
|
||||||
'operator' => 'IN',
|
'category' => '',
|
||||||
), 'sale_products' );
|
'operator' => 'IN',
|
||||||
|
),
|
||||||
|
'sale_products'
|
||||||
|
);
|
||||||
$expected7 = array(
|
$expected7 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -261,12 +282,15 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected7, $shortcode7->get_query_args() );
|
$this->assertEquals( $expected7, $shortcode7->get_query_args() );
|
||||||
|
|
||||||
// best_selling_products shortcode.
|
// best_selling_products shortcode.
|
||||||
$shortcode8 = new WC_Shortcode_Products( array(
|
$shortcode8 = new WC_Shortcode_Products(
|
||||||
'per_page' => '12',
|
array(
|
||||||
'columns' => '4',
|
'per_page' => '12',
|
||||||
'category' => '',
|
'columns' => '4',
|
||||||
'operator' => 'IN',
|
'category' => '',
|
||||||
), 'best_selling_products' );
|
'operator' => 'IN',
|
||||||
|
),
|
||||||
|
'best_selling_products'
|
||||||
|
);
|
||||||
$expected8 = array(
|
$expected8 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -284,14 +308,17 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected8, $shortcode8->get_query_args() );
|
$this->assertEquals( $expected8, $shortcode8->get_query_args() );
|
||||||
|
|
||||||
// top_rated_products shortcode.
|
// top_rated_products shortcode.
|
||||||
$shortcode9 = new WC_Shortcode_Products( array(
|
$shortcode9 = new WC_Shortcode_Products(
|
||||||
'per_page' => '12',
|
array(
|
||||||
'columns' => '4',
|
'per_page' => '12',
|
||||||
'orderby' => 'title',
|
'columns' => '4',
|
||||||
'order' => 'ASC',
|
'orderby' => 'title',
|
||||||
'category' => '',
|
'order' => 'ASC',
|
||||||
'operator' => 'IN',
|
'category' => '',
|
||||||
), 'top_rated_products' );
|
'operator' => 'IN',
|
||||||
|
),
|
||||||
|
'top_rated_products'
|
||||||
|
);
|
||||||
$expected9 = array(
|
$expected9 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -308,15 +335,17 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected9, $shortcode9->get_query_args() );
|
$this->assertEquals( $expected9, $shortcode9->get_query_args() );
|
||||||
|
|
||||||
// featured_products shortcode.
|
// featured_products shortcode.
|
||||||
$shortcode10 = new WC_Shortcode_Products( array(
|
$shortcode10 = new WC_Shortcode_Products(
|
||||||
'per_page' => '12',
|
array(
|
||||||
'columns' => '4',
|
'per_page' => '12',
|
||||||
'orderby' => 'date',
|
'columns' => '4',
|
||||||
'order' => 'DESC',
|
'orderby' => 'date',
|
||||||
'category' => '',
|
'order' => 'DESC',
|
||||||
'operator' => 'IN',
|
'category' => '',
|
||||||
'visibility' => 'featured',
|
'operator' => 'IN',
|
||||||
) );
|
'visibility' => 'featured',
|
||||||
|
)
|
||||||
|
);
|
||||||
$expected10 = array(
|
$expected10 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -326,29 +355,35 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
'order' => 'DESC',
|
'order' => 'DESC',
|
||||||
'posts_per_page' => 12,
|
'posts_per_page' => 12,
|
||||||
'meta_query' => $meta_query,
|
'meta_query' => $meta_query,
|
||||||
'tax_query' => array_merge( $tax_query, array(
|
'tax_query' => array_merge(
|
||||||
|
$tax_query,
|
||||||
array(
|
array(
|
||||||
'taxonomy' => 'product_visibility',
|
array(
|
||||||
'terms' => 'featured',
|
'taxonomy' => 'product_visibility',
|
||||||
'field' => 'name',
|
'terms' => 'featured',
|
||||||
'operator' => 'IN',
|
'field' => 'name',
|
||||||
'include_children' => false,
|
'operator' => 'IN',
|
||||||
),
|
'include_children' => false,
|
||||||
) ),
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals( $expected10, $shortcode10->get_query_args() );
|
$this->assertEquals( $expected10, $shortcode10->get_query_args() );
|
||||||
|
|
||||||
// product_attribute shortcode.
|
// product_attribute shortcode.
|
||||||
$shortcode11 = new WC_Shortcode_Products( array(
|
$shortcode11 = new WC_Shortcode_Products(
|
||||||
'per_page' => '12',
|
array(
|
||||||
'columns' => '4',
|
'per_page' => '12',
|
||||||
'orderby' => 'title',
|
'columns' => '4',
|
||||||
'order' => 'asc',
|
'orderby' => 'title',
|
||||||
'attribute' => 'color',
|
'order' => 'asc',
|
||||||
'filter' => 'black',
|
'attribute' => 'color',
|
||||||
), 'product_attribute' );
|
'filter' => 'black',
|
||||||
|
),
|
||||||
|
'product_attribute'
|
||||||
|
);
|
||||||
$expected11 = array(
|
$expected11 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -358,28 +393,34 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
'posts_per_page' => 12,
|
'posts_per_page' => 12,
|
||||||
'meta_query' => $meta_query,
|
'meta_query' => $meta_query,
|
||||||
'tax_query' => array_merge( $tax_query, array(
|
'tax_query' => array_merge(
|
||||||
|
$tax_query,
|
||||||
array(
|
array(
|
||||||
'taxonomy' => 'pa_color',
|
array(
|
||||||
'terms' => array( 'black' ),
|
'taxonomy' => 'pa_color',
|
||||||
'field' => 'slug',
|
'terms' => array( 'black' ),
|
||||||
'operator' => 'IN',
|
'field' => 'slug',
|
||||||
),
|
'operator' => 'IN',
|
||||||
) ),
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals( $expected11, $shortcode11->get_query_args() );
|
$this->assertEquals( $expected11, $shortcode11->get_query_args() );
|
||||||
|
|
||||||
// product_attribute shortcode using term ids.
|
// product_attribute shortcode using term ids.
|
||||||
$shortcode11_id = new WC_Shortcode_Products( array(
|
$shortcode11_id = new WC_Shortcode_Products(
|
||||||
'per_page' => '12',
|
array(
|
||||||
'columns' => '4',
|
'per_page' => '12',
|
||||||
'orderby' => 'title',
|
'columns' => '4',
|
||||||
'order' => 'asc',
|
'orderby' => 'title',
|
||||||
'attribute' => 'color',
|
'order' => 'asc',
|
||||||
'terms' => '123',
|
'attribute' => 'color',
|
||||||
), 'product_attribute' );
|
'terms' => '123',
|
||||||
|
),
|
||||||
|
'product_attribute'
|
||||||
|
);
|
||||||
$expected11_id = array(
|
$expected11_id = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -389,23 +430,28 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
'posts_per_page' => 12,
|
'posts_per_page' => 12,
|
||||||
'meta_query' => $meta_query,
|
'meta_query' => $meta_query,
|
||||||
'tax_query' => array_merge( $tax_query, array(
|
'tax_query' => array_merge(
|
||||||
|
$tax_query,
|
||||||
array(
|
array(
|
||||||
'taxonomy' => 'pa_color',
|
array(
|
||||||
'terms' => array( 123 ),
|
'taxonomy' => 'pa_color',
|
||||||
'field' => 'term_id',
|
'terms' => array( 123 ),
|
||||||
'operator' => 'IN',
|
'field' => 'term_id',
|
||||||
),
|
'operator' => 'IN',
|
||||||
) ),
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals( $expected11_id, $shortcode11_id->get_query_args() );
|
$this->assertEquals( $expected11_id, $shortcode11_id->get_query_args() );
|
||||||
|
|
||||||
// Check for visibility shortcode.
|
// Check for visibility shortcode.
|
||||||
$shortcode12 = new WC_Shortcode_Products( array(
|
$shortcode12 = new WC_Shortcode_Products(
|
||||||
'visibility' => 'hidden',
|
array(
|
||||||
) );
|
'visibility' => 'hidden',
|
||||||
|
)
|
||||||
|
);
|
||||||
$expected12 = array(
|
$expected12 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -429,9 +475,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( $expected12, $shortcode12->get_query_args() );
|
$this->assertEquals( $expected12, $shortcode12->get_query_args() );
|
||||||
|
|
||||||
$shortcode13 = new WC_Shortcode_Products( array(
|
$shortcode13 = new WC_Shortcode_Products(
|
||||||
'visibility' => 'catalog',
|
array(
|
||||||
) );
|
'visibility' => 'catalog',
|
||||||
|
)
|
||||||
|
);
|
||||||
$expected13 = array(
|
$expected13 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -462,9 +510,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertEquals( $expected13, $shortcode13->get_query_args() );
|
$this->assertEquals( $expected13, $shortcode13->get_query_args() );
|
||||||
|
|
||||||
$shortcode14 = new WC_Shortcode_Products( array(
|
$shortcode14 = new WC_Shortcode_Products(
|
||||||
'visibility' => 'search',
|
array(
|
||||||
) );
|
'visibility' => 'search',
|
||||||
|
)
|
||||||
|
);
|
||||||
$expected14 = array(
|
$expected14 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -496,10 +546,12 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$this->assertEquals( $expected14, $shortcode14->get_query_args() );
|
$this->assertEquals( $expected14, $shortcode14->get_query_args() );
|
||||||
|
|
||||||
// products shortcode -- select multiple categories using AND operator.
|
// products shortcode -- select multiple categories using AND operator.
|
||||||
$shortcode15 = new WC_Shortcode_Products( array(
|
$shortcode15 = new WC_Shortcode_Products(
|
||||||
'category' => 'cat1,cat2',
|
array(
|
||||||
'cat_operator' => 'AND',
|
'category' => 'cat1,cat2',
|
||||||
) );
|
'cat_operator' => 'AND',
|
||||||
|
)
|
||||||
|
);
|
||||||
$expected15 = array(
|
$expected15 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -509,25 +561,30 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'meta_query' => $meta_query,
|
'meta_query' => $meta_query,
|
||||||
'tax_query' => array_merge( $tax_query, array(
|
'tax_query' => array_merge(
|
||||||
|
$tax_query,
|
||||||
array(
|
array(
|
||||||
'taxonomy' => 'product_cat',
|
array(
|
||||||
'terms' => array( 'cat1', 'cat2' ),
|
'taxonomy' => 'product_cat',
|
||||||
'field' => 'slug',
|
'terms' => array( 'cat1', 'cat2' ),
|
||||||
'operator' => 'AND',
|
'field' => 'slug',
|
||||||
'include_children' => false,
|
'operator' => 'AND',
|
||||||
),
|
'include_children' => false,
|
||||||
) ),
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals( $expected15, $shortcode15->get_query_args() );
|
$this->assertEquals( $expected15, $shortcode15->get_query_args() );
|
||||||
|
|
||||||
// products shortcode -- exclude multiple categories using NOT IN operator.
|
// products shortcode -- exclude multiple categories using NOT IN operator.
|
||||||
$shortcode16 = new WC_Shortcode_Products( array(
|
$shortcode16 = new WC_Shortcode_Products(
|
||||||
'category' => 'cat1,cat2',
|
array(
|
||||||
'cat_operator' => 'NOT IN',
|
'category' => 'cat1,cat2',
|
||||||
) );
|
'cat_operator' => 'NOT IN',
|
||||||
|
)
|
||||||
|
);
|
||||||
$expected16 = array(
|
$expected16 = array(
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
@ -537,15 +594,18 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'meta_query' => $meta_query,
|
'meta_query' => $meta_query,
|
||||||
'tax_query' => array_merge( $tax_query, array(
|
'tax_query' => array_merge(
|
||||||
|
$tax_query,
|
||||||
array(
|
array(
|
||||||
'taxonomy' => 'product_cat',
|
array(
|
||||||
'terms' => array( 'cat1', 'cat2' ),
|
'taxonomy' => 'product_cat',
|
||||||
'field' => 'slug',
|
'terms' => array( 'cat1', 'cat2' ),
|
||||||
'operator' => 'NOT IN',
|
'field' => 'slug',
|
||||||
'include_children' => true,
|
'operator' => 'NOT IN',
|
||||||
),
|
'include_children' => true,
|
||||||
) ),
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -579,9 +639,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
||||||
$shortcode = new WC_Shortcode_Products();
|
$shortcode = new WC_Shortcode_Products();
|
||||||
$this->assertFalse( $shortcode->set_product_as_visible( false ) );
|
$this->assertFalse( $shortcode->set_product_as_visible( false ) );
|
||||||
|
|
||||||
$shortcode2 = new WC_Shortcode_Products( array(
|
$shortcode2 = new WC_Shortcode_Products(
|
||||||
'visibility' => 'hidden',
|
array(
|
||||||
) );
|
'visibility' => 'hidden',
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertTrue( $shortcode2->set_product_as_visible( false ) );
|
$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",
|
'groupby' => "$wpdb->posts.ID",
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals( $expected, WC_Shortcode_Products::order_by_rating_post_clauses( array(
|
$this->assertEquals(
|
||||||
'where' => '',
|
$expected,
|
||||||
'join' => '',
|
WC_Shortcode_Products::order_by_rating_post_clauses(
|
||||||
) ) );
|
array(
|
||||||
|
'where' => '',
|
||||||
|
'join' => '',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
|
||||||
$tax_rates = WC_Tax::get_rates();
|
$tax_rates = WC_Tax::get_rates();
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
$tax_rates, array(
|
$tax_rates,
|
||||||
|
array(
|
||||||
$tax_rate_id => array(
|
$tax_rate_id => array(
|
||||||
'rate' => 20.0,
|
'rate' => 20.0,
|
||||||
'label' => 'VAT',
|
'label' => 'VAT',
|
||||||
|
@ -56,7 +57,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
$tax_rates = WC_Tax::get_rates();
|
$tax_rates = WC_Tax::get_rates();
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
$tax_rates, array(
|
$tax_rates,
|
||||||
|
array(
|
||||||
$tax_rate_catch_all_id => array(
|
$tax_rate_catch_all_id => array(
|
||||||
'rate' => 0.0,
|
'rate' => 0.0,
|
||||||
'label' => 'VAT',
|
'label' => 'VAT',
|
||||||
|
@ -89,14 +91,16 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
|
||||||
$tax_rates = WC_Tax::get_shipping_tax_rates();
|
$tax_rates = WC_Tax::get_shipping_tax_rates();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$tax_rates, array(
|
$tax_rates,
|
||||||
|
array(
|
||||||
$tax_rate_id => array(
|
$tax_rate_id => array(
|
||||||
'rate' => '20.0000',
|
'rate' => '20.0000',
|
||||||
'label' => 'VAT',
|
'label' => 'VAT',
|
||||||
'shipping' => 'yes',
|
'shipping' => 'yes',
|
||||||
'compound' => 'no',
|
'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();
|
$tax_rates = WC_Tax::get_base_tax_rates();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$tax_rates, array(
|
$tax_rates,
|
||||||
|
array(
|
||||||
$tax_rate_id => array(
|
$tax_rate_id => array(
|
||||||
'rate' => '20.0000',
|
'rate' => '20.0000',
|
||||||
'label' => 'VAT',
|
'label' => 'VAT',
|
||||||
|
@ -161,7 +166,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$tax_rates, array(
|
$tax_rates,
|
||||||
|
array(
|
||||||
$tax_rate_id => array(
|
$tax_rate_id => array(
|
||||||
'rate' => '20.0000',
|
'rate' => '20.0000',
|
||||||
'label' => 'VAT',
|
'label' => 'VAT',
|
||||||
|
@ -201,7 +207,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$tax_rates, array(
|
$tax_rates,
|
||||||
|
array(
|
||||||
$tax_rate_id => array(
|
$tax_rate_id => array(
|
||||||
'rate' => '20.0000',
|
'rate' => '20.0000',
|
||||||
'label' => 'VAT',
|
'label' => 'VAT',
|
||||||
|
@ -296,7 +303,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
|
||||||
// prices exclusive of tax
|
// prices exclusive of tax
|
||||||
$calced_tax = WC_Tax::calc_tax( '100', $tax_rates, false, false );
|
$calced_tax = WC_Tax::calc_tax( '100', $tax_rates, false, false );
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$calced_tax, array(
|
$calced_tax,
|
||||||
|
array(
|
||||||
$tax_rate_1_id => '5.0000',
|
$tax_rate_1_id => '5.0000',
|
||||||
$tax_rate_2_id => '8.925',
|
$tax_rate_2_id => '8.925',
|
||||||
)
|
)
|
||||||
|
|
|
@ -44,7 +44,7 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
|
||||||
'purchasable',
|
'purchasable',
|
||||||
'product-type-simple',
|
'product-type-simple',
|
||||||
);
|
);
|
||||||
$actual = array_values( wc_get_product_class( 'foo', $product ) );
|
$actual = array_values( wc_get_product_class( 'foo', $product ) );
|
||||||
|
|
||||||
$this->assertEquals( $expected, $actual, print_r( $actual, true ) );
|
$this->assertEquals( $expected, $actual, print_r( $actual, true ) );
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
|
||||||
'purchasable',
|
'purchasable',
|
||||||
'product-type-simple',
|
'product-type-simple',
|
||||||
);
|
);
|
||||||
$actual = array_values( wc_get_product_class( 'foo', $product ) );
|
$actual = array_values( wc_get_product_class( 'foo', $product ) );
|
||||||
|
|
||||||
$this->assertEquals( $expected, $actual, print_r( $actual, true ) );
|
$this->assertEquals( $expected, $actual, print_r( $actual, true ) );
|
||||||
add_filter( 'woocommerce_get_product_class_include_taxonomies', '__return_false' );
|
add_filter( 'woocommerce_get_product_class_include_taxonomies', '__return_false' );
|
||||||
|
@ -91,7 +91,7 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
wc_dropdown_variation_attribute_options(
|
wc_dropdown_variation_attribute_options(
|
||||||
array(
|
array(
|
||||||
'product' => $product,
|
'product' => $product,
|
||||||
'attribute' => 'pa_size',
|
'attribute' => 'pa_size',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -101,14 +101,14 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
|
||||||
* Test: test_wc_dropdown_variation_attribute_options_should_return_attributes_list_and_selected_element.
|
* Test: test_wc_dropdown_variation_attribute_options_should_return_attributes_list_and_selected_element.
|
||||||
*/
|
*/
|
||||||
public function test_wc_dropdown_variation_attribute_options_should_return_attributes_list_and_selected_element() {
|
public function test_wc_dropdown_variation_attribute_options_should_return_attributes_list_and_selected_element() {
|
||||||
$product = WC_Helper_Product::create_variation_product();
|
$product = WC_Helper_Product::create_variation_product();
|
||||||
$_REQUEST['attribute_pa_size'] = 'large';
|
$_REQUEST['attribute_pa_size'] = 'large';
|
||||||
|
|
||||||
$this->expectOutputString( '<select id="pa_size" class="" name="attribute_pa_size" data-attribute_name="attribute_pa_size" data-show_option_none="yes"><option value="">Choose an option</option><option value="large" selected=\'selected\'>large</option><option value="small" >small</option></select>' );
|
$this->expectOutputString( '<select id="pa_size" class="" name="attribute_pa_size" data-attribute_name="attribute_pa_size" data-show_option_none="yes"><option value="">Choose an option</option><option value="large" selected=\'selected\'>large</option><option value="small" >small</option></select>' );
|
||||||
|
|
||||||
wc_dropdown_variation_attribute_options(
|
wc_dropdown_variation_attribute_options(
|
||||||
array(
|
array(
|
||||||
'product' => $product,
|
'product' => $product,
|
||||||
'attribute' => 'pa_size',
|
'attribute' => 'pa_size',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -124,22 +124,22 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
|
||||||
public function test_wc_query_string_form_fields() {
|
public function test_wc_query_string_form_fields() {
|
||||||
$actual_html = wc_query_string_form_fields( '?test=1', array(), '', true );
|
$actual_html = wc_query_string_form_fields( '?test=1', array(), '', true );
|
||||||
$expected_html = '<input type="hidden" name="test" value="1" />';
|
$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 );
|
$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" />';
|
$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 );
|
$actual_html = wc_query_string_form_fields( '?test.something=something.else', array(), '', true );
|
||||||
$expected_html = '<input type="hidden" name="test.something" value="something" />';
|
$expected_html = '<input type="hidden" name="test.something" value="something.else" />';
|
||||||
$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 );
|
$actual_html = wc_query_string_form_fields( '?test+something=something+else', array(), '', true );
|
||||||
$expected_html = '<input type="hidden" name="test+something" value="something" />';
|
$expected_html = '<input type="hidden" name="test+something" value="something+else" />';
|
||||||
$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%20something=something', array(), '', true );
|
$actual_html = wc_query_string_form_fields( '?test%20something=something%20else', array(), '', true );
|
||||||
$expected_html = '<input type="hidden" name="test%20something" value="something" />';
|
$expected_html = '<input type="hidden" name="test%20something" value="something%20else" />';
|
||||||
$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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ class WC_Tests_Totals extends WC_Unit_Test_Case {
|
||||||
public function test_cart_totals() {
|
public function test_cart_totals() {
|
||||||
WC()->customer->set_is_vat_exempt( false );
|
WC()->customer->set_is_vat_exempt( false );
|
||||||
$this->totals = new WC_Cart_Totals( WC()->cart );
|
$this->totals = new WC_Cart_Totals( WC()->cart );
|
||||||
$cart = WC()->cart;
|
$cart = WC()->cart;
|
||||||
|
|
||||||
$this->assertEquals( 40.00, $cart->get_fee_total() );
|
$this->assertEquals( 40.00, $cart->get_fee_total() );
|
||||||
$this->assertEquals( 36.00, $cart->get_cart_contents_total() );
|
$this->assertEquals( 36.00, $cart->get_cart_contents_total() );
|
||||||
|
@ -201,7 +201,7 @@ class WC_Tests_Totals extends WC_Unit_Test_Case {
|
||||||
public function test_cart_totals_tax_exempt_customer() {
|
public function test_cart_totals_tax_exempt_customer() {
|
||||||
WC()->customer->set_is_vat_exempt( true );
|
WC()->customer->set_is_vat_exempt( true );
|
||||||
$this->totals = new WC_Cart_Totals( WC()->cart );
|
$this->totals = new WC_Cart_Totals( WC()->cart );
|
||||||
$cart = WC()->cart;
|
$cart = WC()->cart;
|
||||||
|
|
||||||
$this->assertEquals( 40.00, $cart->get_fee_total() );
|
$this->assertEquals( 40.00, $cart->get_fee_total() );
|
||||||
$this->assertEquals( 36.00, $cart->get_cart_contents_total() );
|
$this->assertEquals( 36.00, $cart->get_cart_contents_total() );
|
||||||
|
|
|
@ -900,10 +900,10 @@ class WC_Tests_Core_Functions extends WC_Unit_Test_Case {
|
||||||
'billing_first_name' => array(
|
'billing_first_name' => array(
|
||||||
'priority' => 10,
|
'priority' => 10,
|
||||||
),
|
),
|
||||||
'billing_last_name' => array(
|
'billing_last_name' => array(
|
||||||
'priority' => 20,
|
'priority' => 20,
|
||||||
),
|
),
|
||||||
'billing_email' => array(
|
'billing_email' => array(
|
||||||
'priority' => 1,
|
'priority' => 1,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,26 +19,32 @@ class WC_Tests_User_Functions extends WC_Unit_Test_Case {
|
||||||
public function test_wc_modify_editable_roles() {
|
public function test_wc_modify_editable_roles() {
|
||||||
$password = wp_generate_password();
|
$password = wp_generate_password();
|
||||||
|
|
||||||
$admin_id = wp_insert_user( array(
|
$admin_id = wp_insert_user(
|
||||||
'user_login' => 'test_admin',
|
array(
|
||||||
'user_pass' => $password,
|
'user_login' => 'test_admin',
|
||||||
'user_email' => 'admin@example.com',
|
'user_pass' => $password,
|
||||||
'role' => 'administrator',
|
'user_email' => 'admin@example.com',
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$editor_id = wp_insert_user( array(
|
$editor_id = wp_insert_user(
|
||||||
'user_login' => 'test_editor',
|
array(
|
||||||
'user_pass' => $password,
|
'user_login' => 'test_editor',
|
||||||
'user_email' => 'editor@example.com',
|
'user_pass' => $password,
|
||||||
'role' => 'editor',
|
'user_email' => 'editor@example.com',
|
||||||
) );
|
'role' => 'editor',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$manager_id = wp_insert_user( array(
|
$manager_id = wp_insert_user(
|
||||||
'user_login' => 'test_manager',
|
array(
|
||||||
'user_pass' => $password,
|
'user_login' => 'test_manager',
|
||||||
'user_email' => 'manager@example.com',
|
'user_pass' => $password,
|
||||||
'role' => 'shop_manager',
|
'user_email' => 'manager@example.com',
|
||||||
) );
|
'role' => 'shop_manager',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Admins should be able to edit anyone.
|
// Admins should be able to edit anyone.
|
||||||
wp_set_current_user( $admin_id );
|
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() {
|
public function test_wc_modify_map_meta_cap() {
|
||||||
$password = wp_generate_password();
|
$password = wp_generate_password();
|
||||||
|
|
||||||
$admin_id = wp_insert_user( array(
|
$admin_id = wp_insert_user(
|
||||||
'user_login' => 'test_admin',
|
array(
|
||||||
'user_pass' => $password,
|
'user_login' => 'test_admin',
|
||||||
'user_email' => 'admin@example.com',
|
'user_pass' => $password,
|
||||||
'role' => 'administrator',
|
'user_email' => 'admin@example.com',
|
||||||
) );
|
'role' => 'administrator',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$editor_id = wp_insert_user( array(
|
$editor_id = wp_insert_user(
|
||||||
'user_login' => 'test_editor',
|
array(
|
||||||
'user_pass' => $password,
|
'user_login' => 'test_editor',
|
||||||
'user_email' => 'editor@example.com',
|
'user_pass' => $password,
|
||||||
'role' => 'editor',
|
'user_email' => 'editor@example.com',
|
||||||
) );
|
'role' => 'editor',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$manager_id = wp_insert_user( array(
|
$manager_id = wp_insert_user(
|
||||||
'user_login' => 'test_manager',
|
array(
|
||||||
'user_pass' => $password,
|
'user_login' => 'test_manager',
|
||||||
'user_email' => 'manager@example.com',
|
'user_pass' => $password,
|
||||||
'role' => 'shop_manager',
|
'user_email' => 'manager@example.com',
|
||||||
) );
|
'role' => 'shop_manager',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$customer_id = wp_insert_user( array(
|
$customer_id = wp_insert_user(
|
||||||
'user_login' => 'test_customer',
|
array(
|
||||||
'user_pass' => $password,
|
'user_login' => 'test_customer',
|
||||||
'user_email' => 'customer@example.com',
|
'user_pass' => $password,
|
||||||
'role' => 'customer',
|
'user_email' => 'customer@example.com',
|
||||||
) );
|
'role' => 'customer',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Admins should be able to edit or promote anyone.
|
// Admins should be able to edit or promote anyone.
|
||||||
wp_set_current_user( $admin_id );
|
wp_set_current_user( $admin_id );
|
||||||
|
@ -123,21 +137,25 @@ class WC_Tests_User_Functions extends WC_Unit_Test_Case {
|
||||||
public function test_wc_shop_manager_has_capability() {
|
public function test_wc_shop_manager_has_capability() {
|
||||||
$password = wp_generate_password();
|
$password = wp_generate_password();
|
||||||
|
|
||||||
$manager_id = wp_insert_user( array(
|
$manager_id = wp_insert_user(
|
||||||
'user_login' => 'test_manager',
|
array(
|
||||||
'user_pass' => $password,
|
'user_login' => 'test_manager',
|
||||||
'user_email' => 'manager@example.com',
|
'user_pass' => $password,
|
||||||
'role' => 'shop_manager',
|
'user_email' => 'manager@example.com',
|
||||||
) );
|
'role' => 'shop_manager',
|
||||||
$manager = new WP_User( $manager_id );
|
)
|
||||||
|
);
|
||||||
|
$manager = new WP_User( $manager_id );
|
||||||
|
|
||||||
$editor_id = wp_insert_user( array(
|
$editor_id = wp_insert_user(
|
||||||
'user_login' => 'test_editor',
|
array(
|
||||||
'user_pass' => $password,
|
'user_login' => 'test_editor',
|
||||||
'user_email' => 'editor@example.com',
|
'user_pass' => $password,
|
||||||
'role' => 'editor',
|
'user_email' => 'editor@example.com',
|
||||||
) );
|
'role' => 'editor',
|
||||||
$editor = new WP_User( $editor_id );
|
)
|
||||||
|
);
|
||||||
|
$editor = new WP_User( $editor_id );
|
||||||
|
|
||||||
// Test capabilities translation is working correctly and only gives shop managers capabilities.
|
// Test capabilities translation is working correctly and only gives shop managers capabilities.
|
||||||
$this->assertTrue( $manager->has_cap( 'edit_users' ) );
|
$this->assertTrue( $manager->has_cap( 'edit_users' ) );
|
||||||
|
|
|
@ -108,7 +108,7 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
|
||||||
public function test_add_query_vars() {
|
public function test_add_query_vars() {
|
||||||
WC()->query->init_query_vars();
|
WC()->query->init_query_vars();
|
||||||
|
|
||||||
$vars = array(
|
$vars = array(
|
||||||
'test1',
|
'test1',
|
||||||
'test2',
|
'test2',
|
||||||
);
|
);
|
||||||
|
|
|
@ -51,11 +51,11 @@ class WC_Tests_Conditional_Functions extends WC_Unit_Test_Case {
|
||||||
array( false, wc_is_valid_url( 'https://google.com/test invalid' ) ),
|
array( false, wc_is_valid_url( 'https://google.com/test invalid' ) ),
|
||||||
|
|
||||||
// Test some valid URLs
|
// Test some valid URLs
|
||||||
array( true, wc_is_valid_url( 'http://google.com' ) ),
|
array( true, wc_is_valid_url( 'http://google.com' ) ),
|
||||||
array( true, wc_is_valid_url( 'https://google.com' ) ),
|
array( true, wc_is_valid_url( 'https://google.com' ) ),
|
||||||
array( true, wc_is_valid_url( 'https://google.com/test%20valid' ) ),
|
array( true, wc_is_valid_url( 'https://google.com/test%20valid' ) ),
|
||||||
array( true, wc_is_valid_url( 'https://google.com/test-valid/?query=test' ) ),
|
array( true, wc_is_valid_url( 'https://google.com/test-valid/?query=test' ) ),
|
||||||
array( true, wc_is_valid_url( 'https://google.com/test-valid/#hash' ) ),
|
array( true, wc_is_valid_url( 'https://google.com/test-valid/#hash' ) ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +86,6 @@ class WC_Tests_Conditional_Functions extends WC_Unit_Test_Case {
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
public function test_wc_is_valid_url( $assert, $values ) {
|
public function test_wc_is_valid_url( $assert, $values ) {
|
||||||
$this->assertEquals( $assert, $values );
|
$this->assertEquals( $assert, $values );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,8 +88,8 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
|
||||||
function test_handle_deprecated_hook_filter() {
|
function test_handle_deprecated_hook_filter() {
|
||||||
$new_hook = 'wc_new_hook';
|
$new_hook = 'wc_new_hook';
|
||||||
$old_hook = 'wc_old_hook';
|
$old_hook = 'wc_old_hook';
|
||||||
$args = array( false );
|
$args = array( false );
|
||||||
$return = -1;
|
$return = -1;
|
||||||
|
|
||||||
add_filter( $old_hook, array( $this, 'toggle_value' ) );
|
add_filter( $old_hook, array( $this, 'toggle_value' ) );
|
||||||
|
|
||||||
|
@ -103,11 +103,11 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
function test_handle_deprecated_hook_action() {
|
function test_handle_deprecated_hook_action() {
|
||||||
$new_hook = 'wc_new_hook';
|
$new_hook = 'wc_new_hook';
|
||||||
$old_hook = 'wc_old_hook';
|
$old_hook = 'wc_old_hook';
|
||||||
$test_value = false;
|
$test_value = false;
|
||||||
$args = array( &$test_value );
|
$args = array( &$test_value );
|
||||||
$return = -1;
|
$return = -1;
|
||||||
|
|
||||||
add_filter( $old_hook, array( $this, 'toggle_value_by_ref' ) );
|
add_filter( $old_hook, array( $this, 'toggle_value_by_ref' ) );
|
||||||
|
|
||||||
|
@ -135,18 +135,18 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
function test_action_handler() {
|
function test_action_handler() {
|
||||||
$test_product = WC_Helper_Product::create_simple_product();
|
$test_product = WC_Helper_Product::create_simple_product();
|
||||||
$test_order = WC_Helper_Order::create_order( 1, $test_product );
|
$test_order = WC_Helper_Order::create_order( 1, $test_product );
|
||||||
$test_order_id = $test_order->get_id();
|
$test_order_id = $test_order->get_id();
|
||||||
$test_items = $test_order->get_items();
|
$test_items = $test_order->get_items();
|
||||||
$test_item = reset( $test_items );
|
$test_item = reset( $test_items );
|
||||||
$test_item_id = $test_item->get_id();
|
$test_item_id = $test_item->get_id();
|
||||||
|
|
||||||
add_action( 'woocommerce_order_edit_product', array( $this, 'set_meta' ), 10, 2 );
|
add_action( 'woocommerce_order_edit_product', array( $this, 'set_meta' ), 10, 2 );
|
||||||
do_action( 'woocommerce_update_order_item', $test_item_id, $test_item, $test_order_id );
|
do_action( 'woocommerce_update_order_item', $test_item_id, $test_item, $test_order_id );
|
||||||
|
|
||||||
$order_update_worked = (bool) get_post_meta( $test_order_id, 'wc_deprecated_hook_test_item1_meta', 1 );
|
$order_update_worked = (bool) get_post_meta( $test_order_id, 'wc_deprecated_hook_test_item1_meta', 1 );
|
||||||
$item_update_worked = (bool) get_post_meta( $test_item_id, 'wc_deprecated_hook_test_item2_meta', 2 );
|
$item_update_worked = (bool) get_post_meta( $test_item_id, 'wc_deprecated_hook_test_item2_meta', 2 );
|
||||||
|
|
||||||
$this->assertTrue( $order_update_worked );
|
$this->assertTrue( $order_update_worked );
|
||||||
$this->assertTrue( $item_update_worked );
|
$this->assertTrue( $item_update_worked );
|
||||||
|
@ -164,7 +164,7 @@ class WC_Tests_Deprecated_Hooks extends WC_Unit_Test_Case {
|
||||||
$token = WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
$token = WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
||||||
$token->save();
|
$token->save();
|
||||||
|
|
||||||
$product = new WC_Product_Variation;
|
$product = new WC_Product_Variation();
|
||||||
$product->save();
|
$product->save();
|
||||||
|
|
||||||
$this->assertEquals( 1, did_action( 'woocommerce_payment_token_created' ) );
|
$this->assertEquals( 1, did_action( 'woocommerce_payment_token_created' ) );
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
|
||||||
*
|
*
|
||||||
* @param string $level
|
* @param string $level
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
*/
|
*/
|
||||||
public function log( $level, $message, $context = array() ) {
|
public function log( $level, $message, $context = array() ) {
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
|
||||||
* Do nothing.
|
* Do nothing.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
*/
|
*/
|
||||||
public function emergency( $message, $context = array() ) {
|
public function emergency( $message, $context = array() ) {
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
|
||||||
* Do nothing.
|
* Do nothing.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
*/
|
*/
|
||||||
public function alert( $message, $context = array() ) {
|
public function alert( $message, $context = array() ) {
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
|
||||||
* Do nothing.
|
* Do nothing.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
*/
|
*/
|
||||||
public function critical( $message, $context = array() ) {
|
public function critical( $message, $context = array() ) {
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
|
||||||
* Do nothing.
|
* Do nothing.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
*/
|
*/
|
||||||
public function error( $message, $context = array() ) {
|
public function error( $message, $context = array() ) {
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
|
||||||
* Do nothing.
|
* Do nothing.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
*/
|
*/
|
||||||
public function warning( $message, $context = array() ) {
|
public function warning( $message, $context = array() ) {
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
|
||||||
* Do nothing.
|
* Do nothing.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
*/
|
*/
|
||||||
public function notice( $message, $context = array() ) {
|
public function notice( $message, $context = array() ) {
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
|
||||||
* Do nothing.
|
* Do nothing.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
*/
|
*/
|
||||||
public function info( $message, $context = array() ) {
|
public function info( $message, $context = array() ) {
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ class Dummy_WC_Logger implements WC_Logger_Interface {
|
||||||
* Do nothing.
|
* Do nothing.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
*/
|
*/
|
||||||
public function debug( $message, $context = array() ) {
|
public function debug( $message, $context = array() ) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,10 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
|
|
||||||
if ( ! class_exists( 'WC_Plugin_Updates' ) ) {
|
if ( ! class_exists( 'WC_Plugin_Updates' ) ) {
|
||||||
$bootstrap = WC_Unit_Tests_Bootstrap::instance();
|
$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();
|
$this->plugins = array();
|
||||||
|
|
||||||
add_filter( 'woocommerce_get_plugins_with_header', array( $this, 'populate_untested_plugins' ), 10, 2 );
|
add_filter( 'woocommerce_get_plugins_with_header', array( $this, 'populate_untested_plugins' ), 10, 2 );
|
||||||
|
@ -35,7 +35,7 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
/**
|
/**
|
||||||
* Allow this test suite to easily define plugin results to test for the version tested header.
|
* Allow this test suite to easily define plugin results to test for the version tested header.
|
||||||
*
|
*
|
||||||
* @param array $plugins array of plugin data in same format as get_plugins.
|
* @param array $plugins array of plugin data in same format as get_plugins.
|
||||||
* @param string $header plugin header results matched on.
|
* @param string $header plugin header results matched on.
|
||||||
* @return array modified $plugins.
|
* @return array modified $plugins.
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
|
@ -57,7 +57,7 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
$release = 'major';
|
$release = 'major';
|
||||||
|
|
||||||
$this->plugins = array(
|
$this->plugins = array(
|
||||||
'test/test.php' => array(
|
'test/test.php' => array(
|
||||||
'Name' => 'Test plugin',
|
'Name' => 'Test plugin',
|
||||||
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.0.0',
|
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.0.0',
|
||||||
),
|
),
|
||||||
|
@ -74,29 +74,29 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.0.1',
|
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.0.1',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$new_version = '4.0.0';
|
$new_version = '4.0.0';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
||||||
|
|
||||||
$new_version = '3.9.0';
|
$new_version = '3.9.0';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
||||||
|
|
||||||
$new_version = '4.3.0';
|
$new_version = '4.3.0';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
||||||
|
|
||||||
$new_version = '4.0.2';
|
$new_version = '4.0.2';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
||||||
|
@ -112,7 +112,7 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
$release = 'major';
|
$release = 'major';
|
||||||
|
|
||||||
$this->plugins = array(
|
$this->plugins = array(
|
||||||
'test/test.php' => array(
|
'test/test.php' => array(
|
||||||
'Name' => 'Test plugin',
|
'Name' => 'Test plugin',
|
||||||
WC_Plugin_Updates::VERSION_TESTED_HEADER => '3.0.0',
|
WC_Plugin_Updates::VERSION_TESTED_HEADER => '3.0.0',
|
||||||
),
|
),
|
||||||
|
@ -125,18 +125,18 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
WC_Plugin_Updates::VERSION_TESTED_HEADER => '3.0',
|
WC_Plugin_Updates::VERSION_TESTED_HEADER => '3.0',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$plugin_keys = array_keys( $this->plugins );
|
$plugin_keys = array_keys( $this->plugins );
|
||||||
|
|
||||||
$new_version = '4.0.0';
|
$new_version = '4.0.0';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
||||||
|
|
||||||
$new_version = '4.3.0';
|
$new_version = '4.3.0';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
||||||
|
|
||||||
$new_version = '4.0.2';
|
$new_version = '4.0.2';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
$release = 'minor';
|
$release = 'minor';
|
||||||
|
|
||||||
$this->plugins = array(
|
$this->plugins = array(
|
||||||
'test/test.php' => array(
|
'test/test.php' => array(
|
||||||
'Name' => 'Test plugin',
|
'Name' => 'Test plugin',
|
||||||
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.1.0',
|
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.1.0',
|
||||||
),
|
),
|
||||||
|
@ -166,22 +166,22 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.2.1',
|
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.2.1',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$new_version = '4.1.0';
|
$new_version = '4.1.0';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
||||||
|
|
||||||
$new_version = '4.2.0';
|
$new_version = '4.2.0';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertArrayHasKey( 'test/test.php', $untested );
|
$this->assertArrayHasKey( 'test/test.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
||||||
$this->assertArrayHasKey( 'test3/test3.php', $untested );
|
$this->assertArrayHasKey( 'test3/test3.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
$this->assertArrayNotHasKey( 'test4/test4.php', $untested );
|
||||||
|
|
||||||
$new_version = '4.1.5';
|
$new_version = '4.1.5';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
||||||
|
@ -197,7 +197,7 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
$release = 'minor';
|
$release = 'minor';
|
||||||
|
|
||||||
$this->plugins = array(
|
$this->plugins = array(
|
||||||
'test/test.php' => array(
|
'test/test.php' => array(
|
||||||
'Name' => 'Test plugin',
|
'Name' => 'Test plugin',
|
||||||
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.1.0',
|
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.1.0',
|
||||||
),
|
),
|
||||||
|
@ -210,14 +210,14 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.2',
|
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4.2',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$plugin_keys = array_keys( $this->plugins );
|
$plugin_keys = array_keys( $this->plugins );
|
||||||
|
|
||||||
$new_version = '4.3.0';
|
$new_version = '4.3.0';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
||||||
|
|
||||||
$new_version = '4.3.1';
|
$new_version = '4.3.1';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
$this->assertEquals( $plugin_keys, array_intersect( $plugin_keys, array_keys( $untested ) ) );
|
||||||
|
|
||||||
$new_version = '4.1.0';
|
$new_version = '4.1.0';
|
||||||
|
@ -237,7 +237,7 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
$release = 'minor';
|
$release = 'minor';
|
||||||
|
|
||||||
$this->plugins = array(
|
$this->plugins = array(
|
||||||
'test/test.php' => array(
|
'test/test.php' => array(
|
||||||
'Name' => 'Test plugin',
|
'Name' => 'Test plugin',
|
||||||
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4',
|
WC_Plugin_Updates::VERSION_TESTED_HEADER => '4',
|
||||||
),
|
),
|
||||||
|
@ -255,13 +255,13 @@ class WC_Tests_Plugin_Updates extends WC_Unit_Test_Case {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$release = 'major';
|
$release = 'major';
|
||||||
$new_version = '5.0.0';
|
$new_version = '5.0.0';
|
||||||
$this->assertArrayHasKey( 'test/test.php', $this->updates->get_untested_plugins( $new_version, $release ) );
|
$this->assertArrayHasKey( 'test/test.php', $this->updates->get_untested_plugins( $new_version, $release ) );
|
||||||
|
|
||||||
$release = 'minor';
|
$release = 'minor';
|
||||||
$new_version = '4.1.0';
|
$new_version = '4.1.0';
|
||||||
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
$untested = $this->updates->get_untested_plugins( $new_version, $release );
|
||||||
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
$this->assertArrayNotHasKey( 'test/test.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
$this->assertArrayNotHasKey( 'test2/test2.php', $untested );
|
||||||
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
$this->assertArrayNotHasKey( 'test3/test3.php', $untested );
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue