コード例 #1
0
 /**
  * Creates a currency entity from a currency from the repository.
  *
  * @param string $currency_code
  *
  * @return \Drupal\currency\Entity\CurrencyInterface
  *
  * @throws \InvalidArgumentException
  *   Thrown when no currency with the given currency code exists.
  */
 protected function createCurrencyFromRepository($currency_code)
 {
     /** @var \Drupal\currency\Entity\CurrencyInterface $currency_entity */
     $currency_entity = $this->currencyStorage->create();
     $currency_resource = $this->currencyResourceRepository->loadCurrency($currency_code);
     if (is_null($currency_resource)) {
         throw new \InvalidArgumentException(sprintf('No currency with currency code %s exists.', $currency_code));
     }
     $currency_entity->setCurrencyCode($currency_resource->getCurrencyCode());
     $currency_entity->setCurrencyNumber($currency_resource->getCurrencyNumber());
     $currency_entity->setLabel($currency_resource->getLabel());
     $currency_entity->setSign($currency_resource->getSign());
     $currency_entity->setAlternativeSigns($currency_resource->getAlternativeSigns());
     $currency_entity->setSubunits($currency_resource->getSubunits());
     $currency_entity->setRoundingStep($currency_resource->getRoundingStep());
     $currency_entity->setUsages($currency_resource->getUsages());
     return $currency_entity;
 }
コード例 #2
0
 /**
  * @covers ::loadCurrency
  *
  * @dataProvider providerLoadCurrencyWithNonExistentCurrencies
  */
 public function testLoadCurrencyWithNonExistentCurrencies($currencyCode)
 {
     $this->assertNull($this->sut->loadCurrency($currencyCode));
 }