Esempio n. 1
0
 public function testPaging()
 {
     $currency1 = CM_Model_Currency::create('123', 'FOO');
     $currency2 = CM_Model_Currency::create('456', 'BAR');
     $paging = new CM_Paging_Currency_All();
     $this->assertContainsAll([$currency1, $currency2], $paging);
 }
Esempio n. 2
0
 public function testCreateAllData()
 {
     CMTest_TH::createDefaultCurrency();
     $site = $this->getMockSite();
     $language = CM_Model_Language::create('English', 'en', true);
     $currency = CM_Model_Currency::create('978', 'EUR');
     $user = CM_Model_User::createStatic(['site' => $site, 'language' => $language, 'currency' => $currency]);
     $this->assertInternalType('int', $user->getCreated());
     $this->assertEquals(time(), $user->getCreated());
     $this->assertEquals(time(), $user->getLatestActivity());
     $this->assertEquals($site, $user->getSite());
     $this->assertEquals($language, $user->getLanguage());
     $this->assertEquals($currency, $user->getCurrency());
 }
Esempio n. 3
0
 public function testSetNull()
 {
     $defaultCurrency = CM_Model_Currency::create('840', 'USD');
     $environment = new CM_Frontend_Environment();
     $this->assertEquals(CM_Site_Abstract::factory(), $environment->getSite());
     $this->assertNull($environment->getViewer());
     $this->assertNull($environment->getLanguage());
     $this->assertSame('en', $environment->getLocale());
     $this->assertEquals(CM_Bootloader::getInstance()->getTimeZone(), $environment->getTimeZone());
     $this->assertSame(CM_Bootloader::getInstance()->isDebug(), $environment->isDebug());
     $this->assertNull($environment->getLocation());
     $this->assertEquals($defaultCurrency, $environment->getCurrency());
     $this->assertNull($environment->getClientDevice());
 }
Esempio n. 4
0
 /**
  * @param CM_Model_Currency $currency
  * @return boolean
  */
 public function contains(CM_Model_Currency $currency)
 {
     return in_array($currency->getId(), $this->getItemsRaw());
 }
Esempio n. 5
0
 /**
  * @return CM_Model_Currency
  */
 public function getCurrency()
 {
     $currency = $this->_currency;
     if (null === $currency) {
         $currency = CM_Model_Currency::getDefaultCurrency();
     }
     return $currency;
 }
Esempio n. 6
0
 public function load(CM_OutputStream_Interface $output)
 {
     $defaultCurrencySettings = CM_Model_Currency::_getConfig()->default;
     CM_Model_Currency::create($defaultCurrencySettings['code'], $defaultCurrencySettings['abbreviation']);
     $this->_setLoaded(true);
 }
Esempio n. 7
0
 /**
  * @return CM_Frontend_Environment
  * @throws CM_Exception_AuthRequired
  */
 public function getEnvironment()
 {
     $request = $this->getRequest();
     $location = $request->getLocation();
     $viewer = $request->getViewer();
     $currency = null;
     if (null === $currency && null !== $viewer) {
         $currency = $viewer->getCurrency();
     }
     if (null === $currency && null !== $location) {
         $currency = CM_Model_Currency::findByLocation($location);
     }
     $clientDevice = new CM_Http_ClientDevice($request);
     return new CM_Frontend_Environment($this->getSite(), $viewer, $request->getLanguage(), $request->getTimeZone(), null, $location, $currency, $clientDevice);
 }
Esempio n. 8
0
 public function testDelete()
 {
     $currencyDefault = CMTest_TH::createDefaultCurrency();
     $currencyEUR = CM_Model_Currency::create('978', 'EUR');
     $paging = new CM_Paging_Currency_All();
     $this->assertCount(2, $paging);
     $this->assertContainsAll([$currencyDefault, $currencyEUR], $paging->getItems());
     $currencyEUR->delete();
     $paging = new CM_Paging_Currency_All();
     $this->assertCount(1, $paging);
     $this->assertContains($currencyDefault, $paging->getItems());
     $this->assertNotContains($currencyEUR, $paging->getItems());
 }
Esempio n. 9
0
 /**
  * @return CM_Model_Currency
  */
 public static function createDefaultCurrency()
 {
     $defaultCurrencyConfig = CM_Config::get()->CM_Model_Currency->default;
     if (!($defaultCurrency = CM_Model_Currency::findByAbbreviation($defaultCurrencyConfig['abbreviation']))) {
         $defaultCurrency = CM_Model_Currency::create($defaultCurrencyConfig['code'], $defaultCurrencyConfig['abbreviation']);
     }
     return $defaultCurrency;
 }
Esempio n. 10
0
 /**
  * @param CM_Model_Currency $currency
  */
 public function setCurrency(CM_Model_Currency $currency)
 {
     CM_Db_Db::update('cm_user', array('currencyId' => $currency->getId()), array('userId' => $this->getId()));
     $this->_change();
 }
Esempio n. 11
0
 /**
  * @return CM_Frontend_Environment
  * @throws CM_Exception_AuthRequired
  */
 public function getEnvironment()
 {
     $location = $this->getRequest()->getLocation();
     $currency = null !== $location ? CM_Model_Currency::findByLocation($location) : null;
     return new CM_Frontend_Environment($this->getSite(), $this->getRequest()->getViewer(), $this->getRequest()->getLanguage(), null, null, $location, $currency);
 }