A free open source IT asset/license management system
Added tests
snipece15cac6450b
diff --git a/tests/Feature/AssetModels/Ui/BulkDeleteAssetModelsTest.php b/tests/Feature/AssetModels/Ui/BulkDeleteAssetModelsTest.phpnew file mode 100644index 0000000000..56b303a306--- /dev/null+++ b/tests/Feature/AssetModels/Ui/BulkDeleteAssetModelsTest.php@@ -0,0 +1,58 @@+<?php++namespace Tests\Feature\AssetModels\Ui;++use App\Models\Asset;+use App\Models\AssetModel;+use App\Models\User;+use Tests\TestCase;++class BulkDeleteAssetModelsTest extends TestCase+{+ public function test_shows_confirmation_when_at_least_one_model_is_deletable()+ {+ // One model has assets attached (not deletable), one is clean.+ $modelWithAssets = AssetModel::factory()->create();+ Asset::factory()->for($modelWithAssets, 'model')->create();+ $cleanModel = AssetModel::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('models.bulkedit.index'), [+ 'ids' => [$modelWithAssets->id, $cleanModel->id],+ 'bulk_actions' => 'delete',+ ])+ ->assertStatus(200)+ ->assertSee($modelWithAssets->name)+ ->assertSee($cleanModel->name);+ }++ public function test_redirects_to_index_with_error_when_no_selected_models_are_deletable()+ {+ // Both models have assets attached, so neither is deletable.+ $modelA = AssetModel::factory()->create();+ Asset::factory()->for($modelA, 'model')->create();+ $modelB = AssetModel::factory()->create();+ Asset::factory()->for($modelB, 'model')->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->from(route('models.index'))+ ->post(route('models.bulkedit.index'), [+ 'ids' => [$modelA->id, $modelB->id],+ 'bulk_actions' => 'delete',+ ])+ ->assertRedirect(route('models.index'))+ ->assertSessionHas('error');+ }++ public function test_redirects_to_index_when_no_models_selected()+ {+ $this->actingAs(User::factory()->superuser()->create())+ ->from(route('models.index'))+ ->post(route('models.bulkedit.index'), [+ 'ids' => null,+ 'bulk_actions' => 'delete',+ ])+ ->assertRedirect(route('models.index'))+ ->assertSessionHas('error');+ }+}diff --git a/tests/Feature/Locations/Ui/BulkDeleteLocationsTest.php b/tests/Feature/Locations/Ui/BulkDeleteLocationsTest.phpnew file mode 100644index 0000000000..078a6bbf76--- /dev/null+++ b/tests/Feature/Locations/Ui/BulkDeleteLocationsTest.php@@ -0,0 +1,55 @@+<?php++namespace Tests\Feature\Locations\Ui;++use App\Models\Asset;+use App\Models\Location;+use App\Models\User;+use Tests\TestCase;++class BulkDeleteLocationsTest extends TestCase+{+ public function test_shows_confirmation_when_at_least_one_location_is_deletable()+ {+ // One location has assets (not deletable), one is clean.+ $locationWithAssets = Location::factory()->create();+ Asset::factory()->for($locationWithAssets, 'location')->create();+ $cleanLocation = Location::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkdelete.show'), [+ 'ids' => [$locationWithAssets->id, $cleanLocation->id],+ ])+ ->assertStatus(200)+ ->assertSee($locationWithAssets->name)+ ->assertSee($cleanLocation->name);+ }++ public function test_redirects_to_index_with_error_when_no_selected_locations_are_deletable()+ {+ // Both locations have assets, so neither is deletable.+ $locationA = Location::factory()->create();+ Asset::factory()->for($locationA, 'location')->create();+ $locationB = Location::factory()->create();+ Asset::factory()->for($locationB, 'location')->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->from(route('locations.index'))+ ->post(route('locations.bulkdelete.show'), [+ 'ids' => [$locationA->id, $locationB->id],+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('error');+ }++ public function test_redirects_to_index_when_no_locations_selected()+ {+ $this->actingAs(User::factory()->superuser()->create())+ ->from(route('locations.index'))+ ->post(route('locations.bulkdelete.show'), [+ 'ids' => null,+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('error');+ }+}