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(
|
2016-04-18 23:21:14 +00:00
|
|
|
'AED' => __( 'United Arab Emirates dirham', 'woocommerce' ),
|
|
|
|
'AFN' => __( 'Afghan afghani', 'woocommerce' ),
|
|
|
|
'ALL' => __( 'Albanian lek', 'woocommerce' ),
|
|
|
|
'AMD' => __( 'Armenian dram', 'woocommerce' ),
|
|
|
|
'ANG' => __( 'Netherlands Antillean guilder', 'woocommerce' ),
|
|
|
|
'AOA' => __( 'Angolan kwanza', 'woocommerce' ),
|
|
|
|
'ARS' => __( 'Argentine peso', 'woocommerce' ),
|
|
|
|
'AUD' => __( 'Australian dollar', 'woocommerce' ),
|
|
|
|
'AWG' => __( 'Aruban florin', 'woocommerce' ),
|
|
|
|
'AZN' => __( 'Azerbaijani manat', 'woocommerce' ),
|
|
|
|
'BAM' => __( 'Bosnia and Herzegovina convertible mark', 'woocommerce' ),
|
|
|
|
'BBD' => __( 'Barbadian dollar', 'woocommerce' ),
|
|
|
|
'BDT' => __( 'Bangladeshi taka', 'woocommerce' ),
|
|
|
|
'BGN' => __( 'Bulgarian lev', 'woocommerce' ),
|
|
|
|
'BHD' => __( 'Bahraini dinar', 'woocommerce' ),
|
|
|
|
'BIF' => __( 'Burundian franc', 'woocommerce' ),
|
|
|
|
'BMD' => __( 'Bermudian dollar', 'woocommerce' ),
|
|
|
|
'BND' => __( 'Brunei dollar', 'woocommerce' ),
|
|
|
|
'BOB' => __( 'Bolivian boliviano', 'woocommerce' ),
|
|
|
|
'BRL' => __( 'Brazilian real', 'woocommerce' ),
|
|
|
|
'BSD' => __( 'Bahamian dollar', 'woocommerce' ),
|
|
|
|
'BTN' => __( 'Bhutanese ngultrum', 'woocommerce' ),
|
|
|
|
'BWP' => __( 'Botswana pula', 'woocommerce' ),
|
|
|
|
'BYR' => __( 'Belarusian ruble', 'woocommerce' ),
|
|
|
|
'BZD' => __( 'Belize dollar', 'woocommerce' ),
|
|
|
|
'CAD' => __( 'Canadian dollar', 'woocommerce' ),
|
|
|
|
'CDF' => __( 'Congolese franc', 'woocommerce' ),
|
|
|
|
'CHF' => __( 'Swiss franc', 'woocommerce' ),
|
|
|
|
'CLP' => __( 'Chilean peso', 'woocommerce' ),
|
|
|
|
'CNY' => __( 'Chinese yuan', 'woocommerce' ),
|
|
|
|
'COP' => __( 'Colombian peso', 'woocommerce' ),
|
|
|
|
'CRC' => __( 'Costa Rican colón', 'woocommerce' ),
|
|
|
|
'CUC' => __( 'Cuban convertible peso', 'woocommerce' ),
|
|
|
|
'CUP' => __( 'Cuban peso', 'woocommerce' ),
|
|
|
|
'CVE' => __( 'Cape Verdean escudo', 'woocommerce' ),
|
|
|
|
'CZK' => __( 'Czech koruna', 'woocommerce' ),
|
|
|
|
'DJF' => __( 'Djiboutian franc', 'woocommerce' ),
|
|
|
|
'DKK' => __( 'Danish krone', 'woocommerce' ),
|
|
|
|
'DOP' => __( 'Dominican peso', 'woocommerce' ),
|
|
|
|
'DZD' => __( 'Algerian dinar', 'woocommerce' ),
|
|
|
|
'EGP' => __( 'Egyptian pound', 'woocommerce' ),
|
|
|
|
'ERN' => __( 'Eritrean nakfa', 'woocommerce' ),
|
|
|
|
'ETB' => __( 'Ethiopian birr', 'woocommerce' ),
|
|
|
|
'EUR' => __( 'Euro', 'woocommerce' ),
|
|
|
|
'FJD' => __( 'Fijian dollar', 'woocommerce' ),
|
|
|
|
'FKP' => __( 'Falkland Islands pound', 'woocommerce' ),
|
|
|
|
'GBP' => __( 'Pound sterling', 'woocommerce' ),
|
|
|
|
'GEL' => __( 'Georgian lari', 'woocommerce' ),
|
|
|
|
'GGP' => __( 'Guernsey pound', 'woocommerce' ),
|
|
|
|
'GHS' => __( 'Ghana cedi', 'woocommerce' ),
|
|
|
|
'GIP' => __( 'Gibraltar pound', 'woocommerce' ),
|
|
|
|
'GMD' => __( 'Gambian dalasi', 'woocommerce' ),
|
|
|
|
'GNF' => __( 'Guinean franc', 'woocommerce' ),
|
|
|
|
'GTQ' => __( 'Guatemalan quetzal', 'woocommerce' ),
|
|
|
|
'GYD' => __( 'Guyanese dollar', 'woocommerce' ),
|
|
|
|
'HKD' => __( 'Hong Kong dollar', 'woocommerce' ),
|
|
|
|
'HNL' => __( 'Honduran lempira', 'woocommerce' ),
|
|
|
|
'HRK' => __( 'Croatian kuna', 'woocommerce' ),
|
|
|
|
'HTG' => __( 'Haitian gourde', 'woocommerce' ),
|
|
|
|
'HUF' => __( 'Hungarian forint', 'woocommerce' ),
|
|
|
|
'IDR' => __( 'Indonesian rupiah', 'woocommerce' ),
|
|
|
|
'ILS' => __( 'Israeli new shekel', 'woocommerce' ),
|
|
|
|
'IMP' => __( 'Manx pound', 'woocommerce' ),
|
|
|
|
'INR' => __( 'Indian rupee', 'woocommerce' ),
|
|
|
|
'IQD' => __( 'Iraqi dinar', 'woocommerce' ),
|
|
|
|
'IRR' => __( 'Iranian rial', 'woocommerce' ),
|
|
|
|
'ISK' => __( 'Icelandic króna', 'woocommerce' ),
|
|
|
|
'JEP' => __( 'Jersey pound', 'woocommerce' ),
|
|
|
|
'JMD' => __( 'Jamaican dollar', 'woocommerce' ),
|
|
|
|
'JOD' => __( 'Jordanian dinar', 'woocommerce' ),
|
|
|
|
'JPY' => __( 'Japanese yen', 'woocommerce' ),
|
2015-12-09 18:38:57 +00:00
|
|
|
'KES' => __( 'Kenyan shilling', 'woocommerce' ),
|
2016-04-18 23:21:14 +00:00
|
|
|
'KGS' => __( 'Kyrgyzstani som', 'woocommerce' ),
|
|
|
|
'KHR' => __( 'Cambodian riel', 'woocommerce' ),
|
|
|
|
'KMF' => __( 'Comorian franc', 'woocommerce' ),
|
|
|
|
'KPW' => __( 'North Korean won', 'woocommerce' ),
|
|
|
|
'KRW' => __( 'South Korean won', 'woocommerce' ),
|
|
|
|
'KWD' => __( 'Kuwaiti dinar', 'woocommerce' ),
|
|
|
|
'KYD' => __( 'Cayman Islands dollar', 'woocommerce' ),
|
|
|
|
'KZT' => __( 'Kazakhstani tenge', 'woocommerce' ),
|
|
|
|
'LAK' => __( 'Lao kip', 'woocommerce' ),
|
|
|
|
'LBP' => __( 'Lebanese pound', 'woocommerce' ),
|
|
|
|
'LKR' => __( 'Sri Lankan rupee', 'woocommerce' ),
|
|
|
|
'LRD' => __( 'Liberian dollar', 'woocommerce' ),
|
|
|
|
'LSL' => __( 'Lesotho loti', 'woocommerce' ),
|
|
|
|
'LYD' => __( 'Libyan dinar', 'woocommerce' ),
|
|
|
|
'MAD' => __( 'Moroccan dirham', 'woocommerce' ),
|
|
|
|
'MDL' => __( 'Moldovan leu', 'woocommerce' ),
|
|
|
|
'MGA' => __( 'Malagasy ariary', 'woocommerce' ),
|
|
|
|
'MKD' => __( 'Macedonian denar', 'woocommerce' ),
|
|
|
|
'MMK' => __( 'Burmese kyat', 'woocommerce' ),
|
|
|
|
'MNT' => __( 'Mongolian tögrög', 'woocommerce' ),
|
|
|
|
'MOP' => __( 'Macanese pataca', 'woocommerce' ),
|
|
|
|
'MRO' => __( 'Mauritanian ouguiya', 'woocommerce' ),
|
|
|
|
'MUR' => __( 'Mauritian rupee', 'woocommerce' ),
|
|
|
|
'MVR' => __( 'Maldivian rufiyaa', 'woocommerce' ),
|
|
|
|
'MWK' => __( 'Malawian kwacha', 'woocommerce' ),
|
|
|
|
'MXN' => __( 'Mexican peso', 'woocommerce' ),
|
|
|
|
'MYR' => __( 'Malaysian ringgit', 'woocommerce' ),
|
|
|
|
'MZN' => __( 'Mozambican metical', 'woocommerce' ),
|
|
|
|
'NAD' => __( 'Namibian dollar', 'woocommerce' ),
|
|
|
|
'NGN' => __( 'Nigerian naira', 'woocommerce' ),
|
|
|
|
'NIO' => __( 'Nicaraguan córdoba', 'woocommerce' ),
|
|
|
|
'NOK' => __( 'Norwegian krone', 'woocommerce' ),
|
|
|
|
'NPR' => __( 'Nepalese rupee', 'woocommerce' ),
|
|
|
|
'NZD' => __( 'New Zealand dollar', 'woocommerce' ),
|
|
|
|
'OMR' => __( 'Omani rial', 'woocommerce' ),
|
|
|
|
'PAB' => __( 'Panamanian balboa', 'woocommerce' ),
|
|
|
|
'PEN' => __( 'Peruvian nuevo sol', 'woocommerce' ),
|
|
|
|
'PGK' => __( 'Papua New Guinean kina', 'woocommerce' ),
|
|
|
|
'PHP' => __( 'Philippine peso', 'woocommerce' ),
|
|
|
|
'PKR' => __( 'Pakistani rupee', 'woocommerce' ),
|
|
|
|
'PLN' => __( 'Polish złoty', 'woocommerce' ),
|
|
|
|
'PRB' => __( 'Transnistrian ruble', 'woocommerce' ),
|
|
|
|
'PYG' => __( 'Paraguayan guaraní', 'woocommerce' ),
|
|
|
|
'QAR' => __( 'Qatari riyal', 'woocommerce' ),
|
|
|
|
'RON' => __( 'Romanian leu', 'woocommerce' ),
|
|
|
|
'RSD' => __( 'Serbian dinar', 'woocommerce' ),
|
|
|
|
'RUB' => __( 'Russian ruble', 'woocommerce' ),
|
|
|
|
'RWF' => __( 'Rwandan franc', 'woocommerce' ),
|
|
|
|
'SAR' => __( 'Saudi riyal', 'woocommerce' ),
|
|
|
|
'SBD' => __( 'Solomon Islands dollar', 'woocommerce' ),
|
|
|
|
'SCR' => __( 'Seychellois rupee', 'woocommerce' ),
|
|
|
|
'SDG' => __( 'Sudanese pound', 'woocommerce' ),
|
|
|
|
'SEK' => __( 'Swedish krona', 'woocommerce' ),
|
|
|
|
'SGD' => __( 'Singapore dollar', 'woocommerce' ),
|
|
|
|
'SHP' => __( 'Saint Helena pound', 'woocommerce' ),
|
|
|
|
'SLL' => __( 'Sierra Leonean leone', 'woocommerce' ),
|
|
|
|
'SOS' => __( 'Somali shilling', 'woocommerce' ),
|
|
|
|
'SRD' => __( 'Surinamese dollar', 'woocommerce' ),
|
|
|
|
'SSP' => __( 'South Sudanese pound', 'woocommerce' ),
|
|
|
|
'STD' => __( 'São Tomé and Príncipe dobra', 'woocommerce' ),
|
|
|
|
'SYP' => __( 'Syrian pound', 'woocommerce' ),
|
|
|
|
'SZL' => __( 'Swazi lilangeni', 'woocommerce' ),
|
|
|
|
'THB' => __( 'Thai baht', 'woocommerce' ),
|
|
|
|
'TJS' => __( 'Tajikistani somoni', 'woocommerce' ),
|
|
|
|
'TMT' => __( 'Turkmenistan manat', 'woocommerce' ),
|
|
|
|
'TND' => __( 'Tunisian dinar', 'woocommerce' ),
|
|
|
|
'TOP' => __( 'Tongan paʻanga', 'woocommerce' ),
|
|
|
|
'TRY' => __( 'Turkish lira', 'woocommerce' ),
|
|
|
|
'TTD' => __( 'Trinidad and Tobago dollar', 'woocommerce' ),
|
|
|
|
'TWD' => __( 'New Taiwan dollar', 'woocommerce' ),
|
|
|
|
'TZS' => __( 'Tanzanian shilling', 'woocommerce' ),
|
|
|
|
'UAH' => __( 'Ukrainian hryvnia', 'woocommerce' ),
|
|
|
|
'UGX' => __( 'Ugandan shilling', 'woocommerce' ),
|
|
|
|
'USD' => __( 'United States dollar', 'woocommerce' ),
|
|
|
|
'UYU' => __( 'Uruguayan peso', 'woocommerce' ),
|
|
|
|
'UZS' => __( 'Uzbekistani som', 'woocommerce' ),
|
|
|
|
'VEF' => __( 'Venezuelan bolívar', 'woocommerce' ),
|
|
|
|
'VND' => __( 'Vietnamese đồng', 'woocommerce' ),
|
|
|
|
'VUV' => __( 'Vanuatu vatu', 'woocommerce' ),
|
|
|
|
'WST' => __( 'Samoan tālā', 'woocommerce' ),
|
|
|
|
'XAF' => __( 'Central African CFA franc', 'woocommerce' ),
|
|
|
|
'XCD' => __( 'East Caribbean dollar', 'woocommerce' ),
|
|
|
|
'XOF' => __( 'West African CFA franc', 'woocommerce' ),
|
|
|
|
'XPF' => __( 'CFP franc', 'woocommerce' ),
|
|
|
|
'YER' => __( 'Yemeni rial', 'woocommerce' ),
|
2015-10-28 18:24:17 +00:00
|
|
|
'ZAR' => __( 'South African rand', 'woocommerce' ),
|
2016-04-18 23:21:14 +00:00
|
|
|
'ZMW' => __( 'Zambian kwacha', '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
|
|
|
}
|