+ $resp = $this->asAdmin()->get('/settings/registration');
+ $this->withHtml($resp)->assertElementExists('[data-system-role-name="admin"]')
+ ->assertElementExists('[data-system-role-name="public"]');
+ }
+
+ public function test_public_role_not_deletable()
+ {
+ /** @var Role $publicRole */
+ $publicRole = Role::getSystemRole('public');
+ $resp = $this->asAdmin()->delete('/settings/roles/delete/' . $publicRole->id);
+ $resp->assertRedirect('/');
+
+ $this->get('/settings/roles/delete/' . $publicRole->id);
+ $resp = $this->delete('/settings/roles/delete/' . $publicRole->id);
+ $resp->assertRedirect('/settings/roles/delete/' . $publicRole->id);
+ $resp = $this->get('/settings/roles/delete/' . $publicRole->id);
+ $resp->assertSee('This role is a system role and cannot be deleted');
+ }
+
+ public function test_image_delete_own_permission()
+ {
+ $this->giveUserPermissions($this->user, ['image-update-all']);
+ /** @var Page $page */
+ $page = Page::query()->first();
+ $image = Image::factory()->create([
+ 'uploaded_to' => $page->id,
+ 'created_by' => $this->user->id,
+ 'updated_by' => $this->user->id,
+ ]);
+
+ $this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403);
+
+ $this->giveUserPermissions($this->user, ['image-delete-own']);
+
+ $this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertOk();
+ $this->assertDatabaseMissing('images', ['id' => $image->id]);
+ }
+
+ public function test_image_delete_all_permission()
+ {
+ $this->giveUserPermissions($this->user, ['image-update-all']);
+ $admin = $this->getAdmin();
+ /** @var Page $page */
+ $page = Page::query()->first();
+ $image = Image::factory()->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]);
+
+ $this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403);
+
+ $this->giveUserPermissions($this->user, ['image-delete-own']);
+
+ $this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403);
+
+ $this->giveUserPermissions($this->user, ['image-delete-all']);
+
+ $this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertOk();
+ $this->assertDatabaseMissing('images', ['id' => $image->id]);
+ }
+
+ public function test_role_permission_removal()
+ {
+ // To cover issue fixed in f99c8ff99aee9beb8c692f36d4b84dc6e651e50a.
+ /** @var Page $page */
+ $page = Page::query()->first();
+ $viewerRole = Role::getRole('viewer');
+ $viewer = $this->getViewer();
+ $this->actingAs($viewer)->get($page->getUrl())->assertOk();
+
+ $this->asAdmin()->put('/settings/roles/' . $viewerRole->id, [
+ 'display_name' => $viewerRole->display_name,
+ 'description' => $viewerRole->description,
+ 'permission' => [],
+ ])->assertStatus(302);
+
+ $this->actingAs($viewer)->get($page->getUrl())->assertStatus(404);
+ }
+
+ public function test_empty_state_actions_not_visible_without_permission()
+ {
+ $admin = $this->getAdmin();
+ // Book links
+ $book = Book::factory()->create(['created_by' => $admin->id, 'updated_by' => $admin->id]);
+ $this->regenEntityPermissions($book);
+ $this->actingAs($this->getViewer())->get($book->getUrl())
+ ->assertDontSee('Create a new page')
+ ->assertDontSee('Add a chapter');