3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-04-02 22:11:01 +00:00
Files
snipe-it/tests/Feature/ReportTemplates/DeleteReportTemplateTest.php
2026-03-16 17:40:57 -07:00

61 lines
2.2 KiB
PHP

<?php
namespace Tests\Feature\ReportTemplates;
use App\Models\ReportTemplate;
use App\Models\User;
use PHPUnit\Framework\Attributes\Group;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
#[Group('custom-reporting')]
class DeleteReportTemplateTest extends TestCase implements TestsPermissionsRequirement
{
public function test_requires_permission()
{
$reportTemplate = ReportTemplate::factory()->create();
$this->actingAs(User::factory()->create())
->post(route('report-templates.destroy', $reportTemplate->id))
->assertRedirect(route('reports/custom'));
$this->assertNotSoftDeleted($reportTemplate);
}
public function test_cannot_delete_another_users_report_template()
{
$reportTemplate = ReportTemplate::factory()->create();
$this->actingAs(User::factory()->canViewReports()->create())
->delete(route('report-templates.destroy', $reportTemplate->id))
->assertRedirect(route('reports/custom'))
->assertSessionHas('error', trans('general.generic_model_not_found', ['model' => 'report template']));
$this->assertNotSoftDeleted($reportTemplate);
}
public function test_cannot_delete_another_users_shared_report_template()
{
$reportTemplate = ReportTemplate::factory()->shared()->create();
$this->actingAs(User::factory()->canViewReports()->create())
->delete(route('report-templates.destroy', $reportTemplate->id))
->assertRedirect(route('report-templates.show', $reportTemplate->id))
->assertSessionHas('error', trans('general.generic_model_not_found', ['model' => 'report template']));
$this->assertNotSoftDeleted($reportTemplate);
}
public function test_can_delete_a_report_template()
{
$user = User::factory()->canViewReports()->create();
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
$this->actingAs($user)
->delete(route('report-templates.destroy', $reportTemplate->id))
->assertRedirect(route('reports/custom'));
$this->assertSoftDeleted($reportTemplate);
}
}