Added unit tests for coupon code sanitization
This commit is contained in:
parent
e94196cea8
commit
4048d19a39
|
@ -171,9 +171,9 @@ class WC_Unit_Test_Case extends WP_HTTP_TestCase {
|
|||
*/
|
||||
public function login_as_administrator() {
|
||||
return $this->login_as_role( 'administrator' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get an instance of a class that has been registered in the dependency injection container.
|
||||
* To get an instance of a legacy class (such as the ones in the 'íncludes' directory) use
|
||||
* 'get_legacy_instance_of' instead.
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* Post data tests
|
||||
*
|
||||
* @package WooCommerce\Tests\Post_Data.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WC_Post_Data_Test
|
||||
*/
|
||||
class WC_Post_Data_Test extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testdox coupon code should be always sanitized.
|
||||
*/
|
||||
public function test_coupon_code_sanitization() {
|
||||
$this->login_as_role( 'shop_manager' );
|
||||
$coupon = WC_Helper_Coupon::create_coupon( 'a&a' );
|
||||
$post_data = get_post( $coupon->get_id() );
|
||||
$this->assertEquals( 'a&a', $post_data->post_title );
|
||||
$coupon->delete( true );
|
||||
|
||||
$this->login_as_administrator();
|
||||
$coupon = WC_Helper_Coupon::create_coupon( 'b&b' );
|
||||
$post_data = get_post( $coupon->get_id() );
|
||||
$this->assertEquals( 'b&b', $post_data->post_title );
|
||||
$coupon->delete( true );
|
||||
|
||||
wp_set_current_user( 0 );
|
||||
$coupon = WC_Helper_Coupon::create_coupon( 'c&c' );
|
||||
$post_data = get_post( $coupon->get_id() );
|
||||
$this->assertEquals( 'c&c', $post_data->post_title );
|
||||
$coupon->delete( true );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
/**
|
||||
* Formatting functions tests
|
||||
*
|
||||
* @package WooCommerce\Tests\Formatting.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WC_Formatting_Functions_Test
|
||||
*/
|
||||
class WC_Formatting_Functions_Test extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test wc_sanitize_coupon_code() function.
|
||||
*/
|
||||
public function test_wc_sanitize_coupon_code() {
|
||||
$this->assertEquals( 'DUMMYCOUPON', wc_sanitize_coupon_code( 'DUMMYCOUPON' ) );
|
||||
$this->assertEquals( 'a&a', wc_sanitize_coupon_code( 'a&a' ) );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue