actingAs(User::factory()->create()) ->get(route('report-templates.show', ReportTemplate::factory()->create())) ->assertRedirectToRoute('reports/custom'); } public function testCanLoadASavedReportTemplate() { $user = User::factory()->canViewReports()->create(); $reportTemplate = ReportTemplate::factory()->make(['name' => 'My Awesome Template']); $user->reportTemplates()->save($reportTemplate); $this->actingAs($user) ->get(route('report-templates.show', $reportTemplate)) ->assertOk() ->assertViewHas(['template' => function (ReportTemplate $templatePassedToView) use ($reportTemplate) { return $templatePassedToView->is($reportTemplate); }]); } public function testCannotLoadAnotherUsersSavedReportTemplateIfNotShared() { $reportTemplate = ReportTemplate::factory()->create(); $this->actingAs(User::factory()->canViewReports()->create()) ->get(route('report-templates.show', $reportTemplate)) ->assertRedirectToRoute('reports/custom') ->assertSessionHas('error', trans('general.generic_model_not_found', ['model' => 'report template']));; } public function testCanLoadAnotherUsersSavedReportTemplateIfShared() { $user = User::factory()->canViewReports()->create(); $reportTemplate = ReportTemplate::factory()->shared()->make(['name' => 'My Awesome Template']); $user->reportTemplates()->save($reportTemplate); $this->actingAs(User::factory()->canViewReports()->create()) ->get(route('report-templates.show', $reportTemplate)) ->assertOk() ->assertViewHas([ 'template' => function (ReportTemplate $templatePassedToView) use ($reportTemplate) { return $templatePassedToView->is($reportTemplate); } ]); } }