Skip to content

Commit

Permalink
Added test for Issue #952
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Mar 30, 2019
1 parent 77dde3e commit a7723c5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
42 changes: 42 additions & 0 deletions app/sprinkles/account/tests/Integration/AuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Facades\Password;
use UserFrosting\Sprinkle\Account\Tests\withTestUser;
use UserFrosting\Sprinkle\Core\Database\Models\Session;
use UserFrosting\Sprinkle\Core\Tests\TestDatabase;
use UserFrosting\Sprinkle\Core\Tests\RefreshDatabase;
use UserFrosting\Tests\TestCase;
Expand Down Expand Up @@ -80,6 +81,47 @@ public function testLogin(Authenticator $authenticator)
$this->assertNotSame($testUser->id, $this->ci->session[$key]);
}

/**
* @depends testConstructor
* @param Authenticator $authenticator
*/
public function testLoginWithSessionDatabase(Authenticator $authenticator)
{
// Change session
$this->ci->config['session.handler'] = 'database';

// Create a test user
$testUser = $this->createTestUser();

// Check the table
$this->assertSame(0, Session::count());

// Test session to avoid false positive
$key = $this->ci->config['session.keys.current_user_id'];
$this->assertNull($this->ci->session[$key]);
$this->assertNotSame($testUser->id, $this->ci->session[$key]);

// Login the test user
$authenticator->login($testUser, false);

// Check the table again
$get = Session::get();
echo print_r($get, true);
$this->assertSame(1, Session::count());

// Test session to see if user was logged in
$this->assertNotNull($this->ci->session[$key]);
$this->assertSame($testUser->id, $this->ci->session[$key]);

// Must logout to avoid test issue
$authenticator->logout(true);

// We'll test the logout system works too while we're at it (and depend on it)
$key = $this->ci->config['session.keys.current_user_id'];
$this->assertNull($this->ci->session[$key]);
$this->assertNotSame($testUser->id, $this->ci->session[$key]);
}

/**
* @depends testConstructor
* @expectedException \UserFrosting\Sprinkle\Account\Authenticate\Exception\AccountInvalidException
Expand Down
25 changes: 25 additions & 0 deletions app/sprinkles/core/src/Database/Models/Session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* UserFrosting (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @copyright Copyright (c) 2019 Alexander Weissman
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
*/

namespace UserFrosting\Sprinkle\Core\Database\Models;

use UserFrosting\Sprinkle\Core\Database\Models\Model;

/**
* Session Class
*
* Represents a session object as stored in the database.
*/
class Session extends Model
{
/**
* @var string The name of the table for the current model.
*/
protected $table = 'sessions';
}

0 comments on commit a7723c5

Please sign in to comment.