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

57 lines
1.8 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
use App\Models\ReportTemplate;
use App\Models\User;
use Tests\TestCase;
class UpdateReportTemplateTest extends TestCase
{
public function testUpdatingReportTemplateRequiresCorrectPermission()
{
2024-01-17 16:25:28 -08:00
$this->actingAs(User::factory()->create())
->post(route('report-templates.update', 1))
->assertForbidden();
}
public function testCanLoadEditReportTemplatePage()
{
$user = User::factory()->canViewReports()->create();
$reportTemplate = ReportTemplate::factory()->for($user)->create();
$this->actingAs($user)
->get(route('report-templates.edit', $reportTemplate))
->assertOk();
2024-01-17 13:19:54 -08:00
}
public function testCanUpdateAReportTemplate()
{
$user = User::factory()->canViewReports()->create();
2024-01-17 16:25:28 -08:00
$reportTemplate = ReportTemplate::factory()->for($user)->create([
'options' => [
'id' => 1,
2024-01-17 16:40:05 -08:00
'category' => 1,
'by_category_id' => 2,
2024-01-17 16:25:28 -08:00
'company' => 1,
'by_company_id' => [1, 2],
],
]);
2024-01-17 13:19:54 -08:00
$this->actingAs($user)
2024-01-17 16:25:28 -08:00
->post(route('report-templates.update', $reportTemplate), [
'id' => 1,
2024-01-17 16:40:05 -08:00
'company' => 1,
2024-01-17 16:25:28 -08:00
'by_company_id' => [3],
2024-01-17 16:40:05 -08:00
]);
$reportTemplate->refresh();
$this->assertEquals(1, $reportTemplate->checkmarkValue('id'));
$this->assertEquals(0, $reportTemplate->checkmarkValue('category'));
$this->assertEquals([], $reportTemplate->selectValues('by_category_id'));
$this->assertEquals(1, $reportTemplate->checkmarkValue('company'));
$this->assertEquals([3], $reportTemplate->selectValues('by_company_id'));
2024-01-17 13:19:54 -08:00
}
}