woocommerce/tests/unit-tests/util/core-functions.php

168 lines
5.3 KiB
PHP
Raw Normal View History

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
*/
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' ),
'ARS' => __( 'Argentine Peso', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'AUD' => __( 'Australian Dollars', 'woocommerce' ),
'BDT' => __( 'Bangladeshi Taka', 'woocommerce' ),
'BGN' => __( 'Bulgarian Lev', 'woocommerce' ),
'BRL' => __( 'Brazilian Real', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'CAD' => __( 'Canadian Dollars', 'woocommerce' ),
'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' ),
'EGP' => __( 'Egyptian Pound', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'EUR' => __( 'Euros', 'woocommerce' ),
'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' ),
'INR' => __( 'Indian Rupee', 'woocommerce' ),
'ISK' => __( 'Icelandic krona', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'JPY' => __( 'Japanese Yen', 'woocommerce' ),
'KES' => __( 'Kenyan shilling', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'KRW' => __( 'South Korean Won', 'woocommerce' ),
'LAK' => __( 'Lao Kip', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'MXN' => __( 'Mexican Peso', 'woocommerce' ),
'MYR' => __( 'Malaysian Ringgits', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'NGN' => __( 'Nigerian Naira', 'woocommerce' ),
'NOK' => __( 'Norwegian Krone', 'woocommerce' ),
'NPR' => __( 'Nepali Rupee', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'NZD' => __( 'New Zealand Dollar', 'woocommerce' ),
'PHP' => __( 'Philippine Pesos', 'woocommerce' ),
'PKR' => __( 'Pakistani Rupee', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'PLN' => __( 'Polish Zloty', 'woocommerce' ),
'PYG' => __( 'Paraguayan Guaraní', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'RON' => __( 'Romanian Leu', 'woocommerce' ),
'RUB' => __( 'Russian Ruble', 'woocommerce' ),
'SAR' => __( 'Saudi Riyal', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'SEK' => __( 'Swedish Krona', 'woocommerce' ),
'SGD' => __( 'Singapore Dollar', 'woocommerce' ),
2014-09-01 06:00:12 +00:00
'THB' => __( 'Thai Baht', 'woocommerce' ),
'TRY' => __( 'Turkish Lira', 'woocommerce' ),
'TWD' => __( 'Taiwan New Dollars', 'woocommerce' ),
'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' ),
'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( '&pound;', get_woocommerce_currency_symbol() );
2014-09-01 06:59:23 +00:00
// given specific currency
$this->assertEquals( '&#36;', 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
$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
$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
/**
2015-11-03 13:31:20 +00:00
* Test wc_get_base_location().
*
* @since 2.3.0
*/
public function test_wc_get_base_location() {
$default = wc_get_base_location();
$this->assertEquals( 'GB', $default['country'] );
$this->assertEquals( '', $default['state'] );
}
/**
* Test wc_format_country_state_string().
*
* @since 2.6.0
*/
public function test_wc_format_country_state_string() {
// Test with correct values.
$this->assertEquals( array( 'country' => 'US', 'state' => 'CA' ), wc_format_country_state_string( 'US:CA' ) );
// Test what happens when we pass an incorrect value.
$this->assertEquals( array( 'country' => 'US-CA', 'state' => '' ), wc_format_country_state_string( 'US-CA' ) );
}
2014-09-01 06:00:12 +00:00
}