2024-10-22 17:50:40 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\ReportTemplates;
|
|
|
|
|
|
|
|
use App\Models\ReportTemplate;
|
|
|
|
use App\Models\User;
|
2024-10-28 14:42:44 -07:00
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
2024-10-22 17:50:40 -07:00
|
|
|
use Tests\Concerns\TestsPermissionsRequirement;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-10-28 14:42:44 -07:00
|
|
|
#[Group('custom-reporting')]
|
2024-10-22 17:50:40 -07:00
|
|
|
class EditReportTemplateTest extends TestCase implements TestsPermissionsRequirement
|
|
|
|
{
|
|
|
|
public function testRequiresPermission()
|
|
|
|
{
|
|
|
|
$this->actingAs(User::factory()->create())
|
2024-10-28 14:24:47 -07:00
|
|
|
->get($this->getRoute(ReportTemplate::factory()->create()))
|
2024-10-22 17:50:40 -07:00
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCannotLoadEditPageForAnotherUsersReportTemplate()
|
|
|
|
{
|
|
|
|
$user = User::factory()->canViewReports()->create();
|
|
|
|
$reportTemplate = ReportTemplate::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAs($user)
|
2024-10-28 14:24:47 -07:00
|
|
|
->get($this->getRoute($reportTemplate))
|
2024-10-22 17:50:40 -07:00
|
|
|
->assertSessionHas('error')
|
|
|
|
->assertRedirect(route('reports/custom'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanLoadEditReportTemplatePage()
|
|
|
|
{
|
|
|
|
$user = User::factory()->canViewReports()->create();
|
2024-10-23 16:40:03 -07:00
|
|
|
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
|
2024-10-22 17:50:40 -07:00
|
|
|
|
|
|
|
$this->actingAs($user)
|
2024-10-28 14:24:47 -07:00
|
|
|
->get($this->getRoute($reportTemplate))
|
2024-10-22 17:50:40 -07:00
|
|
|
->assertOk();
|
|
|
|
}
|
2024-10-28 14:24:47 -07:00
|
|
|
|
|
|
|
private function getRoute(ReportTemplate $reportTemplate): string
|
|
|
|
{
|
|
|
|
return route('report-templates.edit', $reportTemplate);
|
|
|
|
}
|
2024-10-22 17:50:40 -07:00
|
|
|
}
|