snipe-it/tests/Feature/ReportTemplates/DeleteReportTemplateTest.php

47 lines
1.4 KiB
PHP
Raw Normal View History

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
2024-01-17 16:25:28 -08:00
use App\Models\ReportTemplate;
use App\Models\User;
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-22 14:22:19 -07:00
class DeleteReportTemplateTest extends TestCase implements TestsPermissionsRequirement
2024-01-17 13:19:54 -08:00
{
2024-10-22 14:22:19 -07:00
public function testRequiresPermission()
2024-01-17 13:19:54 -08:00
{
2024-10-22 17:37:23 -07:00
$reportTemplate = ReportTemplate::factory()->create();
2024-01-17 16:25:28 -08:00
$this->actingAs(User::factory()->create())
2024-10-22 17:37:23 -07:00
->post(route('report-templates.destroy', $reportTemplate->id))
2024-01-17 16:25:28 -08:00
->assertForbidden();
2024-10-22 17:37:23 -07:00
$this->assertModelExists($reportTemplate);
}
public function testCannotDeleteAnotherUsersReportTemplate()
{
$reportTemplate = ReportTemplate::factory()->create();
$this->actingAs(User::factory()->canViewReports()->create())
->delete(route('report-templates.destroy', $reportTemplate))
->assertSessionHas('error')
->assertRedirect(route('reports/custom'));
$this->assertModelExists($reportTemplate);
2024-01-17 13:19:54 -08:00
}
public function testCanDeleteAReportTemplate()
{
2024-01-17 16:25:28 -08:00
$user = User::factory()->canViewReports()->create();
2024-10-23 16:40:03 -07:00
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
2024-01-17 16:25:28 -08:00
$this->actingAs($user)
->delete(route('report-templates.destroy', $reportTemplate))
->assertRedirect(route('reports/custom'));
2024-10-22 17:37:23 -07:00
$this->assertModelMissing($reportTemplate);
2024-01-17 13:19:54 -08:00
}
}