2024-09-12 16:20:32 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\CustomFields\Api;
|
|
|
|
|
|
|
|
use App\Models\CustomField;
|
|
|
|
use App\Models\CustomFieldset;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\Concerns\TestsPermissionsRequirement;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class DeleteCustomFieldsTest extends TestCase implements TestsPermissionsRequirement
|
|
|
|
{
|
|
|
|
public function testRequiresPermission()
|
|
|
|
{
|
2024-09-12 16:54:29 -07:00
|
|
|
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
|
|
|
|
|
2024-09-12 16:20:32 -07:00
|
|
|
$customField = CustomField::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->deleteJson(route('api.customfields.destroy', $customField))
|
|
|
|
->assertForbidden();
|
2024-09-16 14:32:38 -07:00
|
|
|
|
|
|
|
$this->assertDatabaseHas('custom_fields', ['id' => $customField->id]);
|
2024-09-12 16:20:32 -07:00
|
|
|
}
|
|
|
|
|
2024-09-16 14:25:11 -07:00
|
|
|
public function testCustomFieldsCannotBeDeletedIfTheyHaveAssociatedFieldsets()
|
2024-09-12 16:20:32 -07:00
|
|
|
{
|
2024-09-12 16:54:29 -07:00
|
|
|
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
|
|
|
|
|
2024-09-12 16:20:32 -07:00
|
|
|
$customField = CustomField::factory()->create();
|
2024-09-16 14:25:11 -07:00
|
|
|
$customFieldset = CustomFieldset::factory()->create();
|
|
|
|
|
|
|
|
$customField->fieldset()->attach($customFieldset, ['order' => 1, 'required' => 'false']);
|
2024-09-12 16:20:32 -07:00
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->deleteCustomFields()->create())
|
|
|
|
->deleteJson(route('api.customfields.destroy', $customField))
|
2024-09-16 14:25:11 -07:00
|
|
|
->assertStatusMessageIs('error');
|
2024-09-12 16:20:32 -07:00
|
|
|
|
2024-09-16 14:25:11 -07:00
|
|
|
$this->assertDatabaseHas('custom_fields', ['id' => $customField->id]);
|
2024-09-12 16:20:32 -07:00
|
|
|
}
|
|
|
|
|
2024-09-16 14:25:11 -07:00
|
|
|
public function testCustomFieldsCanBeDeleted()
|
2024-09-12 16:20:32 -07:00
|
|
|
{
|
|
|
|
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
|
|
|
|
|
|
|
|
$customField = CustomField::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->deleteCustomFields()->create())
|
|
|
|
->deleteJson(route('api.customfields.destroy', $customField))
|
2024-09-16 14:25:11 -07:00
|
|
|
->assertStatusMessageIs('success');
|
2024-09-12 16:20:32 -07:00
|
|
|
|
2024-09-16 14:25:11 -07:00
|
|
|
$this->assertDatabaseMissing('custom_fields', ['id' => $customField->id]);
|
2024-09-12 16:20:32 -07:00
|
|
|
}
|
|
|
|
}
|