/**
  * @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();
 }
Exemplo n.º 2
0
 /**
  * @runInSeparateProcess
  */
 public function testLoginRefresh()
 {
     $this->session->start();
     //hash password
     $storedPassword = $this->password->hash('password');
     //attemp first login
     $login = new Login($this->session, $this->password);
     $firstLogin = $login->login('root', 'password', $storedUser = '******', $storedPassword, 1);
     //attemp check if logged
     $firstLogged = $login->logged;
     $this->session->commit();
     $this->session->start();
     //create second instance
     $login = new Login($this->session, $this->password);
     //attemp check if logged
     $secondLogged = $login->logged;
     //simulate expired login
     $this->session->loginTime = time() - 3600;
     //attemp second login
     $secondLogin = new Login($this->session, $this->password);
     $notLogged = $secondLogin->logged;
     $this->assertEquals(true, $firstLogin);
     $this->assertEquals(true, $firstLogged);
     $this->assertEquals(true, $secondLogged);
     $this->assertEquals(false, $notLogged);
     $this->session->destroy();
 }