1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2026-01-03 23:42:28 +03:00

Finished initial implementation of custom role system

This commit is contained in:
Dan Brown
2016-02-27 19:24:42 +00:00
parent a54be85185
commit 473261be35
37 changed files with 644 additions and 213 deletions

View File

@@ -133,12 +133,12 @@ class AuthTest extends TestCase
->click('Add new user')
->type($user->name, '#name')
->type($user->email, '#email')
->select(2, '#role')
->check('roles[admin]')
->type($user->password, '#password')
->type($user->password, '#password-confirm')
->press('Save')
->seeInDatabase('users', $user->toArray())
->seePageIs('/settings/users')
->seeInDatabase('users', $user->toArray())
->see($user->name);
}

48
tests/RolesTest.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
class RolesTest extends TestCase
{
protected $user;
public function setUp()
{
parent::setUp();
}
protected function createNewRole()
{
return \BookStack\Role::forceCreate([
'name' => 'test-role',
'display_name' => 'Test Role',
'description' => 'This is a role for testing'
]);
}
public function test_admin_can_see_settings()
{
$this->asAdmin()->visit('/settings')->see('Settings');
}
public function test_cannot_delete_admin_role()
{
$adminRole = \BookStack\Role::getRole('admin');
$deletePageUrl = '/settings/roles/delete/' . $adminRole->id;
$this->asAdmin()->visit($deletePageUrl)
->press('Confirm')
->seePageIs($deletePageUrl)
->see('cannot be deleted');
}
public function test_role_cannot_be_deleted_if_default()
{
$newRole = $this->createNewRole();
$this->setSettings(['registration-role' => $newRole->id]);
$deletePageUrl = '/settings/roles/delete/' . $newRole->id;
$this->asAdmin()->visit($deletePageUrl)
->press('Confirm')
->seePageIs($deletePageUrl)
->see('cannot be deleted');
}
}

View File

@@ -32,7 +32,8 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
public function asAdmin()
{
if($this->admin === null) {
$this->admin = \BookStack\User::find(1);
$adminRole = \BookStack\Role::getRole('admin');
$this->admin = $adminRole->users->first();
}
return $this->actingAs($this->admin);
}