Merge pull request #7613 from SiR-DanieL/unit
Unit tests for conditional, formatting and order functions
This commit is contained in:
commit
250f3e7fe6
|
@ -35,4 +35,25 @@ class WC_Tests_Conditional_Functions extends WC_Unit_Test_Case {
|
|||
|
||||
$this->assertEquals( false, wc_prices_include_tax() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wc_is_valid_url()
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function test_wc_is_valid_url() {
|
||||
|
||||
// Test some invalid URLs
|
||||
$this->assertEquals( false, wc_is_valid_url( 'google.com' ) );
|
||||
$this->assertEquals( false, wc_is_valid_url( 'ftp://google.com' ) );
|
||||
$this->assertEquals( false, wc_is_valid_url( 'sftp://google.com' ) );
|
||||
$this->assertEquals( false, wc_is_valid_url( 'https://google.com/test invalid' ) );
|
||||
|
||||
// Test some valid URLs
|
||||
$this->assertEquals( true, wc_is_valid_url( 'http://google.com' ) );
|
||||
$this->assertEquals( true, wc_is_valid_url( 'https://google.com' ) );
|
||||
$this->assertEquals( true, wc_is_valid_url( 'https://google.com/test%20valid' ) );
|
||||
$this->assertEquals( true, wc_is_valid_url( 'https://google.com/test-valid/?query=test' ) );
|
||||
$this->assertEquals( true, wc_is_valid_url( 'https://google.com/test-valid/#hash' ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -542,4 +542,16 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( '1-610-385-0000', wc_format_phone_number( '1.610.385.0000' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wc_trim_string()
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
public function test_wc_trim_string() {
|
||||
|
||||
$this->assertEquals( 'string', wc_trim_string( 'string' ) );
|
||||
$this->assertEquals( 's...', wc_trim_string( 'string', 4 ) );
|
||||
$this->assertEquals( 'st.', wc_trim_string( 'string', 3, '.' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* Test WC order functions
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test wc_get_order_statuses()
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function test_wc_get_order_statuses() {
|
||||
|
||||
$order_statuses = apply_filters( 'wc_order_statuses', array(
|
||||
'wc-pending' => _x( 'Pending Payment', 'Order status', 'woocommerce' ),
|
||||
'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
|
||||
'wc-on-hold' => _x( 'On Hold', 'Order status', 'woocommerce' ),
|
||||
'wc-completed' => _x( 'Completed', 'Order status', 'woocommerce' ),
|
||||
'wc-cancelled' => _x( 'Cancelled', 'Order status', 'woocommerce' ),
|
||||
'wc-refunded' => _x( 'Refunded', 'Order status', 'woocommerce' ),
|
||||
'wc-failed' => _x( 'Failed', 'Order status', 'woocommerce' ),
|
||||
) );
|
||||
|
||||
$this->assertEquals( $order_statuses, wc_get_order_statuses() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wc_is_order_status()
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function test_wc_is_order_status() {
|
||||
|
||||
$this->assertEquals( true, wc_is_order_status( 'wc-pending' ) );
|
||||
$this->assertEquals( false, wc_is_order_status( 'wc-another-status' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wc_get_order_status_name()
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function test_wc_get_order_status_name() {
|
||||
|
||||
$this->assertEquals( _x( 'Pending Payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( 'wc-pending' ) );
|
||||
$this->assertEquals( _x( 'Pending Payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( 'pending' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wc_ship_to_billing_address_only()
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function test_wc_ship_to_billing_address_only() {
|
||||
|
||||
$default = get_option( 'woocommerce_ship_to_destination' );
|
||||
|
||||
update_option( 'woocommerce_ship_to_destination', 'shipping' );
|
||||
$this->assertEquals( false, wc_ship_to_billing_address_only() );
|
||||
|
||||
update_option( 'woocommerce_ship_to_destination', 'billing_only' );
|
||||
$this->assertEquals( true, wc_ship_to_billing_address_only() );
|
||||
|
||||
update_option( 'woocommerce_ship_to_destination', $default );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue