示例#1
0
 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();
 }
示例#2
0
 protected function _setLocale($locale)
 {
     if (strpos($locale, '..') || !is_dir($this->localePath . '/' . $locale)) {
         $locale = $this->defaultLocale;
     }
     Session::set('current_locale', $this->currentLocale = $locale);
     $this->loadLocale($locale);
 }
示例#3
0
 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);
 }
示例#4
0
 /**
  * @param User $user
  * @return $this
  */
 public function setUserAsLoggedIn($user)
 {
     $this->user = $user;
     $user and Session::set($this->sessionKey . '.uid', $user->getId());
     return $this;
 }