Removed line item limit and make sure the URL is shorter than 2083 characters
- removed limit to 9 line items per Paypal order - if the request URL with all line items will be longer than 2083 characters, send it as one line item - fix the character limit function to account for URL encoding happening in http_build_query
This commit is contained in:
parent
dc7aa30694
commit
27a309d2df
|
@ -53,15 +53,16 @@ class WC_Gateway_Paypal_Request {
|
|||
* @return string
|
||||
*/
|
||||
public function get_request_url( $order, $sandbox = false ) {
|
||||
if ( $sandbox ) {
|
||||
$this->request_url_prefix = 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&';
|
||||
} else {
|
||||
$this->request_url_prefix = 'https://www.paypal.com/cgi-bin/webscr?';
|
||||
}
|
||||
$paypal_args = http_build_query( $this->get_paypal_args( $order ), '', '&' );
|
||||
|
||||
WC_Gateway_Paypal::log( 'PayPal Request Args for order ' . $order->get_order_number() . ': ' . wc_print_r( $paypal_args, true ) );
|
||||
|
||||
if ( $sandbox ) {
|
||||
return 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' . $paypal_args;
|
||||
} else {
|
||||
return 'https://www.paypal.com/cgi-bin/webscr?' . $paypal_args;
|
||||
}
|
||||
return $this->request_url_prefix . $paypal_args;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,8 +73,12 @@ class WC_Gateway_Paypal_Request {
|
|||
* @return string
|
||||
*/
|
||||
protected function limit_length( $string, $limit = 127 ) {
|
||||
if ( strlen( $string ) > $limit ) {
|
||||
$string = substr( $string, 0, $limit - 3 ) . '...';
|
||||
// As the output is to be used in http_build_query which applies URL encoding, the string needs to be
|
||||
// cut as if it was URL-encoded, but returned non-encoded (it will be encoded by http_build_query later).
|
||||
$url_encoded_str = rawurlencode( $string );
|
||||
|
||||
if ( strlen( $url_encoded_str ) > $limit ) {
|
||||
$string = rawurldecode( substr( $url_encoded_str, 0, $limit - 3 ) . '...' );
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
@ -87,43 +92,49 @@ class WC_Gateway_Paypal_Request {
|
|||
protected function get_paypal_args( $order ) {
|
||||
WC_Gateway_Paypal::log( 'Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url );
|
||||
|
||||
$initial_paypal_args = array(
|
||||
'cmd' => '_cart',
|
||||
'business' => $this->gateway->get_option( 'email' ),
|
||||
'no_note' => 1,
|
||||
'currency_code' => get_woocommerce_currency(),
|
||||
'charset' => 'utf-8',
|
||||
'rm' => is_ssl() ? 2 : 1,
|
||||
'upload' => 1,
|
||||
'return' => esc_url_raw( add_query_arg( 'utm_nooverride', '1', $this->gateway->get_return_url( $order ) ) ),
|
||||
'cancel_return' => esc_url_raw( $order->get_cancel_order_url_raw() ),
|
||||
'page_style' => $this->gateway->get_option( 'page_style' ),
|
||||
'image_url' => esc_url_raw( $this->gateway->get_option( 'image_url' ) ),
|
||||
'paymentaction' => $this->gateway->get_option( 'paymentaction' ),
|
||||
'bn' => 'WooThemes_Cart',
|
||||
'invoice' => $this->limit_length( $this->gateway->get_option( 'invoice_prefix' ) . $order->get_order_number(), 127 ),
|
||||
'custom' => wp_json_encode(
|
||||
array(
|
||||
'order_id' => $order->get_id(),
|
||||
'order_key' => $order->get_order_key(),
|
||||
)
|
||||
),
|
||||
'notify_url' => $this->limit_length( $this->notify_url, 255 ),
|
||||
'first_name' => $this->limit_length( $order->get_billing_first_name(), 32 ),
|
||||
'last_name' => $this->limit_length( $order->get_billing_last_name(), 64 ),
|
||||
'address1' => $this->limit_length( $order->get_billing_address_1(), 100 ),
|
||||
'address2' => $this->limit_length( $order->get_billing_address_2(), 100 ),
|
||||
'city' => $this->limit_length( $order->get_billing_city(), 40 ),
|
||||
'state' => $this->get_paypal_state( $order->get_billing_country(), $order->get_billing_state() ),
|
||||
'zip' => $this->limit_length( wc_format_postcode( $order->get_billing_postcode(), $order->get_billing_country() ), 32 ),
|
||||
'country' => $this->limit_length( $order->get_billing_country(), 2 ),
|
||||
'email' => $this->limit_length( $order->get_billing_email() ),
|
||||
);
|
||||
$phone_number_args = $this->get_phone_number_args( $order );
|
||||
$shipping_args = $this->get_shipping_args( $order );
|
||||
$query_str_except_line_items = http_build_query( array_merge( $initial_paypal_args, $phone_number_args, $shipping_args ), '', '&' );
|
||||
$url_except_line_items_length = strlen( $this->request_url_prefix . $query_str_except_line_items );
|
||||
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_args', array_merge(
|
||||
array(
|
||||
'cmd' => '_cart',
|
||||
'business' => $this->gateway->get_option( 'email' ),
|
||||
'no_note' => 1,
|
||||
'currency_code' => get_woocommerce_currency(),
|
||||
'charset' => 'utf-8',
|
||||
'rm' => is_ssl() ? 2 : 1,
|
||||
'upload' => 1,
|
||||
'return' => esc_url_raw( add_query_arg( 'utm_nooverride', '1', $this->gateway->get_return_url( $order ) ) ),
|
||||
'cancel_return' => esc_url_raw( $order->get_cancel_order_url_raw() ),
|
||||
'page_style' => $this->gateway->get_option( 'page_style' ),
|
||||
'image_url' => esc_url_raw( $this->gateway->get_option( 'image_url' ) ),
|
||||
'paymentaction' => $this->gateway->get_option( 'paymentaction' ),
|
||||
'bn' => 'WooThemes_Cart',
|
||||
'invoice' => $this->limit_length( $this->gateway->get_option( 'invoice_prefix' ) . $order->get_order_number(), 127 ),
|
||||
'custom' => wp_json_encode(
|
||||
array(
|
||||
'order_id' => $order->get_id(),
|
||||
'order_key' => $order->get_order_key(),
|
||||
)
|
||||
),
|
||||
'notify_url' => $this->limit_length( $this->notify_url, 255 ),
|
||||
'first_name' => $this->limit_length( $order->get_billing_first_name(), 32 ),
|
||||
'last_name' => $this->limit_length( $order->get_billing_last_name(), 64 ),
|
||||
'address1' => $this->limit_length( $order->get_billing_address_1(), 100 ),
|
||||
'address2' => $this->limit_length( $order->get_billing_address_2(), 100 ),
|
||||
'city' => $this->limit_length( $order->get_billing_city(), 40 ),
|
||||
'state' => $this->get_paypal_state( $order->get_billing_country(), $order->get_billing_state() ),
|
||||
'zip' => $this->limit_length( wc_format_postcode( $order->get_billing_postcode(), $order->get_billing_country() ), 32 ),
|
||||
'country' => $this->limit_length( $order->get_billing_country(), 2 ),
|
||||
'email' => $this->limit_length( $order->get_billing_email() ),
|
||||
),
|
||||
$this->get_phone_number_args( $order ),
|
||||
$this->get_shipping_args( $order ),
|
||||
$this->get_line_item_args( $order )
|
||||
$initial_paypal_args,
|
||||
$phone_number_args,
|
||||
$shipping_args,
|
||||
$this->get_line_item_args( $order, $url_except_line_items_length )
|
||||
), $order
|
||||
);
|
||||
}
|
||||
|
@ -180,19 +191,63 @@ class WC_Gateway_Paypal_Request {
|
|||
return $shipping_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shipping cost line item args for paypal request.
|
||||
*
|
||||
* @param WC_Order $order Order object.
|
||||
* @param bool $include_shipping_tax Whether to include shipping tax or not.
|
||||
* @return array
|
||||
*/
|
||||
protected function get_shipping_cost_line_item( $order, $include_shipping_tax ) {
|
||||
$line_item_args = array();
|
||||
$shipping_total = $order->get_shipping_total();
|
||||
if ( $include_shipping_tax ) {
|
||||
$shipping_total += $order->get_shipping_tax();
|
||||
}
|
||||
|
||||
// Add shipping costs. Paypal ignores anything over 5 digits (999.99 is the max).
|
||||
// We also check that shipping is not the **only** cost as PayPal won't allow payment
|
||||
// if the items have no cost.
|
||||
if ( $order->get_shipping_total() > 0 && $order->get_shipping_total() < 999.99 && $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) !== $this->number_format( $order->get_total(), $order ) ) {
|
||||
$line_item_args['shipping_1'] = $this->number_format( $shipping_total, $order );
|
||||
} elseif ( $order->get_shipping_total() > 0 ) {
|
||||
/* translators: %s: Order shipping method */
|
||||
$this->add_line_item( sprintf( __( 'Shipping via %s', 'woocommerce' ), $order->get_shipping_method() ), 1, $this->number_format( $shipping_total, $order ) );
|
||||
}
|
||||
|
||||
return $line_item_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line item args for paypal request as a single line item.
|
||||
*
|
||||
* @param WC_Order $order Order object.
|
||||
* @param bool $include_shipping_tax Whether to include shipping tax or not.
|
||||
* @return array
|
||||
*/
|
||||
protected function get_line_item_args_single_item( $order, $include_shipping_tax ) {
|
||||
$this->delete_line_items();
|
||||
|
||||
$all_items_name = $this->get_order_item_names( $order );
|
||||
$this->add_line_item( $all_items_name ? $all_items_name : __( 'Order', 'woocommerce' ), 1, $this->number_format( $order->get_total() - $this->round( $order->get_shipping_total() + $order->get_shipping_tax(), $order ), $order ), $order->get_order_number() );
|
||||
$line_item_args = $this->get_shipping_cost_line_item( $order, $include_shipping_tax );
|
||||
|
||||
return array_merge( $line_item_args, $this->get_line_items() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line item args for paypal request.
|
||||
*
|
||||
* @param WC_Order $order Order object.
|
||||
* @param int $url_except_line_items_length Length of URL without line items.
|
||||
* @return array
|
||||
*/
|
||||
protected function get_line_item_args( $order ) {
|
||||
protected function get_line_item_args( $order, $url_except_line_items_length ) {
|
||||
|
||||
/**
|
||||
* Try passing a line item per product if supported.
|
||||
*/
|
||||
if ( ( ! wc_tax_enabled() || ! wc_prices_include_tax() ) && $this->prepare_line_items( $order ) ) {
|
||||
|
||||
$line_item_args = array();
|
||||
$line_item_args['tax_cart'] = $this->number_format( $order->get_total_tax(), $order );
|
||||
|
||||
|
@ -200,41 +255,29 @@ class WC_Gateway_Paypal_Request {
|
|||
$line_item_args['discount_amount_cart'] = $this->number_format( $this->round( $order->get_total_discount(), $order ), $order );
|
||||
}
|
||||
|
||||
// Add shipping costs. Paypal ignores anything over 5 digits (999.99 is the max).
|
||||
// We also check that shipping is not the **only** cost as PayPal won't allow payment
|
||||
// if the items have no cost.
|
||||
if ( $order->get_shipping_total() > 0 && $order->get_shipping_total() < 999.99 && $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) !== $this->number_format( $order->get_total(), $order ) ) {
|
||||
$line_item_args['shipping_1'] = $this->number_format( $order->get_shipping_total(), $order );
|
||||
} elseif ( $order->get_shipping_total() > 0 ) {
|
||||
/* translators: %s: Order shipping method */
|
||||
$this->add_line_item( sprintf( __( 'Shipping via %s', 'woocommerce' ), $order->get_shipping_method() ), 1, $this->number_format( $order->get_shipping_total(), $order ) );
|
||||
}
|
||||
|
||||
$include_shipping_tax = false;
|
||||
$line_item_args = array_merge( $line_item_args, $this->get_shipping_cost_line_item( $order, $include_shipping_tax ) );
|
||||
$line_item_args = array_merge( $line_item_args, $this->get_line_items() );
|
||||
|
||||
$line_items_query_str_length = strlen( http_build_query( $line_item_args, '', '&' ) );
|
||||
|
||||
// If URL is longer than 2,083 chars, ignore line items and send cart to Paypal as a single item.
|
||||
// One item's name can only be 127 characters long, so the URL should not be longer than limit.
|
||||
// URL character limit via:
|
||||
// https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer
|
||||
// +1 for '&' that needs to connect 2 query strings.
|
||||
if ( $url_except_line_items_length + 1 + $line_items_query_str_length > 2083 ) {
|
||||
$line_item_args = $this->get_line_item_args_single_item( $order, $include_shipping_tax );
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* Send order as a single item.
|
||||
*
|
||||
* For shipping, we longer use shipping_1 because paypal ignores it if *any* shipping rules are within paypal, and paypal ignores anything over 5 digits (999.99 is the max).
|
||||
*/
|
||||
$include_shipping_tax = true;
|
||||
$line_item_args = $this->get_line_item_args_single_item( $order, $include_shipping_tax );
|
||||
|
||||
$this->delete_line_items();
|
||||
|
||||
$line_item_args = array();
|
||||
$all_items_name = $this->get_order_item_names( $order );
|
||||
$this->add_line_item( $all_items_name ? $all_items_name : __( 'Order', 'woocommerce' ), 1, $this->number_format( $order->get_total() - $this->round( $order->get_shipping_total() + $order->get_shipping_tax(), $order ), $order ), $order->get_order_number() );
|
||||
|
||||
// Add shipping costs. Paypal ignores anything over 5 digits (999.99 is the max).
|
||||
// We also check that shipping is not the **only** cost as PayPal won't allow payment
|
||||
// if the items have no cost.
|
||||
if ( $order->get_shipping_total() > 0 && $order->get_shipping_total() < 999.99 && $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) !== $this->number_format( $order->get_total(), $order ) ) {
|
||||
$line_item_args['shipping_1'] = $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order );
|
||||
} elseif ( $order->get_shipping_total() > 0 ) {
|
||||
/* translators: %s: Order shipping method */
|
||||
$this->add_line_item( sprintf( __( 'Shipping via %s', 'woocommerce' ), $order->get_shipping_method() ), 1, $this->number_format( $order->get_shipping_total() + $order->get_shipping_tax(), $order ) );
|
||||
}
|
||||
|
||||
$line_item_args = array_merge( $line_item_args, $this->get_line_items() );
|
||||
}
|
||||
|
||||
return $line_item_args;
|
||||
|
@ -364,7 +407,7 @@ class WC_Gateway_Paypal_Request {
|
|||
protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
|
||||
$index = ( count( $this->line_items ) / 4 ) + 1;
|
||||
|
||||
if ( $amount < 0 || $index > 9 ) {
|
||||
if ( $amount < 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,261 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for Paypal standard gateway request.
|
||||
*
|
||||
* @package WooCommerce\Tests\Gateways\Paypal
|
||||
*/
|
||||
|
||||
class WC_Tests_Paypal_Gateway_Request extends WC_Unit_Test_Case {
|
||||
|
||||
protected $products;
|
||||
|
||||
/**
|
||||
* Create $product_count simple products and store them in $this->products.
|
||||
*
|
||||
* @param int $product_count Number of products to create.
|
||||
*/
|
||||
protected function create_products( $product_count = 30 ) {
|
||||
$this->products = array();
|
||||
for ( $i = 0; $i < $product_count; $i++ ) {
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$product->set_name( 'Dummy Product ' . $i );
|
||||
$this->products[] = $product;
|
||||
|
||||
}
|
||||
|
||||
// To test limit length properly, we need a product with a name that is shorter than 127 chars,
|
||||
// but longer than 127 chars when URL-encoded.
|
||||
if ( array_key_exists( 0, $this->products ) ) {
|
||||
$this->products[0]->set_name( 'Dummy Product 😎😎😎😎😎😎😎😎😎😎😎' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add products from $this->products to $order as items, clearing existing order items.
|
||||
*
|
||||
* @param WC_Order $order Order to which the products should be added.
|
||||
*/
|
||||
protected function add_products_to_order( $order ) {
|
||||
// Remove previous items.
|
||||
foreach ( $order->get_items() as $item ) {
|
||||
$order->remove_item( $item->get_id() );
|
||||
}
|
||||
|
||||
// Add new products.
|
||||
foreach ( $this->products as $product ) {
|
||||
$item = new WC_Order_Item_Product();
|
||||
$item->set_props( array(
|
||||
'product' => $product,
|
||||
'quantity' => 3,
|
||||
'subtotal' => wc_get_price_excluding_tax( $product, array( 'qty' => 3 ) ),
|
||||
'total' => wc_get_price_excluding_tax( $product, array( 'qty' => 3 ) ),
|
||||
) );
|
||||
|
||||
$item->save();
|
||||
$order->add_item( $item );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Paypal gateway and Request objects.
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$bootstrap = WC_Unit_Tests_Bootstrap::instance();
|
||||
include_once $bootstrap->plugin_dir . '/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php';
|
||||
|
||||
$this->paypal_gateway = new WC_Gateway_Paypal();
|
||||
$this->paypal_request = new WC_Gateway_Paypal_Request( $this->paypal_gateway );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create Paypal request URL for $product_count number of products.
|
||||
*
|
||||
* @param int $product_count Number of products to include in the order.
|
||||
* @param bool $testmode Whether to test using sandbox or not.
|
||||
*
|
||||
* @return string
|
||||
* @throws WC_Data_Exception
|
||||
*/
|
||||
protected function get_request_url( $product_count, $testmode ) {
|
||||
// Create products.
|
||||
$this->create_products( $product_count );
|
||||
|
||||
$this->order = WC_Helper_Order::create_order( $this->user );
|
||||
$this->add_products_to_order( $this->order );
|
||||
|
||||
// Set payment method to Paypal.
|
||||
$payment_gateways = WC()->payment_gateways->payment_gateways();
|
||||
$this->order->set_payment_method( $payment_gateways['paypal'] );
|
||||
$this->order->calculate_totals();
|
||||
$this->order->calculate_shipping();
|
||||
|
||||
return $this->paypal_request->get_request_url( $this->order, $testmode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up order, deletes all products in order, too.
|
||||
*/
|
||||
protected function clean_up() {
|
||||
WC_Helper_Order::delete_order( $this->order->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the shipping tax is included in the total according to $shipping_tax_included.
|
||||
*
|
||||
* @param array $query_array Request URL parsed into associative array.
|
||||
* @param bool $shipping_tax_included Whether the shipping tax should be included or not.
|
||||
*/
|
||||
protected function check_shipping_tax( $query_array, $shipping_tax_included ) {
|
||||
$shipping_total = $this->order->get_shipping_total();
|
||||
if ( $shipping_tax_included ) {
|
||||
$shipping_total += $this->order->get_shipping_tax();
|
||||
}
|
||||
$epsilon = 0.01;
|
||||
$this->assertTrue( abs( $shipping_total - floatval( $query_array['shipping_1'] ) ) < $epsilon );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test common order asserts.
|
||||
*
|
||||
* @param string $request_url Paypal request URL.
|
||||
* @param bool $testmode Whether Paypal sandbox is used or not.
|
||||
*/
|
||||
protected function check_order_common_props( $request_url, $testmode ) {
|
||||
if ( $testmode ) {
|
||||
$this->assertEquals( 'https://www.sandbox.paypal.com', substr( $request_url, 0, 30 ) );
|
||||
} else {
|
||||
$this->assertEquals( 'https://www.paypal.com', substr( $request_url, 0, 22 ) );
|
||||
}
|
||||
$this->assertLessThanOrEqual( 2083, strlen( $request_url ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test large order with 30 items, URL length > 2083 characters.
|
||||
*
|
||||
* @param bool $shipping_tax_included Whether the shipping tax should be included or not.
|
||||
* @param bool $testmode Whether to use Paypal sandbox.
|
||||
*
|
||||
* @throws WC_Data_Exception
|
||||
*/
|
||||
protected function check_large_order( $shipping_tax_included, $testmode ) {
|
||||
$request_url = $this->get_request_url( 30, $testmode );
|
||||
|
||||
$this->check_order_common_props( $request_url, $testmode );
|
||||
|
||||
// Check fields limited to 127 characters for length.
|
||||
$fields_limited_to_127_chars = array(
|
||||
'invoice',
|
||||
'item_name_1',
|
||||
'item_number_1',
|
||||
);
|
||||
|
||||
$query_string = wp_parse_url( $request_url, PHP_URL_QUERY )
|
||||
? wp_parse_url( $request_url, PHP_URL_QUERY )
|
||||
: '';
|
||||
$query_array = array();
|
||||
parse_str( $query_string, $query_array );
|
||||
foreach ( $fields_limited_to_127_chars as $field_name ) {
|
||||
$this->assertLessThanOrEqual( 127, strlen( $query_array[ $field_name ] ) );
|
||||
}
|
||||
|
||||
// Check that there is actually only one item for order with URL length > limit.
|
||||
$this->assertFalse( array_key_exists( 'item_name_2', $query_array ) );
|
||||
|
||||
$this->check_shipping_tax( $query_array, $shipping_tax_included );
|
||||
|
||||
// Remove order and created products.
|
||||
$this->clean_up();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test small order with fewer items, URL length should be < 2083 characters.
|
||||
*
|
||||
* @param int $product_count Number of products to include in the order.
|
||||
* @param bool $shipping_tax_included Whether the shipping tax should be included or not.
|
||||
* @param bool $testmode Whether to use Paypal sandbox.
|
||||
*
|
||||
* @throws WC_Data_Exception
|
||||
*/
|
||||
protected function check_small_order( $product_count, $shipping_tax_included, $testmode ) {
|
||||
$request_url = $this->get_request_url( $product_count, $testmode );
|
||||
|
||||
$this->check_order_common_props( $request_url, $testmode );
|
||||
|
||||
$query_string = wp_parse_url( $request_url, PHP_URL_QUERY )
|
||||
? wp_parse_url( $request_url, PHP_URL_QUERY )
|
||||
: '';
|
||||
$query_array = array();
|
||||
parse_str( $query_string, $query_array );
|
||||
|
||||
// Check that there are $product_count line items in the request URL.
|
||||
// However, if shipping tax is included, there is only one item.
|
||||
if ( $shipping_tax_included ) {
|
||||
$product_count = 1;
|
||||
}
|
||||
|
||||
for ( $i = 1; $i <= $product_count; $i++ ) {
|
||||
$this->assertTrue( array_key_exists( 'item_name_' . $i, $query_array ), 'Item name ' . $i . ' does not exist' );
|
||||
$this->assertTrue( array_key_exists( 'quantity_' . $i, $query_array ) );
|
||||
$this->assertTrue( array_key_exists( 'amount_' . $i, $query_array ) );
|
||||
$this->assertTrue( array_key_exists( 'item_number_' . $i, $query_array ) );
|
||||
|
||||
$this->assertLessThanOrEqual( 127, strlen( $query_array[ 'item_name_' . $i ] ) );
|
||||
$this->assertLessThanOrEqual( 127, strlen( $query_array[ 'item_number_' . $i ] ) );
|
||||
|
||||
}
|
||||
|
||||
$this->check_shipping_tax( $query_array, $shipping_tax_included );
|
||||
|
||||
// Remove order and created products.
|
||||
$this->clean_up();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function test_request_url() {
|
||||
// User set up.
|
||||
$this->user = $this->factory->user->create( array(
|
||||
'role' => 'administrator',
|
||||
) );
|
||||
wp_set_current_user( $this->user );
|
||||
|
||||
// Paths through code changed by:
|
||||
// $sandbox (true/false)
|
||||
// wc_tax_enabled() === get_option( 'woocommerce_calc_taxes' ) === 'yes'
|
||||
// wc_prices_include_tax() === wc_tax_enabled() && 'yes' === get_option( 'woocommerce_prices_include_tax' );.
|
||||
$correct_options = array(
|
||||
[ 'no', 'no', false ],
|
||||
[ 'yes', 'no', false ],
|
||||
// ['no', 'yes', false], // this is not a valid option due to definition of wc_prices_include_tax
|
||||
[ 'yes', 'yes', true ],
|
||||
);
|
||||
foreach ( array( true, false ) as $testmode ) {
|
||||
foreach ( $correct_options as $values ) {
|
||||
update_option( 'woocommerce_calc_taxes', $values[0] );
|
||||
update_option( 'woocommerce_prices_include_tax', $values[1] );
|
||||
$shipping_tax_included = $values[2];
|
||||
|
||||
// Test order with < 9 items (URL shorter than limit).
|
||||
$this->check_small_order( 5, $shipping_tax_included, $testmode );
|
||||
|
||||
// Test order with >9 items with URL shorter than limit.
|
||||
$this->check_small_order( 11, $shipping_tax_included, $testmode );
|
||||
|
||||
// Test order with URL longer than limit.
|
||||
$this->check_large_order( $shipping_tax_included, $testmode );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue