A free open source IT asset/license management system
Updated tests
snipe1cd50fffce47
diff --git a/tests/Feature/Reporting/AcceptanceReportFmcsScopeTest.php b/tests/Feature/Reporting/AcceptanceReportFmcsScopeTest.phpindex 13d62fb550..d59ace56a0 100644--- a/tests/Feature/Reporting/AcceptanceReportFmcsScopeTest.php+++ b/tests/Feature/Reporting/AcceptanceReportFmcsScopeTest.php@@ -9,18 +9,18 @@ use App\Models\User;use Tests\TestCase;/**- * Regression coverage for the FMCS scope gap reported by Arpit Jain- * (arpitjain099) on 2026-08-02. Both getAssetAcceptanceReport (the page)- * and postAssetAcceptanceReport (the CSV export) ran- * CheckoutAcceptance::pending() with no company scope. CheckoutAcceptance- * has no company_id column and does not use CompanyableTrait /- * CompanyableChildTrait, so it is not covered by the CompanyableScope- * global scope. Companion read-side bug to GHSA-p5wx-p3vv-g6p2, which- * fixed the same scope gap on the mutating actions.+ * Regression coverage for the FMCS scope gap originally reported by+ * Arpit Jain (arpitjain099) on 2026-08-02. The old+ * /reports/unaccepted_assets page ran CheckoutAcceptance::pending()+ * with no company scope. CheckoutAcceptance has no company_id column+ * and does not use CompanyableTrait / CompanyableChildTrait, so the+ * CompanyableScope global scope never applies on its own.*- * Both read paths now filter their result set through- * currentUserCanAccessAcceptance(), matching the pattern the mutating- * actions on the same page use.+ * Post-v8.9 the surface is API-driven. The API filters at the DB+ * layer via whereHasMorph(viewableTypes), which routes each morph+ * type through its own CompanyableTrait (and CompanyableChildTrait+ * for LicenseSeat). Companies the caller can't see fall out of the+ * query, so both the row list AND the total count stay scoped.*/class AcceptanceReportFmcsScopeTest extends TestCase{@@ -32,7 +32,7 @@ class AcceptanceReportFmcsScopeTest extends TestCasereturn [$asset, $acceptance];}- public function test_page_render_hides_other_company_pending_acceptances_under_fmcs()+ public function test_api_hides_other_company_pending_acceptances_under_fmcs(){$this->settings->enableMultipleFullCompanySupport();@@ -40,54 +40,19 @@ class AcceptanceReportFmcsScopeTest extends TestCase[$assetA] = $this->seedPendingAcceptanceOwnedBy($companyA);[$assetB] = $this->seedPendingAcceptanceOwnedBy($companyB);- $reporterA = User::factory()->canViewReports()->forCompany($companyA)->create();+ $callerA = User::factory()->checkoutAccessories()->forCompany($companyA)->create();- $response = $this->actingAs($reporterA)- ->get(route('reports/unaccepted_assets'))+ $response = $this->actingAsForApi($callerA)+ ->getJson(route('api.unaccepted-acceptances.index'))->assertOk();- $this->assertStringContainsString($assetA->name, $response->getContent());- $this->assertStringNotContainsString($assetB->name, $response->getContent());+ $this->assertSame(1, $response->json('total'));+ $itemNames = array_map(fn ($row) => $row['item']['name'], $response->json('rows'));+ $this->assertContains($assetA->name, $itemNames);+ $this->assertNotContains($assetB->name, $itemNames);}- public function test_csv_export_hides_other_company_pending_acceptances_under_fmcs()- {- $this->settings->enableMultipleFullCompanySupport();-- [$companyA, $companyB] = Company::factory()->count(2)->create();- [$assetA] = $this->seedPendingAcceptanceOwnedBy($companyA);- [$assetB] = $this->seedPendingAcceptanceOwnedBy($companyB);-- $reporterA = User::factory()->canViewReports()->forCompany($companyA)->create();-- $response = $this->actingAs($reporterA)- ->post(route('reports/export/unaccepted_assets'))- ->assertOk();-- $body = $response->getContent();- $this->assertStringContainsString($assetA->name, $body);- $this->assertStringNotContainsString($assetB->name, $body);- }-- public function test_superuser_sees_all_company_pending_acceptances_in_page()- {- $this->settings->enableMultipleFullCompanySupport();-- [$companyA, $companyB] = Company::factory()->count(2)->create();- [$assetA] = $this->seedPendingAcceptanceOwnedBy($companyA);- [$assetB] = $this->seedPendingAcceptanceOwnedBy($companyB);-- $superuser = User::factory()->superuser()->forCompany($companyA)->create();-- $response = $this->actingAs($superuser)- ->get(route('reports/unaccepted_assets'))- ->assertOk();-- $this->assertStringContainsString($assetA->name, $response->getContent());- $this->assertStringContainsString($assetB->name, $response->getContent());- }-- public function test_superuser_sees_all_company_pending_acceptances_in_csv()+ public function test_api_shows_all_pending_acceptances_to_a_superuser(){$this->settings->enableMultipleFullCompanySupport();@@ -97,31 +62,34 @@ class AcceptanceReportFmcsScopeTest extends TestCase$superuser = User::factory()->superuser()->forCompany($companyA)->create();- $response = $this->actingAs($superuser)- ->post(route('reports/export/unaccepted_assets'))+ $response = $this->actingAsForApi($superuser)+ ->getJson(route('api.unaccepted-acceptances.index'))->assertOk();- $body = $response->getContent();- $this->assertStringContainsString($assetA->name, $body);- $this->assertStringContainsString($assetB->name, $body);+ $this->assertSame(2, $response->json('total'));+ $itemNames = array_map(fn ($row) => $row['item']['name'], $response->json('rows'));+ $this->assertContains($assetA->name, $itemNames);+ $this->assertContains($assetB->name, $itemNames);}- public function test_fmcs_disabled_leaves_report_unscoped()+ public function test_fmcs_disabled_leaves_api_unscoped(){- // With FMCS off the helper short-circuits and every row passes.- // Guard against future refactors that accidentally add scoping on- // installs that do not have FMCS enabled.+ // With FMCS off the CompanyableTrait scope short-circuits and+ // every row passes. Guard against future refactors that would+ // accidentally scope installs that haven't opted into FMCS.[$companyA, $companyB] = Company::factory()->count(2)->create();[$assetA] = $this->seedPendingAcceptanceOwnedBy($companyA);[$assetB] = $this->seedPendingAcceptanceOwnedBy($companyB);- $reporterA = User::factory()->canViewReports()->forCompany($companyA)->create();+ $callerA = User::factory()->checkoutAccessories()->forCompany($companyA)->create();- $response = $this->actingAs($reporterA)- ->get(route('reports/unaccepted_assets'))+ $response = $this->actingAsForApi($callerA)+ ->getJson(route('api.unaccepted-acceptances.index'))->assertOk();- $this->assertStringContainsString($assetA->name, $response->getContent());- $this->assertStringContainsString($assetB->name, $response->getContent());+ $this->assertSame(2, $response->json('total'));+ $itemNames = array_map(fn ($row) => $row['item']['name'], $response->json('rows'));+ $this->assertContains($assetA->name, $itemNames);+ $this->assertContains($assetB->name, $itemNames);}}diff --git a/tests/Feature/Reporting/ActivityReportPageAuthTest.php b/tests/Feature/Reporting/ActivityReportPageAuthTest.phpindex 795d37aa9d..2ca2c3763e 100644--- a/tests/Feature/Reporting/ActivityReportPageAuthTest.php+++ b/tests/Feature/Reporting/ActivityReportPageAuthTest.php@@ -81,21 +81,4 @@ class ActivityReportPageAuthTest extends TestCase->assertSee(route('reports.index').'"', false);}- public function test_scoped_viewer_unaccepted_acceptance_breadcrumb_does_not_link_to_reports_index()- {- // Same fix retroactively applied to the acceptances report- // widened in an earlier batch.- $this->actingAs(User::factory()->viewComponents()->create())- ->get(route('reports/unaccepted_assets'))- ->assertOk()- ->assertDontSee(route('reports.index').'"', false);- }-- public function test_reports_view_holder_unaccepted_acceptance_breadcrumb_links_to_reports_index()- {- $this->actingAs(User::factory()->canViewReports()->create())- ->get(route('reports/unaccepted_assets'))- ->assertOk()- ->assertSee(route('reports.index').'"', false);- }}