Add tests for wc_sanitize_order_id()
This commit adds four test cases (via a PHPUnit data provider) for the `wc_sanitize_order_id()` function. While writing the tests, it was also discovered that the function was returning a *string*, not an integer as indicated by the DocBlock, so explicit type-casting was added.
This commit is contained in:
parent
96005a51c4
commit
65cda44fe6
|
@ -886,7 +886,7 @@ add_action( 'woocommerce_cancel_unpaid_orders', 'wc_cancel_unpaid_orders' );
|
|||
* @param int $order_id Order ID.
|
||||
*/
|
||||
function wc_sanitize_order_id( $order_id ) {
|
||||
return filter_var( $order_id, FILTER_SANITIZE_NUMBER_INT );
|
||||
return (int) filter_var( $order_id, FILTER_SANITIZE_NUMBER_INT );
|
||||
}
|
||||
add_filter( 'woocommerce_shortcode_order_tracking_order_id', 'wc_sanitize_order_id' );
|
||||
|
||||
|
|
|
@ -1271,6 +1271,18 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( $expected, $orders );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wc_sanitize_order_id().
|
||||
*
|
||||
* @testWith ["123", 123]
|
||||
* ["#123", 123]
|
||||
* ["# 123", 123]
|
||||
* ["Order #123", 123]
|
||||
*/
|
||||
public function test_wc_sanitize_order_id( $id, $expected ) {
|
||||
$this->assertSame( $expected, wc_sanitize_order_id( $id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test wc_get_order_note().
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue