Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
laravel-adminpanel
Commits
d3771538
Commit
d3771538
authored
Dec 22, 2017
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
User Login Test With Helper function
parent
0f47fe87
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
148 additions
and
15 deletions
+148
-15
ModelFactory.php
database/factories/ModelFactory.php
+4
-2
UserTableSeeder.php
database/seeds/Access/UserTableSeeder.php
+6
-6
BrowserKitTestCase.php
tests/BrowserKitTestCase.php
+55
-0
CreatesUsers.php
tests/CreatesUsers.php
+0
-1
AuthTest.php
tests/Feature/AuthTest.php
+28
-6
TestCase.php
tests/TestCase.php
+55
-0
No files found.
database/factories/ModelFactory.php
View file @
d3771538
...
...
@@ -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
)
];
});
...
...
@@ -51,6 +52,7 @@ $factory->state(User::class, 'unconfirmed', function () {
];
});
/*
* Roles
*/
...
...
database/seeds/Access/UserTableSeeder.php
View file @
d3771538
...
...
@@ -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
)),
...
...
tests/BrowserKitTestCase.php
View file @
d3771538
...
...
@@ -2,6 +2,9 @@
namespace
Tests
;
use
App\Models\Access\Role\Role
;
use
App\Models\Access\User\User
;
use
Illuminate\Support\Facades\Artisan
;
use
Laravel\BrowserKitTesting\TestCase
as
BaseTestCase
;
abstract
class
BrowserKitTestCase
extends
BaseTestCase
...
...
@@ -9,4 +12,56 @@ abstract class BrowserKitTestCase extends BaseTestCase
use
CreatesApplication
;
public
$baseUrl
=
'http://localhost:8000'
;
/**
* @var
*/
protected
$admin
;
/**
* @var
*/
protected
$executive
;
/**
* @var
*/
protected
$user
;
/**
* @var
*/
protected
$adminRole
;
/**
* @var
*/
protected
$executiveRole
;
/**
* @var
*/
protected
$userRole
;
/**
* Set up tests.
*/
public
function
setUp
()
{
parent
::
setUp
();
// 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
);
}
}
tests/CreatesUsers.php
View file @
d3771538
...
...
@@ -23,7 +23,6 @@ trait CreatesUsers
'username'
=>
'johndoe'
,
'email'
=>
'john@example.com'
,
'password'
=>
bcrypt
(
'password'
),
'github_username'
=>
'johndoe'
,
],
$attributes
));
}
}
tests/Feature/AuthTest.php
View file @
d3771538
...
...
@@ -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
{
...
...
@@ -40,11 +43,30 @@ class AuthTest extends BrowserKitTestCase
/** @test */
public
function
users_can_login
()
{
//$this->createUser();
$this
->
visit
(
'/login'
)
->
type
(
'user@user.com'
,
'email'
)
->
type
(
'1234'
,
'password'
)
//->press('Login')
->
seePageIs
(
'/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
(
$this
->
admin
->
email
,
'email'
)
->
type
(
'1234'
,
'password'
)
->
press
(
'Login'
)
->
seePageIs
(
'/admin/dashboard'
)
->
see
(
$this
->
admin
->
first_name
)
->
see
(
'Access Management'
);
Event
::
assertDispatched
(
UserLoggedIn
::
class
);
}
}
tests/TestCase.php
View file @
d3771538
...
...
@@ -2,9 +2,64 @@
namespace
Tests
;
use
App\Models\Access\Role\Role
;
use
App\Models\Access\User\User
;
use
Illuminate\Support\Facades\Artisan
;
use
Illuminate\Foundation\Testing\TestCase
as
BaseTestCase
;
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
;
/**
* Set up tests.
*/
public
function
setUp
()
{
parent
::
setUp
();
// 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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment