seedOrgWithLogic(); [$orgB, $fieldB] = $this->seedOrgWithLogic(); $this->withOrgRoute($orgA); $fieldIdsA = FormFieldConditionalLogicGroup::query()->pluck('form_field_id')->unique()->values()->all(); $this->assertSame([$fieldA->id], $fieldIdsA); $this->withOrgRoute($orgB); $fieldIdsB = FormFieldConditionalLogicGroup::query()->pluck('form_field_id')->unique()->values()->all(); $this->assertSame([$fieldB->id], $fieldIdsB); } public function test_scope_isolates_conditions_per_organisation(): void { [$orgA, $fieldA] = $this->seedOrgWithLogic(); $this->seedOrgWithLogic(); $this->withOrgRoute($orgA); $this->assertSame( 1, FormFieldConditionalLogicCondition::query() ->where('field_slug', 'gate') ->count(), ); } public function test_without_global_scope_exposes_cross_org(): void { [$orgA] = $this->seedOrgWithLogic(); $this->seedOrgWithLogic(); $this->withOrgRoute($orgA); $this->assertSame(1, FormFieldConditionalLogicGroup::query()->count()); $this->assertSame( 2, FormFieldConditionalLogicGroup::query() ->withoutGlobalScope(OrganisationScope::class) ->count(), ); $this->assertSame(1, FormFieldConditionalLogicCondition::query()->count()); $this->assertSame( 2, FormFieldConditionalLogicCondition::query() ->withoutGlobalScope(OrganisationScope::class) ->count(), ); } /** @return array{0:Organisation,1:FormField} */ private function seedOrgWithLogic(): array { $org = Organisation::factory()->create(); $schema = FormSchema::factory()->create(['organisation_id' => $org->id]); $field = FormField::factory()->create(['form_schema_id' => $schema->id]); $root = FormFieldConditionalLogicGroup::factory()->forField($field)->create(); FormFieldConditionalLogicCondition::factory() ->inGroup($root) ->forFieldSlug('gate') ->create(); return [$org, $field]; } 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); } }