A free open source IT asset/license management system
Tests
snipe7e1910ef37e9
diff --git a/tests/Feature/Locations/Api/BulkSelectableTest.php b/tests/Feature/Locations/Api/BulkSelectableTest.phpnew file mode 100644index 0000000000..8bab755feb--- /dev/null+++ b/tests/Feature/Locations/Api/BulkSelectableTest.php@@ -0,0 +1,61 @@+<?php++namespace Tests\Feature\Locations\Api;++use App\Models\Asset;+use App\Models\Location;+use App\Models\User;+use Tests\TestCase;++/**+ * Verifies the JS-visible flag that drives the bulk-actions dropdown on+ * the locations index. bootstrap-table.blade.php intersects each selected+ * row's `available_actions.bulk_selectable` with the dropdown's static+ * action list, so an action only surfaces when every selected row+ * reports it. Locations must report both `edit` and `delete` under+ * bulk_selectable, gated on the acting user's edit permission and the+ * row's deletability respectively.+ */+class BulkSelectableTest extends TestCase+{+ public function test_clean_location_reports_edit_and_delete_as_bulk_selectable(): void+ {+ $location = Location::factory()->create();++ $this->actingAsForApi(User::factory()->superuser()->create())+ ->getJson(route('api.locations.show', $location))+ ->assertOk()+ ->assertJsonPath('available_actions.bulk_selectable.edit', true)+ ->assertJsonPath('available_actions.bulk_selectable.delete', true);+ }++ public function test_location_with_assets_reports_delete_as_not_bulk_selectable(): void+ {+ // Per-row bulk_selectable is truthful: delete gates on+ // isDeletable() so a location with dependents reports false.+ // bootstrap-table's index-page auto-uncheck picks up that+ // signal and clears the row's checkbox when the operator picks+ // "delete" from the bulk-actions dropdown. Edit stays true+ // because deletability blockers don't affect edit eligibility.+ $location = Location::factory()->create();+ Asset::factory()->for($location, 'location')->create();++ $this->actingAsForApi(User::factory()->superuser()->create())+ ->getJson(route('api.locations.show', $location))+ ->assertOk()+ ->assertJsonPath('available_actions.bulk_selectable.edit', true)+ ->assertJsonPath('available_actions.bulk_selectable.delete', false);+ }++ public function test_user_without_edit_permission_reports_edit_as_false(): void+ {+ $location = Location::factory()->create();++ // locations.view grants the show endpoint but not locations.edit,+ // so the row's bulk_selectable.edit must report false.+ $this->actingAsForApi(User::factory()->viewLocationHistory()->create())+ ->getJson(route('api.locations.show', $location))+ ->assertOk()+ ->assertJsonPath('available_actions.bulk_selectable.edit', false);+ }+}diff --git a/tests/Feature/Locations/Api/LocationsForSelectListTest.php b/tests/Feature/Locations/Api/LocationsForSelectListTest.phpindex a199641b12..a897f6430a 100644--- a/tests/Feature/Locations/Api/LocationsForSelectListTest.php+++ b/tests/Feature/Locations/Api/LocationsForSelectListTest.php@@ -49,6 +49,40 @@ class LocationsForSelectListTest extends TestCase);}+ public function test_multiple_locations_are_excluded_when_exclude_ids_is_a_comma_separated_list(): void+ {+ // Used by the bulk-edit form's parent picker so a location can't+ // be picked as its own new parent (or the parent of a sibling+ // in the same batch, which would collapse the hierarchy).+ [$locationA, $locationB, $locationC] = Location::factory()->count(3)->create();++ $response = $this->actingAsForApi(User::factory()->createUsers()->create())+ ->getJson(route('api.locations.selectlist', ['excludeIds' => $locationA->id.','.$locationB->id]))+ ->assertOk();++ $ids = collect($response->json('results'))->pluck('id')->all();+ $this->assertNotContains($locationA->id, $ids);+ $this->assertNotContains($locationB->id, $ids);+ $this->assertContains($locationC->id, $ids);+ }++ public function test_exclude_ids_also_accepts_a_native_array(): void+ {+ // Belt-and-braces: js-data-ajax forwards data-exclude-ids as a+ // comma-separated string, but a caller building the URL by hand+ // (Postman, cURL, etc.) could pass excludeIds[] as an array.+ [$locationA, $locationB, $locationC] = Location::factory()->count(3)->create();++ $response = $this->actingAsForApi(User::factory()->createUsers()->create())+ ->getJson(route('api.locations.selectlist', ['excludeIds' => [$locationA->id, $locationB->id]]))+ ->assertOk();++ $ids = collect($response->json('results'))->pluck('id')->all();+ $this->assertNotContains($locationA->id, $ids);+ $this->assertNotContains($locationB->id, $ids);+ $this->assertContains($locationC->id, $ids);+ }+public function test_locations_are_returned_when_user_is_updating_their_profile_and_has_permission_to_update_location(){$this->actingAsForApi(User::factory()->canEditOwnLocation()->create())diff --git a/tests/Feature/Locations/Ui/BulkDeleteLocationsTest.php b/tests/Feature/Locations/Ui/BulkDeleteLocationsTest.phpindex 078a6bbf76..fb18bb92ea 100644--- a/tests/Feature/Locations/Ui/BulkDeleteLocationsTest.php+++ b/tests/Feature/Locations/Ui/BulkDeleteLocationsTest.php@@ -52,4 +52,53 @@ class BulkDeleteLocationsTest extends TestCase->assertRedirect(route('locations.index'))->assertSessionHas('error');}++ public function test_confirmation_view_shows_blocking_dependency_counts_for_undeletable_rows()+ {+ // Populate several dependent-relations on the undeletable row+ // so the confirm view can render the per-icon counts for each.+ // Uses the icon-column layout mirroring users/confirm-bulk-delete:+ // each dependency type gets its own column with a header icon+ // and a per-row numeric count that is text-danger when >0.+ $undeletable = Location::factory()->create();+ Asset::factory()->count(2)->for($undeletable, 'location')->create();+ Location::factory()->count(3)->create(['parent_id' => $undeletable->id]);+ $deletable = Location::factory()->create();++ $response = $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkdelete.show'), [+ 'ids' => [$undeletable->id, $deletable->id],+ ])+ ->assertStatus(200);++ // Column icons in the table header. Icons match the tabs on the+ // location view page so the two surfaces read consistently.+ $response->assertSee('fa-barcode', false);+ $response->assertSee('fa-city', false);++ // Per-row counts on the undeletable row. 2 assets (assets_count+ // column) + 3 children (children_count column) each render in+ // their own cell as `text-danger">N</td>` when non-zero.+ $response->assertSee('text-danger">2</td>', false);+ $response->assertSee('text-danger">3</td>', false);+ }++ public function test_confirmation_view_shows_partial_selection_warning_when_some_rows_are_undeletable()+ {+ $undeletable = Location::factory()->create();+ Asset::factory()->for($undeletable, 'location')->create();+ $deletable = Location::factory()->create();++ $response = $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkdelete.show'), [+ 'ids' => [$undeletable->id, $deletable->id],+ ])+ ->assertStatus(200);++ // The partial-selection copy names both the selected count and+ // the smaller deletable count so the operator sees the batch+ // isn't going to fire against every row.+ $response->assertSeeText('You selected 2');+ $response->assertSeeText('1 will be deleted');+ }}diff --git a/tests/Feature/Locations/Ui/BulkEditLocationsTest.php b/tests/Feature/Locations/Ui/BulkEditLocationsTest.phpnew file mode 100644index 0000000000..0ce52509e1--- /dev/null+++ b/tests/Feature/Locations/Ui/BulkEditLocationsTest.php@@ -0,0 +1,598 @@+<?php++namespace Tests\Feature\Locations\Ui;++use App\Models\Company;+use App\Models\Location;+use App\Models\User;+use Tests\TestCase;++class BulkEditLocationsTest extends TestCase+{+ public function test_permission_required_to_render_bulk_edit_form(): void+ {+ $locations = Location::factory()->count(2)->create();++ $this->actingAs(User::factory()->create())+ ->post(route('locations.bulkdelete.show'), [+ 'bulk_actions' => 'edit',+ 'ids' => $locations->pluck('id')->all(),+ ])+ ->assertForbidden();+ }++ public function test_renders_bulk_edit_form_when_edit_action_is_selected(): void+ {+ $locations = Location::factory()->count(2)->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkdelete.show'), [+ 'bulk_actions' => 'edit',+ 'ids' => $locations->pluck('id')->all(),+ ])+ ->assertOk()+ ->assertSee($locations->first()->name)+ ->assertSee($locations->last()->name)+ ->assertSee(route('locations.bulkedit.store'), false);+ }++ public function test_redirects_to_index_when_no_ids_submitted_to_bulk_edit(): void+ {+ $this->actingAs(User::factory()->superuser()->create())+ ->from(route('locations.index'))+ ->post(route('locations.bulkdelete.show'), [+ 'bulk_actions' => 'edit',+ 'ids' => [],+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('error');+ }++ public function test_permission_required_to_save_bulk_edit(): void+ {+ $locations = Location::factory()->count(2)->create();++ $this->actingAs(User::factory()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => $locations->pluck('id')->all(),+ 'currency' => 'EUR',+ ])+ ->assertForbidden();+ }++ public function test_applies_parent_id_to_every_selected_location(): void+ {+ $newParent = Location::factory()->create();+ $targets = Location::factory()->count(3)->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => $targets->pluck('id')->all(),+ 'parent_id' => $newParent->id,+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ foreach ($targets as $target) {+ $this->assertSame($newParent->id, $target->fresh()->parent_id);+ }+ }++ public function test_skips_parent_id_on_the_row_that_would_become_its_own_parent(): void+ {+ // If the operator picks a location that is itself in the selection+ // as the new parent, that specific row must skip parent_id but+ // other rows in the selection still get moved under it. Other+ // fields on the self-picked row still apply.+ $selfPicked = Location::factory()->create();+ $sibling = Location::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$selfPicked->id, $sibling->id],+ 'parent_id' => $selfPicked->id,+ 'currency' => 'JPY',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $this->assertNull($selfPicked->fresh()->parent_id);+ $this->assertSame('JPY', $selfPicked->fresh()->currency);+ $this->assertSame($selfPicked->id, $sibling->fresh()->parent_id);+ $this->assertSame('JPY', $sibling->fresh()->currency);+ }++ public function test_applies_manager_id_and_currency_and_state_and_country(): void+ {+ $manager = User::factory()->create();+ $targets = Location::factory()->count(2)->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => $targets->pluck('id')->all(),+ 'manager_id' => $manager->id,+ 'currency' => 'CAD',+ 'state' => 'ON',+ 'country' => 'CA',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ foreach ($targets as $target) {+ $fresh = $target->fresh();+ $this->assertSame($manager->id, $fresh->manager_id);+ $this->assertSame('CAD', $fresh->currency);+ $this->assertSame('ON', $fresh->state);+ $this->assertSame('CA', $fresh->country);+ }+ }++ public function test_null_state_checkbox_clears_the_state_column(): void+ {+ $target = Location::factory()->create(['state' => 'CA']);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'null_state' => '1',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $this->assertNull($target->fresh()->state);+ }++ public function test_company_id_is_applied_only_when_fmcs_is_on(): void+ {+ $this->settings->enableMultipleFullCompanySupport();+ $company = Company::factory()->create();+ $target = Location::factory()->create(['company_id' => null]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'company_id' => $company->id,+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $this->assertSame($company->id, $target->fresh()->company_id);+ }++ public function test_company_id_is_ignored_when_fmcs_is_off(): void+ {+ $this->settings->disableMultipleFullCompanySupport();+ $company = Company::factory()->create();+ $target = Location::factory()->create(['company_id' => null]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'company_id' => $company->id,+ 'currency' => 'USD',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $fresh = $target->fresh();+ $this->assertNull($fresh->company_id);+ $this->assertSame('USD', $fresh->currency);+ }++ public function test_blank_fields_are_skipped_so_other_columns_survive(): void+ {+ // Operator only wants to change the currency. Every other field+ // on the row must survive the bulk write untouched.+ $existingManager = User::factory()->create();+ $target = Location::factory()->create([+ 'currency' => 'USD',+ 'country' => 'US',+ 'manager_id' => $existingManager->id,+ ]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'currency' => 'GBP',+ 'country' => '',+ 'manager_id' => '',+ 'parent_id' => '',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $fresh = $target->fresh();+ $this->assertSame('GBP', $fresh->currency);+ $this->assertSame('US', $fresh->country);+ $this->assertSame($existingManager->id, $fresh->manager_id);+ }++ public function test_all_blank_fields_returns_warning_and_updates_nothing(): void+ {+ $target = Location::factory()->create(['currency' => 'USD']);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'currency' => '',+ 'country' => '',+ 'manager_id' => '',+ 'parent_id' => '',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('warning');++ $this->assertSame('USD', $target->fresh()->currency);+ }++ public function test_non_superuser_cannot_bulk_reassign_company_even_within_their_own_memberships(): void+ {+ // Bulk company reassignment is superuser-only under FMCS. A+ // company-scoped user with multi-membership can still reassign+ // via the single-location edit path, but bulk has amplified+ // blast radius and the more defensive default applies here.+ $this->settings->enableMultipleFullCompanySupport();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $editor = User::factory()->editLocations()->forCompany($companyA)->create();+ $editor->companies()->sync([$companyA->id, $companyB->id]);++ $target = Location::factory()->create(['company_id' => $companyA->id]);++ $this->actingAs($editor)+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'company_id' => $companyB->id,+ 'currency' => 'EUR',+ ])+ ->assertRedirect(route('locations.index'));++ $fresh = $target->fresh();+ $this->assertSame($companyA->id, $fresh->company_id, 'Non-superuser cannot bulk-reassign company_id, even to a company they belong to.');+ $this->assertSame('EUR', $fresh->currency, 'Other fields still apply after the company_id is filtered out.');+ }++ public function test_non_superuser_cannot_null_company_in_bulk_when_fmcs_is_on(): void+ {+ $this->settings->enableMultipleFullCompanySupport();++ $companyA = Company::factory()->create();++ $editor = User::factory()->editLocations()->forCompany($companyA)->create();+ $editor->companies()->sync([$companyA->id]);++ $target = Location::factory()->create(['company_id' => $companyA->id]);++ $this->actingAs($editor)+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'null_company_id' => '1',+ 'currency' => 'EUR',+ ])+ ->assertRedirect(route('locations.index'));++ $fresh = $target->fresh();+ $this->assertSame($companyA->id, $fresh->company_id, 'Non-superuser null_company_id checkbox must be a no-op.');+ $this->assertSame('EUR', $fresh->currency);+ }++ public function test_superuser_can_reassign_company_in_bulk_when_fmcs_is_on(): void+ {+ $this->settings->enableMultipleFullCompanySupport();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $target = Location::factory()->create(['company_id' => $companyA->id]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'company_id' => $companyB->id,+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $this->assertSame($companyB->id, $target->fresh()->company_id);+ }++ public function test_scope_locations_fmcs_skips_company_id_on_rows_with_cross_company_users(): void+ {+ // Under FMCS + location scoping, reassigning a location's+ // company to a company that doesn't match items or users at+ // that location would create visibility mismatches. The bulk+ // path skips company_id per row instead of failing the whole+ // batch, so other fields on that row still apply and a warning+ // flash tells the operator how many rows were skipped.+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $clean = Location::factory()->create(['company_id' => $companyA->id]);++ // conflicted: has a user pinned at that location whose company+ // pivot is Company A. Moving the location to Company B would+ // leave the user stranded at a location whose tenant they+ // can't receive from under strict FMCS.+ $conflicted = Location::factory()->create(['company_id' => $companyA->id]);+ $userAtConflicted = User::factory()->forCompany($companyA)->create(['location_id' => $conflicted->id]);+ $userAtConflicted->companies()->sync([$companyA->id]);++ $response = $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$clean->id, $conflicted->id],+ 'company_id' => $companyB->id,+ 'currency' => 'JPY',+ ])+ ->assertRedirect(route('locations.index'));++ $this->assertSame($companyB->id, $clean->fresh()->company_id);+ $this->assertSame('JPY', $clean->fresh()->currency);+ $this->assertSame($companyA->id, $conflicted->fresh()->company_id);+ $this->assertSame('JPY', $conflicted->fresh()->currency);++ $response->assertSessionHas('success');+ $response->assertSessionHas('warning');+ }++ public function test_parent_id_is_skipped_when_new_parent_belongs_to_a_different_company(): void+ {+ // FMCS on. Location A is in Company X; picking a Company Y+ // parent would violate the child.company == parent.company+ // invariant that single-edit enforces. Bulk skips parent_id+ // for that row and applies other fields normally.+ $this->settings->enableMultipleFullCompanySupport();++ $companyX = Company::factory()->create();+ $companyY = Company::factory()->create();++ $mismatchedParent = Location::factory()->create(['company_id' => $companyY->id]);+ $target = Location::factory()->create(['company_id' => $companyX->id, 'parent_id' => null]);++ $response = $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'parent_id' => $mismatchedParent->id,+ 'currency' => 'USD',+ ])+ ->assertRedirect(route('locations.index'));++ $fresh = $target->fresh();+ $this->assertNull($fresh->parent_id, 'parent_id must be skipped when it would leave the child in a different company than its parent.');+ $this->assertSame('USD', $fresh->currency, 'Other fields still apply.');++ $response->assertSessionHas('warning');+ }++ public function test_company_id_is_skipped_when_existing_parent_would_be_in_different_company(): void+ {+ // FMCS on. Location has an existing parent in Company X.+ // Operator changes company_id to Company Y but leaves parent_id+ // untouched. That would violate the invariant, so company_id+ // is the skip (respect the existing hierarchy).+ $this->settings->enableMultipleFullCompanySupport();++ $companyX = Company::factory()->create();+ $companyY = Company::factory()->create();++ $existingParent = Location::factory()->create(['company_id' => $companyX->id]);+ $target = Location::factory()->create(['company_id' => $companyX->id, 'parent_id' => $existingParent->id]);++ $response = $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'company_id' => $companyY->id,+ 'currency' => 'USD',+ ])+ ->assertRedirect(route('locations.index'));++ $fresh = $target->fresh();+ $this->assertSame($companyX->id, $fresh->company_id, 'company_id must be skipped when the existing parent is in a different company.');+ $this->assertSame($existingParent->id, $fresh->parent_id);+ $this->assertSame('USD', $fresh->currency);++ $response->assertSessionHas('warning');+ }++ public function test_parent_and_company_together_are_allowed_when_they_match(): void+ {+ // FMCS on. Operator submits both parent_id and company_id and+ // they line up. No mismatch, no skip.+ $this->settings->enableMultipleFullCompanySupport();++ $companyY = Company::factory()->create();+ $newParent = Location::factory()->create(['company_id' => $companyY->id]);+ $target = Location::factory()->create(['company_id' => Company::factory()->create()->id, 'parent_id' => null]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'parent_id' => $newParent->id,+ 'company_id' => $companyY->id,+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success')+ ->assertSessionMissing('warning');++ $fresh = $target->fresh();+ $this->assertSame($companyY->id, $fresh->company_id);+ $this->assertSame($newParent->id, $fresh->parent_id);+ }++ public function test_scope_locations_fmcs_reports_all_skipped_when_every_row_has_cross_company_users(): void+ {+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $target = Location::factory()->create(['company_id' => $companyA->id]);+ $user = User::factory()->forCompany($companyA)->create(['location_id' => $target->id]);+ $user->companies()->sync([$companyA->id]);++ // Only company_id was requested. Every row's company_id gets+ // skipped, so no updates apply anywhere and the operator sees+ // the "no locations were reassigned" warning instead of the+ // generic "no fields changed" one.+ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'company_id' => $companyB->id,+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('warning')+ ->assertSessionMissing('success');++ $this->assertSame($companyA->id, $target->fresh()->company_id);+ }++ public function test_scoped_editor_cannot_bulk_edit_a_location_outside_their_scope(): void+ {+ // With scope_locations_fmcs on, the CompanyableScope hides+ // out-of-tenant locations from Location::whereIn(), so a POST+ // that names one silently drops it from the update batch.+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $editor = User::factory()->editLocations()->forCompany($companyA)->create();+ $editor->companies()->sync([$companyA->id]);++ $ownLocation = Location::factory()->create(['company_id' => $companyA->id, 'currency' => 'USD']);+ $otherTenantLocation = Location::factory()->create(['company_id' => $companyB->id, 'currency' => 'USD']);++ $this->actingAs($editor)+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$ownLocation->id, $otherTenantLocation->id],+ 'currency' => 'JPY',+ ])+ ->assertRedirect(route('locations.index'));++ $this->assertSame('JPY', $ownLocation->fresh()->currency);+ $this->assertSame('USD', $otherTenantLocation->fresh()->currency, 'Location outside editor scope must not be touched.');+ }++ public function test_null_parent_id_checkbox_clears_the_parent_column(): void+ {+ $existingParent = Location::factory()->create();+ $target = Location::factory()->create(['parent_id' => $existingParent->id]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'null_parent_id' => '1',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $this->assertNull($target->fresh()->parent_id);+ }++ public function test_null_manager_id_checkbox_clears_the_manager_column(): void+ {+ $existingManager = User::factory()->create();+ $target = Location::factory()->create(['manager_id' => $existingManager->id]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'null_manager_id' => '1',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $this->assertNull($target->fresh()->manager_id);+ }++ public function test_null_currency_and_null_country_checkboxes_clear_those_columns(): void+ {+ $target = Location::factory()->create(['currency' => 'USD', 'country' => 'US']);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'null_currency' => '1',+ 'null_country' => '1',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $fresh = $target->fresh();+ $this->assertNull($fresh->currency);+ $this->assertNull($fresh->country);+ }++ public function test_null_checkbox_wins_over_a_populated_field_value(): void+ {+ // Operator picked a manager AND also checked the null_manager_id+ // box. Clear intent wins over the picked value so the row ends+ // up null. Matches the users bulk-edit precedence.+ $picked = User::factory()->create();+ $existing = User::factory()->create();+ $target = Location::factory()->create(['manager_id' => $existing->id]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'manager_id' => $picked->id,+ 'null_manager_id' => '1',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $this->assertNull($target->fresh()->manager_id);+ }++ public function test_null_company_id_is_ignored_when_fmcs_is_off(): void+ {+ // Consistent with the value-set path: company_id fields on the+ // bulk-edit form are silently dropped when FMCS is off, so the+ // matching null checkbox must also be a no-op.+ $this->settings->disableMultipleFullCompanySupport();+ $existingCompany = Company::factory()->create();+ $target = Location::factory()->create(['company_id' => $existingCompany->id]);++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$target->id],+ 'null_company_id' => '1',+ 'currency' => 'EUR',+ ])+ ->assertRedirect(route('locations.index'))+ ->assertSessionHas('success');++ $fresh = $target->fresh();+ $this->assertSame($existingCompany->id, $fresh->company_id);+ $this->assertSame('EUR', $fresh->currency);+ }++ public function test_scoped_editor_cannot_set_parent_id_to_a_location_outside_their_scope(): void+ {+ $this->settings->enableScopedLocationsWithFullMultipleCompanySupport();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $editor = User::factory()->editLocations()->forCompany($companyA)->create();+ $editor->companies()->sync([$companyA->id]);++ $ownLocation = Location::factory()->create(['company_id' => $companyA->id, 'parent_id' => null]);+ $otherTenantParent = Location::factory()->create(['company_id' => $companyB->id]);++ $this->actingAs($editor)+ ->post(route('locations.bulkedit.store'), [+ 'ids' => [$ownLocation->id],+ 'parent_id' => $otherTenantParent->id,+ 'currency' => 'CAD',+ ])+ ->assertRedirect(route('locations.index'));++ $fresh = $ownLocation->fresh();+ $this->assertNull($fresh->parent_id, 'Cross-tenant parent_id must be dropped.');+ $this->assertSame('CAD', $fresh->currency, 'Other fields still apply after the parent_id is filtered out.');+ }+}