Added tests for user crud

This commit is contained in:
Dan Brown 2015-10-18 16:06:06 +01:00
parent 68a149109a
commit 13fa1080dc
4 changed files with 49 additions and 3 deletions

View File

@ -30,6 +30,11 @@ body.dragging, body.dragging * {
// User Avatar Images
.avatar {
border-radius: 100%;
background-color: #EEE;
&.med {
width: 40px;
height: 40px;
}
}
// System wide notifications

View File

@ -9,7 +9,7 @@
<div class="col-md-6"></div>
<div class="col-md-6 faded">
<div class="action-buttons">
<a href="/users/{{$user->id}}/delete" class="text-neg text-button"><i class="zmdi zmdi-delete"></i>Delete User</a>
<a href="/users/{{$user->id}}/delete" class="text-neg text-button"><i class="zmdi zmdi-delete"></i>Delete user</a>
</div>
</div>
</div>

View File

@ -10,7 +10,7 @@
<h1>Users</h1>
@if($currentUser->can('user-create'))
<p>
<a href="/users/create" class="text-pos"><i class="zmdi zmdi-account-add"></i>Add New User</a>
<a href="/users/create" class="text-pos"><i class="zmdi zmdi-account-add"></i>Add new user</a>
</p>
@endif
<table class="table">
@ -22,7 +22,7 @@
</tr>
@foreach($users as $user)
<tr>
<td style="line-height: 0;"><img class="avatar" src="{{$user->getAvatar(40)}}" alt="{{$user->name}}"></td>
<td style="line-height: 0;"><img class="avatar med" src="{{$user->getAvatar(40)}}" alt="{{$user->name}}"></td>
<td>
@if($currentUser->can('user-update') || $currentUser->id == $user->id)
<a href="/users/{{$user->id}}">

View File

@ -102,6 +102,47 @@ class AuthTest extends TestCase
->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => true]);
}
public function testUserControl()
{
$user = factory(\BookStack\User::class)->make();
// Test creation
$this->asAdmin()
->visit('/users')
->click('Add new user')
->type($user->name, '#name')
->type($user->email, '#email')
->select(2, '#role')
->type($user->password, '#password')
->type($user->password, '#password-confirm')
->press('Save')
->seeInDatabase('users', $user->toArray())
->seePageIs('/users')
->see($user->name);
$user = $user->where('email', '=', $user->email)->first();
// Test editing
$this->asAdmin()
->visit('/users')
->click($user->name)
->seePageIs('/users/' . $user->id)
->see($user->email)
->type('Barry Scott', '#name')
->press('Save')
->seePageIs('/users')
->seeInDatabase('users', ['id' => $user->id, 'name' => 'Barry Scott'])
->notSeeInDatabase('users', ['name' => $user->name]);
$user = $user->find($user->id);
// Test Deletion
$this->asAdmin()
->visit('/users/' . $user->id)
->click('Delete user')
->see($user->name)
->press('Confirm')
->seePageIs('/users')
->notSeeInDatabase('users', ['name' => $user->name]);
}
public function testLogout()
{
$this->asAdmin()