X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/5283919d2493a396f588043b68bf9a4b3d5876a2..refs/pull/234/head:/tests/Permissions/RolesTest.php diff --git a/tests/Permissions/RolesTest.php b/tests/Permissions/RolesTest.php index 9c312626f..500dd3b67 100644 --- a/tests/Permissions/RolesTest.php +++ b/tests/Permissions/RolesTest.php @@ -7,7 +7,15 @@ class RolesTest extends TestCase public function setUp() { parent::setUp(); - $this->user = $this->getNewBlankUser(); + $this->user = $this->getViewer(); + } + + protected function getViewer() + { + $role = \BookStack\Role::getRole('viewer'); + $viewer = $this->getNewBlankUser(); + $viewer->attachRole($role);; + return $viewer; } /** @@ -73,7 +81,7 @@ class RolesTest extends TestCase $this->asAdmin()->visit('/settings') ->click('Roles') ->seePageIs('/settings/roles') - ->click('Add new role') + ->click('Create New Role') ->type('Test Role', 'display_name') ->type('A little test description', 'description') ->press('Save Role') @@ -129,43 +137,43 @@ class RolesTest extends TestCase { $page = \BookStack\Page::take(1)->get()->first(); $this->actingAs($this->user)->visit($page->getUrl()) - ->dontSee('Restrict') - ->visit($page->getUrl() . '/restrict') + ->dontSee('Permissions') + ->visit($page->getUrl() . '/permissions') ->seePageIs('/'); $this->giveUserPermissions($this->user, ['restrictions-manage-all']); $this->actingAs($this->user)->visit($page->getUrl()) - ->see('Restrict') - ->click('Restrict') - ->see('Page Restrictions')->seePageIs($page->getUrl() . '/restrict'); + ->see('Permissions') + ->click('Permissions') + ->see('Page Permissions')->seePageIs($page->getUrl() . '/permissions'); } public function test_restrictions_manage_own_permission() { - $otherUsersPage = \BookStack\Page::take(1)->get()->first(); + $otherUsersPage = \BookStack\Page::first(); $content = $this->createEntityChainBelongingToUser($this->user); // Check can't restrict other's content $this->actingAs($this->user)->visit($otherUsersPage->getUrl()) - ->dontSee('Restrict') - ->visit($otherUsersPage->getUrl() . '/restrict') + ->dontSee('Permissions') + ->visit($otherUsersPage->getUrl() . '/permissions') ->seePageIs('/'); // Check can't restrict own content $this->actingAs($this->user)->visit($content['page']->getUrl()) - ->dontSee('Restrict') - ->visit($content['page']->getUrl() . '/restrict') + ->dontSee('Permissions') + ->visit($content['page']->getUrl() . '/permissions') ->seePageIs('/'); $this->giveUserPermissions($this->user, ['restrictions-manage-own']); // Check can't restrict other's content $this->actingAs($this->user)->visit($otherUsersPage->getUrl()) - ->dontSee('Restrict') - ->visit($otherUsersPage->getUrl() . '/restrict') + ->dontSee('Permissions') + ->visit($otherUsersPage->getUrl() . '/permissions') ->seePageIs('/'); // Check can restrict own content $this->actingAs($this->user)->visit($content['page']->getUrl()) - ->see('Restrict') - ->click('Restrict') - ->seePageIs($content['page']->getUrl() . '/restrict'); + ->see('Permissions') + ->click('Permissions') + ->seePageIs($content['page']->getUrl() . '/permissions'); } /** @@ -203,7 +211,7 @@ class RolesTest extends TestCase $this->checkAccessPermission('book-create-all', [ '/books/create' ], [ - '/books' => 'Add new book' + '/books' => 'Create New Book' ]); $this->visit('/books/create') @@ -536,4 +544,38 @@ class RolesTest extends TestCase ->dontSeeInElement('.book-content', $otherPage->name); } + public function test_public_role_visible_in_user_edit_screen() + { + $user = \BookStack\User::first(); + $this->asAdmin()->visit('/settings/users/' . $user->id) + ->seeElement('#roles-admin') + ->seeElement('#roles-public'); + } + + public function test_public_role_visible_in_role_listing() + { + $this->asAdmin()->visit('/settings/roles') + ->see('Admin') + ->see('Public'); + } + + public function test_public_role_visible_in_default_role_setting() + { + $this->asAdmin()->visit('/settings') + ->seeElement('[data-role-name="admin"]') + ->seeElement('[data-role-name="public"]'); + + } + + public function test_public_role_not_deleteable() + { + $this->asAdmin()->visit('/settings/roles') + ->click('Public') + ->see('Edit Role') + ->click('Delete Role') + ->press('Confirm') + ->see('Delete Role') + ->see('Cannot be deleted'); + } + }