2014-09-01 06:00:12 +00:00
|
|
|
<?php
|
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Class Core_Functions.
|
2015-03-06 15:32:40 +00:00
|
|
|
* @package WooCommerce\Tests\Util
|
2014-09-01 06:59:23 +00:00
|
|
|
* @since 2.2
|
|
|
|
*/
|
2016-03-23 12:14:13 +00:00
|
|
|
class WC_Tests_Core_Functions extends WC_Unit_Test_Case {
|
2014-09-01 06:59:23 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test get_woocommerce_currency().
|
2014-09-01 06:59:23 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
2014-09-01 06:00:12 +00:00
|
|
|
public function test_get_woocommerce_currency() {
|
|
|
|
|
|
|
|
$this->assertEquals( 'GBP', get_woocommerce_currency() );
|
|
|
|
}
|
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test get_woocommerce_currencies().
|
2014-09-01 06:59:23 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
2014-09-01 06:00:12 +00:00
|
|
|
public function test_get_woocommerce_currencies() {
|
|
|
|
|
|
|
|
$expected_currencies = array(
|
|
|
|
'AED' => __( 'United Arab Emirates Dirham', 'woocommerce' ),
|
2015-06-29 18:13:42 +00:00
|
|
|
'ARS' => __( 'Argentine Peso', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'AUD' => __( 'Australian Dollars', 'woocommerce' ),
|
|
|
|
'BDT' => __( 'Bangladeshi Taka', 'woocommerce' ),
|
|
|
|
'BGN' => __( 'Bulgarian Lev', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'BRL' => __( 'Brazilian Real', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'CAD' => __( 'Canadian Dollars', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'CHF' => __( 'Swiss Franc', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'CLP' => __( 'Chilean Peso', 'woocommerce' ),
|
|
|
|
'CNY' => __( 'Chinese Yuan', 'woocommerce' ),
|
|
|
|
'COP' => __( 'Colombian Peso', 'woocommerce' ),
|
|
|
|
'CZK' => __( 'Czech Koruna', 'woocommerce' ),
|
|
|
|
'DKK' => __( 'Danish Krone', 'woocommerce' ),
|
|
|
|
'DOP' => __( 'Dominican Peso', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'EGP' => __( 'Egyptian Pound', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'EUR' => __( 'Euros', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'GBP' => __( 'Pounds Sterling', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'HKD' => __( 'Hong Kong Dollar', 'woocommerce' ),
|
|
|
|
'HRK' => __( 'Croatia kuna', 'woocommerce' ),
|
|
|
|
'HUF' => __( 'Hungarian Forint', 'woocommerce' ),
|
|
|
|
'IDR' => __( 'Indonesia Rupiah', 'woocommerce' ),
|
|
|
|
'ILS' => __( 'Israeli Shekel', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'INR' => __( 'Indian Rupee', 'woocommerce' ),
|
|
|
|
'ISK' => __( 'Icelandic krona', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'JPY' => __( 'Japanese Yen', 'woocommerce' ),
|
2015-12-09 18:38:57 +00:00
|
|
|
'KES' => __( 'Kenyan shilling', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'KRW' => __( 'South Korean Won', 'woocommerce' ),
|
2016-01-27 06:17:43 +00:00
|
|
|
'LAK' => __( 'Lao Kip', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'MXN' => __( 'Mexican Peso', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'MYR' => __( 'Malaysian Ringgits', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'NGN' => __( 'Nigerian Naira', 'woocommerce' ),
|
|
|
|
'NOK' => __( 'Norwegian Krone', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'NPR' => __( 'Nepali Rupee', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'NZD' => __( 'New Zealand Dollar', 'woocommerce' ),
|
|
|
|
'PHP' => __( 'Philippine Pesos', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'PKR' => __( 'Pakistani Rupee', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'PLN' => __( 'Polish Zloty', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'PYG' => __( 'Paraguayan Guaraní', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'RON' => __( 'Romanian Leu', 'woocommerce' ),
|
|
|
|
'RUB' => __( 'Russian Ruble', 'woocommerce' ),
|
2016-01-27 06:17:43 +00:00
|
|
|
'SAR' => __( 'Saudi Riyal', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'SEK' => __( 'Swedish Krona', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'SGD' => __( 'Singapore Dollar', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'THB' => __( 'Thai Baht', 'woocommerce' ),
|
|
|
|
'TRY' => __( 'Turkish Lira', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'TWD' => __( 'Taiwan New Dollars', 'woocommerce' ),
|
2014-10-30 12:47:36 +00:00
|
|
|
'UAH' => __( 'Ukrainian Hryvnia', 'woocommerce' ),
|
2016-04-05 20:31:15 +00:00
|
|
|
'UGX' => __( 'Ugandan Shilling', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
'USD' => __( 'US Dollars', 'woocommerce' ),
|
|
|
|
'VND' => __( 'Vietnamese Dong', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'ZAR' => __( 'South African rand', 'woocommerce' ),
|
2014-09-01 06:00:12 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected_currencies, get_woocommerce_currencies() );
|
|
|
|
}
|
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test get_woocommerce_currency_symbol().
|
2014-09-01 06:59:23 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
2014-09-01 06:00:12 +00:00
|
|
|
public function test_get_woocommerce_currency_symbol() {
|
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
// default currency
|
2014-09-01 06:00:12 +00:00
|
|
|
$this->assertEquals( '£', get_woocommerce_currency_symbol() );
|
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
// given specific currency
|
|
|
|
$this->assertEquals( '$', get_woocommerce_currency_symbol( 'USD' ) );
|
2014-09-01 06:00:12 +00:00
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
// each case
|
|
|
|
foreach ( array_keys( get_woocommerce_currencies() ) as $currency_code ) {
|
|
|
|
$this->assertInternalType( 'string', get_woocommerce_currency_symbol( $currency_code ) );
|
|
|
|
}
|
2014-09-01 06:00:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test get_woocommerce_api_url().
|
2014-09-01 06:59:23 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
|
|
|
public function test_get_woocommerce_api_url() {
|
2014-09-01 06:00:12 +00:00
|
|
|
|
2014-09-05 15:17:53 +00:00
|
|
|
$base_uri = get_home_url();
|
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
// base uri
|
2015-06-18 22:24:57 +00:00
|
|
|
$this->assertEquals( "$base_uri/wc-api/v3/", get_woocommerce_api_url( null ) );
|
2014-09-01 06:00:12 +00:00
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
// path
|
2015-06-18 22:24:57 +00:00
|
|
|
$this->assertEquals( "$base_uri/wc-api/v3/orders", get_woocommerce_api_url( 'orders' ) );
|
2014-09-01 06:00:12 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 15:55:54 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_get_log_file_path().
|
2015-04-08 15:55:54 +00:00
|
|
|
*
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public function test_wc_get_log_file_path() {
|
|
|
|
$log_dir = trailingslashit( WC_LOG_DIR );
|
|
|
|
$hash_name = sanitize_file_name( wp_hash( 'unit-tests' ) );
|
|
|
|
|
|
|
|
$this->assertEquals( $log_dir . 'unit-tests-' . $hash_name . '.log', wc_get_log_file_path( 'unit-tests' ) );
|
|
|
|
}
|
|
|
|
|
2014-09-01 06:59:23 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_get_core_supported_themes().
|
2014-09-01 06:59:23 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
2014-09-01 06:00:12 +00:00
|
|
|
public function test_wc_get_core_supported_themes() {
|
|
|
|
|
2015-11-23 11:55:50 +00:00
|
|
|
$expected_themes = array( 'twentysixteen', 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' );
|
2014-09-01 06:00:12 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected_themes, wc_get_core_supported_themes() );
|
|
|
|
}
|
2014-09-01 06:59:23 +00:00
|
|
|
|
2014-11-18 14:56:13 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_get_base_location().
|
2014-11-18 14:56:13 +00:00
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
2015-01-05 10:26:35 +00:00
|
|
|
public function test_wc_get_base_location() {
|
|
|
|
$default = wc_get_base_location();
|
2014-11-18 14:56:13 +00:00
|
|
|
|
|
|
|
$this->assertEquals( 'GB', $default['country'] );
|
|
|
|
$this->assertEquals( '', $default['state'] );
|
|
|
|
}
|
|
|
|
|
2016-02-16 07:31:29 +00:00
|
|
|
/**
|
|
|
|
* Test wc_format_country_state_string().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_format_country_state_string() {
|
2016-02-16 09:05:32 +00:00
|
|
|
// Test with correct values.
|
2016-02-16 07:31:29 +00:00
|
|
|
$this->assertEquals( array( 'country' => 'US', 'state' => 'CA' ), wc_format_country_state_string( 'US:CA' ) );
|
2016-02-16 09:05:32 +00:00
|
|
|
// Test what happens when we pass an incorrect value.
|
|
|
|
$this->assertEquals( array( 'country' => 'US-CA', 'state' => '' ), wc_format_country_state_string( 'US-CA' ) );
|
2016-02-16 07:31:29 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 06:00:12 +00:00
|
|
|
}
|