snipe-it/tests/Feature/CustomFieldsets/Api/DeleteCustomFieldsetsTest.php

68 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\CustomFieldsets\Api;
use App\Models\CustomField;
use App\Models\CustomFieldset;
use App\Models\User;
use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
class DeleteCustomFieldsetsTest extends TestCase implements TestsPermissionsRequirement
{
public function testRequiresPermission()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$customFieldset = CustomFieldset::factory()->create();
$this->actingAsForApi(User::factory()->create())
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
->assertForbidden();
2024-09-16 14:32:38 -07:00
$this->assertDatabaseHas('custom_fieldsets', ['id' => $customFieldset->id]);
}
2024-09-16 14:25:11 -07:00
public function testCannotDeleteCustomFieldsetWithAssociatedFields()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
2024-09-16 14:25:11 -07:00
$customField = CustomField::factory()->create();
$customFieldset = CustomFieldset::factory()->create();
2024-09-16 14:25:11 -07:00
$customField->fieldset()->attach($customFieldset, ['order' => 1, 'required' => 'false']);
$this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create())
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
2024-09-16 14:25:11 -07:00
->assertStatusMessageIs('error');
2024-09-16 14:25:11 -07:00
$this->assertDatabaseHas('custom_fieldsets', ['id' => $customFieldset->id]);
}
2024-09-16 14:25:11 -07:00
public function testCannotDeleteCustomFieldsetWithAssociatedModels()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
2024-09-16 14:25:11 -07:00
$customFieldset = CustomFieldset::factory()->hasModels()->create();
$this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create())
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
->assertStatusMessageIs('error');
$this->assertDatabaseHas('custom_fieldsets', ['id' => $customFieldset->id]);
}
2024-09-16 14:25:11 -07:00
public function testCanDeleteCustomFieldsets()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
2024-09-16 14:25:11 -07:00
$customFieldset = CustomFieldset::factory()->create();
$this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create())
->deleteJson(route('api.fieldsets.destroy', $customFieldset))
2024-09-16 14:25:11 -07:00
->assertStatusMessageIs('success');
2024-09-16 14:25:11 -07:00
$this->assertDatabaseMissing('custom_fieldsets', ['id' => $customFieldset->id]);
}
}