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

83 lines
1.9 KiB
PHP
Raw Normal View History

2014-09-05 06:36:35 +00:00
<?php
2015-03-06 15:32:40 +00:00
2014-09-05 06:36:35 +00:00
/**
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(
'fixed_cart' => 'Cart discount',
'percent' => 'Cart % discount',
'fixed_product' => 'Product discount',
'percent_product' => 'Product % discount',
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() {
$this->assertEquals( '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().
*
* @since 2.7.0
*/
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().
*
* @since 2.7.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->assertEmpty( wc_get_coupon_id_by_code( 0 ) );
}
2014-09-05 06:36:35 +00:00
}