Fix unit tests for new default USD currency
This commit is contained in:
parent
55ab8cb966
commit
cd7b8ee30f
|
@ -593,32 +593,32 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
|
|||
*/
|
||||
public function test_wc_price() {
|
||||
// Common prices.
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>1.00</bdi></span>', wc_price( 1 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>1.10</bdi></span>', wc_price( 1.1 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>1.17</bdi></span>', wc_price( 1.17 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>1,111.17</bdi></span>', wc_price( 1111.17 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>0.00</bdi></span>', wc_price( 0 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>1.00</bdi></span>', wc_price( 1 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>1.10</bdi></span>', wc_price( 1.1 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>1.17</bdi></span>', wc_price( 1.17 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>1,111.17</bdi></span>', wc_price( 1111.17 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>0.00</bdi></span>', wc_price( 0 ) );
|
||||
|
||||
// Different currency.
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>1,111.17</bdi></span>', wc_price( 1111.17, array( 'currency' => 'USD' ) ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>1,111.17</bdi></span>', wc_price( 1111.17, array( 'currency' => 'GBP' ) ) );
|
||||
|
||||
// Negative price.
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi>-<span class="woocommerce-Price-currencySymbol">£</span>1.17</bdi></span>', wc_price( -1.17 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi>-<span class="woocommerce-Price-currencySymbol">$</span>1.17</bdi></span>', wc_price( -1.17 ) );
|
||||
|
||||
// Bogus prices.
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>0.00</bdi></span>', wc_price( null ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>0.00</bdi></span>', wc_price( 'Q' ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>0.00</bdi></span>', wc_price( 'ಠ_ಠ' ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>0.00</bdi></span>', wc_price( null ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>0.00</bdi></span>', wc_price( 'Q' ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>0.00</bdi></span>', wc_price( 'ಠ_ಠ' ) );
|
||||
|
||||
// Trim zeros.
|
||||
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>1</bdi></span>', wc_price( 1.00 ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>1</bdi></span>', wc_price( 1.00 ) );
|
||||
remove_filter( 'woocommerce_price_trim_zeros', '__return_true' );
|
||||
|
||||
// Ex tax label.
|
||||
$calc_taxes = get_option( 'woocommerce_calc_taxes' );
|
||||
update_option( 'woocommerce_calc_taxes', 'yes' );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>1,111.17</bdi></span> <small class="woocommerce-Price-taxLabel tax_label">(ex. tax)</small>', wc_price( '1111.17', array( 'ex_tax_label' => true ) ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>1,111.17</bdi></span> <small class="woocommerce-Price-taxLabel tax_label">(ex. tax)</small>', wc_price( '1111.17', array( 'ex_tax_label' => true ) ) );
|
||||
update_option( 'woocommerce_calc_taxes', $calc_taxes );
|
||||
}
|
||||
|
||||
|
@ -926,7 +926,7 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
|
|||
* @since 3.3.0
|
||||
*/
|
||||
public function test_wc_format_sale_price() {
|
||||
$this->assertEquals( '<del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>10.00</bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>5.00</bdi></span></ins>', wc_format_sale_price( '10', '5' ) );
|
||||
$this->assertEquals( '<del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>10.00</bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>5.00</bdi></span></ins>', wc_format_sale_price( '10', '5' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -935,7 +935,7 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
|
|||
* @since 3.3.0
|
||||
*/
|
||||
public function test_wc_format_price_range() {
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>10.00</bdi></span> – <span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>5.00</bdi></span>', wc_format_price_range( '10', '5' ) );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>10.00</bdi></span> – <span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>5.00</bdi></span>', wc_format_price_range( '10', '5' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -259,15 +259,15 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
|||
|
||||
$product = wc_get_product( $product1_id );
|
||||
$this->assertEquals( $product1_id, $product->get_id() );
|
||||
$this->assertEquals( '<del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>10.00</bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>7.00</bdi></span></ins>', $product->get_price_html() );
|
||||
$this->assertEquals( '<del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>10.00</bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>7.00</bdi></span></ins>', $product->get_price_html() );
|
||||
|
||||
$product = wc_get_product( $product2_id );
|
||||
$this->assertEquals( $product2_id, $product->get_id() );
|
||||
$this->assertEquals( '<del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>20.00</bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>16.00</bdi></span></ins>', $product->get_price_html() );
|
||||
$this->assertEquals( '<del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>20.00</bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>16.00</bdi></span></ins>', $product->get_price_html() );
|
||||
|
||||
$product = wc_get_product( $product3_id );
|
||||
$this->assertEquals( $product3_id, $product->get_id() );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">£</span>50.00</bdi></span>', $product->get_price_html() );
|
||||
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>50.00</bdi></span>', $product->get_price_html() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -222,10 +222,10 @@ class WC_Tests_Core_Functions extends WC_Unit_Test_Case {
|
|||
public function test_get_woocommerce_currency_symbol() {
|
||||
|
||||
// Default currency.
|
||||
$this->assertEquals( '£', get_woocommerce_currency_symbol() );
|
||||
$this->assertEquals( '$', get_woocommerce_currency_symbol() );
|
||||
|
||||
// Given specific currency.
|
||||
$this->assertEquals( '$', get_woocommerce_currency_symbol( 'USD' ) );
|
||||
$this->assertEquals( '£', get_woocommerce_currency_symbol( 'GBP' ) );
|
||||
|
||||
// Each case.
|
||||
foreach ( array_keys( get_woocommerce_currencies() ) as $currency_code ) {
|
||||
|
|
Loading…
Reference in New Issue