public function testSetLocale() { Session::start(); $currentLocale = I18n::getCurrentLocale(); $_REQUEST['_locale'] = 'en'; I18n::staticReset(); $this->assertEquals('en', I18n::getCurrentLocale(), 'Unable to set locale via request'); $_REQUEST['_locale'] = $currentLocale; I18n::staticReset(); unset($_REQUEST['_locale']); I18n::setLocale('en'); $this->assertEquals('en', I18n::getCurrentLocale(), 'Unable to set locale via setLocale()'); I18n::setLocale($currentLocale); $this->assertEquals($currentLocale, I18n::getCurrentLocale(), 'Unable to set locale via setLocale()'); I18n::setLocale('non-existing'); $this->assertEquals($currentLocale, I18n::getCurrentLocale(), 'Unable to restore default locale via setLocale()'); Session::end(); I18n::clearCache(true); Cookies::set('locale', 'en'); Session::start(); I18n::staticReset(); $this->assertEquals('en', I18n::getCurrentLocale(), 'Unable to set locale via cookie'); $_REQUEST['_locale'] = $currentLocale; I18n::staticReset(); unset($_REQUEST['_locale']); Session::set('current_locale', 'en'); I18n::staticReset(); $this->assertEquals('en', I18n::getCurrentLocale(), 'Unable to set locale via session'); Session::set('current_locale', null); I18n::staticReset(); $this->assertEquals($currentLocale, I18n::getCurrentLocale(), 'Unable to restore default locale'); Session::end(); }
public function testGetResponseValue() { Cookies::reset(); Cookies::set($name = 'hello', $value = 'world'); $cookie = Cookies::get($name); $cookie->useEncryption(false); $this->assertEquals($name, $cookie->getName()); $this->assertEquals($value, $cookie->getResponseValue()); $cookie->useEncryption(true); $this->assertNotEquals($value, $encrypted = $cookie->getResponseValue()); /* @var \Phalcon\Crypt $crypt */ $crypt = $this->di->getShared('crypt'); $this->assertEquals($value, $crypt->decryptBase64($encrypted)); Cookies::reset(); }
public function logout() { if ($this->getUser() && method_exists($this->user, 'removeRememberToken')) { $this->user->removeRememberToken(); } Cookies::set($cookieName = $this->options['remember_login']['cookie_key'], '', null, null, null, null, true); Cookies::get($cookieName)->useEncryption(false); $this->user = null; Session::clear(); return $this; }
public function delete() { $this->_value = null; Cookies::set($this->_name, $this->_value, time() - Cache::TTL_ONE_MONTH, $this->_path, $this->_secure, $this->_domain, $this->_httpOnly)->get($this->_name)->useEncryption(false); }
public function setCookie() { $now = time(); if ($lazyRenew = $this->_options['cookie_lazy_renew_interval']) { if ($this->cookieRenewedAt + $lazyRenew > $now) { return $this; } $this->set('_cookie_renewed_at', $this->cookieRenewedAt = $now); } Cookies::set($cookieName = $this->getName(), $this->getId(), $now + $this->_options['lifetime'], $this->_options['cookies']['path'], $this->_options['cookies']['secure'], $this->_options['cookies']['domain'], $this->_options['cookies']['http_only']); Cookies::get($cookieName)->useEncryption(false); return $this; }