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(); }
protected function getTestController() { $this->getView()->reset(); $controller = new TestController(); Cookies::reset(); $controller->response->resetHeaders()->setContent(null); return $controller; }
/** * @param string $uri * @param string $method * @return CsrfException|NotFoundException|Response */ protected function dispatch($uri, $method = 'GET') { $_SERVER['REQUEST_METHOD'] = $method; $router = $this->getRouter(); $router::staticReset(); Cookies::reset(); $this->getView()->reset(); try { return $router->dispatch($uri); } catch (Exception $e) { Log::exception($e); return $e; } }
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 setUp() { $_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['PHWOOLCON_PHALCON_VERSION'] = Version::getId(); /* @var Di $di */ $di = $this->di = Di::getDefault(); Events::register($di); DiFix::register($di); Db::register($di); Cache::register($di); Log::register($di); Config::register($di); Counter::register($this->di); Aliases::register($di); I18n::register($di); Cookies::register($di); Session::register($di); Cache::flush(); Config::clearCache(); parent::setUp(); $class = get_class($this); Log::debug("================== Running {$class}::{$this->getName()}() ... =================="); Timer::start(); }
protected function realTestSessionCRUD($driver) { Config::set('session.default', $driver); Session::register($this->di); $suffix = " ({$driver})"; Session::flush(); // Start session $this->assertFalse(isset($_SESSION), '$_SESSION should not exist before session start' . $suffix); $this->assertTrue(Session::start(), 'Failed to start session' . $suffix); $this->assertFalse(Session::start(), 'Should not start duplicated sessions' . $suffix); // Get session id $this->assertNotEmpty($sid = Session::getId(), 'Session id not generated'); // Session detection $this->assertTrue(isset($_SESSION), '$_SESSION should exist after session start' . $suffix); $this->assertFalse(isset($_SESSION[$key = 'test_key']), 'Session value should not exist before set' . $suffix); // Set session value Session::set($key, $value = 'Test value'); $this->assertTrue(isset($_SESSION[$key]), 'Session value should exist after set' . $suffix); $this->assertEquals($value, $_SESSION[$key], 'Bad session set result' . $suffix); // Update session value Session::set($key, $value = 'Test value 2'); $this->assertEquals($value, $_SESSION[$key], 'Bad session update result' . $suffix); // Delete session value Session::remove($key); $this->assertFalse(isset($_SESSION[$key]), 'Session value should be deleted' . $suffix); // Load existing session Session::set($key, $value); Session::end(); $this->assertEquals($sid, Cookies::get('phwoolcon')->getValue(), 'Session cookie not set properly' . $suffix); $this->assertFalse(isset($_SESSION), '$_SESSION should be ended' . $suffix); $this->assertTrue(Session::start(), 'Failed to restart session' . $suffix); $this->assertEquals($value, $_SESSION[$key], 'Bad session load result' . $suffix); Session::end(); Config::set('session.default', 'native'); Session::register($this->di); }
use Phalcon\Version; use Phwoolcon\Aliases; use Phwoolcon\Cache; use Phwoolcon\Config; use Phwoolcon\Cookies; use Phwoolcon\Db; use Phwoolcon\DiFix; use Phwoolcon\Events; use Phwoolcon\I18n; use Phwoolcon\Log; use Phwoolcon\Queue; use Phwoolcon\Router; use Phwoolcon\Session; use Phwoolcon\Util\Counter; use Phwoolcon\View; $_SERVER['PHWOOLCON_PHALCON_VERSION'] = Version::getId(); Events::register($di); DiFix::register($di); Db::register($di); Cache::register($di); Log::register($di); Config::register($di); Counter::register($di); Aliases::register($di); Router::register($di); I18n::register($di); Cookies::register($di); Session::register($di); View::register($di); Queue::register($di); $loader->registerNamespaces(Config::get('app.autoload.namespaces', []), true);
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 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; }
protected function parseResponseHeaders(Response $response) { $headers = ['status' => '', 'headers' => [], 'set_cookies' => []]; // status $headers['status'] = 'HTTP/1.1 ' . $response->getStatusCode(); // headers foreach ($response->getHeaders()->toArray() as $name => $value) { $headers['headers'][] = $name . ($value === null ? '' : ': ' . $value); } // cookies foreach (Cookies::toArray() as $cookie) { $headers['set_cookies'][] = [$cookie->getName(), $cookie->getResponseValue(), $cookie->getExpiration(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure(), $cookie->getHttpOnly()]; } return $headers; }
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; }
public function reset() { if (!$this->multiLocale) { return; } $this->request or $this->request = static::$di->getShared('request'); if ($locale = $this->request->get('_locale')) { $this->_setLocale($locale); return; } if (($cookie = Cookies::get('locale')) && ($locale = $cookie->useEncryption(false)->getValue())) { $this->_setLocale($locale); $cookie->setHttpOnly(false)->delete(); return; } if ($locale = Session::get('current_locale')) { $this->loadLocale($this->currentLocale = $locale); return; } // @codeCoverageIgnoreStart if ($this->detectClientLocale) { $this->_setLocale($this->request->getBestLanguage()); return; } // @codeCoverageIgnoreEnd $this->loadLocale($this->currentLocale = $this->defaultLocale); }