public function CommerceMulticurrencyTestCase::testGetCurrency in Commerce Multicurrency 7
Test that the currency retrieving works.
File
- tests/
commerce_multicurrency.test, line 56 - Tests for the commerce currency module.
Class
- CommerceMulticurrencyTestCase
- Tests for the commerce currency module.
Code
public function testGetCurrency() {
// Ensure environment is clean.
$currency_code =& drupal_static('commerce_multicurrency_get_user_currency_code', FALSE);
$currency_code = FALSE;
unset($_COOKIE[$this->cookieName]);
// Check fallback behaviour if no currency is explicitly set.
$this
->assertEqual(commerce_default_currency(), commerce_multicurrency_get_user_currency_code(), 'Default: ' . commerce_default_currency() . ' returned.');
// Inject currency.
$currency_code = 'CHF';
$this
->assertEqual($currency_code, commerce_multicurrency_get_user_currency_code(), 'Static cache: CHF returned.');
// Reset currency code, but set cookie.
$currency_code = FALSE;
$_COOKIE[$this->cookieName] = 'EUR';
$this
->assertEqual('EUR', commerce_multicurrency_get_user_currency_code(), 'Cookie: EUR returned.');
// Check if the static cache works.
unset($_COOKIE[$this->cookieName]);
$this
->assertEqual('EUR', commerce_multicurrency_get_user_currency_code(), 'Static Cache follow up: EUR returned.');
// Ensure only valid currencies are accepted from cookies.
$_COOKIE[$this->cookieName] = 'NOP';
$currency_code = FALSE;
$this
->assertEqual(commerce_default_currency(), commerce_multicurrency_get_user_currency_code(), 'Invalid currency was not returned.');
}