/** * Test the Auth::logout method. * * @group laravel */ public function testLogoutMethodLogsOutUser() { Session::$instance = new Payload($this->getMock('Laravel\\Session\\Drivers\\Driver')); $data = Session::$instance->session['data']['laravel_auth_drivers_fluent_login'] = 1; Auth::logout(); // A workaround since Cookie will is only stored in memory, until Response class is called. Auth::driver()->token = null; $this->assertNull(Auth::user()); $this->assertFalse(isset(Session::$instance->session['data']['laravel_auth_drivers_fluent_login'])); $this->assertTrue(Cookie::$jar['laravel_auth_drivers_fluent_remember']['expiration'] < time()); }
/** * Test the Session::started method. * * @group laravel */ public function testStartedMethodIndicatesIfSessionIsStarted() { $this->assertFalse(Session::started()); Session::$instance = 'foo'; $this->assertTrue(Session::started()); }
/** * Create a fresh session array with a unique ID. * * @return array */ public function fresh() { // Fetch a guest session with the same IP address $old_guest_session = $this->table()->where_user_id(1)->where_last_ip(Request::ip())->first(); // We will simply generate an empty session payload array, using an ID // that is either not currently assigned to any existing session or // that belongs to a guest with the same IP address. if (is_null($old_guest_session)) { $id = $this->id(); } else { $id = $old_guest_session->id; Session::instance()->exists = true; } return array('id' => $id, 'data' => array(':new:' => array(), ':old:' => array())); }
/** * Test the Auth::logout method. * * @group laravel */ public function testLogoutMethodLogsOutUser() { Session::$instance = new Payload($this->getMock('Laravel\\Session\\Drivers\\Driver')); $data = Session::$instance->session['data']['laravel_auth_drivers_fluent_login'] = 1; Auth::logout(); $this->assertNull(Auth::user()); $this->assertFalse(isset(Session::$instance->session['data']['laravel_auth_drivers_fluent_login'])); $this->assertTrue(Cookie::$jar['laravel_auth_drivers_fluent_remember']['expiration'] < time()); }
/** * Test `laravel.auth: login` and `laravel.auth: logout` is called properly * * @group laravel */ public function testAuthEventIsCalledProperly() { Session::$instance = new Payload($this->getMock('Laravel\\Session\\Drivers\\Driver')); Event::listen('laravel.auth: login', function () { $_SERVER['test.user.login'] = '******'; }); Event::listen('laravel.auth: logout', function () { $_SERVER['test.user.logout'] = 'foo'; }); $this->assertNull($_SERVER['test.user.login']); $this->assertNull($_SERVER['test.user.logout']); Auth::login(1, true); $this->assertEquals('foo', $_SERVER['test.user.login']); Auth::logout(); $this->assertEquals('foo', $_SERVER['test.user.logout']); }