A free open source IT asset/license management system
Added more tests
snipe22d651e696ee
diff --git a/tests/Feature/Components/ComponentArchiveValidationTest.php b/tests/Feature/Components/ComponentArchiveValidationTest.phpnew file mode 100644index 0000000000..697feb9ddf--- /dev/null+++ b/tests/Feature/Components/ComponentArchiveValidationTest.php@@ -0,0 +1,94 @@+<?php++namespace Tests\Feature\Components;++use App\Models\Asset;+use App\Models\Category;+use App\Models\Component;+use Tests\TestCase;++/**+ * Exercises Watson's integration of the archive-related rules on the+ * Component model (the mutex plus the no-archive-with-active-checkouts+ * guard). These fire through getRules() so test the full save path+ * end-to-end rather than hitting the Rule classes in isolation.+ */+class ComponentArchiveValidationTest extends TestCase+{+ public function test_component_can_save_as_requestable_without_archived(): void+ {+ $component = Component::factory()->create();++ $component->requestable = 1;+ $component->archived = 0;++ $this->assertTrue($component->save());+ }++ public function test_component_can_save_as_archived_without_requestable(): void+ {+ $component = Component::factory()->create();++ $component->archived = 1;+ $component->requestable = 0;++ $this->assertTrue($component->save());+ }++ public function test_component_cannot_save_as_both_requestable_and_archived(): void+ {+ $component = Component::factory()->create();++ $component->requestable = 1;+ $component->archived = 1;++ $this->assertFalse($component->save());+ $this->assertArrayHasKey('archived', $component->getErrors()->toArray());+ $this->assertArrayHasKey('requestable', $component->getErrors()->toArray());+ }++ public function test_component_with_active_checkouts_cannot_be_archived(): void+ {+ $component = Component::factory()->create(['qty' => 10]);+ $asset = Asset::factory()->create();+ $component->assets()->attach($asset->id, [+ 'assigned_qty' => 2,+ 'created_at' => now(),+ 'created_by' => 1,+ ]);++ $component->archived = 1;++ $this->assertFalse($component->save());+ $this->assertSame(+ trans('admin/components/message.archived_blocked_by_checkouts'),+ $component->getErrors()->get('archived')[0],+ );+ }++ public function test_component_without_active_checkouts_can_be_archived(): void+ {+ $component = Component::factory()->create(['qty' => 10]);++ $component->archived = 1;++ $this->assertTrue($component->save());+ }++ public function test_new_component_can_be_created_as_archived(): void+ {+ // Regression check: ComponentsController::store() was setting+ // every attribute by hand and skipping `archived`, so a form+ // POST with `archived=1` persisted as 0. Pin so a future refactor+ // can't silently drop the field again.+ $component = new Component([+ 'name' => 'archived at birth',+ 'qty' => 1,+ 'category_id' => Category::factory()->create()->id,+ ]);+ $component->archived = 1;++ $this->assertTrue($component->save());+ $this->assertTrue((bool) $component->fresh()->archived);+ }+}diff --git a/tests/Feature/Components/Ui/ArchivedComponentCheckoutGuardTest.php b/tests/Feature/Components/Ui/ArchivedComponentCheckoutGuardTest.phpnew file mode 100644index 0000000000..d8cd8473fa--- /dev/null+++ b/tests/Feature/Components/Ui/ArchivedComponentCheckoutGuardTest.php@@ -0,0 +1,47 @@+<?php++namespace Tests\Feature\Components\Ui;++use App\Models\Asset;+use App\Models\Component;+use App\Models\User;+use Tests\TestCase;++class ArchivedComponentCheckoutGuardTest extends TestCase+{+ public function test_checkout_create_screen_blocks_archived_component(): void+ {+ $component = Component::factory()->archived()->create(['qty' => 5]);++ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('components.checkout.show', ['componentID' => $component->id]))+ ->assertRedirect(route('components.index'))+ ->assertSessionHas('error', trans('admin/components/message.checkout.archived'));+ }++ public function test_checkout_store_blocks_archived_component(): void+ {+ $component = Component::factory()->archived()->create(['qty' => 5]);+ $asset = Asset::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.checkout.store', ['componentID' => $component->id]), [+ 'asset_id' => $asset->id,+ 'assigned_qty' => 1,+ ])+ ->assertRedirect(route('components.index'))+ ->assertSessionHas('error', trans('admin/components/message.checkout.archived'));++ // No pivot row created.+ $this->assertSame(0, $component->assets()->count());+ }++ public function test_checkout_create_screen_allows_non_archived_component(): void+ {+ $component = Component::factory()->create(['qty' => 5]);++ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('components.checkout.show', ['componentID' => $component->id]))+ ->assertOk();+ }+}diff --git a/tests/Feature/Components/Ui/BulkCheckinComponentsTest.php b/tests/Feature/Components/Ui/BulkCheckinComponentsTest.phpnew file mode 100644index 0000000000..12731f7880--- /dev/null+++ b/tests/Feature/Components/Ui/BulkCheckinComponentsTest.php@@ -0,0 +1,95 @@+<?php++namespace Tests\Feature\Components\Ui;++use App\Events\CheckoutableCheckedIn;+use App\Models\Asset;+use App\Models\Component;+use App\Models\ComponentAssignment;+use App\Models\User;+use Illuminate\Support\Facades\Event;+use Tests\TestCase;++class BulkCheckinComponentsTest extends TestCase+{+ private function attachCheckout(Component $component, Asset $asset, int $qty = 1): int+ {+ $component->assets()->attach($asset->id, [+ 'assigned_qty' => $qty,+ 'created_at' => now(),+ 'created_by' => 1,+ ]);++ return (int) ComponentAssignment::where('component_id', $component->id)+ ->where('asset_id', $asset->id)+ ->latest('id')+ ->value('id');+ }++ public function test_requires_checkin_permission(): void+ {+ $component = Component::factory()->create(['qty' => 5]);+ $asset = Asset::factory()->create();+ $pivotId = $this->attachCheckout($component, $asset);++ $this->actingAs(User::factory()->viewComponents()->create())+ ->post(route('components.bulkcheckin.selected'), ['ids' => [$pivotId]])+ ->assertRedirect();++ $this->assertDatabaseHas('components_assets', ['id' => $pivotId]);+ }++ public function test_removes_pivot_rows_and_fires_event(): void+ {+ Event::fake([CheckoutableCheckedIn::class]);++ $component = Component::factory()->create(['qty' => 10]);+ $assetA = Asset::factory()->create();+ $assetB = Asset::factory()->create();++ $pivotA = $this->attachCheckout($component, $assetA, 2);+ $pivotB = $this->attachCheckout($component, $assetB, 3);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkcheckin.selected'), ['ids' => [$pivotA, $pivotB]])+ ->assertRedirect()+ ->assertSessionHas('success');++ $this->assertDatabaseMissing('components_assets', ['id' => $pivotA]);+ $this->assertDatabaseMissing('components_assets', ['id' => $pivotB]);++ // Fully-returned pivots mean the component is now entirely+ // back in stock.+ $this->assertSame(0, (int) $component->fresh()->numCheckedOut(true));++ Event::assertDispatchedTimes(CheckoutableCheckedIn::class, 2);+ }++ public function test_warns_when_no_rows_selected(): void+ {+ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkcheckin.selected'), ['ids' => []])+ ->assertRedirect()+ ->assertSessionHas('warning');+ }++ public function test_unknown_pivot_ids_are_silently_skipped(): void+ {+ // Mirrors the LicenseCheckinController flow: stale pivot ids+ // posted from a dropdown-swap race just get skipped so the+ // real selections still check in cleanly.+ Event::fake([CheckoutableCheckedIn::class]);++ $component = Component::factory()->create(['qty' => 10]);+ $asset = Asset::factory()->create();+ $pivotId = $this->attachCheckout($component, $asset);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkcheckin.selected'), ['ids' => [$pivotId, 999999]])+ ->assertRedirect()+ ->assertSessionHas('success');++ $this->assertDatabaseMissing('components_assets', ['id' => $pivotId]);+ Event::assertDispatchedTimes(CheckoutableCheckedIn::class, 1);+ }+}diff --git a/tests/Feature/Components/Ui/BulkComponentsFmcsScopingTest.php b/tests/Feature/Components/Ui/BulkComponentsFmcsScopingTest.phpnew file mode 100644index 0000000000..3ef36c9988--- /dev/null+++ b/tests/Feature/Components/Ui/BulkComponentsFmcsScopingTest.php@@ -0,0 +1,146 @@+<?php++namespace Tests\Feature\Components\Ui;++use App\Events\CheckoutableCheckedIn;+use App\Models\Asset;+use App\Models\Company;+use App\Models\Component;+use App\Models\ComponentAssignment;+use App\Models\User;+use Illuminate\Support\Facades\Event;+use Tests\TestCase;++/**+ * Adversarial cross-company tests for every bulk endpoint added in+ * this feature slice. These are belt-and-braces: the controllers+ * route through auto-scoped Component queries, so cross-company ids+ * should never reach the per-row handlers. Pin the behavior anyway+ * because any future refactor that bypasses the CompanyableScope+ * (e.g. switching to a raw DB query) would otherwise silently open+ * a cross-tenant hole.+ */+class BulkComponentsFmcsScopingTest extends TestCase+{+ private function pivotId(Component $component, Asset $asset): int+ {+ $component->assets()->attach($asset->id, [+ 'assigned_qty' => 1,+ 'created_at' => now(),+ 'created_by' => 1,+ ]);++ return (int) ComponentAssignment::where('component_id', $component->id)+ ->where('asset_id', $asset->id)+ ->latest('id')+ ->value('id');+ }++ public function test_bulk_delete_cannot_delete_cross_company_component_under_fmcs(): void+ {+ $this->settings->enableMultipleFullCompanySupport();++ [$companyA, $companyB] = Company::factory()->count(2)->create();+ $actor = $companyA->users()->save(User::factory()->editComponents()->deleteComponents()->viewComponents()->make());+ $target = Component::factory()->for($companyB)->create();++ $this->actingAs($actor)+ ->post(route('components.bulkdelete.store'), ['ids' => [$target->id]])+ ->assertRedirect(route('components.index'));++ $this->assertNull($target->fresh()->deleted_at);+ }++ public function test_bulk_edit_dispatcher_does_not_leak_cross_company_component_under_fmcs(): void+ {+ $this->settings->enableMultipleFullCompanySupport();++ [$companyA, $companyB] = Company::factory()->count(2)->create();+ $actor = $companyA->users()->save(User::factory()->viewComponents()->editComponents()->checkinComponents()->make());++ $visible = Component::factory()->for($companyA)->create(['name' => 'Visible']);+ $hidden = Component::factory()->for($companyB)->create(['name' => 'Hidden']);++ $response = $this->actingAs($actor)+ ->post(route('components.bulkedit.show'), [+ 'ids' => [$visible->id, $hidden->id],+ 'bulk_actions' => 'edit',+ ])+ ->assertOk()+ ->assertViewIs('components.bulk-edit');++ $components = $response->viewData('components');+ $this->assertTrue($components->contains('id', $visible->id));+ $this->assertFalse($components->contains('id', $hidden->id));+ }++ public function test_bulk_update_cannot_write_cross_company_component_under_fmcs(): void+ {+ $this->settings->enableMultipleFullCompanySupport();++ [$companyA, $companyB] = Company::factory()->count(2)->create();+ $actor = $companyA->users()->save(User::factory()->editComponents()->viewComponents()->make());++ $target = Component::factory()->for($companyB)->create();+ $originalName = $target->name;++ $this->actingAs($actor)+ ->post(route('components.bulkedit.store'), [+ 'ids' => [$target->id],+ 'archived' => '1',+ ])+ ->assertRedirect(route('components.index'));++ $fresh = $target->fresh();+ $this->assertSame($originalName, $fresh->name);+ $this->assertFalse((bool) $fresh->archived);+ }++ public function test_bulk_checkin_cannot_check_in_cross_company_pivot_under_fmcs(): void+ {+ // Floater off: company A actor should not be able to check in+ // pivots whose component belongs to company B, even if they+ // post the pivot id by hand (the row isn't in their table).+ Event::fake([CheckoutableCheckedIn::class]);++ $this->settings->enableMultipleFullCompanySupport();+ $this->settings->disableFloaterMode();++ [$companyA, $companyB] = Company::factory()->count(2)->create();+ $actor = $companyA->users()->save(User::factory()->viewComponents()->editComponents()->checkinComponents()->make());++ $foreignComponent = Component::factory()->for($companyB)->create(['qty' => 5]);+ $pivot = $this->pivotId($foreignComponent, Asset::factory()->create());++ $this->actingAs($actor)+ ->post(route('components.bulkcheckin.selected'), ['ids' => [$pivot]])+ ->assertRedirect();++ $this->assertDatabaseHas('components_assets', ['id' => $pivot]);+ Event::assertNothingDispatched();+ }++ public function test_bulk_checkin_floater_can_checkin_null_company_pivot(): void+ {+ // Floater ON: company A actor is allowed to touch null-company+ // (floater) components. Pin so a future refactor that over-+ // tightens the subquery doesn't block a legitimate flow.+ Event::fake([CheckoutableCheckedIn::class]);++ $this->settings->enableFloaterMode();++ $companyA = Company::factory()->create();+ $actor = $companyA->users()->save(User::factory()->viewComponents()->editComponents()->checkinComponents()->make());++ $floater = Component::factory()->create(['company_id' => null, 'qty' => 5]);+ $pivot = $this->pivotId($floater, Asset::factory()->create());++ $this->actingAs($actor)+ ->post(route('components.bulkcheckin.selected'), ['ids' => [$pivot]])+ ->assertRedirect()+ ->assertSessionHas('success');++ $this->assertDatabaseMissing('components_assets', ['id' => $pivot]);+ Event::assertDispatched(CheckoutableCheckedIn::class);+ }+}diff --git a/tests/Feature/Components/Ui/BulkDeleteComponentsTest.php b/tests/Feature/Components/Ui/BulkDeleteComponentsTest.phpnew file mode 100644index 0000000000..8efe04dab1--- /dev/null+++ b/tests/Feature/Components/Ui/BulkDeleteComponentsTest.php@@ -0,0 +1,69 @@+<?php++namespace Tests\Feature\Components\Ui;++use App\Models\Asset;+use App\Models\Component;+use App\Models\User;+use Tests\TestCase;++class BulkDeleteComponentsTest extends TestCase+{+ public function test_requires_delete_permission(): void+ {+ $component = Component::factory()->create();++ $this->actingAs(User::factory()->viewComponents()->create())+ ->post(route('components.bulkdelete.store'), ['ids' => [$component->id]])+ ->assertForbidden();++ $this->assertNull($component->fresh()->deleted_at);+ }++ public function test_soft_deletes_selected_components(): void+ {+ $one = Component::factory()->create();+ $two = Component::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkdelete.store'), ['ids' => [$one->id, $two->id]])+ ->assertRedirect(route('components.index'))+ ->assertSessionHas('success');++ $this->assertNotNull($one->fresh()->deleted_at);+ $this->assertNotNull($two->fresh()->deleted_at);+ }++ public function test_skips_components_with_active_checkouts(): void+ {+ // Pin so a future refactor can't silently delete checked-out+ // components. isDeletable() returns false while any pivot row+ // has a positive assigned_qty, so the handler should route+ // this row into the error bucket instead of calling delete().+ $clean = Component::factory()->create();++ $withCheckouts = Component::factory()->create(['qty' => 10]);+ $asset = Asset::factory()->create();+ $withCheckouts->assets()->attach($asset->id, [+ 'assigned_qty' => 1,+ 'created_at' => now(),+ 'created_by' => 1,+ ]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkdelete.store'), ['ids' => [$clean->id, $withCheckouts->id]])+ ->assertRedirect(route('components.index'))+ ->assertSessionHas('multi_error_messages');++ $this->assertNotNull($clean->fresh()->deleted_at);+ $this->assertNull($withCheckouts->fresh()->deleted_at);+ }++ public function test_unknown_ids_fall_through_to_error_bucket(): void+ {+ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkdelete.store'), ['ids' => [999999]])+ ->assertRedirect(route('components.index'))+ ->assertSessionHas('multi_error_messages');+ }+}diff --git a/tests/Feature/Components/Ui/BulkEditComponentsTest.php b/tests/Feature/Components/Ui/BulkEditComponentsTest.phpnew file mode 100644index 0000000000..ffbcaa6566--- /dev/null+++ b/tests/Feature/Components/Ui/BulkEditComponentsTest.php@@ -0,0 +1,180 @@+<?php++namespace Tests\Feature\Components\Ui;++use App\Models\Category;+use App\Models\Company;+use App\Models\Component;+use App\Models\Location;+use App\Models\Manufacturer;+use App\Models\Supplier;+use App\Models\User;+use Tests\TestCase;++class BulkEditComponentsTest extends TestCase+{+ public function test_requires_update_permission_to_save(): void+ {+ $component = Component::factory()->create();++ $this->actingAs(User::factory()->viewComponents()->create())+ ->post(route('components.bulkedit.store'), [+ 'ids' => [$component->id],+ 'archived' => '1',+ ])+ ->assertForbidden();++ $this->assertFalse((bool) $component->fresh()->archived);+ }++ public function test_dispatcher_shows_edit_view_for_edit_action(): void+ {+ $component = Component::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkedit.show'), [+ 'ids' => [$component->id],+ 'bulk_actions' => 'edit',+ ])+ ->assertOk()+ ->assertViewIs('components.bulk-edit');+ }++ public function test_dispatcher_shows_delete_view_for_delete_action(): void+ {+ $component = Component::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkedit.show'), [+ 'ids' => [$component->id],+ 'bulk_actions' => 'delete',+ ])+ ->assertOk()+ ->assertViewIs('components.bulk-delete');+ }++ public function test_dispatcher_rejects_empty_selection(): void+ {+ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkedit.show'), ['bulk_actions' => 'edit'])+ ->assertRedirect(route('components.index'))+ ->assertSessionHas('error');+ }++ public function test_update_writes_only_provided_fields(): void+ {+ // Blank form inputs mean "keep as-is". Mirror a form POST where+ // only location changes to confirm every other column is left+ // alone across the selected rows.+ $originalCategory = Category::factory()->create();+ $originalLocation = Location::factory()->create();+ $newLocation = Location::factory()->create();++ $one = Component::factory()->create([+ 'category_id' => $originalCategory->id,+ 'location_id' => $originalLocation->id,+ 'min_amt' => 5,+ ]);+ $two = Component::factory()->create([+ 'category_id' => $originalCategory->id,+ 'location_id' => $originalLocation->id,+ 'min_amt' => 5,+ ]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkedit.store'), [+ 'ids' => [$one->id, $two->id],+ 'company_id' => '',+ 'category_id' => '',+ 'manufacturer_id' => '',+ 'location_id' => (string) $newLocation->id,+ 'default_supplier_id' => '',+ 'min_amt' => '',+ 'requestable' => '',+ 'archived' => '',+ ])+ ->assertRedirect(route('components.index'))+ ->assertSessionHas('success');++ $this->assertSame($newLocation->id, $one->fresh()->location_id);+ $this->assertSame($newLocation->id, $two->fresh()->location_id);+ $this->assertSame($originalCategory->id, $one->fresh()->category_id);+ $this->assertSame(5, (int) $one->fresh()->min_amt);+ }++ public function test_update_can_set_archived_across_selection(): void+ {+ $one = Component::factory()->create();+ $two = Component::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkedit.store'), [+ 'ids' => [$one->id, $two->id],+ 'archived' => '1',+ ])+ ->assertRedirect(route('components.index'));++ $this->assertTrue((bool) $one->fresh()->archived);+ $this->assertTrue((bool) $two->fresh()->archived);+ }++ public function test_update_rejects_empty_selection(): void+ {+ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkedit.store'), ['archived' => '1'])+ ->assertRedirect(route('components.index'))+ ->assertSessionHas('error');+ }++ public function test_update_warns_when_no_fields_posted(): void+ {+ $component = Component::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkedit.store'), [+ 'ids' => [$component->id],+ ])+ ->assertRedirect(route('components.index'))+ ->assertSessionHas('warning');+ }++ public function test_update_covers_full_classification_field_set(): void+ {+ // The field set exposed by BulkComponentsController::EDITABLE_FIELDS+ // is the contract the UI depends on. If someone narrows it (removes+ // a column from EDITABLE_FIELDS or the bulk-edit view), that column+ // silently stops writing across the selection. Pin all of them so+ // the regression surfaces here.+ $company = Company::factory()->create();+ $category = Category::factory()->create();+ $manufacturer = Manufacturer::factory()->create();+ $location = Location::factory()->create();+ $supplier = Supplier::factory()->create();++ $component = Component::factory()->create(['min_amt' => 1]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('components.bulkedit.store'), [+ 'ids' => [$component->id],+ 'company_id' => (string) $company->id,+ 'category_id' => (string) $category->id,+ 'manufacturer_id' => (string) $manufacturer->id,+ 'location_id' => (string) $location->id,+ 'default_supplier_id' => (string) $supplier->id,+ 'min_amt' => '42',+ 'requestable' => '1',+ 'archived' => '0',+ ])+ ->assertRedirect(route('components.index'));++ $fresh = $component->fresh();+ $this->assertSame($company->id, $fresh->company_id);+ $this->assertSame($category->id, $fresh->category_id);+ $this->assertSame($manufacturer->id, $fresh->manufacturer_id);+ $this->assertSame($location->id, $fresh->location_id);+ $this->assertSame($supplier->id, $fresh->default_supplier_id);+ $this->assertSame(42, (int) $fresh->min_amt);+ $this->assertTrue((bool) $fresh->requestable);+ $this->assertFalse((bool) $fresh->archived);+ }+}diff --git a/tests/Feature/Helpers/CheckLowInventoryTest.php b/tests/Feature/Helpers/CheckLowInventoryTest.phpindex 33b8801b95..71f96c305f 100644--- a/tests/Feature/Helpers/CheckLowInventoryTest.php+++ b/tests/Feature/Helpers/CheckLowInventoryTest.php@@ -178,6 +178,21 @@ class CheckLowInventoryTest extends TestCase$this->assertSame(0, (int) $rows[$component->id]['remaining']);}+ public function test_archived_component_is_excluded_even_when_below_min_amt()+ {+ // Archived components are retired from active inventory and+ // should not drive low-stock alerts even when they fall below+ // their min_amt threshold.+ $this->settings->set(['alert_threshold' => 0]);++ $component = Component::factory()->archived()->create(['qty' => 1, 'min_amt' => 5]);++ $this->assertNotContains(+ $component->id,+ $this->idsForType(Helper::checkLowInventory(), 'components'),+ );+ }+/*** Sums across multiple pivot rows too: 4 + 3 = 7 units shipped, so* a qty=10 component reports remaining=3, not 8 (row-count) ordiff --git a/tests/Unit/Components/ComponentQueryBuilderArchivedScopeTest.php b/tests/Unit/Components/ComponentQueryBuilderArchivedScopeTest.phpnew file mode 100644index 0000000000..406b7ca2ac--- /dev/null+++ b/tests/Unit/Components/ComponentQueryBuilderArchivedScopeTest.php@@ -0,0 +1,68 @@+<?php++namespace Tests\Unit\Components;++use App\Models\Component;+use Tests\TestCase;++class ComponentQueryBuilderArchivedScopeTest extends TestCase+{+ public function test_archived_scope_returns_only_archived(): void+ {+ $live = Component::factory()->create();+ $archived = Component::factory()->archived()->create();++ $ids = Component::query()->archived()->pluck('id')->all();++ $this->assertContains($archived->id, $ids);+ $this->assertNotContains($live->id, $ids);+ }++ public function test_not_archived_scope_excludes_archived(): void+ {+ $live = Component::factory()->create();+ $archived = Component::factory()->archived()->create();++ $ids = Component::query()->notArchived()->pluck('id')->all();++ $this->assertContains($live->id, $ids);+ $this->assertNotContains($archived->id, $ids);+ }++ public function test_components_for_show_hides_archived_when_setting_off(): void+ {+ $this->settings->set(['show_archived_in_list' => 0]);++ $live = Component::factory()->create();+ $archived = Component::factory()->archived()->create();++ $ids = Component::query()->componentsForShow()->pluck('id')->all();++ $this->assertContains($live->id, $ids);+ $this->assertNotContains($archived->id, $ids);+ }++ public function test_components_for_show_includes_archived_when_setting_on(): void+ {+ $this->settings->set(['show_archived_in_list' => 1]);++ $live = Component::factory()->create();+ $archived = Component::factory()->archived()->create();++ $ids = Component::query()->componentsForShow()->pluck('id')->all();++ $this->assertContains($live->id, $ids);+ $this->assertContains($archived->id, $ids);+ }++ public function test_requestable_scope_excludes_archived(): void+ {+ $requestable = Component::factory()->create(['requestable' => 1]);+ $archivedButRequestable = Component::factory()->archived()->create(['requestable' => 1]);++ $ids = Component::query()->requestable()->pluck('id')->all();++ $this->assertContains($requestable->id, $ids);+ $this->assertNotContains($archivedButRequestable->id, $ids);+ }+}diff --git a/tests/Unit/Rules/RequestableArchivedMutexTest.php b/tests/Unit/Rules/RequestableArchivedMutexTest.phpnew file mode 100644index 0000000000..289217bbc8--- /dev/null+++ b/tests/Unit/Rules/RequestableArchivedMutexTest.php@@ -0,0 +1,57 @@+<?php++namespace Tests\Unit\Rules;++use App\Rules\RequestableArchivedMutex;+use Illuminate\Support\Facades\Validator;+use Tests\TestCase;++/**+ * The rule is wired on BOTH requestable and archived. Whichever side+ * is being toggled fires the conflict. Verify every corner of the+ * truth table rather than trusting prohibited_if-shaped semantics,+ * which treat `0` as "present and not empty" and mis-fire on+ * single-flag changes.+ */+class RequestableArchivedMutexTest extends TestCase+{+ private function validate(array $data): array+ {+ $v = Validator::make($data, [+ 'requestable' => ['nullable', 'boolean', new RequestableArchivedMutex],+ 'archived' => ['nullable', 'boolean', new RequestableArchivedMutex],+ ]);++ return $v->errors()->toArray();+ }++ public function test_both_truthy_fires_on_both_fields(): void+ {+ $errors = $this->validate(['requestable' => 1, 'archived' => 1]);++ $this->assertArrayHasKey('requestable', $errors);+ $this->assertArrayHasKey('archived', $errors);+ $this->assertSame(trans('general.requestable_archived_conflict'), $errors['requestable'][0]);+ }++ public function test_only_requestable_truthy_passes(): void+ {+ $this->assertEmpty($this->validate(['requestable' => 1, 'archived' => 0]));+ }++ public function test_only_archived_truthy_passes(): void+ {+ $this->assertEmpty($this->validate(['requestable' => 0, 'archived' => 1]));+ }++ public function test_both_falsy_passes(): void+ {+ $this->assertEmpty($this->validate(['requestable' => 0, 'archived' => 0]));+ }++ public function test_missing_sibling_passes(): void+ {+ $this->assertEmpty($this->validate(['archived' => 1]));+ $this->assertEmpty($this->validate(['requestable' => 1]));+ }+}