Пример #1
0
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 public function setUp()
 {
     $this->clearRegistry();
     $this->_cache = Cache\Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => sys_get_temp_dir()));
     Currency\Currency::setCache($this->_cache);
     $this->helper = new Helper\Currency('de_AT');
 }
Пример #2
0
    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     *
     * @return void
     */
    public function setUp()
    {
        $this->clearRegistry();

        $this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
        Currency\Currency::setCache($this->_cache);

        $this->helper = new Helper\Currency('de_AT');
    }
Пример #3
0
 /**
  * Output a formatted currency
  *
  * @param  integer|float                    $value    Currency value to output
  * @param  string|Zend_Locale|\Zend\Currency\Currency $currency OPTIONAL Currency to use for this call
  * @return string Formatted currency
  */
 public function direct($value = null, $currency = null)
 {
     if ($value === null) {
         return $this;
     }
     if (is_string($currency) || $currency instanceof Locale\Locale) {
         if (Locale\Locale::isLocale($currency)) {
             $currency = array('locale' => $currency);
         }
     }
     if (is_string($currency)) {
         $currency = array('currency' => $currency);
     }
     if (is_array($currency)) {
         return $this->_currency->toCurrency($value, $currency);
     }
     return $this->_currency->toCurrency($value);
 }
Пример #4
0
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 public function setUp()
 {
     $this->clearRegistry();
     $this->_cacheDir = sys_get_temp_dir() . '/zend_view_helper_currency';
     $this->_removeRecursive($this->_cacheDir);
     mkdir($this->_cacheDir);
     $this->_cache = CacheFactory::factory(array('adapter' => array('name' => 'Filesystem', 'options' => array('ttl' => 120, 'cache_dir' => $this->_cacheDir)), 'plugins' => array(array('name' => 'serializer', 'options' => array('serializer' => 'php_serialize')))));
     Currency\Currency::setCache($this->_cache);
     $this->helper = new Helper\Currency('de_AT');
 }
Пример #5
0
 /**
  * @ZF-9941
  */
 public function testSetValueByOutput()
 {
     $currency = new Currency\Currency(array('value' => 1000, 'locale' => 'de_AT'));
     $this->assertEquals('€ 2.000,00', $currency->toCurrency(null, array('value' => 2000)));
 }
Пример #6
0
    /**
     * Internal method which calculates the exchanges currency
     *
     * @param float|integer|Currency $value    Compares the currency with this value
     * @param string|Currency        $currency The currency to compare this value from
     * @return float
     */
    protected function _exchangeCurrency($value, $currency)
    {
        if ($value instanceof Currency) {
            $currency = $value->getShortName();
            $value    = $value->getValue();
        } else {
            $currency = $this->getShortName($currency, $this->getLocale());
        }

        $rate = 1;
        if ($currency !== $this->getShortName()) {
            $service = $this->getService();
            if (!($service instanceof CurrencyService)) {
                throw new Exception\RuntimeException('No exchange service applied');
            }

            $rate = $service->getRate($currency, $this->getShortName());
        }

        $value *= $rate;
        return $value;
    }
Пример #7
0
 /**
  * @ZF-9519
  */
 public function testSetValueWithoutLocale()
 {
     $currency = new Currency\Currency('RUB', 'ru_RU');
     require_once __DIR__ . '/ExchangeTest.php';
     $this->assertEquals(null, $currency->getService());
     $currency->setService(new ExchangeTest());
     $this->assertTrue($currency->getService() instanceof Currency\CurrencyServiceInterface);
     $currency->setValue(100, 'USD');
     $this->assertEquals(50, $currency->getValue());
     $this->assertEquals('RUB', $currency->getShortName());
 }