seedOrgWithBindings(); [$orgB, $fieldB, $libraryB] = $this->seedOrgWithBindings(); $this->withOrgRoute($orgA); $ownerIdsA = FormFieldBinding::query()->pluck('owner_id')->sort()->values()->all(); $expectedA = collect([$fieldA->id, $libraryA->id])->sort()->values()->all(); $this->assertSame($expectedA, $ownerIdsA); $this->withOrgRoute($orgB); $ownerIdsB = FormFieldBinding::query()->pluck('owner_id')->sort()->values()->all(); $expectedB = collect([$fieldB->id, $libraryB->id])->sort()->values()->all(); $this->assertSame($expectedB, $ownerIdsB); } public function test_without_global_scope_exposes_cross_org(): void { [$orgA, , ] = $this->seedOrgWithBindings(); $this->seedOrgWithBindings(); $this->withOrgRoute($orgA); $this->assertSame( 4, FormFieldBinding::query()->withoutGlobalScope(FormFieldBindingScope::class)->count(), ); $this->assertSame(2, FormFieldBinding::query()->count()); } /** @return array{0:Organisation,1:FormField,2:FormFieldLibrary} */ private function seedOrgWithBindings(): array { $org = Organisation::factory()->create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $field = FormField::factory()->create(['form_schema_id' => $schema->id]); $library = FormFieldLibrary::factory()->create(['organisation_id' => $org->id]); FormFieldBinding::factory()->forField($field)->entityOwned('person', 'email')->create(); FormFieldBinding::factory()->forLibrary($library)->entityOwned('person', 'first_name')->create(); return [$org, $field, $library]; } private function withOrgRoute(Organisation $org): void { $route = new Route(['GET'], '/_test', static fn () => null); $route->bind(request()); $route->setParameter('organisation', $org); request()->setRouteResolver(static fn () => $route); } }