Commit be50a012 authored by Viral Solani's avatar Viral Solani

Merge branch 'test-cases' of https://github.com/viralsolani/laravel-adminpanel into develop

parents 546a8362 cf420162
...@@ -19,11 +19,12 @@ $factory->define(User::class, function (Generator $faker) { ...@@ -19,11 +19,12 @@ $factory->define(User::class, function (Generator $faker) {
static $password; static $password;
return [ return [
'name' => $faker->name, 'first_name' => $faker->name,
'last_name' => $faker->name,
'email' => $faker->safeEmail, 'email' => $faker->safeEmail,
'password' => $password ?: $password = bcrypt('secret'), 'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
'confirmation_code' => md5(uniqid(mt_rand(), true)), 'confirmation_code' => md5(uniqid(mt_rand(), true)),
'remember_token' => str_random(10),
]; ];
}); });
......
...@@ -26,8 +26,8 @@ class UserTableSeeder extends Seeder ...@@ -26,8 +26,8 @@ class UserTableSeeder extends Seeder
//Add the master administrator, user id of 1 //Add the master administrator, user id of 1
$users = [ $users = [
[ [
'first_name' => 'Admin Istrator', 'first_name' => 'Viral',
'last_name' => 'Admin Istrator', 'last_name' => 'Solani',
'email' => 'admin@admin.com', 'email' => 'admin@admin.com',
'password' => bcrypt('1234'), 'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)), 'confirmation_code' => md5(uniqid(mt_rand(), true)),
...@@ -39,8 +39,8 @@ class UserTableSeeder extends Seeder ...@@ -39,8 +39,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null, 'deleted_at' => null,
], ],
[ [
'first_name' => 'Backend User', 'first_name' => 'Vipul',
'last_name' => 'Admin Istrator', 'last_name' => 'Basapati',
'email' => 'executive@executive.com', 'email' => 'executive@executive.com',
'password' => bcrypt('1234'), 'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)), 'confirmation_code' => md5(uniqid(mt_rand(), true)),
...@@ -52,8 +52,8 @@ class UserTableSeeder extends Seeder ...@@ -52,8 +52,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null, 'deleted_at' => null,
], ],
[ [
'first_name' => 'Default User', 'first_name' => 'John',
'last_name' => 'Admin Istrator', 'last_name' => 'Doe',
'email' => 'user@user.com', 'email' => 'user@user.com',
'password' => bcrypt('1234'), 'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)), 'confirmation_code' => md5(uniqid(mt_rand(), true)),
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
namespace Tests\Feature; namespace Tests\Feature;
use Illuminate\Support\Facades\Auth;
use Tests\BrowserKitTestCase; use Tests\BrowserKitTestCase;
use Illuminate\Support\Facades\Event;
use App\Events\Frontend\Auth\UserLoggedIn;
class AuthTest extends BrowserKitTestCase class AuthTest extends BrowserKitTestCase
{ {
...@@ -27,23 +30,43 @@ class AuthTest extends BrowserKitTestCase ...@@ -27,23 +30,43 @@ class AuthTest extends BrowserKitTestCase
} }
/** @test */ /** @test */
public function test_login_failure_with_wrong_inputs() /*public function test_login_failure_with_wrong_inputs()
{ {
$this->visit('/login') $this->visit("/login")
->type('wrongusername@wrongpassword.com', 'email') ->type('wrongusername@wrongpassword.com', 'email')
->type('wrongpassword', 'password') ->type('wrongpassword', 'password')
->press('Login') ->press('Login')
->seePageIs('/login') ->seePageIs('/login')
->see('These credentials do not match our records.'); ->see('These credentials do not match our records.');
} }*/
/** @test */ /** @test */
public function users_can_login() public function users_can_login()
{ {
// Make sure our events are fired
Event::fake();
Auth::logout();
//User Test
$this->visit('/login')
->type($this->user->email, 'email')
->type('1234', 'password')
->press('Login')
->see($this->user->name)
->seePageIs('/dashboard');
Auth::logout();
//Admin Test
$this->visit('/login') $this->visit('/login')
->type('user@user.com', 'email') ->type($this->admin->email, 'email')
->type('1234', 'password') ->type('1234', 'password')
->press('Login') ->press('Login')
->seePageIs(route('frontend.user.dashboard')); ->seePageIs('/admin/dashboard')
->see($this->admin->first_name)
->see('Access Management');
Event::assertDispatched(UserLoggedIn::class);
} }
} }
\ No newline at end of file
...@@ -2,12 +2,45 @@ ...@@ -2,12 +2,45 @@
namespace Tests; namespace Tests;
use App\Models\Access\Role\Role;
use App\Models\Access\User\User;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Artisan;
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
use CreatesApplication; use CreatesApplication;
/**
* @var
*/
protected $admin;
/**
* @var
*/
protected $executive;
/**
* @var
*/
protected $user;
/**
* @var
*/
protected $adminRole;
/**
* @var
*/
protected $executiveRole;
/**
* @var
*/
protected $userRole;
public function signIn($user = null) public function signIn($user = null)
{ {
$user = $user ?: create('App\User'); $user = $user ?: create('App\User');
...@@ -17,10 +50,28 @@ abstract class TestCase extends BaseTestCase ...@@ -17,10 +50,28 @@ abstract class TestCase extends BaseTestCase
return $this; return $this;
} }
/**
* Set up tests.
*/
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->withoutExceptionHandling(); $this->withoutExceptionHandling();
// Set up the database
Artisan::call('migrate:refresh');
Artisan::call('db:seed');
/*
* Create class properties to be used in tests
*/
$this->admin = User::find(1);
$this->executive = User::find(2);
$this->user = User::find(3);
$this->adminRole = Role::find(1);
$this->executiveRole = Role::find(2);
$this->userRole = Role::find(3);
} }
} }
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