actingAs(User::factory()->create()) ->get($this->getRoute(ReportTemplate::factory()->create())) ->assertForbidden(); } public function testCannotLoadEditPageForAnotherUsersReportTemplate() { $user = User::factory()->canViewReports()->create(); $reportTemplate = ReportTemplate::factory()->create(); $this->actingAs($user) ->get($this->getRoute($reportTemplate)) ->assertSessionHas('error') ->assertRedirect(route('reports/custom')); } public function testCanLoadEditReportTemplatePage() { $user = User::factory()->canViewReports()->create(); $reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create(); $this->actingAs($user) ->get($this->getRoute($reportTemplate)) ->assertOk(); } private function getRoute(ReportTemplate $reportTemplate): string { return route('report-templates.edit', $reportTemplate); } }