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
de9ab079
Commit
de9ab079
authored
Dec 24, 2017
by
Vipul Basapati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Backend Tests, User Form tests are failing
parent
21655760
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
1602 additions
and
42 deletions
+1602
-42
StoreRoleRequest.php
app/Http/Requests/Backend/Access/Role/StoreRoleRequest.php
+14
-1
UpdateRoleRequest.php
app/Http/Requests/Backend/Access/Role/UpdateRoleRequest.php
+14
-1
RoleRepository.php
app/Repositories/Backend/Access/Role/RoleRepository.php
+4
-4
composer.lock
composer.lock
+10
-10
ModelFactory.php
database/factories/ModelFactory.php
+1
-1
phpunit.xml
phpunit.xml
+8
-0
script.js
public/js/backend/access/roles/script.js
+1
-1
mix-manifest.json
public/mix-manifest.json
+6
-6
create.blade.php
resources/views/backend/access/roles/create.blade.php
+2
-2
edit.blade.php
resources/views/backend/access/roles/edit.blade.php
+2
-7
create.blade.php
resources/views/backend/access/users/create.blade.php
+3
-2
AccessHelperTest.php
tests/Backend/Access/AccessHelperTest.php
+123
-0
AccessRepositoryTest.php
tests/Backend/Access/AccessRepositoryTest.php
+98
-0
RolePermissionTest.php
tests/Backend/Access/Role/RolePermissionTest.php
+87
-0
UserAccessTest.php
tests/Backend/Access/User/UserAccessTest.php
+38
-0
UserRoleTest.php
tests/Backend/Access/User/UserRoleTest.php
+83
-0
RoleFormTest.php
tests/Backend/Forms/Access/RoleFormTest.php
+214
-0
UserFormTest.php
tests/Backend/Forms/Access/UserFormTest.php
+242
-0
SearchFormTest.php
tests/Backend/Forms/Search/SearchFormTest.php
+27
-0
HistoryLogTest.php
tests/Backend/History/HistoryLogTest.php
+59
-0
HistoryRenderEntityTest.php
tests/Backend/History/HistoryRenderEntityTest.php
+73
-0
HistoryRenderTest.php
tests/Backend/History/HistoryRenderTest.php
+57
-0
HistoryRenderTypeTest.php
tests/Backend/History/HistoryRenderTypeTest.php
+70
-0
RoleRouteTest.php
tests/Backend/Routes/Access/RoleRouteTest.php
+27
-0
UserRouteTest.php
tests/Backend/Routes/Access/UserRouteTest.php
+186
-0
DashboardRouteTest.php
tests/Backend/Routes/DashboardRouteTest.php
+14
-0
LogViewerRouteTest.php
tests/Backend/Routes/LogViewerRouteTest.php
+37
-0
BrowserKitTestCase.php
tests/BrowserKitTestCase.php
+71
-2
AuthTest.php
tests/Feature/AuthTest.php
+4
-5
TestCase.php
tests/TestCase.php
+16
-0
helpers.php
tests/Utilities/helpers.php
+11
-0
No files found.
app/Http/Requests/Backend/Access/Role/StoreRoleRequest.php
View file @
de9ab079
...
...
@@ -26,9 +26,22 @@ class StoreRoleRequest extends Request
*/
public
function
rules
()
{
$permissions
=
''
;
if
(
$this
->
associated_permissions
!=
'all'
)
{
$permissions
=
'required'
;
}
return
[
'name'
=>
'required|max:191'
,
'permissions'
=>
'required'
,
'permissions'
=>
$permissions
,
];
}
public
function
messages
()
{
return
[
'permissions.required'
=>
'You must select at least one permission for this role.'
];
}
}
app/Http/Requests/Backend/Access/Role/UpdateRoleRequest.php
View file @
de9ab079
...
...
@@ -26,9 +26,22 @@ class UpdateRoleRequest extends Request
*/
public
function
rules
()
{
$permissions
=
''
;
if
(
$this
->
associated_permissions
!=
'all'
)
{
$permissions
=
'required'
;
}
return
[
'name'
=>
'required|max:191'
,
'permissions'
=>
'required'
,
'permissions'
=>
$permissions
,
];
}
public
function
messages
()
{
return
[
'permissions.required'
=>
'You must select at least one permission for this role.'
];
}
}
app/Repositories/Backend/Access/Role/RoleRepository.php
View file @
de9ab079
...
...
@@ -69,7 +69,7 @@ class RoleRepository extends BaseRepository
}
//See if the role has all access
$all
=
$input
[
'associated
-
permissions'
]
==
'all'
?
true
:
false
;
$all
=
$input
[
'associated
_
permissions'
]
==
'all'
?
true
:
false
;
if
(
!
isset
(
$input
[
'permissions'
]))
{
$input
[
'permissions'
]
=
[];
...
...
@@ -133,7 +133,7 @@ class RoleRepository extends BaseRepository
if
(
$role
->
id
==
1
)
{
$all
=
true
;
}
else
{
$all
=
$input
[
'associated
-
permissions'
]
==
'all'
?
true
:
false
;
$all
=
$input
[
'associated
_
permissions'
]
==
'all'
?
true
:
false
;
}
if
(
!
isset
(
$input
[
'permissions'
]))
{
...
...
@@ -190,13 +190,13 @@ class RoleRepository extends BaseRepository
}
/**
* @param
Model
$role
* @param
Role
$role
*
* @throws GeneralException
*
* @return bool
*/
public
function
delete
(
Model
$role
)
public
function
delete
(
Role
$role
)
{
//Would be stupid to delete the administrator role
if
(
$role
->
id
==
1
)
{
//id is 1 because of the seeder
...
...
composer.lock
View file @
de9ab079
...
...
@@ -1367,16 +1367,16 @@
},
{
"name": "laravel/framework",
"version": "v5.5.2
6
",
"version": "v5.5.2
7
",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "
d7e6a7aab600c5cfae595ea22074ac3c536cbc28
"
"reference": "
b4fb6eeb227b7327b4ca7f92263b693ec9ac9875
"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/
d7e6a7aab600c5cfae595ea22074ac3c536cbc28
",
"reference": "
d7e6a7aab600c5cfae595ea22074ac3c536cbc28
",
"url": "https://api.github.com/repos/laravel/framework/zipball/
b4fb6eeb227b7327b4ca7f92263b693ec9ac9875
",
"reference": "
b4fb6eeb227b7327b4ca7f92263b693ec9ac9875
",
"shasum": ""
},
"require": {
...
...
@@ -1497,7 +1497,7 @@
"framework",
"laravel"
],
"time": "2017-12-
18T14:15:59
+00:00"
"time": "2017-12-
20T15:43:48
+00:00"
},
{
"name": "laravel/socialite",
...
...
@@ -5100,16 +5100,16 @@
},
{
"name": "sebastian/comparator",
"version": "2.1.
0
",
"version": "2.1.
1
",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "
1174d9018191e93cb9d719edec01257fc05f8158
"
"reference": "
b11c729f95109b56a0fe9650c6a63a0fcd8c439f
"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/
1174d9018191e93cb9d719edec01257fc05f8158
",
"reference": "
1174d9018191e93cb9d719edec01257fc05f8158
",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/
b11c729f95109b56a0fe9650c6a63a0fcd8c439f
",
"reference": "
b11c729f95109b56a0fe9650c6a63a0fcd8c439f
",
"shasum": ""
},
"require": {
...
...
@@ -5160,7 +5160,7 @@
"compare",
"equality"
],
"time": "2017-1
1-03T07:16:52
+00:00"
"time": "2017-1
2-22T14:50:35
+00:00"
},
{
"name": "sebastian/diff",
...
...
database/factories/ModelFactory.php
View file @
de9ab079
...
...
@@ -58,7 +58,7 @@ $factory->define(Role::class, function (Generator $faker) {
return
[
'name'
=>
$faker
->
name
,
'all'
=>
0
,
'sort'
=>
$faker
->
numberBetween
(
1
,
100
)
,
'sort'
=>
$faker
->
numberBetween
(
1
,
100
)
];
});
...
...
phpunit.xml
View file @
de9ab079
...
...
@@ -30,5 +30,13 @@
<env
name=
"SESSION_DRIVER"
value=
"array"
/>
<env
name=
"QUEUE_DRIVER"
value=
"sync"
/>
<env
name=
"SCOUT_DRIVER"
value=
"null"
/>
</php>
<testsuites>
<testsuite
name=
"Application Test Suite"
>
<directory
suffix=
"Test.php"
>
./tests
</directory>
</testsuite>
</testsuites>
</phpunit>
public/js/backend/access/roles/script.js
View file @
de9ab079
var
associated
=
$
(
"
select[name='associated
-
permissions']
"
);
var
associated
=
$
(
"
select[name='associated
_
permissions']
"
);
var
associated_container
=
$
(
"
#available-permissions
"
);
if
(
associated
.
val
()
==
"
custom
"
)
...
...
public/mix-manifest.json
View file @
de9ab079
{
"/js/frontend.js"
:
"/js/frontend.
945469bbbc12df3ad9e1
.js"
,
"/js/backend.js"
:
"/js/backend.
79d9e4698dadbc0d93c7
.js"
,
"/js/frontend.js"
:
"/js/frontend.
73cf49d8b6d18a5a1c25
.js"
,
"/js/backend.js"
:
"/js/backend.
0793752cf3fad02356e8
.js"
,
"/mix.js"
:
"/mix.247ab120fe7680658924.js"
,
"/css/frontend.css"
:
"/css/frontend.3af0a6cbd7d1d8d042f2a37e97008b7c.css"
,
"/css/backend.css"
:
"/css/backend.
f8550f50504e5b8ef6055285205f223a
.css"
,
"/css/backend-custom.css"
:
"/css/backend-custom.
18e74fbe4c755b817a022d6d3d4e76b1
.css"
,
"/js/backend-custom.js"
:
"/js/backend-custom.
e6ea05e1824d0dd8e7c62027c135b7f2
.js"
,
"/js/dataTable.js"
:
"/js/dataTable.
f968d300a6a0b871f138f114361259c8
.js"
"/css/backend.css"
:
"/css/backend.
36a92480e1e31ce01581619e88309999
.css"
,
"/css/backend-custom.css"
:
"/css/backend-custom.
a20fa78977f121da31678989a7c7c7f7
.css"
,
"/js/backend-custom.js"
:
"/js/backend-custom.
4b0f464c2fe057f6bfb98b866af195d3
.js"
,
"/js/dataTable.js"
:
"/js/dataTable.
e95e7044bc17a1973f8ca0b22b65c5dd
.js"
}
\ No newline at end of file
resources/views/backend/access/roles/create.blade.php
View file @
de9ab079
...
...
@@ -31,10 +31,10 @@
</div><!--form control-->
<div class="
form
-
group
">
{{ Form::label('associated
-
permissions', trans('validation.attributes.backend.access.roles.associated_permissions'), ['class' => 'col-lg-2 control-label']) }}
{{ Form::label('associated
_
permissions', trans('validation.attributes.backend.access.roles.associated_permissions'), ['class' => 'col-lg-2 control-label']) }}
<div class="
col
-
lg
-
10
">
{{ Form::select('associated
-
permissions', array('all' => trans('labels.general.all'), 'custom' => trans('labels.general.custom')), 'all', ['class' => 'form-control select2 box-size']) }}
{{ Form::select('associated
_
permissions', array('all' => trans('labels.general.all'), 'custom' => trans('labels.general.custom')), 'all', ['class' => 'form-control select2 box-size']) }}
<div id="
available
-
permissions
" class="
hidden
mt
-
20
" style="
width
:
700
px
;
height
:
200
px
;
overflow
-
x
:
hidden
;
overflow
-
y
:
scroll
;
">
<div class="
row
">
...
...
resources/views/backend/access/roles/edit.blade.php
View file @
de9ab079
...
...
@@ -31,15 +31,10 @@
</div><!--form control-->
<div class="
form
-
group
">
{{ Form::label('associated
-
permissions', trans('validation.attributes.backend.access.roles.associated_permissions'), ['class' => 'col-lg-2 control-label']) }}
{{ Form::label('associated
_
permissions', trans('validation.attributes.backend.access.roles.associated_permissions'), ['class' => 'col-lg-2 control-label']) }}
<div class="
col
-
lg
-
10
">
@if (
$role->id
!= 1)
{{-- Administrator has to be set to all --}}
{{ Form::select('associated-permissions', ['all' => 'All', 'custom' => 'Custom'],
$role->all
? 'all' : 'custom', ['class' => 'form-control select2 box-size']) }}
@else
<span class="
label
label
-
success
">{{ trans('labels.general.all') }}</span>
@endif
{{ Form::select('associated_permissions', ['all' => 'All', 'custom' => 'Custom'],
$role->all
? 'all' : 'custom', ['class' => 'form-control select2 box-size']) }}
<div id="
available
-
permissions
" class="
hidden
mt
-
20
" style="
width
:
700
px
;
height
:
200
px
;
overflow
-
x
:
hidden
;
overflow
-
y
:
scroll
;
">
<div class="
row
">
...
...
resources/views/backend/access/users/create.blade.php
View file @
de9ab079
...
...
@@ -120,7 +120,7 @@
@foreach(
$roles
as
$role
)
<div>
<label for="
role
-
{{
$role
->
id
}}
" class="
control
control
--
radio
">
<input type="
radio
" value="
{{
$role
->
id
}}
" name="
assignees_roles
[]
" id="
role
-
{{
$role
->
id
}}
" class="
get
-
role
-
for
-
permissions
" /> {!!
$role->name
!!}
<input type="
radio
" value="
{{
$role
->
id
}}
" name="
assignees_roles
[]
" id="
role
-
{{
$role
->
id
}}
" class="
get
-
role
-
for
-
permissions
"
{{
$role->id
== 3 ? 'checked' : '' }}
/> {!!
$role->name
!!}
<div class="
control__indicator
"></div>
<a href="
#" data-role="role_{{ $role->id }}" class="show-permissions small">
(
...
...
@@ -184,7 +184,7 @@
$(document).ready(function() {
Backend.Access.init();
/**
* This function is used to get clicked element role id and return required result
*/
...
...
@@ -220,6 +220,7 @@
});
});
$("
#role-3").click();
});
</
script
>
@
endsection
tests/Backend/Access/AccessHelperTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class AccessHelperTest.
*/
class
AccessHelperTest
extends
BrowserKitTestCase
{
public
function
testAccessUser
()
{
$this
->
actingAs
(
$this
->
user
);
$this
->
assertEquals
(
auth
()
->
user
(),
access
()
->
user
());
}
public
function
testAccessGuest
()
{
$this
->
assertEquals
(
auth
()
->
guest
(),
access
()
->
guest
());
}
public
function
testAccessLogout
()
{
$this
->
actingAs
(
$this
->
user
);
$this
->
assertFalse
(
access
()
->
guest
());
access
()
->
logout
();
$this
->
assertTrue
(
access
()
->
guest
());
}
public
function
testAccessGetsUserId
()
{
$this
->
actingAs
(
$this
->
user
);
$this
->
assertEquals
(
auth
()
->
id
(),
access
()
->
id
());
}
public
function
testAccessLogsUserInById
()
{
access
()
->
loginUsingId
(
3
);
$this
->
assertEquals
(
auth
()
->
user
(),
access
()
->
user
());
}
public
function
testAccessHasRole
()
{
$this
->
actingAs
(
$this
->
executive
);
$this
->
assertTrue
(
access
()
->
hasRole
(
'Executive'
));
$this
->
assertFalse
(
access
()
->
hasRole
(
'Administrator'
));
$this
->
assertTrue
(
access
()
->
hasRole
(
2
));
$this
->
assertFalse
(
access
()
->
hasRole
(
1
));
}
public
function
testAdminHasAllRoles
()
{
$this
->
actingAs
(
$this
->
admin
);
$this
->
assertTrue
(
access
()
->
hasRole
(
'Administrator'
));
$this
->
assertTrue
(
access
()
->
hasRole
(
'Non-Existing Role'
));
$this
->
assertTrue
(
access
()
->
hasRole
(
1
));
$this
->
assertTrue
(
access
()
->
hasRole
(
123
));
}
public
function
testAccessHasRoles
()
{
$this
->
actingAs
(
$this
->
executive
);
$this
->
assertTrue
(
access
()
->
hasRoles
([
'Executive'
,
'User'
]));
$this
->
assertTrue
(
access
()
->
hasRoles
([
2
,
3
]));
}
public
function
testAccessHasRolesNeedsAll
()
{
$this
->
actingAs
(
$this
->
executive
);
$this
->
assertFalse
(
access
()
->
hasRoles
([
'Executive'
,
'User'
],
true
));
$this
->
assertFalse
(
access
()
->
hasRoles
([
2
,
3
],
true
));
}
public
function
testAccessAllow
()
{
$this
->
actingAs
(
$this
->
executive
);
$this
->
assertTrue
(
access
()
->
allow
(
'view-backend'
));
$this
->
assertTrue
(
access
()
->
allow
(
1
));
}
public
function
testAdminHasAllAccess
()
{
$this
->
actingAs
(
$this
->
admin
);
$this
->
assertTrue
(
access
()
->
allow
(
'view-backend'
));
$this
->
assertTrue
(
access
()
->
allow
(
'view-something-that-doesnt-exist'
));
$this
->
assertTrue
(
access
()
->
allow
(
1
));
$this
->
assertTrue
(
access
()
->
allow
(
123
));
}
public
function
testAccessAllowMultiple
()
{
$this
->
actingAs
(
$this
->
executive
);
$this
->
assertTrue
(
access
()
->
allowMultiple
([
'view-backend'
]));
$this
->
assertTrue
(
access
()
->
allowMultiple
([
1
]));
}
public
function
testAccessAllowMultipleNeedsAll
()
{
$this
->
actingAs
(
$this
->
executive
);
$this
->
assertTrue
(
access
()
->
allowMultiple
([
'view-backend'
],
true
));
$this
->
assertTrue
(
access
()
->
allowMultiple
([
1
],
true
));
}
public
function
testAccessHasPermission
()
{
$this
->
actingAs
(
$this
->
executive
);
$this
->
assertTrue
(
access
()
->
hasPermission
(
'view-backend'
));
$this
->
assertTrue
(
access
()
->
hasPermission
(
1
));
}
public
function
testAccessHasPermissions
()
{
$this
->
actingAs
(
$this
->
executive
);
$this
->
assertTrue
(
access
()
->
hasPermissions
([
'view-backend'
]));
$this
->
assertTrue
(
access
()
->
hasPermissions
([
1
]));
}
public
function
testAccessHasPermissionsNeedsAll
()
{
$this
->
actingAs
(
$this
->
executive
);
$this
->
assertTrue
(
access
()
->
hasPermissions
([
'view-backend'
],
true
));
$this
->
assertTrue
(
access
()
->
hasPermissions
([
1
],
true
));
}
}
tests/Backend/Access/AccessRepositoryTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class AccessRepositoryTest.
*/
class
AccessRepositoryTest
extends
BrowserKitTestCase
{
public
function
testGetUsersByPermissionUsingName
()
{
$results
=
app
()
->
make
(
\App\Repositories\Backend\Access\User\UserRepository
::
class
)
->
getByPermission
(
'view-backend'
)
->
toArray
();
$this
->
assertCount
(
1
,
$results
);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
executive
->
first_name
],
$results
[
0
]);
$this
->
assertArraySubset
([
'last_name'
=>
$this
->
executive
->
last_name
],
$results
[
0
]);
}
public
function
testGetUsersByPermissionsUsingNames
()
{
$this
->
userRole
->
permissions
()
->
sync
([
1
]);
$results
=
app
()
->
make
(
\App\Repositories\Backend\Access\User\UserRepository
::
class
)
->
getByPermission
([
'view-backend'
])
->
toArray
();
$this
->
assertCount
(
2
,
$results
);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
executive
->
first_name
],
$results
[
0
]);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
user
->
first_name
],
$results
[
1
]);
}
public
function
testGetUsersByPermissionUsingId
()
{
$results
=
app
()
->
make
(
\App\Repositories\Backend\Access\User\UserRepository
::
class
)
->
getByPermission
(
1
,
'id'
)
->
toArray
();
$this
->
assertCount
(
1
,
$results
);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
executive
->
first_name
],
$results
[
0
]);
}
public
function
testGetUsersByPermissionsUsingIds
()
{
$this
->
userRole
->
permissions
()
->
sync
([
1
]);
$results
=
app
()
->
make
(
\App\Repositories\Backend\Access\User\UserRepository
::
class
)
->
getByPermission
([
1
],
'id'
)
->
toArray
();
$this
->
assertCount
(
2
,
$results
);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
executive
->
first_name
],
$results
[
0
]);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
user
->
first_name
],
$results
[
1
]);
}
public
function
testGetUsersByRoleUsingName
()
{
$results
=
app
()
->
make
(
\App\Repositories\Backend\Access\User\UserRepository
::
class
)
->
getByRole
(
'User'
)
->
toArray
();
$this
->
assertCount
(
1
,
$results
);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
user
->
first_name
],
$results
[
0
]);
}
public
function
testGetUsersByRolesUsingNames
()
{
$results
=
app
()
->
make
(
\App\Repositories\Backend\Access\User\UserRepository
::
class
)
->
getByRole
([
'User'
,
'Executive'
])
->
toArray
();
$this
->
assertCount
(
2
,
$results
);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
executive
->
first_name
],
$results
[
0
]);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
user
->
first_name
],
$results
[
1
]);
}
public
function
testGetUsersByRoleUsingId
()
{
$results
=
app
()
->
make
(
\App\Repositories\Backend\Access\User\UserRepository
::
class
)
->
getByRole
(
1
,
'id'
)
->
toArray
();
$this
->
assertCount
(
1
,
$results
);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
admin
->
first_name
],
$results
[
0
]);
}
public
function
testGetUsersByRolesUsingIds
()
{
$results
=
app
()
->
make
(
\App\Repositories\Backend\Access\User\UserRepository
::
class
)
->
getByRole
([
1
,
3
],
'id'
)
->
toArray
();
$this
->
assertCount
(
2
,
$results
);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
admin
->
first_name
],
$results
[
0
]);
$this
->
assertArraySubset
([
'first_name'
=>
$this
->
user
->
first_name
],
$results
[
1
]);
}
}
tests/Backend/Access/Role/RolePermissionTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
use
App\Models\Access\Permission\Permission
;
class
RolePermissionTest
extends
BrowserKitTestCase
{
public
function
testSavePermissionsToRole
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
permissions
()
->
sync
([
1
]);
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
public
function
testEmptyPermissionsFromRole
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
permissions
()
->
sync
([
1
]);
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
permissions
()
->
sync
([]);
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
public
function
testAttachPermissionToRoleById
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
attachPermission
(
1
);
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
public
function
testAttachPermissionToRoleByObject
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
attachPermission
(
Permission
::
findOrFail
(
1
));
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
public
function
testDetachPermissionFromRoleById
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
attachPermission
(
1
);
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
detachPermission
(
1
);
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
public
function
testDetachPermissionFromRoleByObject
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
attachPermission
(
Permission
::
findOrFail
(
1
));
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
detachPermission
(
Permission
::
findOrFail
(
1
));
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
public
function
testAttachPermissionsToRoleById
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
attachPermissions
([
1
]);
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
public
function
testAttachPermissionsToRoleByObject
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
attachPermissions
([
Permission
::
findOrFail
(
1
)]);
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
public
function
testDetachPermissionsFromRoleById
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
attachPermissions
([
1
]);
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
detachPermissions
([
1
]);
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
public
function
testDetachPermissionsFromRoleByObject
()
{
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
attachPermissions
([
Permission
::
findOrFail
(
1
)]);
$this
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
$this
->
userRole
->
detachPermissions
([
Permission
::
findOrFail
(
1
)]);
$this
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
$this
->
userRole
->
id
]);
}
}
tests/Backend/Access/User/UserAccessTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class UserAccessTest.
*/
class
UserAccessTest
extends
BrowserKitTestCase
{
public
function
testUserCantAccessAdminDashboard
()
{
$this
->
visit
(
'/'
)
->
actingAs
(
$this
->
user
)
->
visit
(
'/admin/dashboard'
)
->
seePageIs
(
'/'
)
->
see
(
'You do not have access to do that.'
);
}
public
function
testExecutiveCanAccessAdminDashboard
()
{
$this
->
visit
(
'/'
)
->
actingAs
(
$this
->
executive
)
->
visit
(
'/admin/dashboard'
)
->
seePageIs
(
'/admin/dashboard'
)
->
see
(
$this
->
executive
->
name
);
}
public
function
testExecutiveCantAccessManageRoles
()
{
$this
->
visit
(
'/'
)
->
actingAs
(
$this
->
executive
)
->
visit
(
'/admin/dashboard'
)
->
seePageIs
(
'/admin/dashboard'
)
->
visit
(
'/admin/access/role'
)
->
seePageIs
(
'/'
)
->
see
(
'You do not have access to do that.'
);
}
}
tests/Backend/Access/User/UserRoleTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class UserRoleTest.
*/
class
UserRoleTest
extends
BrowserKitTestCase
{
public
function
testAttachRoleToUserById
()
{
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
user
->
attachRole
(
$this
->
adminRole
->
id
);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
}
public
function
testAttachRoleToUserByObject
()
{
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
user
->
attachRole
(
$this
->
adminRole
);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
}
public
function
testDetachRoleByIdFromUser
()
{
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
user
->
attachRole
(
$this
->
adminRole
->
id
);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
user
->
detachRole
(
$this
->
adminRole
->
id
);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
}
public
function
testDetachRoleByObjectFromUser
()
{
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
user
->
attachRole
(
$this
->
adminRole
);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
user
->
detachRole
(
$this
->
adminRole
);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
}
public
function
testAttachRolesByIdToUser
()
{
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
$this
->
user
->
attachRoles
([
$this
->
adminRole
->
id
,
$this
->
executiveRole
->
id
]);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
}
public
function
testAttachRolesByObjectToUser
()
{
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
$this
->
user
->
attachRoles
([
$this
->
adminRole
,
$this
->
executiveRole
]);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
}
public
function
testDetachRolesByIdFromUser
()
{
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
$this
->
user
->
attachRoles
([
$this
->
adminRole
->
id
,
$this
->
executiveRole
->
id
]);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
$this
->
user
->
detachRoles
([
$this
->
adminRole
->
id
,
$this
->
executiveRole
->
id
]);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
}
public
function
testDetachRolesByObjectFromUser
()
{
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
$this
->
user
->
attachRoles
([
$this
->
adminRole
,
$this
->
executiveRole
]);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
$this
->
user
->
detachRoles
([
$this
->
adminRole
,
$this
->
executiveRole
]);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
adminRole
->
id
]);
$this
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
$this
->
executiveRole
->
id
]);
}
}
tests/Backend/Forms/Access/RoleFormTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
use
App\Models\Access\Role\Role
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Event
;
use
App\Events\Backend\Access\Role\RoleCreated
;
use
App\Events\Backend\Access\Role\RoleDeleted
;
use
App\Events\Backend\Access\Role\RoleUpdated
;
/**
* Class RoleFormTest.
*/
class
RoleFormTest
extends
BrowserKitTestCase
{
public
function
testCreateRoleRequiredFieldsAll
()
{
// All Permissions
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/create'
)
->
type
(
''
,
'name'
)
->
press
(
'Create'
)
->
seePageIs
(
'/admin/access/role/create'
)
->
see
(
'The name field is required.'
);
}
public
function
testCreateRoleRequiredFieldsSpecificPermissions
()
{
// Custom Permissions
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/create'
)
->
type
(
'Test Role'
,
'name'
)
->
select
(
'custom'
,
'associated_permissions'
)
->
press
(
'Create'
)
->
seePageIs
(
'/admin/access/role/create'
)
->
see
(
'You must select at least one permission for this role.'
);
}
public
function
testCreateRoleFormAll
()
{
// Make sure our events are fired
Event
::
fake
();
// Test create with all permissions
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/create'
)
->
type
(
'Test Role'
,
'name'
)
->
type
(
'999'
,
'sort'
)
->
press
(
'Create'
)
->
seePageIs
(
'/admin/access/role'
)
->
see
(
'The role was successfully created.'
)
->
seeInDatabase
(
config
(
'access.roles_table'
),
[
'name'
=>
'Test Role'
,
'all'
=>
1
,
'sort'
=>
999
]);
Event
::
assertDispatched
(
RoleCreated
::
class
);
}
public
function
testCreateRoleFormSpecificPermissions
()
{
// Make sure our events are fired
Event
::
fake
();
// Test create with some permissions
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/create'
)
->
type
(
'Test Role'
,
'name'
)
->
select
(
'custom'
,
'associated_permissions'
)
->
check
(
'permissions[1]'
)
->
press
(
'Create'
)
->
seePageIs
(
'/admin/access/role'
)
->
see
(
'The role was successfully created.'
)
->
seeInDatabase
(
config
(
'access.roles_table'
),
[
'name'
=>
'Test Role'
,
'all'
=>
0
])
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
4
]);
Event
::
assertDispatched
(
RoleCreated
::
class
);
}
public
function
testRoleAlreadyExists
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/create'
)
->
type
(
'Administrator'
,
'name'
)
->
press
(
'Create'
)
->
seePageIs
(
'/admin/access/role/create'
)
->
see
(
'That role already exists. Please choose a different name.'
);
}
public
function
testRoleRequiresPermission
()
{
if
(
config
(
'access.roles.role_must_contain_permission'
))
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/create'
)
->
type
(
'Test Role'
,
'name'
)
->
select
(
'custom'
,
'associated_permissions'
)
->
press
(
'Create'
)
->
seePageIs
(
'/admin/access/role/create'
)
->
see
(
'You must select at least one permission for this role.'
);
}
}
public
function
testUpdateRoleRequiredFields
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/1/edit'
)
->
type
(
''
,
'name'
)
->
press
(
'Update'
)
->
seePageIs
(
'/admin/access/role/1/edit'
)
->
see
(
'The name field is required.'
);
}
public
function
testUpdateRoleFormAll
()
{
// Make sure our events are fired
Event
::
fake
();
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/1/edit'
)
->
type
(
'Administrator Edited'
,
'name'
)
->
type
(
'123'
,
'sort'
)
->
press
(
'Update'
)
->
seePageIs
(
'/admin/access/role'
)
->
see
(
'The role was successfully updated.'
)
->
seeInDatabase
(
config
(
'access.roles_table'
),
[
'id'
=>
1
,
'name'
=>
'Administrator Edited'
,
'sort'
=>
123
]);
Event
::
assertDispatched
(
RoleUpdated
::
class
);
}
public
function
testUpdateRoleFormSpecificPermissions
()
{
// Make sure our events are fired
Event
::
fake
();
$this
->
actingAs
(
$this
->
admin
)
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
3
])
->
visit
(
'/admin/access/role/3/edit'
)
->
check
(
'permissions[1]'
)
->
press
(
'Update'
)
->
seePageIs
(
'/admin/access/role'
)
->
see
(
'The role was successfully updated.'
)
->
seeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
3
]);
Event
::
assertDispatched
(
RoleUpdated
::
class
);
}
public
function
testUpdateRoleRequiresPermission
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/3/edit'
)
->
uncheck
(
'permissions[2]'
)
->
press
(
'Update'
)
->
seePageIs
(
'/admin/access/role/3/edit'
)
->
see
(
'You must select at least one permission for this role.'
);
}
public
function
testDeleteRoleForm
()
{
// Make sure our events are fired
Event
::
fake
();
$this
->
actingAs
(
$this
->
admin
);
$role
=
factory
(
Role
::
class
)
->
create
([
'created_by'
=>
$this
->
admin
->
id
]);
$this
->
seeInDatabase
(
config
(
'access.roles_table'
),
[
'id'
=>
$role
->
id
])
->
delete
(
route
(
'admin.access.role.destroy'
,
$role
))
->
assertRedirectedTo
(
route
(
'admin.access.role.index'
))
->
notSeeInDatabase
(
config
(
'access.roles_table'
),
[
'id'
=>
$role
->
id
,
'deleted_at'
=>
null
])
->
seeInSession
([
'flash_success'
=>
'The role was successfully deleted.'
]);
$this
->
assertCount
(
3
,
Role
::
all
());
Event
::
assertDispatched
(
RoleDeleted
::
class
);
}
public
function
testDeleteRoleWithPermissions
()
{
// Make sure our events are fired
Event
::
fake
();
// Remove users from role first because it will error on that first
DB
::
table
(
config
(
'access.role_user_table'
))
->
where
(
'role_id'
,
2
)
->
delete
();
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role'
)
->
delete
(
'/admin/access/role/2'
)
->
assertRedirectedTo
(
'/admin/access/role'
)
->
notSeeInDatabase
(
config
(
'access.roles_table'
),
[
'id'
=>
2
,
'deleted_at'
=>
null
])
->
notSeeInDatabase
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
1
,
'role_id'
=>
2
])
->
seeInSession
([
'flash_success'
=>
'The role was successfully deleted.'
]);
Event
::
assertDispatched
(
RoleDeleted
::
class
);
}
public
function
testCanNotDeleteAdministratorRole
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role'
)
->
delete
(
'/admin/access/role/1'
)
->
assertRedirectedTo
(
'/admin/access/role'
)
->
seeInDatabase
(
config
(
'access.roles_table'
),
[
'id'
=>
1
,
'name'
=>
'Administrator'
])
->
seeInSession
([
'flash_danger'
=>
'You can not delete the Administrator role.'
]);
}
public
function
testCanNotDeleteRoleWithUsers
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role'
)
->
delete
(
'/admin/access/role/2'
)
->
assertRedirectedTo
(
'/admin/access/role'
)
->
seeInDatabase
(
config
(
'access.roles_table'
),
[
'id'
=>
2
])
->
seeInSession
([
'flash_danger'
=>
'You can not delete a role with associated users.'
]);
}
}
tests/Backend/Forms/Access/UserFormTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
use
App\Models\Access\User\User
;
use
Illuminate\Support\Facades\Event
;
use
Illuminate\Support\Facades\Notification
;
use
App\Events\Backend\Access\User\UserCreated
;
use
App\Events\Backend\Access\User\UserDeleted
;
use
App\Events\Backend\Access\User\UserUpdated
;
use
App\Events\Backend\Access\User\UserPasswordChanged
;
use
App\Notifications\Frontend\Auth\UserNeedsConfirmation
;
/**
* Class UserFormTest.
*/
class
UserFormTest
extends
BrowserKitTestCase
{
public
function
testCreateUserRequiredFields
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/create'
)
->
type
(
''
,
'first_name'
)
->
type
(
''
,
'last_name'
)
->
type
(
''
,
'email'
)
->
type
(
''
,
'password'
)
->
type
(
''
,
'password_confirmation'
)
->
press
(
'Create'
)
->
see
(
'The first name field is required.'
)
->
see
(
'The last name field is required.'
)
->
see
(
'The email field is required.'
)
->
see
(
'The password field is required.'
);
}
public
function
testCreateUserPasswordsDoNotMatch
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/create'
)
->
type
(
'Test'
,
'first_name'
)
->
type
(
'User'
,
'last_name'
)
->
type
(
'test@test.com'
,
'email'
)
->
type
(
'123456'
,
'password'
)
->
type
(
'1234567'
,
'password_confirmation'
)
->
press
(
'Create'
)
->
see
(
'The password confirmation does not match.'
);
}
public
function
testCreateUserConfirmedForm
()
{
// Make sure our events are fired
Event
::
fake
();
// Create any needed resources
$faker
=
Faker\Factory
::
create
();
$name
=
$faker
->
name
;
$email
=
$faker
->
safeEmail
;
$password
=
"Admin@123"
;
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/create'
)
->
type
(
explode
(
' '
,
$name
)[
0
],
'first_name'
)
->
type
(
explode
(
' '
,
$name
)[
1
],
'last_name'
)
->
type
(
$email
,
'email'
)
->
type
(
$password
,
'password'
)
->
type
(
$password
,
'password_confirmation'
)
->
seeIsChecked
(
'status'
)
->
seeIsChecked
(
'confirmed'
)
->
seeIsChecked
(
'permissions[2]'
)
->
dontSeeIsChecked
(
'confirmation_email'
)
->
press
(
'Create'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'The user was successfully created.'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'name'
=>
$name
,
'email'
=>
$email
,
'status'
=>
1
,
'confirmed'
=>
1
])
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
4
,
'role_id'
=>
2
])
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
4
,
'role_id'
=>
3
]);
Event
::
assertDispatched
(
UserCreated
::
class
);
}
public
function
testCreateUserUnconfirmedForm
()
{
// Make sure our events are fired
Event
::
fake
();
// Make sure our notifications are sent
Notification
::
fake
();
// Create any needed resources
$faker
=
Faker\Factory
::
create
();
$name
=
$faker
->
name
;
$email
=
$faker
->
safeEmail
;
$password
=
$faker
->
password
(
8
);
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/create'
)
->
type
(
$name
,
'name'
)
->
type
(
$email
,
'email'
)
->
type
(
$password
,
'password'
)
->
type
(
$password
,
'password_confirmation'
)
->
seeIsChecked
(
'status'
)
->
uncheck
(
'confirmed'
)
->
check
(
'confirmation_email'
)
->
check
(
'assignees_roles[2]'
)
->
check
(
'assignees_roles[3]'
)
->
press
(
'Create'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'The user was successfully created.'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'name'
=>
$name
,
'email'
=>
$email
,
'status'
=>
1
,
'confirmed'
=>
0
])
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
4
,
'role_id'
=>
2
])
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
4
,
'role_id'
=>
3
]);
// Get the user that was inserted into the database
$user
=
User
::
where
(
'email'
,
$email
)
->
first
();
// Check that the user was sent the confirmation email
Notification
::
assertSentTo
([
$user
],
UserNeedsConfirmation
::
class
);
Event
::
assertDispatched
(
UserCreated
::
class
);
}
public
function
testCreateUserFailsIfEmailExists
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/create'
)
->
type
(
'User'
,
'name'
)
->
type
(
'user@user.com'
,
'email'
)
->
type
(
'123456'
,
'password'
)
->
type
(
'123456'
,
'password_confirmation'
)
->
press
(
'Create'
)
->
seePageIs
(
'/admin/access/user/create'
)
->
see
(
'The email has already been taken.'
);
}
public
function
testUpdateUserRequiredFields
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/3/edit'
)
->
type
(
''
,
'name'
)
->
type
(
''
,
'email'
)
->
press
(
'Update'
)
->
see
(
'The name field is required.'
)
->
see
(
'The email field is required.'
);
}
public
function
testUpdateUserForm
()
{
// Make sure our events are fired
Event
::
fake
();
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/edit'
)
->
see
(
$this
->
user
->
name
)
->
see
(
$this
->
user
->
email
)
->
type
(
'User New'
,
'name'
)
->
type
(
'user2@user.com'
,
'email'
)
->
uncheck
(
'status'
)
->
uncheck
(
'confirmed'
)
->
check
(
'assignees_roles[2]'
)
->
uncheck
(
'assignees_roles[3]'
)
->
press
(
'Update'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'The user was successfully updated.'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'name'
=>
'User New'
,
'email'
=>
'user2@user.com'
,
'status'
=>
0
,
'confirmed'
=>
0
,
])
->
seeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
2
])
->
notSeeInDatabase
(
config
(
'access.role_user_table'
),
[
'user_id'
=>
$this
->
user
->
id
,
'role_id'
=>
3
]);
Event
::
assertDispatched
(
UserUpdated
::
class
);
}
public
function
testDeleteUserForm
()
{
// Make sure our events are fired
Event
::
fake
();
$this
->
actingAs
(
$this
->
admin
)
->
delete
(
'/admin/access/user/'
.
$this
->
user
->
id
)
->
assertRedirectedTo
(
'/admin/access/user/deleted'
)
->
notSeeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'deleted_at'
=>
null
]);
Event
::
assertDispatched
(
UserDeleted
::
class
);
}
public
function
testUserCanNotDeleteSelf
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user'
)
->
delete
(
'/admin/access/user/'
.
$this
->
admin
->
id
)
->
assertRedirectedTo
(
'/admin/access/user'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
admin
->
id
,
'deleted_at'
=>
null
])
->
seeInSession
([
'flash_danger'
=>
'You can not delete yourself.'
]);
}
public
function
testChangeUserPasswordRequiredFields
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/password/change'
)
->
see
(
'Change Password for '
.
$this
->
user
->
name
)
->
type
(
''
,
'password'
)
->
type
(
''
,
'password_confirmation'
)
->
press
(
'Update'
)
->
seePageIs
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/password/change'
)
->
see
(
'The password field is required.'
);
}
public
function
testChangeUserPasswordForm
()
{
// Make sure our events are fired
Event
::
fake
();
$password
=
'87654321'
;
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/password/change'
)
->
see
(
'Change Password for '
.
$this
->
user
->
name
)
->
type
(
$password
,
'password'
)
->
type
(
$password
,
'password_confirmation'
)
->
press
(
'Update'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'The user\'s password was successfully updated.'
);
Event
::
assertDispatched
(
UserPasswordChanged
::
class
);
}
public
function
testChangeUserPasswordDoNotMatch
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/password/change'
)
->
see
(
'Change Password for '
.
$this
->
user
->
name
)
->
type
(
'123456'
,
'password'
)
->
type
(
'1234567'
,
'password_confirmation'
)
->
press
(
'Update'
)
->
seePageIs
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/password/change'
)
->
see
(
'The password confirmation does not match.'
);
}
}
tests/Backend/Forms/Search/SearchFormTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class SearchFormTest.
*/
class
SearchFormTest
extends
BrowserKitTestCase
{
public
function
testSearchPageWithNoQuery
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/search'
)
->
seePageIs
(
'/admin/dashboard'
)
->
see
(
'Please enter a search term.'
);
}
// public function testSearchFormRedirectsToResults()
// {
// $this->actingAs($this->admin)
// ->visit('/admin/dashboard')
// ->type('Test Query', 'q')
// ->press('search-btn')
// ->seePageIs('/admin/search?q=Test%20Query')
// ->see('Search Results for Test Query');
// }
}
tests/Backend/History/HistoryLogTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class HistoryLogTest.
*/
class
HistoryLogTest
extends
BrowserKitTestCase
{
public
function
testHistoryLogByTypeNameFunction
()
{
$this
->
actingAs
(
$this
->
admin
);
history
()
->
withType
(
'User'
)
->
withText
(
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'plus'
)
->
withClass
(
'bg-green'
)
->
log
();
$this
->
seeInDatabase
(
'history'
,
[
'type_id'
=>
1
,
'user_id'
=>
$this
->
admin
->
id
,
'entity_id'
=>
$this
->
user
->
id
,
'icon'
=>
'plus'
,
'class'
=>
'bg-green'
,
'text'
=>
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
,
])
->
visit
(
'/admin/dashboard'
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> '
.
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
);
}
public
function
testHistoryLogByTypeIdFunction
()
{
$this
->
actingAs
(
$this
->
admin
);
history
()
->
withType
(
1
)
->
withText
(
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'plus'
)
->
withClass
(
'bg-green'
)
->
log
();
$this
->
seeInDatabase
(
'history'
,
[
'type_id'
=>
1
,
'user_id'
=>
$this
->
admin
->
id
,
'entity_id'
=>
$this
->
user
->
id
,
'icon'
=>
'plus'
,
'class'
=>
'bg-green'
,
'text'
=>
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
,
])
->
visit
(
'/admin/dashboard'
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> '
.
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
);
}
}
tests/Backend/History/HistoryRenderEntityTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
use
App\Models\Access\User\User
;
/**
* Class HistoryRenderEntityTest.
*/
class
HistoryRenderEntityTest
extends
BrowserKitTestCase
{
public
function
testViewOnlyHasHistoryOfEntity
()
{
$this
->
actingAs
(
$this
->
admin
);
$test_user
=
factory
(
User
::
class
)
->
create
();
history
()
->
withType
(
'User'
)
->
withText
(
'trans("history.backend.users.created") '
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'plus'
)
->
withClass
(
'bg-green'
)
->
log
();
history
()
->
withType
(
'User'
)
->
withText
(
'trans("history.backend.users.updated") '
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'pencil'
)
->
withClass
(
'bg-blue'
)
->
log
();
history
()
->
withType
(
'User'
)
->
withText
(
'trans("history.backend.users.deleted") '
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'trash'
)
->
withClass
(
'bg-red'
)
->
log
();
history
()
->
withType
(
'User'
)
->
withText
(
'trans("history.backend.roles.created") '
.
$test_user
->
name
)
->
withEntity
(
$test_user
->
id
)
->
withIcon
(
'plus'
)
->
withClass
(
'bg-red'
)
->
log
();
history
()
->
withType
(
'User'
)
->
withText
(
'trans("history.backend.roles.updated") '
.
$test_user
->
name
)
->
withEntity
(
$test_user
->
id
)
->
withIcon
(
'pencil'
)
->
withClass
(
'bg-red'
)
->
log
();
history
()
->
withType
(
'User'
)
->
withText
(
'trans("history.backend.roles.deleted") '
.
$test_user
->
name
)
->
withEntity
(
$test_user
->
id
)
->
withIcon
(
'trash'
)
->
withClass
(
'bg-red'
)
->
log
();
$this
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> created user '
.
$this
->
user
->
name
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> updated user '
.
$this
->
user
->
name
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> deleted user '
.
$this
->
user
->
name
)
->
dontSee
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> created user '
.
$test_user
->
name
)
->
dontSee
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> updated user '
.
$test_user
->
name
)
->
dontSee
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> deleted user '
.
$test_user
->
name
);
}
}
tests/Backend/History/HistoryRenderTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class HistoryRenderTest.
*/
class
HistoryRenderTest
extends
BrowserKitTestCase
{
public
function
testDashboardDisplaysHistory
()
{
$this
->
actingAs
(
$this
->
admin
);
history
()
->
withType
(
'User'
)
->
withText
(
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'plus'
)
->
withClass
(
'bg-green'
)
->
log
();
$this
->
visit
(
'/admin/dashboard'
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> '
.
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
);
}
public
function
testTypeDisplaysHistory
()
{
$this
->
actingAs
(
$this
->
admin
);
history
()
->
withType
(
'User'
)
->
withText
(
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'plus'
)
->
withClass
(
'bg-green'
)
->
log
();
$this
->
visit
(
'/admin/access/user'
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> '
.
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
);
}
public
function
testEntityDisplaysHistory
()
{
$this
->
actingAs
(
$this
->
admin
);
history
()
->
withType
(
'User'
)
->
withText
(
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'plus'
)
->
withClass
(
'bg-green'
)
->
log
();
$this
->
visit
(
'/admin/access/user/3'
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> '
.
trans
(
'history.backend.users.created'
)
.
$this
->
user
->
name
);
}
}
tests/Backend/History/HistoryRenderTypeTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class HistoryRenderTypeTest.
*/
class
HistoryRenderTypeTest
extends
BrowserKitTestCase
{
public
function
testViewOnlyHasHistoryOfType
()
{
$this
->
actingAs
(
$this
->
admin
);
history
()
->
withType
(
'User'
)
->
withText
(
'trans("history.backend.users.created") '
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'plus'
)
->
withClass
(
'bg-green'
)
->
log
();
history
()
->
withType
(
'User'
)
->
withText
(
'trans("history.backend.users.updated") '
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'pencil'
)
->
withClass
(
'bg-blue'
)
->
log
();
history
()
->
withType
(
'User'
)
->
withText
(
'trans("history.backend.users.deleted") '
.
$this
->
user
->
name
)
->
withEntity
(
$this
->
user
->
id
)
->
withIcon
(
'trash'
)
->
withClass
(
'bg-red'
)
->
log
();
history
()
->
withType
(
'Role'
)
->
withText
(
'trans("history.backend.roles.created") '
.
$this
->
adminRole
->
name
)
->
withEntity
(
$this
->
adminRole
->
id
)
->
withIcon
(
'plus'
)
->
withClass
(
'bg-red'
)
->
log
();
history
()
->
withType
(
'Role'
)
->
withText
(
'trans("history.backend.roles.updated") '
.
$this
->
adminRole
->
name
)
->
withEntity
(
$this
->
adminRole
->
id
)
->
withIcon
(
'pencil'
)
->
withClass
(
'bg-red'
)
->
log
();
history
()
->
withType
(
'Role'
)
->
withText
(
'trans("history.backend.roles.deleted") '
)
->
withEntity
(
$this
->
adminRole
->
id
)
->
withIcon
(
'trash'
)
->
withClass
(
'bg-red'
)
->
log
();
$this
->
visit
(
'/admin/access/user'
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> created user '
.
$this
->
user
->
name
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> updated user '
.
$this
->
user
->
name
)
->
see
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> deleted user '
.
$this
->
user
->
name
)
->
dontSee
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> created role '
.
$this
->
adminRole
->
name
)
->
dontSee
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> updated role '
.
$this
->
adminRole
->
name
)
->
dontSee
(
'<strong>'
.
$this
->
admin
->
name
.
'</strong> deleted role '
.
$this
->
adminRole
->
name
);
}
}
tests/Backend/Routes/Access/RoleRouteTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class RoleRouteTest.
*/
class
RoleRouteTest
extends
BrowserKitTestCase
{
public
function
testRolesIndex
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role'
)
->
see
(
'Role Management'
);
}
public
function
testCreateRole
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/create'
)
->
see
(
'Create Role'
);
}
public
function
testEditRole
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/role/'
.
$this
->
adminRole
->
id
.
'/edit'
)
->
see
(
'Edit Role'
)
->
see
(
$this
->
adminRole
->
name
);
}
}
tests/Backend/Routes/Access/UserRouteTest.php
0 → 100644
View file @
de9ab079
<?php
use
Carbon\Carbon
;
use
Tests\BrowserKitTestCase
;
use
Illuminate\Support\Facades\Event
;
use
App\Events\Backend\Access\User\UserRestored
;
use
App\Events\Backend\Access\User\UserDeactivated
;
use
App\Events\Backend\Access\User\UserReactivated
;
use
App\Events\Backend\Access\User\UserPermanentlyDeleted
;
use
App\Notifications\Frontend\Auth\UserNeedsConfirmation
;
/**
* Class UserRouteTest.
*/
class
UserRouteTest
extends
BrowserKitTestCase
{
public
function
testActiveUsers
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user'
)
->
see
(
'Active Users'
);
}
public
function
testDeactivatedUsers
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/deactivated'
)
->
see
(
'Deactivated Users'
);
}
public
function
testDeletedUsers
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/deleted'
)
->
see
(
'Deleted Users'
);
}
public
function
testCreateUser
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/create'
)
->
see
(
'Create User'
);
}
public
function
testViewUser
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
)
->
see
(
'View User'
)
->
see
(
'Overview'
)
->
see
(
'History'
)
->
see
(
$this
->
user
->
name
)
->
see
(
$this
->
user
->
email
);
}
public
function
testEditUser
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/edit'
)
->
see
(
'Edit User'
)
->
see
(
$this
->
user
->
name
)
->
see
(
$this
->
user
->
email
);
}
public
function
testChangeUserPassword
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/password/change'
)
->
see
(
'Change Password for '
.
$this
->
user
->
name
);
}
public
function
testResendUserConfirmationEmail
()
{
Notification
::
fake
();
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user'
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/account/confirm/resend'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'A new confirmation e-mail has been sent to the address on file.'
);
Notification
::
assertSentTo
(
$this
->
user
,
UserNeedsConfirmation
::
class
);
}
public
function
testLoginAsUser
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/login-as'
)
->
seePageIs
(
'/'
)
->
see
(
'You are currently logged in as '
.
$this
->
user
->
name
.
'.'
)
->
see
(
$this
->
admin
->
name
)
->
assertTrue
(
access
()
->
id
()
==
$this
->
user
->
id
);
}
public
function
testCantLoginAsSelf
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
admin
->
id
.
'/login-as'
)
->
see
(
'Do not try to login as yourself.'
);
}
public
function
testLogoutAsUser
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/login-as'
)
->
seePageIs
(
'/'
)
->
see
(
'You are currently logged in as '
.
$this
->
user
->
name
.
'.'
)
->
click
(
'Re-Login as '
.
$this
->
admin
->
name
)
->
seePageIs
(
'/admin/access/user'
)
->
assertTrue
(
access
()
->
id
()
==
$this
->
admin
->
id
);
}
public
function
testDeactivateReactivateUser
()
{
// Make sure our events are fired
Event
::
fake
();
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/mark/0'
)
->
seePageIs
(
'/admin/access/user/deactivated'
)
->
see
(
'The user was successfully updated.'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'status'
=>
0
])
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/mark/1'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'The user was successfully updated.'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'status'
=>
1
]);
Event
::
assertDispatched
(
UserDeactivated
::
class
);
Event
::
assertDispatched
(
UserReactivated
::
class
);
}
public
function
testRestoreUser
()
{
// Make sure our events are fired
Event
::
fake
();
$this
->
user
->
deleted_at
=
Carbon
::
now
();
$this
->
user
->
save
();
$this
->
actingAs
(
$this
->
admin
)
->
notSeeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'deleted_at'
=>
null
])
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/restore'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'The user was successfully restored.'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'deleted_at'
=>
null
]);
Event
::
assertDispatched
(
UserRestored
::
class
);
}
public
function
testUserIsDeletedBeforeBeingRestored
()
{
$this
->
actingAs
(
$this
->
admin
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'deleted_at'
=>
null
])
->
visit
(
'/admin/access/user'
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/restore'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'This user is not deleted so it can not be restored.'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'deleted_at'
=>
null
]);
}
public
function
testPermanentlyDeleteUser
()
{
// Make sure our events are fired
Event
::
fake
();
$this
->
actingAs
(
$this
->
admin
)
->
delete
(
'/admin/access/user/'
.
$this
->
user
->
id
)
->
notSeeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'deleted_at'
=>
null
])
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/delete'
)
->
seePageIs
(
'/admin/access/user/deleted'
)
->
see
(
'The user was deleted permanently.'
)
->
notSeeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
]);
Event
::
assertDispatched
(
UserPermanentlyDeleted
::
class
);
}
public
function
testUserIsDeletedBeforeBeingPermanentlyDeleted
()
{
$this
->
actingAs
(
$this
->
admin
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'deleted_at'
=>
null
])
->
visit
(
'/admin/access/user'
)
->
visit
(
'/admin/access/user/'
.
$this
->
user
->
id
.
'/delete'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'This user must be deleted first before it can be destroyed permanently.'
)
->
seeInDatabase
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
user
->
id
,
'deleted_at'
=>
null
]);
}
public
function
testCantNotDeactivateSelf
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/access/user'
)
->
visit
(
'/admin/access/user/'
.
$this
->
admin
->
id
.
'/mark/0'
)
->
seePageIs
(
'/admin/access/user'
)
->
see
(
'You can not do that to yourself.'
);
}
}
tests/Backend/Routes/DashboardRouteTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class DashboardRouteTest.
*/
class
DashboardRouteTest
extends
BrowserKitTestCase
{
public
function
testAdminDashboard
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/dashboard'
)
->
see
(
'Access Management'
)
->
see
(
$this
->
admin
->
name
);
}
}
\ No newline at end of file
tests/Backend/Routes/LogViewerRouteTest.php
0 → 100644
View file @
de9ab079
<?php
use
Tests\BrowserKitTestCase
;
/**
* Class LogViewerRouteTest.
*/
class
LogViewerRouteTest
extends
BrowserKitTestCase
{
public
function
testLogViewerDashboard
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/log-viewer'
)
->
see
(
'Log Viewer'
);
}
public
function
testLogViewerList
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/log-viewer/logs'
)
->
see
(
'Logs'
);
}
public
function
testLogViewerSingle
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/log-viewer/logs/'
.
date
(
'Y-m-d'
))
->
see
(
'Log ['
.
date
(
'Y-m-d'
)
.
']'
);
}
public
function
testLogViewerSingleType
()
{
$this
->
actingAs
(
$this
->
admin
)
->
visit
(
'/admin/log-viewer/logs/'
.
date
(
'Y-m-d'
)
.
'/error'
)
->
see
(
'Log ['
.
date
(
'Y-m-d'
)
.
']'
);
}
}
tests/BrowserKitTestCase.php
View file @
de9ab079
...
...
@@ -2,11 +2,80 @@
namespace
Tests
;
use
App\Models\Access\User\User
;
use
App\Models\Access\Role\Role
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Artisan
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
use
Laravel\BrowserKitTesting\TestCase
as
BaseTestCase
;
abstract
class
BrowserKitTestCase
extends
BaseTestCase
{
use
CreatesApplication
;
use
CreatesApplication
,
RefreshDatabase
;
public
$baseUrl
=
'http://localhost:8000'
;
/**
* @var
*/
public
$baseUrl
;
/**
* @var
*/
protected
$admin
;
/**
* @var
*/
protected
$executive
;
/**
* @var
*/
protected
$user
;
/**
* @var
*/
protected
$adminRole
;
/**
* @var
*/
protected
$executiveRole
;
/**
* @var
*/
protected
$userRole
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
baseUrl
=
config
(
'app.url'
,
'http://localhost:8000'
);
// 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
);
}
public
function
tearDown
()
{
$this
->
beforeApplicationDestroyed
(
function
()
{
DB
::
disconnect
();
});
parent
::
tearDown
();
}
}
tests/Feature/AuthTest.php
View file @
de9ab079
...
...
@@ -27,7 +27,7 @@ class AuthTest extends BrowserKitTestCase
}
/** @test */
/*
public function test_login_failure_with_wrong_inputs()
public
function
test_login_failure_with_wrong_inputs
()
{
$this
->
visit
(
"/login"
)
->
type
(
'wrongusername@wrongpassword.com'
,
'email'
)
...
...
@@ -35,16 +35,15 @@ class AuthTest extends BrowserKitTestCase
->
press
(
'Login'
)
->
seePageIs
(
'/login'
)
->
see
(
'These credentials do not match our records.'
);
}
*/
}
/** @test */
public
function
users_can_login
()
{
//$this->createUser();
$this
->
visit
(
'/login'
)
->
type
(
'user@user.com'
,
'email'
)
->
type
(
'1234'
,
'password'
)
//
->press('Login')
->
seePageIs
(
'/login'
);
->
press
(
'Login'
)
->
seePageIs
(
route
(
'frontend.user.dashboard'
)
);
}
}
tests/TestCase.php
View file @
de9ab079
...
...
@@ -7,4 +7,20 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract
class
TestCase
extends
BaseTestCase
{
use
CreatesApplication
;
public
function
signIn
(
$user
=
null
)
{
$user
=
$user
?:
create
(
'App\User'
);
$this
->
be
(
$user
);
return
$this
;
}
public
function
setUp
()
{
parent
::
setUp
();
$this
->
withoutExceptionHandling
();
}
}
tests/Utilities/helpers.php
0 → 100644
View file @
de9ab079
<?php
function
create
(
$class
,
$attributes
=
[],
$times
=
null
)
{
return
factory
(
$class
,
$times
)
->
create
(
$attributes
);
}
function
make
(
$class
,
$attributes
=
[],
$times
=
null
)
{
return
factory
(
$class
,
$times
)
->
make
(
$attributes
);
}
\ No newline at end of file
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