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) {
static $password;
return [
'name' => $faker->name,
'first_name' => $faker->name,
'last_name' => $faker->name,
'email' => $faker->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
'remember_token' => str_random(10),
];
});
......
......@@ -26,8 +26,8 @@ class UserTableSeeder extends Seeder
//Add the master administrator, user id of 1
$users = [
[
'first_name' => 'Admin Istrator',
'last_name' => 'Admin Istrator',
'first_name' => 'Viral',
'last_name' => 'Solani',
'email' => 'admin@admin.com',
'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
......@@ -39,8 +39,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null,
],
[
'first_name' => 'Backend User',
'last_name' => 'Admin Istrator',
'first_name' => 'Vipul',
'last_name' => 'Basapati',
'email' => 'executive@executive.com',
'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
......@@ -52,8 +52,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null,
],
[
'first_name' => 'Default User',
'last_name' => 'Admin Istrator',
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'user@user.com',
'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
......
......@@ -2,7 +2,10 @@
namespace Tests\Feature;
use Illuminate\Support\Facades\Auth;
use Tests\BrowserKitTestCase;
use Illuminate\Support\Facades\Event;
use App\Events\Frontend\Auth\UserLoggedIn;
class AuthTest extends BrowserKitTestCase
{
......@@ -27,23 +30,43 @@ class AuthTest extends BrowserKitTestCase
}
/** @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('wrongpassword', 'password')
->press('Login')
->seePageIs('/login')
->see('These credentials do not match our records.');
}
}*/
/** @test */
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')
->type('user@user.com', 'email')
->type($this->admin->email, 'email')
->type('1234', 'password')
->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 @@
namespace Tests;
use App\Models\Access\Role\Role;
use App\Models\Access\User\User;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Artisan;
abstract class TestCase extends BaseTestCase
{
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)
{
$user = $user ?: create('App\User');
......@@ -17,10 +50,28 @@ abstract class TestCase extends BaseTestCase
return $this;
}
/**
* Set up tests.
*/
public function setUp()
{
parent::setUp();
$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