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

48 lines
1.4 KiB
PHP
Raw Permalink 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-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 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-11-07 16:54:55 -08:00
->post(route('report-templates.destroy', $reportTemplate->id))
2024-10-31 12:34:06 -07:00
->assertNotFound();
2024-10-22 17:37:23 -07:00
$this->assertModelExists($reportTemplate);
}
public function testCannotDeleteAnotherUsersReportTemplate()
{
$reportTemplate = ReportTemplate::factory()->create();
$this->actingAs(User::factory()->canViewReports()->create())
2024-11-07 16:54:55 -08:00
->delete(route('report-templates.destroy', $reportTemplate->id))
2024-10-31 12:34:06 -07:00
->assertNotFound();
2024-10-22 17:37:23 -07:00
$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)
2024-11-07 16:54:55 -08:00
->delete(route('report-templates.destroy', $reportTemplate->id))
2024-01-17 16:25:28 -08:00
->assertRedirect(route('reports/custom'));
2024-11-07 16:40:37 -08:00
$this->assertSoftDeleted($reportTemplate);
2024-01-17 13:19:54 -08:00
}
}