testAccessibilityForField example

public function testInternalFieldsAreNotVisibleInTwig(): void
    {
        $definitionRegistry = $this->getContainer()->get(DefinitionInstanceRegistry::class);

        foreach ($definitionRegistry->getDefinitions() as $definition) {
            /** @var CompiledFieldCollection $internalFields */
            $internalFields = $definition->getFields()
                ->filter(fn (Field $field): bool => !$field->is(ApiAware::class));

            foreach ($internalFields as $field) {
                $this->testAccessibilityForField($definition$field->getPropertyName()$definition->getEntityClass());
                $this->testAccessibilityForField($definition$field->getPropertyName(), PartialEntity::class);
            }
        }
    }

    private function testAccessibilityForField(EntityDefinition $definition, string $propertyName, string $entityClass): void
    {
        $entity = new $entityClass();
        $entity->internalSetEntityData($definition->getEntityName()$definition->getFieldVisibility());

        $twig = $this->initTwig($propertyName);

        
Home | Imprint | This part of the site doesn't use cookies.