seedOrgWithRules(); [$orgB, $fieldB, $libraryB] = $this->seedOrgWithRules(); $this->withOrgRoute($orgA); $ownerIdsA = FormFieldValidationRule::query()->pluck('owner_id')->sort()->values()->all(); $expectedA = collect([$fieldA->id, $libraryA->id])->sort()->values()->all(); $this->assertSame($expectedA, $ownerIdsA); $this->withOrgRoute($orgB); $ownerIdsB = FormFieldValidationRule::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->seedOrgWithRules(); $this->seedOrgWithRules(); $this->withOrgRoute($orgA); $this->assertSame( 4, FormFieldValidationRule::query() ->withoutGlobalScope(FormFieldValidationRuleScope::class) ->count(), ); $this->assertSame(2, FormFieldValidationRule::query()->count()); } /** @return array{0:Organisation,1:FormField,2:FormFieldLibrary} */ private function seedOrgWithRules(): 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]); FormFieldValidationRule::factory()->forField($field)->create(); FormFieldValidationRule::factory()->forLibrary($library)->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); } }