diff --git a/currency/currency.tokens.inc b/currency/currency.tokens.inc index 85cdcc2..2ead7b7 100644 --- a/currency/currency.tokens.inc +++ b/currency/currency.tokens.inc @@ -62,20 +62,22 @@ function currency_tokens($type, array $tokens, array $data = array(), array $opt if ($tokens) { /** @var \Drupal\currency\Entity\CurrencyInterface $currency */ $currency = \Drupal::entityManager()->getStorage('currency')->load($currency_code); - foreach ($tokens as $token => $original) { - switch ($token) { - case 'number': - $replacements[$original] = $currency->getCurrencyNumber(); - break; - case 'sign': - $replacements[$original] = $currency->getSign(); - break; - case 'subunits': - $replacements[$original] = $currency->getSubunits(); - break; - case 'title': - $replacements[$original] = $currency->label(); - break; + if ($currency) { + foreach ($tokens as $token => $original) { + switch ($token) { + case 'number': + $replacements[$original] = $currency->getCurrencyNumber(); + break; + case 'sign': + $replacements[$original] = $currency->getSign(); + break; + case 'subunits': + $replacements[$original] = $currency->getSubunits(); + break; + case 'title': + $replacements[$original] = $currency->label(); + break; + } } } } diff --git a/currency/src/Controller/CurrencyLocaleImportForm.php b/currency/src/Controller/CurrencyLocaleImportForm.php index b4e60d6..f94bc4c 100644 --- a/currency/src/Controller/CurrencyLocaleImportForm.php +++ b/currency/src/Controller/CurrencyLocaleImportForm.php @@ -5,7 +5,7 @@ * Contains \Drupal\currency\Controller\CurrencyLocaleImportForm. */ -namespace Drupal\currency\Controller; +namespace Drupal\currency\Controller { use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Form\FormBase; @@ -120,3 +120,14 @@ class CurrencyLocaleImportForm extends FormBase implements ContainerInjectionInt } } + +} + +namespace { + + if (!function_exists('drupal_set_message')) { + function drupal_set_message() {} + } + +} + diff --git a/currency/src/Tests/Controller/FixedRatesFormWebTest.php b/currency/src/Tests/Controller/FixedRatesFormWebTest.php index f276ac6..f5f1167 100644 --- a/currency/src/Tests/Controller/FixedRatesFormWebTest.php +++ b/currency/src/Tests/Controller/FixedRatesFormWebTest.php @@ -33,6 +33,11 @@ class FixedRatesFormWebTest extends WebTestBase { $this->drupalGet($path); $this->assertText(t('Add an exchange rate')); + // Set up the currencies. + /** @var \Drupal\currency\ConfigImporterInterface $config_importer */ + $config_importer = \Drupal::service('currency.config_importer'); + $config_importer->importCurrency('EUR'); + $config_importer->importCurrency('UAH'); $currency_code_from = 'EUR'; $currency_code_to = 'UAH'; diff --git a/currency/src/Tests/ModuleInstallUninstallWebTest.php b/currency/src/Tests/ModuleInstallUninstallWebTest.php index 6415b67..d10cb50 100644 --- a/currency/src/Tests/ModuleInstallUninstallWebTest.php +++ b/currency/src/Tests/ModuleInstallUninstallWebTest.php @@ -34,17 +34,8 @@ class ModuleInstallUninstallWebTest extends WebTestBase { * Test configuration import. */ function testConfigImport() { - // The Dutch guilder was replaced by the Belgian franc, the euro, and the - // Surinamese guilder. This means it is obsolete and should be disabled by - // default. - /** @var \Drupal\currency\Entity\CurrencyInterface $currency */ - $currency = entity_load('currency', 'NLG'); - $this->assertFalse($currency->status()); - - // The euro is still in use in most countries and should be enabled by - // default. - /** @var \Drupal\currency\Entity\CurrencyInterface $currency */ - $currency = entity_load('currency', 'EUR'); - $this->assertTrue($currency->status()); + // XXX ("No currency") is the fallback currency and must always be available. + $currency = entity_load('currency', 'XXX'); + $this->assertTrue((bool) $currency); } } diff --git a/currency/src/Tests/Token.php b/currency/src/Tests/Token.php index 67574c5..d0c24c0 100644 --- a/currency/src/Tests/Token.php +++ b/currency/src/Tests/Token.php @@ -24,25 +24,16 @@ class Token extends WebTestBase { function testTokenIntegration() { $token_service = \Drupal::token(); + $tokens = array( + '[currency:code]' => 'XXX', + '[currency:number]' => '999', + '[currency:subunits]' => '0', + ); $data = array( - 'EUR' => array( - '[currency:code]' => 'EUR', - '[currency:number]' => '978', - '[currency:subunits]' => '100', - ), - 'BHD' => array( - '[currency:code]' => 'BHD', - '[currency:number]' => '048', - '[currency:subunits]' => '1000', - ), + 'currency' => 'XXX', ); - foreach ($data as $currency_code => $tokens) { - $data = array( - 'currency' => $currency_code, - ); - foreach ($tokens as $token => $replacement) { - $this->assertEqual($token_service->replace($token, $data), $replacement); - } + foreach ($tokens as $token => $replacement) { + $this->assertEqual($token_service->replace($token, $data), $replacement); } } } diff --git a/currency/tests/src/Unit/Controller/CurrencyImportFormUnitTest.php b/currency/tests/src/Unit/Controller/CurrencyImportFormUnitTest.php index c82d398..dfb7880 100644 --- a/currency/tests/src/Unit/Controller/CurrencyImportFormUnitTest.php +++ b/currency/tests/src/Unit/Controller/CurrencyImportFormUnitTest.php @@ -5,7 +5,7 @@ * Contains \Drupal\Tests\currency\Unit\Controller\CurrencyImportFormUnitTest. */ -namespace Drupal\Tests\currency\Unit\Controller; +namespace Drupal\Tests\currency\Unit\Controller { use Drupal\currency\Controller\CurrencyImportForm; use Drupal\Tests\UnitTestCase; @@ -154,3 +154,14 @@ class CurrencyImportFormUnitTest extends UnitTestCase { } } + +} + +namespace { + + if (!function_exists('drupal_set_message')) { + function drupal_set_message() {} + } + +} +