woocommerce/tests/unit-tests/coupon/functions.php

84 lines
2.0 KiB
PHP
Raw Normal View History

2014-09-05 06:36:35 +00:00
<?php
/**
2015-11-03 13:31:20 +00:00
* Class Functions.
2015-03-06 15:32:40 +00:00
* @package WooCommerce\Tests\Coupon
* @since 2.2
*/
class WC_Tests_Functions extends WC_Unit_Test_Case {
2014-09-05 06:36:35 +00:00
/**
2015-11-03 13:31:20 +00:00
* Test wc_get_coupon_types().
2014-09-05 06:36:35 +00:00
*
* @since 2.2
*/
public function test_wc_get_coupon_types() {
$coupon_types = array(
'percent' => __( 'Percentage discount', 'woocommerce' ),
'fixed_cart' => __( 'Fixed cart discount', 'woocommerce' ),
'fixed_product' => __( 'Fixed product discount', 'woocommerce' ),
2014-09-05 06:36:35 +00:00
);
$this->assertEquals( $coupon_types, wc_get_coupon_types() );
}
/**
2015-11-03 13:31:20 +00:00
* Test wc_get_coupon_type().
2014-09-05 06:36:35 +00:00
*
* @since 2.2
*/
public function test_wc_get_coupon_type() {
2016-12-14 11:07:39 +00:00
$this->assertEquals( 'Fixed cart discount', wc_get_coupon_type( 'fixed_cart' ) );
2014-09-05 06:36:35 +00:00
$this->assertEmpty( wc_get_coupon_type( 'bogus_type' ) );
}
/**
2015-11-03 13:31:20 +00:00
* Test coupons_enabled method.
*
* @since 2.5.0
*/
public function test_wc_coupons_enabled() {
$this->assertEquals( apply_filters( 'woocommerce_coupons_enabled', get_option( 'woocommerce_enable_coupons' ) === 'yes' ), wc_coupons_enabled() );
}
2016-08-24 17:17:58 +00:00
/**
* Test wc_get_coupon_code_by_id().
*
2017-03-15 16:36:53 +00:00
* @since 3.0.0
2016-08-24 17:17:58 +00:00
*/
public function test_wc_get_coupon_code_by_id() {
// Create coupon.
$code = 'testcoupon';
$coupon = WC_Helper_Coupon::create_coupon( $code );
$this->assertEquals( $code, wc_get_coupon_code_by_id( $coupon->get_id() ) );
// Delete coupon.
WC_Helper_Coupon::delete_coupon( $coupon->get_id() );
$this->assertEmpty( wc_get_coupon_code_by_id( 0 ) );
}
/**
* Test wc_get_coupon_id_by_code().
*
2017-03-15 16:36:53 +00:00
* @since 3.0.0
*/
public function test_wc_get_coupon_id_by_code() {
// Create coupon.
$code = 'testcoupon';
$coupon = WC_Helper_Coupon::create_coupon( $code );
$this->assertEquals( $coupon->get_id(), wc_get_coupon_id_by_code( $coupon->get_code() ) );
// Delete coupon.
WC_Helper_Coupon::delete_coupon( $coupon->get_id() );
$this->assertEquals( 0, wc_get_coupon_id_by_code( '' ) );
$this->assertEmpty( wc_get_coupon_id_by_code( 0 ) );
}
2014-09-05 06:36:35 +00:00
}