|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\CustomFieldsets\Api; |
| 4 | + |
| 5 | +use App\Models\CustomField; |
| 6 | +use App\Models\CustomFieldset; |
| 7 | +use App\Models\User; |
| 8 | +use Tests\Concerns\TestsPermissionsRequirement; |
| 9 | +use Tests\TestCase; |
| 10 | + |
| 11 | +class DeleteCustomFieldsetsTest extends TestCase implements TestsPermissionsRequirement |
| 12 | +{ |
| 13 | + public function testRequiresPermission() |
| 14 | + { |
| 15 | + $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL'); |
| 16 | + |
| 17 | + $customFieldset = CustomFieldset::factory()->create(); |
| 18 | + |
| 19 | + $this->actingAsForApi(User::factory()->create()) |
| 20 | + ->deleteJson(route('api.fieldsets.destroy', $customFieldset)) |
| 21 | + ->assertForbidden(); |
| 22 | + } |
| 23 | + |
| 24 | + public function testCanDeleteCustomFieldsets() |
| 25 | + { |
| 26 | + $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL'); |
| 27 | + |
| 28 | + $customFieldset = CustomFieldset::factory()->create(); |
| 29 | + |
| 30 | + $this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create()) |
| 31 | + ->deleteJson(route('api.fieldsets.destroy', $customFieldset)) |
| 32 | + ->assertStatusMessageIs('success'); |
| 33 | + |
| 34 | + $this->assertDatabaseMissing('custom_fieldsets', ['id' => $customFieldset->id]); |
| 35 | + } |
| 36 | + |
| 37 | + public function testCannotDeleteCustomFieldsetWithAssociatedFields() |
| 38 | + { |
| 39 | + $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL'); |
| 40 | + |
| 41 | + $customField = CustomField::factory()->create(); |
| 42 | + $customFieldset = CustomFieldset::factory()->create(); |
| 43 | + |
| 44 | + $customField->fieldset()->attach($customFieldset, ['order' => 1, 'required' => 'false']); |
| 45 | + |
| 46 | + $this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create()) |
| 47 | + ->deleteJson(route('api.fieldsets.destroy', $customFieldset)) |
| 48 | + ->assertStatusMessageIs('error'); |
| 49 | + |
| 50 | + $this->assertDatabaseHas('custom_fieldsets', ['id' => $customFieldset->id]); |
| 51 | + } |
| 52 | + |
| 53 | + public function testCannotDeleteCustomFieldsetWithAssociatedModels() |
| 54 | + { |
| 55 | + $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL'); |
| 56 | + |
| 57 | + $customFieldset = CustomFieldset::factory()->hasModels()->create(); |
| 58 | + |
| 59 | + $this->actingAsForApi(User::factory()->deleteCustomFieldsets()->create()) |
| 60 | + ->deleteJson(route('api.fieldsets.destroy', $customFieldset)) |
| 61 | + ->assertStatusMessageIs('error'); |
| 62 | + |
| 63 | + $this->assertDatabaseHas('custom_fieldsets', ['id' => $customFieldset->id]); |
| 64 | + } |
| 65 | +} |
0 commit comments