Commit 9d0e3718 authored by Viral Solani's avatar Viral Solani

add assertion function for login and logout

parent 8d3ce723
...@@ -5,6 +5,7 @@ namespace Tests; ...@@ -5,6 +5,7 @@ namespace Tests;
use App\Models\Access\Role\Role; use App\Models\Access\Role\Role;
use App\Models\Access\User\User; use App\Models\Access\User\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Laravel\BrowserKitTesting\TestCase as BaseTestCase; use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
...@@ -78,4 +79,24 @@ abstract class BrowserKitTestCase extends BaseTestCase ...@@ -78,4 +79,24 @@ abstract class BrowserKitTestCase extends BaseTestCase
parent::tearDown(); parent::tearDown();
} }
/**
* Check if User is logged in or not.
*
* @return boolean true or false
*/
protected function assertLoggedIn()
{
$this->assertTrue(Auth::check());
}
/**
* Check if User is logged out or not
*
* @return boolean true or false
*/
protected function assertLoggedOut()
{
$this->assertFalse(Auth::check());
}
} }
...@@ -58,6 +58,7 @@ class LoginTest extends BrowserKitTestCase ...@@ -58,6 +58,7 @@ class LoginTest extends BrowserKitTestCase
public function unconfirmed_users_can_not_logIn() public function unconfirmed_users_can_not_logIn()
{ {
Auth::logout(); Auth::logout();
config(['access.users.requires_approval' => false]); config(['access.users.requires_approval' => false]);
// Create default user to test with // Create default user to test with
...@@ -104,6 +105,8 @@ class LoginTest extends BrowserKitTestCase ...@@ -104,6 +105,8 @@ class LoginTest extends BrowserKitTestCase
->see($this->user->name) ->see($this->user->name)
->seePageIs('/dashboard'); ->seePageIs('/dashboard');
$this->assertLoggedIn();
Auth::logout(); Auth::logout();
//Admin Test //Admin Test
...@@ -115,6 +118,8 @@ class LoginTest extends BrowserKitTestCase ...@@ -115,6 +118,8 @@ class LoginTest extends BrowserKitTestCase
->see($this->admin->first_name) ->see($this->admin->first_name)
->see('Access Management'); ->see('Access Management');
$this->assertLoggedIn();
Event::assertDispatched(UserLoggedIn::class); Event::assertDispatched(UserLoggedIn::class);
} }
} }
...@@ -9,3 +9,5 @@ function make($class, $attributes = [], $times = null) ...@@ -9,3 +9,5 @@ function make($class, $attributes = [], $times = null)
{ {
return factory($class, $times)->make($attributes); return factory($class, $times)->make($attributes);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment