You are here

public function CommerceMulticurrencyTestCase::testNotOverwrittingCurrency in Commerce Multicurrency 7

Test that the currency switching works as expected.

File

tests/commerce_multicurrency.test, line 107
Tests for the commerce currency module.

Class

CommerceMulticurrencyTestCase
Tests for the commerce currency module.

Code

public function testNotOverwrittingCurrency() {

  // Reset currency to default.
  $currency_code =& drupal_static('commerce_multicurrency_get_user_currency_code', FALSE);
  $currency_code = commerce_default_currency();

  // Set currency only if no cookie is set.
  $_COOKIE[$this->cookieName] = $currency_code;
  commerce_multicurrency_set_user_currency_code('CHF', FALSE);
  $this
    ->assertEqual(commerce_default_currency(), commerce_multicurrency_get_user_currency_code(), 'Currency is not overwritten if cookie is set.');
  $this
    ->assertEqual(commerce_default_currency(), $currency_code, 'Static cache currency is not overwritten if cookie is set.');
  $this
    ->assertEqual(commerce_default_currency(), $_COOKIE[$this->cookieName], 'Cookie currency is not overwritten if cookie is set.');

  // Set currency only if no cookie is set.
  unset($_COOKIE[$this->cookieName]);
  commerce_multicurrency_set_user_currency_code('EUR', FALSE);
  $this
    ->assertEqual('EUR', commerce_multicurrency_get_user_currency_code(), 'Currency is set if no cookie is set.');
  $this
    ->assertEqual('EUR', $currency_code, 'Static cache currency is set if no cookie is set.');

  // We can't check if cookie is set in unit tests.
}