X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1a56de6cb41b0597e15c4bbd54023402102602bd..refs/pull/5676/head:/tests/Permissions/RolePermissionsTest.php diff --git a/tests/Permissions/RolePermissionsTest.php b/tests/Permissions/RolePermissionsTest.php index 0b2e16686..97cce6817 100644 --- a/tests/Permissions/RolePermissionsTest.php +++ b/tests/Permissions/RolePermissionsTest.php @@ -2,7 +2,6 @@ namespace Tests\Permissions; -use BookStack\Activity\ActivityType; use BookStack\Activity\Models\Comment; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Bookshelf; @@ -10,7 +9,6 @@ use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Entity; use BookStack\Entities\Models\Page; use BookStack\Uploads\Image; -use BookStack\Users\Models\Role; use BookStack\Users\Models\User; use Illuminate\Testing\TestResponse; use Tests\TestCase; @@ -44,14 +42,13 @@ class RolePermissionsTest extends TestCase public function test_user_cannot_change_email_unless_they_have_manage_users_permission() { - $userProfileUrl = '/settings/users/' . $this->user->id; $originalEmail = $this->user->email; $this->actingAs($this->user); - $resp = $this->get($userProfileUrl) - ->assertOk(); + $resp = $this->get('/my-account/profile')->assertOk(); $this->withHtml($resp)->assertElementExists('input[name=email][disabled]'); - $this->put($userProfileUrl, [ + $resp->assertSee('Unfortunately you don\'t have permission to change your email address.'); + $this->put('/my-account/profile', [ 'name' => 'my_new_name', 'email' => 'new_email@example.com', ]); @@ -63,11 +60,12 @@ class RolePermissionsTest extends TestCase $this->permissions->grantUserRolePermissions($this->user, ['users-manage']); - $resp = $this->get($userProfileUrl) - ->assertOk(); - $this->withHtml($resp)->assertElementNotExists('input[name=email][disabled]') + $resp = $this->get('/my-account/profile')->assertOk(); + $this->withHtml($resp) + ->assertElementNotExists('input[name=email][disabled]') ->assertElementExists('input[name=email]'); - $this->put($userProfileUrl, [ + + $this->put('/my-account/profile', [ 'name' => 'my_new_name_2', 'email' => 'new_email@example.com', ]); @@ -152,10 +150,14 @@ class RolePermissionsTest extends TestCase /** * Check a standard entity access permission. */ - private function checkAccessPermission(string $permission, array $accessUrls = [], array $visibles = []) - { + private function checkAccessPermission( + string $permission, + array $accessUrls = [], + array $visibles = [], + string $expectedRedirectUri = '/', + ) { foreach ($accessUrls as $url) { - $this->actingAs($this->user)->get($url)->assertRedirect('/'); + $this->actingAs($this->user)->get($url)->assertRedirect($expectedRedirectUri); } foreach ($visibles as $url => $text) { @@ -535,11 +537,11 @@ class RolePermissionsTest extends TestCase $ownPage->getUrl() . '/edit', ], [ $ownPage->getUrl() => 'Edit', - ]); + ], $ownPage->getUrl()); $resp = $this->get($otherPage->getUrl()); $this->withHtml($resp)->assertElementNotContains('.action-buttons', 'Edit'); - $this->get($otherPage->getUrl() . '/edit')->assertRedirect('/'); + $this->get($otherPage->getUrl() . '/edit')->assertRedirect($otherPage->getUrl()); } public function test_page_edit_all_permission() @@ -550,7 +552,7 @@ class RolePermissionsTest extends TestCase $otherPage->getUrl('/edit'), ], [ $otherPage->getUrl() => 'Edit', - ]); + ], $otherPage->getUrl()); } public function test_page_delete_own_permission() @@ -738,16 +740,12 @@ class RolePermissionsTest extends TestCase private function addComment(Page $page): TestResponse { - $comment = Comment::factory()->make(); - - return $this->postJson("/comment/$page->id", $comment->only('text', 'html')); + return $this->postJson("/comment/$page->id", ['html' => '
New comment content
']); } private function updateComment(Comment $comment): TestResponse { - $commentData = Comment::factory()->make(); - - return $this->putJson("/comment/{$comment->id}", $commentData->only('text', 'html')); + return $this->putJson("/comment/{$comment->id}", ['html' => 'Updated comment content
']); } private function deleteComment(Comment $comment): TestResponse