/**
  * @runInSeparateProcess
  * @outputBuffering disabled
  */
 public function testProtectedController()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('Xdebug not installed');
     }
     $autoloader = new Autoloader();
     $autoloader->register();
     $autoloader->addNamespaces([['Linna\\FOO', dirname(__DIR__) . '/FOO']]);
     //config options
     $session = new Session();
     $session->start();
     $password = new Password();
     $storedPassword = $password->hash('password');
     //attemp first login
     $login = new Login($session, $password);
     $login->login('root', 'password', $storedUser = '******', $storedPassword, 1);
     $loginLogged = $login->logged;
     $model = new FOOModel();
     $controller1 = new FOOProtectedController($model, $login);
     $controllerTest1 = $controller1->test;
     $login->logout();
     $loginNoLogged = $login->logged;
     ob_start();
     $controller2 = new FOOProtectedController($model, $login);
     $headers_list = xdebug_get_headers();
     ob_end_clean();
     $this->assertEquals(true, $loginLogged);
     $this->assertEquals(false, $loginNoLogged);
     $this->assertEquals(true, $controllerTest1);
     $this->assertEquals(true, in_array('Location: http://localhost', $headers_list));
     $session->destroy();
 }
 /**
  * @runInSeparateProcess
  */
 public function testExpiredSession()
 {
     $MysqlAdapter = new MysqlPDOAdapter($GLOBALS['db_type'] . ':host=' . $GLOBALS['db_host'] . ';dbname=' . $GLOBALS['db_name'] . ';charset=utf8mb4', $GLOBALS['db_username'], $GLOBALS['db_password'], array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING));
     $dbase = new Database($MysqlAdapter);
     $sessionHandler = new DatabaseSessionHandler($dbase);
     $session = new Session(['expire' => 8]);
     $session->setSessionHandler($sessionHandler);
     $session->start();
     $session_id = $session->id;
     $session->time = $session->time - 1800;
     $session->commit();
     $session->setSessionHandler($sessionHandler);
     $session->start();
     $session_id2 = $session->id;
     $test = $session_id === $session_id2 ? 1 : 0;
     $this->assertEquals(0, $test);
     $session->destroy();
 }
 /**
  * @runInSeparateProcess
  */
 public function testExpiredSession()
 {
     if (!class_exists('Memcached')) {
         $this->markTestSkipped('Memcached module not installed');
     }
     //create memcached instance
     $memcached = new Memcached();
     //connect to memcached server
     $memcached->addServer($GLOBALS['mem_host'], $GLOBALS['mem_port']);
     $sessionHandler = new MemcachedSessionHandler($memcached, 8);
     $session = new Session(['expire' => 8]);
     $session->setSessionHandler($sessionHandler);
     $session->start();
     $session_id = $session->id;
     $session->time = $session->time - 1800;
     $session->commit();
     $session->setSessionHandler($sessionHandler);
     $session->start();
     $session_id2 = $session->id;
     $test = $session_id === $session_id2 ? 1 : 0;
     $this->assertEquals(0, $test);
     $session->destroy();
 }
Ejemplo n.º 4
0
//$DIResolver->cacheUnResolvable('\Memcached', $memcached);
//$DIResolver->cacheUnResolvable('\Linna\Session\MemcachedSessionHandler', new MemcachedSessionHandler($memcached, $options['session']['expire']));
/**
 * Session section
 *
 */
//resolve Session Handler
$sessionHandler = $DIResolver->resolve('\\Linna\\Session\\DatabaseSessionHandler');
//$sessionHandler = $DIResolver->resolve('\Linna\Session\MemcachedSessionHandler');
//create session object
$session = new Session($options['session']);
//set session handler
//optional if not set, app will use php session standard storage
$session->setSessionHandler($sessionHandler);
//start session
$session->start();
//store session instance
$DIResolver->cacheUnResolvable('\\Linna\\Session\\Session', $session);
/**
 * Router Section
 *
 */
//start router
$router = new Router($appRoutes, $options['router']);
//evaluate request uri and method
$router->validate($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
//get route
$route = $router->getRoute();
//get model linked to route
$routeModel = '\\App\\Models\\' . $route->getModel();
//get view linked to route