Skip to content

A free open source IT asset/license management system

MOAR tests

snipe3a103a4e29c6
diff --git a/tests/Feature/Companies/Api/CompanyHierarchyTest.php b/tests/Feature/Companies/Api/CompanyHierarchyTest.php
index f14428b12a..2661731527 100644
--- a/tests/Feature/Companies/Api/CompanyHierarchyTest.php
+++ b/tests/Feature/Companies/Api/CompanyHierarchyTest.php
@@ -384,6 +384,54 @@ class CompanyHierarchyTest extends TestCase
$this->assertEquals('SearchableChild', $byId[$child->id]['text'], 'Children should render flat (no indent) when searching');
}
+ public function test_selectlist_marks_children_disabled_when_only_top_level_is_set()
+ {
+ $top = Company::factory()->create(['name' => 'TopLevelSelect']);
+ $child = Company::factory()->childOf($top)->create(['name' => 'ChildSelect']);
+
+ $response = $this->actingAsForApi(User::factory()->superuser()->create())
+ ->getJson(route('api.companies.selectlist', ['onlyTopLevel' => 1]))
+ ->assertOk()
+ ->json();
+
+ $byId = collect($response['results'])->keyBy('id');
+
+ $this->assertArrayNotHasKey('disabled', $byId[$top->id], 'Top-level company should not be disabled');
+ $this->assertTrue($byId[$child->id]['disabled'] ?? false, 'Child company should be marked disabled');
+ }
+
+ public function test_selectlist_does_not_mark_disabled_without_only_top_level()
+ {
+ $top = Company::factory()->create();
+ $child = Company::factory()->childOf($top)->create();
+
+ $response = $this->actingAsForApi(User::factory()->superuser()->create())
+ ->getJson(route('api.companies.selectlist'))
+ ->assertOk()
+ ->json();
+
+ $byId = collect($response['results'])->keyBy('id');
+
+ $this->assertArrayNotHasKey('disabled', $byId[$top->id]);
+ $this->assertArrayNotHasKey('disabled', $byId[$child->id], 'Without onlyTopLevel, no rows should be disabled');
+ }
+
+ public function test_selectlist_excludes_company_passed_as_exclude_id()
+ {
+ $excluded = Company::factory()->create(['name' => 'ExcludedFromList']);
+ $included = Company::factory()->create(['name' => 'IncludedInList']);
+
+ $response = $this->actingAsForApi(User::factory()->superuser()->create())
+ ->getJson(route('api.companies.selectlist', ['excludeId' => $excluded->id]))
+ ->assertOk()
+ ->json();
+
+ $ids = collect($response['results'])->pluck('id')->all();
+
+ $this->assertNotContains($excluded->id, $ids);
+ $this->assertContains($included->id, $ids);
+ }
+
public function test_selectlist_surfaces_orphaned_child_when_parent_is_out_of_scope()
{
$this->settings->enableMultipleFullCompanySupport();
diff --git a/tests/Feature/Companies/Ui/ShowCompanyTest.php b/tests/Feature/Companies/Ui/ShowCompanyTest.php
index 956d7152fd..037dc60b1f 100644
--- a/tests/Feature/Companies/Ui/ShowCompanyTest.php
+++ b/tests/Feature/Companies/Ui/ShowCompanyTest.php
@@ -39,7 +39,7 @@ class ShowCompanyTest extends TestCase
$this->actingAs(User::factory()->superuser()->create())
->get(route('companies.show', $parent))
->assertOk()
- ->assertSee(trans('admin/companies/table.hierarchy'))
+ ->assertSee(trans('admin/companies/table.children'))
->assertSee($childA->name)
->assertSee($childB->name)
->assertDontSee($unrelated->name);
@@ -53,17 +53,56 @@ class ShowCompanyTest extends TestCase
$this->actingAs(User::factory()->superuser()->create())
->get(route('companies.show', $child))
->assertOk()
- ->assertSee(trans('admin/companies/table.hierarchy'))
+ ->assertSee(trans('admin/companies/table.parent'))
->assertSee($parent->name);
}
- public function test_sidebar_hierarchy_box_hidden_when_company_is_standalone()
+ public function test_child_companies_tab_appears_when_company_has_children()
+ {
+ $parent = Company::factory()->create(['name' => 'TabbedParent']);
+ Company::factory()->childOf($parent)->create(['name' => 'TabbedChild']);
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->get(route('companies.show', $parent))
+ ->assertOk()
+ ->assertSee('href="#companies"', false); // raw HTML attribute substring
+ }
+
+ public function test_child_companies_tab_does_not_appear_for_standalone_company()
+ {
+ $solo = Company::factory()->create(['name' => 'TabbedStandalone']);
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->get(route('companies.show', $solo))
+ ->assertOk()
+ ->assertDontSee('href="#companies"', false);
+ }
+
+ public function test_sidebar_shows_children_for_fmcs_scoped_non_superuser()
+ {
+ // Regression: $company->children uses withoutGlobalScopes() on the relation
+ // so a non-superuser viewing a parent (they belong to) still sees its kids
+ // listed in the info-panel even though they don't directly belong to those kids.
+ $this->settings->enableMultipleFullCompanySupport();
+
+ $parent = Company::factory()->create(['name' => 'FMCSParent']);
+ $child = Company::factory()->childOf($parent)->create(['name' => 'FMCSChild']);
+
+ $user = $parent->users()->save(User::factory()->viewCompanies()->create());
+
+ $this->actingAs($user)
+ ->get(route('companies.show', $parent))
+ ->assertOk()
+ ->assertSee($child->name);
+ }
+
+ public function test_sidebar_hierarchy_blocks_hidden_when_company_is_standalone()
{
$solo = Company::factory()->create(['name' => 'Standalone Sidebar Co']);
$this->actingAs(User::factory()->superuser()->create())
->get(route('companies.show', $solo))
->assertOk()
- ->assertDontSee(trans('admin/companies/table.hierarchy'));
+ ->assertDontSee(trans('admin/companies/table.children'));
}
}