2024-01-17 13:19:54 -08:00
|
|
|
<?php
|
|
|
|
|
2024-01-17 16:25:28 -08:00
|
|
|
namespace Tests\Feature\ReportTemplates;
|
2024-01-17 13:19:54 -08:00
|
|
|
|
|
|
|
use App\Models\ReportTemplate;
|
|
|
|
use App\Models\User;
|
2024-10-28 14:42:44 -07:00
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
2024-10-22 14:22:19 -07:00
|
|
|
use Tests\Concerns\TestsPermissionsRequirement;
|
2024-01-17 13:19:54 -08:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-10-28 14:42:44 -07:00
|
|
|
#[Group('custom-reporting')]
|
2024-10-22 14:22:19 -07:00
|
|
|
class ShowReportTemplateTest extends TestCase implements TestsPermissionsRequirement
|
2024-01-17 13:19:54 -08:00
|
|
|
{
|
2024-10-22 14:22:19 -07:00
|
|
|
public function testRequiresPermission()
|
|
|
|
{
|
|
|
|
$this->actingAs(User::factory()->create())
|
2024-10-28 14:24:47 -07:00
|
|
|
->get($this->getRoute(ReportTemplate::factory()->create()))
|
2024-10-31 12:34:06 -07:00
|
|
|
->assertNotFound();
|
2024-10-22 14:22:19 -07:00
|
|
|
}
|
|
|
|
|
2024-01-17 13:19:54 -08:00
|
|
|
public function testCanLoadASavedReportTemplate()
|
|
|
|
{
|
|
|
|
$user = User::factory()->canViewReports()->create();
|
|
|
|
$reportTemplate = ReportTemplate::factory()->make(['name' => 'My Awesome Template']);
|
|
|
|
$user->reportTemplates()->save($reportTemplate);
|
|
|
|
|
|
|
|
$this->actingAs($user)
|
2024-10-28 14:24:47 -07:00
|
|
|
->get($this->getRoute($reportTemplate))
|
2024-01-17 13:19:54 -08:00
|
|
|
->assertOk()
|
|
|
|
->assertViewHas(['template' => function (ReportTemplate $templatePassedToView) use ($reportTemplate) {
|
|
|
|
return $templatePassedToView->is($reportTemplate);
|
|
|
|
}]);
|
|
|
|
}
|
2024-10-22 16:52:59 -07:00
|
|
|
|
|
|
|
public function testCannotLoadAnotherUsersSavedReportTemplate()
|
|
|
|
{
|
|
|
|
$reportTemplate = ReportTemplate::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAs(User::factory()->canViewReports()->create())
|
2024-10-28 14:24:47 -07:00
|
|
|
->get($this->getRoute($reportTemplate))
|
2024-10-31 12:34:06 -07:00
|
|
|
->assertNotFound();
|
2024-10-22 16:52:59 -07:00
|
|
|
}
|
2024-10-28 14:24:47 -07:00
|
|
|
|
|
|
|
private function getRoute(ReportTemplate $reportTemplate): string
|
|
|
|
{
|
|
|
|
return route('report-templates.show', $reportTemplate);
|
|
|
|
}
|
2024-01-17 13:19:54 -08:00
|
|
|
}
|