NOW MANAGED ON CODEBERG
Started updating RolesTest away from Browserkit
Dan Brownd74255df5db4
diff --git a/app/Actions/Comment.php b/app/Actions/Comment.phpindex ef390939e..e652bf8a8 100644--- a/app/Actions/Comment.php+++ b/app/Actions/Comment.php@@ -7,10 +7,11 @@ use BookStack\Traits\HasCreatorAndUpdater;use Illuminate\Database\Eloquent\Relations\MorphTo;/**- * @property string text- * @property string html- * @property int|null parent_id- * @property int local_id+ * @property int $id+ * @property string $text+ * @property string $html+ * @property int|null $parent_id+ * @property int $local_id*/class Comment extends Model{diff --git a/tests/Permissions/RolesTest.php b/tests/Permissions/RolesTest.phpindex b9b1805b6..c9c3195a9 100644--- a/tests/Permissions/RolesTest.php+++ b/tests/Permissions/RolesTest.php@@ -10,10 +10,10 @@ use BookStack\Entities\Models\Bookshelf;use BookStack\Entities\Models\Chapter;use BookStack\Entities\Models\Page;use BookStack\Uploads\Image;-use Laravel\BrowserKitTesting\HttpException;-use Tests\BrowserKitTest;+use Tests\TestCase;+use Tests\TestResponse;-class RolesTest extends BrowserKitTest+class RolesTest extends TestCase{protected $user;@@ -25,17 +25,17 @@ class RolesTest extends BrowserKitTestpublic function test_admin_can_see_settings(){- $this->asAdmin()->visit('/settings')->see('Settings');+ $this->asAdmin()->get('/settings')->assertSee('Settings');}public function test_cannot_delete_admin_role(){$adminRole = Role::getRole('admin');$deletePageUrl = '/settings/roles/delete/' . $adminRole->id;- $this->asAdmin()->visit($deletePageUrl)- ->press('Confirm')- ->seePageIs($deletePageUrl)- ->see('cannot be deleted');++ $this->asAdmin()->get($deletePageUrl);+ $this->delete($deletePageUrl)->assertRedirect($deletePageUrl);+ $this->get($deletePageUrl)->assertSee('cannot be deleted');}public function test_role_cannot_be_deleted_if_default()@@ -44,10 +44,9 @@ class RolesTest extends BrowserKitTest$this->setSettings(['registration-role' => $newRole->id]);$deletePageUrl = '/settings/roles/delete/' . $newRole->id;- $this->asAdmin()->visit($deletePageUrl)- ->press('Confirm')- ->seePageIs($deletePageUrl)- ->see('cannot be deleted');+ $this->asAdmin()->get($deletePageUrl);+ $this->delete($deletePageUrl)->assertRedirect($deletePageUrl);+ $this->get($deletePageUrl)->assertSee('cannot be deleted');}public function test_role_create_update_delete_flow()@@ -57,35 +56,37 @@ class RolesTest extends BrowserKitTest$testRoleUpdateName = 'An Super Updated role';// Creation- $this->asAdmin()->visit('/settings')+ $this->asAdmin()->get('/settings')->click('Roles')->seePageIs('/settings/roles')->click('Create New Role')->type('Test Role', 'display_name')->type('A little test description', 'description')->press('Save Role')- ->seeInDatabase('roles', ['display_name' => $testRoleName, 'description' => $testRoleDesc, 'mfa_enforced' => false])+ ->assertDatabaseHas('roles', ['display_name' => $testRoleName, 'description' => $testRoleDesc, 'mfa_enforced' => false])->seePageIs('/settings/roles');+// Updating- $this->asAdmin()->visit('/settings/roles')- ->see($testRoleDesc)+ $this->asAdmin()->get('/settings/roles')+ ->assertSee($testRoleDesc)->click($testRoleName)->type($testRoleUpdateName, '#display_name')->check('#mfa_enforced')->press('Save Role')- ->seeInDatabase('roles', ['display_name' => $testRoleUpdateName, 'description' => $testRoleDesc, 'mfa_enforced' => true])+ ->assertDatabaseHas('roles', ['display_name' => $testRoleUpdateName, 'description' => $testRoleDesc, 'mfa_enforced' => true])->seePageIs('/settings/roles');+// Deleting- $this->asAdmin()->visit('/settings/roles')+ $this->asAdmin()->get('/settings/roles')->click($testRoleUpdateName)->click('Delete Role')- ->see($testRoleUpdateName)+ ->assertSee($testRoleUpdateName)->press('Confirm')->seePageIs('/settings/roles')- ->dontSee($testRoleUpdateName);+ ->assertDontSee($testRoleUpdateName);}- public function test_admin_role_cannot_be_removed_if_last_admin()+ public function test_admin_role_cannot_be_removed_if_user_last_admin(){$adminRole = Role::where('system_name', '=', 'admin')->first();$adminUser = $this->getAdmin();@@ -104,7 +105,7 @@ class RolesTest extends BrowserKitTest])->followRedirects();$this->seePageIs($editUrl);- $this->see('This user is the only user assigned to the administrator role');+ $this->assertSee('This user is the only user assigned to the administrator role');}public function test_migrate_users_on_delete_works()@@ -117,7 +118,7 @@ class RolesTest extends BrowserKitTest$this->assertCount(1, $roleB->users()->get());$deletePage = $this->asAdmin()->get("/settings/roles/delete/{$roleB->id}");- $deletePage->seeElement('select[name=migrate_role_id]');+ $deletePage->assertElementExists('select[name=migrate_role_id]');$this->asAdmin()->delete("/settings/roles/delete/{$roleB->id}", ['migrate_role_id' => $roleA->id,]);@@ -128,21 +129,21 @@ class RolesTest extends BrowserKitTestpublic function test_manage_user_permission(){- $this->actingAs($this->user)->visit('/settings/users')+ $this->actingAs($this->user)->get('/settings/users')->seePageIs('/');$this->giveUserPermissions($this->user, ['users-manage']);- $this->actingAs($this->user)->visit('/settings/users')+ $this->actingAs($this->user)->get('/settings/users')->seePageIs('/settings/users');}public function test_manage_users_permission_shows_link_in_header_if_does_not_have_settings_manage_permision(){$usersLink = 'href="' . url('/settings/users') . '"';- $this->actingAs($this->user)->visit('/')->dontSee($usersLink);+ $this->actingAs($this->user)->get('/')->assertDontSee($usersLink);$this->giveUserPermissions($this->user, ['users-manage']);- $this->actingAs($this->user)->visit('/')->see($usersLink);+ $this->actingAs($this->user)->get('/')->assertSee($usersLink);$this->giveUserPermissions($this->user, ['settings-manage', 'users-manage']);- $this->actingAs($this->user)->visit('/')->dontSee($usersLink);+ $this->actingAs($this->user)->get('/')->assertDontSee($usersLink);}public function test_user_cannot_change_email_unless_they_have_manage_users_permission()@@ -151,14 +152,14 @@ class RolesTest extends BrowserKitTest$originalEmail = $this->user->email;$this->actingAs($this->user);- $this->visit($userProfileUrl)- ->assertResponseOk()- ->seeElement('input[name=email][disabled]');+ $this->get($userProfileUrl)+ ->assertOk()+ ->assertElementExists('input[name=email][disabled]');$this->put($userProfileUrl, ['name' => 'my_new_name','email' => '[email protected]',]);- $this->seeInDatabase('users', [+ $this->assertDatabaseHas('users', ['id' => $this->user->id,'email' => $originalEmail,'name' => 'my_new_name',@@ -166,16 +167,16 @@ class RolesTest extends BrowserKitTest$this->giveUserPermissions($this->user, ['users-manage']);- $this->visit($userProfileUrl)- ->assertResponseOk()- ->dontSeeElement('input[name=email][disabled]')- ->seeElement('input[name=email]');+ $this->get($userProfileUrl)+ ->assertOk()+ ->assertElementNotExists('input[name=email][disabled]')+ ->assertElementExists('input[name=email]');$this->put($userProfileUrl, ['name' => 'my_new_name_2','email' => '[email protected]',]);- $this->seeInDatabase('users', [+ $this->assertDatabaseHas('users', ['id' => $this->user->id,'email' => '[email protected]','name' => 'my_new_name_2',@@ -184,40 +185,41 @@ class RolesTest extends BrowserKitTestpublic function test_user_roles_manage_permission(){- $this->actingAs($this->user)->visit('/settings/roles')- ->seePageIs('/')->visit('/settings/roles/1')->seePageIs('/');+ $this->actingAs($this->user)->get('/settings/roles')+ ->seePageIs('/')->get('/settings/roles/1')->seePageIs('/');$this->giveUserPermissions($this->user, ['user-roles-manage']);- $this->actingAs($this->user)->visit('/settings/roles')+ $this->actingAs($this->user)->get('/settings/roles')->seePageIs('/settings/roles')->click('Admin')- ->see('Edit Role');+ ->assertSee('Edit Role');}public function test_settings_manage_permission(){- $this->actingAs($this->user)->visit('/settings')+ $this->actingAs($this->user)->get('/settings')->seePageIs('/');$this->giveUserPermissions($this->user, ['settings-manage']);- $this->actingAs($this->user)->visit('/settings')- ->seePageIs('/settings')->press('Save Settings')->see('Settings Saved');+ $this->actingAs($this->user)->get('/settings')+ ->seePageIs('/settings')->press('Save Settings')->assertSee('Settings Saved');}public function test_restrictions_manage_all_permission(){$page = Page::take(1)->get()->first();- $this->actingAs($this->user)->visit($page->getUrl())- ->dontSee('Permissions')- ->visit($page->getUrl() . '/permissions')+ $this->actingAs($this->user)->get($page->getUrl())+ ->assertDontSee('Permissions')+ ->get($page->getUrl() . '/permissions')->seePageIs('/');$this->giveUserPermissions($this->user, ['restrictions-manage-all']);- $this->actingAs($this->user)->visit($page->getUrl())- ->see('Permissions')+ $this->actingAs($this->user)->get($page->getUrl())+ ->assertSee('Permissions')->click('Permissions')- ->see('Page Permissions')->seePageIs($page->getUrl() . '/permissions');+ ->assertSee('Page Permissions')->seePageIs($page->getUrl() . '/permissions');}public function test_restrictions_manage_own_permission(){- $otherUsersPage = Page::first();+ /** @var Page $otherUsersPage */+ $otherUsersPage = Page::query()->first();$content = $this->createEntityChainBelongingToUser($this->user);// Set a different creator on the page we're checking to ensure@@ -228,26 +230,26 @@ class RolesTest extends BrowserKitTest$page->save();// Check can't restrict other's content- $this->actingAs($this->user)->visit($otherUsersPage->getUrl())- ->dontSee('Permissions')- ->visit($otherUsersPage->getUrl() . '/permissions')+ $this->actingAs($this->user)->get($otherUsersPage->getUrl())+ ->assertDontSee('Permissions')+ ->get($otherUsersPage->getUrl() . '/permissions')->seePageIs('/');// Check can't restrict own content- $this->actingAs($this->user)->visit($page->getUrl())- ->dontSee('Permissions')- ->visit($page->getUrl() . '/permissions')+ $this->actingAs($this->user)->get($page->getUrl())+ ->assertDontSee('Permissions')+ ->get($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('Permissions')- ->visit($otherUsersPage->getUrl() . '/permissions')+ $this->actingAs($this->user)->get($otherUsersPage->getUrl())+ ->assertDontSee('Permissions')+ ->get($otherUsersPage->getUrl() . '/permissions')->seePageIs('/');// Check can restrict own content- $this->actingAs($this->user)->visit($page->getUrl())- ->see('Permissions')+ $this->actingAs($this->user)->get($page->getUrl())+ ->assertSee('Permissions')->click('Permissions')->seePageIs($page->getUrl() . '/permissions');}@@ -262,23 +264,23 @@ class RolesTest extends BrowserKitTestprivate function checkAccessPermission($permission, $accessUrls = [], $visibles = []){foreach ($accessUrls as $url) {- $this->actingAs($this->user)->visit($url)+ $this->actingAs($this->user)->get($url)->seePageIs('/');}foreach ($visibles as $url => $text) {- $this->actingAs($this->user)->visit($url)- ->dontSeeInElement('.action-buttons', $text);+ $this->actingAs($this->user)->get($url)+ ->assertElementNotContains('.action-buttons', $text);}$this->giveUserPermissions($this->user, [$permission]);foreach ($accessUrls as $url) {- $this->actingAs($this->user)->visit($url)+ $this->actingAs($this->user)->get($url)->seePageIs($url);}foreach ($visibles as $url => $text) {- $this->actingAs($this->user)->visit($url)- ->see($text);+ $this->actingAs($this->user)->get($url)+ ->assertSee($text);}}@@ -290,7 +292,7 @@ class RolesTest extends BrowserKitTest'/shelves' => 'New Shelf',]);- $this->visit('/create-shelf')+ $this->get('/create-shelf')->type('test shelf', 'name')->type('shelf desc', 'description')->press('Save Shelf')@@ -299,7 +301,8 @@ class RolesTest extends BrowserKitTestpublic function test_bookshelves_edit_own_permission(){- $otherShelf = Bookshelf::first();+ /** @var Bookshelf $otherShelf */+ $otherShelf = Bookshelf::query()->first();$ownShelf = $this->newShelf(['name' => 'test-shelf', 'slug' => 'test-shelf']);$ownShelf->forceFill(['owned_by' => $this->user->id, 'updated_by' => $this->user->id])->save();$this->regenEntityPermissions($ownShelf);@@ -310,15 +313,16 @@ class RolesTest extends BrowserKitTest$ownShelf->getUrl() => 'Edit',]);- $this->visit($otherShelf->getUrl())- ->dontSeeInElement('.action-buttons', 'Edit')- ->visit($otherShelf->getUrl('/edit'))+ $this->get($otherShelf->getUrl())+ ->assertElementNotContains('.action-buttons', 'Edit')+ ->get($otherShelf->getUrl('/edit'))->seePageIs('/');}public function test_bookshelves_edit_all_permission(){- $otherShelf = Bookshelf::first();+ /** @var Bookshelf $otherShelf */+ $otherShelf = Bookshelf::query()->first();$this->checkAccessPermission('bookshelf-update-all', [$otherShelf->getUrl('/edit'),], [@@ -329,7 +333,8 @@ class RolesTest extends BrowserKitTestpublic function test_bookshelves_delete_own_permission(){$this->giveUserPermissions($this->user, ['bookshelf-update-all']);- $otherShelf = Bookshelf::first();+ /** @var Bookshelf $otherShelf */+ $otherShelf = Bookshelf::query()->first();$ownShelf = $this->newShelf(['name' => 'test-shelf', 'slug' => 'test-shelf']);$ownShelf->forceFill(['owned_by' => $this->user->id, 'updated_by' => $this->user->id])->save();$this->regenEntityPermissions($ownShelf);@@ -340,30 +345,31 @@ class RolesTest extends BrowserKitTest$ownShelf->getUrl() => 'Delete',]);- $this->visit($otherShelf->getUrl())- ->dontSeeInElement('.action-buttons', 'Delete')- ->visit($otherShelf->getUrl('/delete'))+ $this->get($otherShelf->getUrl())+ ->assertElementNotContains('.action-buttons', 'Delete')+ ->get($otherShelf->getUrl('/delete'))->seePageIs('/');- $this->visit($ownShelf->getUrl())->visit($ownShelf->getUrl('/delete'))+ $this->get($ownShelf->getUrl())->get($ownShelf->getUrl('/delete'))->press('Confirm')->seePageIs('/shelves')- ->dontSee($ownShelf->name);+ ->assertDontSee($ownShelf->name);}public function test_bookshelves_delete_all_permission(){$this->giveUserPermissions($this->user, ['bookshelf-update-all']);- $otherShelf = Bookshelf::first();+ /** @var Bookshelf $otherShelf */+ $otherShelf = Bookshelf::query()->first();$this->checkAccessPermission('bookshelf-delete-all', [$otherShelf->getUrl('/delete'),], [$otherShelf->getUrl() => 'Delete',]);- $this->visit($otherShelf->getUrl())->visit($otherShelf->getUrl('/delete'))+ $this->get($otherShelf->getUrl())->get($otherShelf->getUrl('/delete'))->press('Confirm')->seePageIs('/shelves')- ->dontSee($otherShelf->name);+ ->assertDontSee($otherShelf->name);}public function test_books_create_all_permissions()@@ -374,7 +380,7 @@ class RolesTest extends BrowserKitTest'/books' => 'Create New Book',]);- $this->visit('/create-book')+ $this->get('/create-book')->type('test book', 'name')->type('book desc', 'description')->press('Save Book')@@ -383,7 +389,8 @@ class RolesTest extends BrowserKitTestpublic function test_books_edit_own_permission(){- $otherBook = Book::take(1)->get()->first();+ /** @var Book $otherBook */+ $otherBook = Book::query()->take(1)->get()->first();$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];$this->checkAccessPermission('book-update-own', [$ownBook->getUrl() . '/edit',@@ -391,15 +398,16 @@ class RolesTest extends BrowserKitTest$ownBook->getUrl() => 'Edit',]);- $this->visit($otherBook->getUrl())- ->dontSeeInElement('.action-buttons', 'Edit')- ->visit($otherBook->getUrl() . '/edit')+ $this->get($otherBook->getUrl())+ ->assertElementNotContains('.action-buttons', 'Edit')+ ->get($otherBook->getUrl() . '/edit')->seePageIs('/');}public function test_books_edit_all_permission(){- $otherBook = Book::take(1)->get()->first();+ /** @var Book $otherBook */+ $otherBook = Book::query()->take(1)->get()->first();$this->checkAccessPermission('book-update-all', [$otherBook->getUrl() . '/edit',], [@@ -410,7 +418,8 @@ class RolesTest extends BrowserKitTestpublic function test_books_delete_own_permission(){$this->giveUserPermissions($this->user, ['book-update-all']);- $otherBook = Book::take(1)->get()->first();+ /** @var Book $otherBook */+ $otherBook = Book::query()->take(1)->get()->first();$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];$this->checkAccessPermission('book-delete-own', [$ownBook->getUrl() . '/delete',@@ -418,35 +427,37 @@ class RolesTest extends BrowserKitTest$ownBook->getUrl() => 'Delete',]);- $this->visit($otherBook->getUrl())- ->dontSeeInElement('.action-buttons', 'Delete')- ->visit($otherBook->getUrl() . '/delete')+ $this->get($otherBook->getUrl())+ ->assertElementNotContains('.action-buttons', 'Delete')+ ->get($otherBook->getUrl() . '/delete')->seePageIs('/');- $this->visit($ownBook->getUrl())->visit($ownBook->getUrl() . '/delete')+ $this->get($ownBook->getUrl())->get($ownBook->getUrl() . '/delete')->press('Confirm')->seePageIs('/books')- ->dontSee($ownBook->name);+ ->assertDontSee($ownBook->name);}public function test_books_delete_all_permission(){$this->giveUserPermissions($this->user, ['book-update-all']);- $otherBook = Book::take(1)->get()->first();+ /** @var Book $otherBook */+ $otherBook = Book::query()->take(1)->get()->first();$this->checkAccessPermission('book-delete-all', [$otherBook->getUrl() . '/delete',], [$otherBook->getUrl() => 'Delete',]);- $this->visit($otherBook->getUrl())->visit($otherBook->getUrl() . '/delete')+ $this->get($otherBook->getUrl())->get($otherBook->getUrl() . '/delete')->press('Confirm')->seePageIs('/books')- ->dontSee($otherBook->name);+ ->assertDontSee($otherBook->name);}public function test_chapter_create_own_permissions(){- $book = Book::take(1)->get()->first();+ /** @var Book $book */+ $book = Book::query()->take(1)->get()->first();$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];$this->checkAccessPermission('chapter-create-own', [$ownBook->getUrl('/create-chapter'),@@ -454,15 +465,15 @@ class RolesTest extends BrowserKitTest$ownBook->getUrl() => 'New Chapter',]);- $this->visit($ownBook->getUrl('/create-chapter'))+ $this->get($ownBook->getUrl('/create-chapter'))->type('test chapter', 'name')->type('chapter desc', 'description')->press('Save Chapter')->seePageIs($ownBook->getUrl('/chapter/test-chapter'));- $this->visit($book->getUrl())- ->dontSeeInElement('.action-buttons', 'New Chapter')- ->visit($book->getUrl('/create-chapter'))+ $this->get($book->getUrl())+ ->assertElementNotContains('.action-buttons', 'New Chapter')+ ->get($book->getUrl('/create-chapter'))->seePageIs('/');}@@ -475,7 +486,7 @@ class RolesTest extends BrowserKitTest$book->getUrl() => 'New Chapter',]);- $this->visit($book->getUrl('/create-chapter'))+ $this->get($book->getUrl('/create-chapter'))->type('test chapter', 'name')->type('chapter desc', 'description')->press('Save Chapter')@@ -492,15 +503,16 @@ class RolesTest extends BrowserKitTest$ownChapter->getUrl() => 'Edit',]);- $this->visit($otherChapter->getUrl())- ->dontSeeInElement('.action-buttons', 'Edit')- ->visit($otherChapter->getUrl() . '/edit')+ $this->get($otherChapter->getUrl())+ ->assertElementNotContains('.action-buttons', 'Edit')+ ->get($otherChapter->getUrl() . '/edit')->seePageIs('/');}public function test_chapter_edit_all_permission(){- $otherChapter = Chapter::take(1)->get()->first();+ /** @var Chapter $otherChapter */+ $otherChapter = Chapter::query()->take(1)->get()->first();$this->checkAccessPermission('chapter-update-all', [$otherChapter->getUrl() . '/edit',], [@@ -511,7 +523,8 @@ class RolesTest extends BrowserKitTestpublic function test_chapter_delete_own_permission(){$this->giveUserPermissions($this->user, ['chapter-update-all']);- $otherChapter = Chapter::take(1)->get()->first();+ /** @var Chapter $otherChapter */+ $otherChapter = Chapter::query()->take(1)->get()->first();$ownChapter = $this->createEntityChainBelongingToUser($this->user)['chapter'];$this->checkAccessPermission('chapter-delete-own', [$ownChapter->getUrl() . '/delete',@@ -520,14 +533,14 @@ class RolesTest extends BrowserKitTest]);$bookUrl = $ownChapter->book->getUrl();- $this->visit($otherChapter->getUrl())- ->dontSeeInElement('.action-buttons', 'Delete')- ->visit($otherChapter->getUrl() . '/delete')+ $this->get($otherChapter->getUrl())+ ->assertElementNotContains('.action-buttons', 'Delete')+ ->get($otherChapter->getUrl() . '/delete')->seePageIs('/');- $this->visit($ownChapter->getUrl())->visit($ownChapter->getUrl() . '/delete')+ $this->get($ownChapter->getUrl())->get($ownChapter->getUrl() . '/delete')->press('Confirm')->seePageIs($bookUrl)- ->dontSeeInElement('.book-content', $ownChapter->name);+ ->assertElementNotContains('.book-content', $ownChapter->name);}public function test_chapter_delete_all_permission()@@ -541,16 +554,18 @@ class RolesTest extends BrowserKitTest]);$bookUrl = $otherChapter->book->getUrl();- $this->visit($otherChapter->getUrl())->visit($otherChapter->getUrl() . '/delete')+ $this->get($otherChapter->getUrl())->get($otherChapter->getUrl() . '/delete')->press('Confirm')->seePageIs($bookUrl)- ->dontSeeInElement('.book-content', $otherChapter->name);+ ->assertElementNotContains('.book-content', $otherChapter->name);}public function test_page_create_own_permissions(){- $book = Book::first();- $chapter = Chapter::first();+ /** @var Book $book */+ $book = Book::query()->first();+ /** @var Chapter $chapter */+ $chapter = Chapter::query()->first();$entities = $this->createEntityChainBelongingToUser($this->user);$ownBook = $entities['book'];@@ -561,7 +576,7 @@ class RolesTest extends BrowserKitTest$accessUrls = [$createUrl, $createUrlChapter];foreach ($accessUrls as $url) {- $this->actingAs($this->user)->visit($url)+ $this->actingAs($this->user)->get($url)->seePageIs('/');}@@ -573,24 +588,24 @@ class RolesTest extends BrowserKitTest$this->giveUserPermissions($this->user, ['page-create-own']);foreach ($accessUrls as $index => $url) {- $this->actingAs($this->user)->visit($url);+ $this->actingAs($this->user)->get($url);$expectedUrl = Page::where('draft', '=', true)->orderBy('id', 'desc')->first()->getUrl();$this->seePageIs($expectedUrl);}- $this->visit($createUrl)+ $this->get($createUrl)->type('test page', 'name')->type('page desc', 'html')->press('Save Page')->seePageIs($ownBook->getUrl('/page/test-page'));- $this->visit($book->getUrl())- ->dontSeeInElement('.action-buttons', 'New Page')- ->visit($book->getUrl() . '/create-page')+ $this->get($book->getUrl())+ ->assertElementNotContains('.action-buttons', 'New Page')+ ->get($book->getUrl() . '/create-page')->seePageIs('/');- $this->visit($chapter->getUrl())- ->dontSeeInElement('.action-buttons', 'New Page')- ->visit($chapter->getUrl() . '/create-page')+ $this->get($chapter->getUrl())+ ->assertElementNotContains('.action-buttons', 'New Page')+ ->get($chapter->getUrl() . '/create-page')->seePageIs('/');}@@ -598,14 +613,13 @@ class RolesTest extends BrowserKitTest{$book = Book::take(1)->get()->first();$chapter = Chapter::take(1)->get()->first();- $baseUrl = $book->getUrl() . '/page';$createUrl = $book->getUrl('/create-page');$createUrlChapter = $chapter->getUrl('/create-page');$accessUrls = [$createUrl, $createUrlChapter];foreach ($accessUrls as $url) {- $this->actingAs($this->user)->visit($url)+ $this->actingAs($this->user)->get($url)->seePageIs('/');}@@ -617,18 +631,18 @@ class RolesTest extends BrowserKitTest$this->giveUserPermissions($this->user, ['page-create-all']);foreach ($accessUrls as $index => $url) {- $this->actingAs($this->user)->visit($url);+ $this->actingAs($this->user)->get($url);$expectedUrl = Page::where('draft', '=', true)->orderBy('id', 'desc')->first()->getUrl();$this->seePageIs($expectedUrl);}- $this->visit($createUrl)+ $this->get($createUrl)->type('test page', 'name')->type('page desc', 'html')->press('Save Page')->seePageIs($book->getUrl('/page/test-page'));- $this->visit($chapter->getUrl('/create-page'))+ $this->get($chapter->getUrl('/create-page'))->type('new test page', 'name')->type('page desc', 'html')->press('Save Page')@@ -645,9 +659,9 @@ class RolesTest extends BrowserKitTest$ownPage->getUrl() => 'Edit',]);- $this->visit($otherPage->getUrl())- ->dontSeeInElement('.action-buttons', 'Edit')- ->visit($otherPage->getUrl() . '/edit')+ $this->get($otherPage->getUrl())+ ->assertElementNotContains('.action-buttons', 'Edit')+ ->get($otherPage->getUrl() . '/edit')->seePageIs('/');}@@ -673,14 +687,14 @@ class RolesTest extends BrowserKitTest]);$parent = $ownPage->chapter ?? $ownPage->book;- $this->visit($otherPage->getUrl())- ->dontSeeInElement('.action-buttons', 'Delete')- ->visit($otherPage->getUrl() . '/delete')+ $this->get($otherPage->getUrl())+ ->assertElementNotContains('.action-buttons', 'Delete')+ ->get($otherPage->getUrl() . '/delete')->seePageIs('/');- $this->visit($ownPage->getUrl())->visit($ownPage->getUrl() . '/delete')+ $this->get($ownPage->getUrl())->get($ownPage->getUrl() . '/delete')->press('Confirm')->seePageIs($parent->getUrl())- ->dontSeeInElement('.book-content', $ownPage->name);+ ->assertElementNotContains('.book-content', $ownPage->name);}public function test_page_delete_all_permission()@@ -694,10 +708,10 @@ class RolesTest extends BrowserKitTest]);$parent = $otherPage->chapter ?? $otherPage->book;- $this->visit($otherPage->getUrl())->visit($otherPage->getUrl() . '/delete')+ $this->get($otherPage->getUrl())->get($otherPage->getUrl() . '/delete')->press('Confirm')->seePageIs($parent->getUrl())- ->dontSeeInElement('.book-content', $otherPage->name);+ ->assertElementNotContains('.book-content', $otherPage->name);}public function test_public_role_visible_in_user_edit_screen()@@ -705,34 +719,34 @@ class RolesTest extends BrowserKitTest$user = User::first();$adminRole = Role::getSystemRole('admin');$publicRole = Role::getSystemRole('public');- $this->asAdmin()->visit('/settings/users/' . $user->id)- ->seeElement('[name="roles[' . $adminRole->id . ']"]')- ->seeElement('[name="roles[' . $publicRole->id . ']"]');+ $this->asAdmin()->get('/settings/users/' . $user->id)+ ->assertElementExists('[name="roles[' . $adminRole->id . ']"]')+ ->assertElementExists('[name="roles[' . $publicRole->id . ']"]');}public function test_public_role_visible_in_role_listing(){- $this->asAdmin()->visit('/settings/roles')- ->see('Admin')- ->see('Public');+ $this->asAdmin()->get('/settings/roles')+ ->assertSee('Admin')+ ->assertSee('Public');}public function test_public_role_visible_in_default_role_setting(){- $this->asAdmin()->visit('/settings')- ->seeElement('[data-system-role-name="admin"]')- ->seeElement('[data-system-role-name="public"]');+ $this->asAdmin()->get('/settings')+ ->assertElementExists('[data-system-role-name="admin"]')+ ->assertElementExists('[data-system-role-name="public"]');}public function test_public_role_not_deleteable(){- $this->asAdmin()->visit('/settings/roles')+ $this->asAdmin()->get('/settings/roles')->click('Public')- ->see('Edit Role')+ ->assertSee('Edit Role')->click('Delete Role')->press('Confirm')- ->see('Delete Role')- ->see('Cannot be deleted');+ ->assertSee('Delete Role')+ ->assertSee('Cannot be deleted');}public function test_image_delete_own_permission()@@ -742,13 +756,13 @@ class RolesTest extends BrowserKitTest$image = factory(Image::class)->create(['uploaded_to' => $page->id, 'created_by' => $this->user->id, 'updated_by' => $this->user->id]);$this->actingAs($this->user)->json('delete', '/images/' . $image->id)- ->seeStatusCode(403);+ ->assertStatus(403);$this->giveUserPermissions($this->user, ['image-delete-own']);$this->actingAs($this->user)->json('delete', '/images/' . $image->id)- ->seeStatusCode(200)- ->dontSeeInDatabase('images', ['id' => $image->id]);+ ->assertOk()+ ->assertDatabaseMissing('images', ['id' => $image->id]);}public function test_image_delete_all_permission()@@ -759,36 +773,36 @@ class RolesTest extends BrowserKitTest$image = factory(Image::class)->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]);$this->actingAs($this->user)->json('delete', '/images/' . $image->id)- ->seeStatusCode(403);+ ->assertStatus(403);$this->giveUserPermissions($this->user, ['image-delete-own']);$this->actingAs($this->user)->json('delete', '/images/' . $image->id)- ->seeStatusCode(403);+ ->assertStatus(403);$this->giveUserPermissions($this->user, ['image-delete-all']);$this->actingAs($this->user)->json('delete', '/images/' . $image->id)- ->seeStatusCode(200)- ->dontSeeInDatabase('images', ['id' => $image->id]);+ ->assertOk()+ ->assertDatabaseMissing('images', ['id' => $image->id]);}public function test_role_permission_removal(){// To cover issue fixed in f99c8ff99aee9beb8c692f36d4b84dc6e651e50a.- $page = Page::first();+ /** @var Page $page */+ $page = Page::query()->first();$viewerRole = Role::getRole('viewer');$viewer = $this->getViewer();- $this->actingAs($viewer)->visit($page->getUrl())->assertResponseStatus(200);+ $this->actingAs($viewer)->get($page->getUrl())->assertOk();$this->asAdmin()->put('/settings/roles/' . $viewerRole->id, ['display_name' => $viewerRole->display_name,'description' => $viewerRole->description,'permission' => [],- ])->assertResponseStatus(302);+ ])->assertStatus(302);- $this->expectException(HttpException::class);- $this->actingAs($viewer)->visit($page->getUrl())->assertResponseStatus(404);+ $this->actingAs($viewer)->get($page->getUrl())->assertStatus(404);}public function test_empty_state_actions_not_visible_without_permission()@@ -796,130 +810,118 @@ class RolesTest extends BrowserKitTest$admin = $this->getAdmin();// Book links$book = factory(Book::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id]);- $this->updateEntityPermissions($book);- $this->actingAs($this->getViewer())->visit($book->getUrl())- ->dontSee('Create a new page')- ->dontSee('Add a chapter');+ $this->regenEntityPermissions($book);+ $this->actingAs($this->getViewer())->get($book->getUrl())+ ->assertDontSee('Create a new page')+ ->assertDontSee('Add a chapter');// Chapter links$chapter = factory(Chapter::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id, 'book_id' => $book->id]);- $this->updateEntityPermissions($chapter);- $this->actingAs($this->getViewer())->visit($chapter->getUrl())- ->dontSee('Create a new page')- ->dontSee('Sort the current book');+ $this->regenEntityPermissions($chapter);+ $this->actingAs($this->getViewer())->get($chapter->getUrl())+ ->assertDontSee('Create a new page')+ ->assertDontSee('Sort the current book');}public function test_comment_create_permission(){$ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];- $this->actingAs($this->user)->addComment($ownPage);-- $this->assertResponseStatus(403);+ $this->actingAs($this->user)+ ->addComment($ownPage)+ ->assertStatus(403);$this->giveUserPermissions($this->user, ['comment-create-all']);- $this->actingAs($this->user)->addComment($ownPage);- $this->assertResponseStatus(200);+ $this->actingAs($this->user)+ ->addComment($ownPage)+ ->assertOk();}public function test_comment_update_own_permission(){$ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];$this->giveUserPermissions($this->user, ['comment-create-all']);- $commentId = $this->actingAs($this->user)->addComment($ownPage);+ $this->actingAs($this->user)->addComment($ownPage);+ /** @var Comment $comment */+ $comment = $ownPage->comments()->latest()->first();// no comment-update-own- $this->actingAs($this->user)->updateComment($commentId);- $this->assertResponseStatus(403);+ $this->actingAs($this->user)->updateComment($comment)->assertStatus(403);$this->giveUserPermissions($this->user, ['comment-update-own']);// now has comment-update-own- $this->actingAs($this->user)->updateComment($commentId);- $this->assertResponseStatus(200);+ $this->actingAs($this->user)->updateComment($comment)->assertOk();}public function test_comment_update_all_permission(){+ /** @var Page $ownPage */$ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];- $commentId = $this->asAdmin()->addComment($ownPage);+ $this->asAdmin()->addComment($ownPage);+ /** @var Comment $comment */+ $comment = $ownPage->comments()->latest()->first();// no comment-update-all- $this->actingAs($this->user)->updateComment($commentId);- $this->assertResponseStatus(403);+ $this->actingAs($this->user)->updateComment($comment)->assertStatus(403);$this->giveUserPermissions($this->user, ['comment-update-all']);// now has comment-update-all- $this->actingAs($this->user)->updateComment($commentId);- $this->assertResponseStatus(200);+ $this->actingAs($this->user)->updateComment($comment)->assertOk();}public function test_comment_delete_own_permission(){+ /** @var Page $ownPage */$ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];$this->giveUserPermissions($this->user, ['comment-create-all']);- $commentId = $this->actingAs($this->user)->addComment($ownPage);+ $this->actingAs($this->user)->addComment($ownPage);++ /** @var Comment $comment */+ $comment = $ownPage->comments()->latest()->first();// no comment-delete-own- $this->actingAs($this->user)->deleteComment($commentId);- $this->assertResponseStatus(403);+ $this->actingAs($this->user)->deleteComment($comment)->assertStatus(403);$this->giveUserPermissions($this->user, ['comment-delete-own']);// now has comment-update-own- $this->actingAs($this->user)->deleteComment($commentId);- $this->assertResponseStatus(200);+ $this->actingAs($this->user)->deleteComment($comment)->assertOk();}public function test_comment_delete_all_permission(){+ /** @var Page $ownPage */$ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];- $commentId = $this->asAdmin()->addComment($ownPage);+ $this->asAdmin()->addComment($ownPage);+ /** @var Comment $comment */+ $comment = $ownPage->comments()->latest()->first();// no comment-delete-all- $this->actingAs($this->user)->deleteComment($commentId);- $this->assertResponseStatus(403);+ $this->actingAs($this->user)->deleteComment($comment)->assertStatus(403);$this->giveUserPermissions($this->user, ['comment-delete-all']);// now has comment-delete-all- $this->actingAs($this->user)->deleteComment($commentId);- $this->assertResponseStatus(200);+ $this->actingAs($this->user)->deleteComment($comment)->assertOk();}- private function addComment($page)+ private function addComment(Page $page): TestResponse{$comment = factory(Comment::class)->make();- $url = "/comment/$page->id";- $request = [- 'text' => $comment->text,- 'html' => $comment->html,- ];-- $this->postJson($url, $request);- $comment = $page->comments()->first();-- return $comment === null ? null : $comment->id;+ return $this->postJson("/comment/$page->id", $comment->only('text', 'html'));}- private function updateComment($commentId)+ private function updateComment(Comment $comment): TestResponse{- $comment = factory(Comment::class)->make();- $url = "/comment/$commentId";- $request = [- 'text' => $comment->text,- 'html' => $comment->html,- ];-- return $this->putJson($url, $request);+ $commentData = factory(Comment::class)->make();+ return $this->putJson("/comment/{$comment->id}", $commentData->only('text', 'html'));}- private function deleteComment($commentId)+ private function deleteComment(Comment $comment): TestResponse{- $url = '/comment/' . $commentId;-- return $this->json('DELETE', $url);+ return $this->json('DELETE', '/comment/' . $comment->id);}}