Ejemplo n.º 1
0
 public function testCurrencyCodeOption()
 {
     $filter = new Uncurrency();
     $this->assertInstanceOf('MoneyLaundry\\Filter\\Uncurrency', $filter->setCurrencyCode());
     $this->assertNull($filter->getCurrencyCode());
     $filter = new Uncurrency();
     $this->assertInstanceOf('MoneyLaundry\\Filter\\Uncurrency', $filter->setCurrencyCode('GBP'));
     $this->assertEquals('GBP', $filter->getCurrencyCode());
 }
Ejemplo n.º 2
0
 /**
  * Returns true if and only if $value is a currency amount well-formatted for the given locale
  *
  * It validates according to the specified options, i.e. whether to consider valid:
  * a negative currency amount,
  * a currency different than the locale's default,
  * a currency string that could not contain currency symbol,
  * a currency string that could contain an inexact number of decimal places.
  *
  * @param  string $value
  * @return bool
  * @throws I18nException\InvalidArgumentException
  */
 public function isValid($value)
 {
     $this->setValue($value);
     if (!is_string($value)) {
         $this->error(self::INVALID);
         return false;
     }
     // Setup filter
     $filter = new Uncurrency($this->getLocale(), $this->getCurrencyCode());
     $filter->setScaleCorrectness($this->getScaleCorrectness());
     $filter->setCurrencyCorrectness($this->getCurrencyCorrectness());
     $filter->setBreakingSpaceAllowed($this->isBreakingSpaceAllowed());
     // Filtering
     $result = $filter->filter($this->getValue());
     // Retrieve updated currency code
     $this->currencyCode = $filter->getCurrencyCode();
     if ($result !== $this->getValue()) {
         // Filter succedeed
         if (!$this->isNegativeAllowed() && $result < 0) {
             $this->error(self::NOT_POSITIVE);
             return false;
         }
         return true;
     }
     $this->pattern = $filter->getFormatter()->getPattern();
     $this->error(self::NOT_CURRENCY);
     return false;
 }