AllowEmptyString example



    public function since(): ?string
    {
        return '6.4.15.0';
    }

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new PrimaryKey()new Required()),
            (new LongTextField('value', 'value'))->addFlags(new ApiAware()new Required()new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)new AllowEmptyString()),

            (new FkField('app_id', 'appId', AppDefinition::class))->addFlags(new ApiAware()new Required()),
            (new FkField('locale_id', 'localeId', LocaleDefinition::class))->addFlags(new ApiAware()new Required()),
        ]);
    }
}
protected function getParentDefinitionClass(): ?string
    {
        return SnippetSetDefinition::class;
    }

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new PrimaryKey()new Required()),
            (new FkField('snippet_set_id', 'setId', SnippetSetDefinition::class))->addFlags(new ApiAware()new Required()),
            (new StringField('translation_key', 'translationKey'))->addFlags(new ApiAware()new Required()new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
            (new LongTextField('value', 'value'))->addFlags(new ApiAware()new Required()new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)new AllowHtml()new AllowEmptyString()),
            (new StringField('author', 'author'))->addFlags(new Required()new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
            (new CustomFields())->addFlags(new ApiAware()),
            new ManyToOneAssociationField('set', 'snippet_set_id', SnippetSetDefinition::class, 'id', false),
        ]);
    }
}
use DataAbstractionLayerFieldTestBehaviour;
    use KernelTestBehaviour;

    public static function serializerProvider(): \Generator
    {
        $update = new EntityExistence('product', [], true, false, false, []);
        $create = new EntityExistence('product', [], false, false, false, []);

        $required = (new StringField('name', 'name'))->addFlags(new Required());
        $maxLength = new StringField('name', 'name', 5);
        $optional = new StringField('name', 'name');
        $allowEmpty = (new StringField('name', 'name'))->addFlags(new AllowEmptyString());
        $allowEmptyAndRequired = (new StringField('name', 'name'))->addFlags(new Required()new AllowEmptyString());

        yield 'Create with null and required' => [$required, null, null, true, $create];
        yield 'Create with null and optional' => [$optional, null, null, false, $create];
        yield 'Update with null and required' => [$required, null, null, true, $update];
        yield 'Update with null and optional' => [$optional, null, null, false, $update];

        yield 'Create with empty and required' => [$required, '', null, true, $create];
        yield 'Create with empty and optional' => [$optional, '', null, false, $create];
        yield 'Update with empty and required' => [$required, '', null, true, $update];
        yield 'Update with empty and optional' => [$optional, '', null, false, $update];

        
public static function stringFieldDataProvider(): array
    {
        return [
            ['writeException', '<test>', 'This value should not be blank.', [new Required()]],
            ['writeException', null, 'This value should not be blank.', [new Required()]],
            ['writeException', '', 'This value should not be blank.', [new Required()]],
            ['writeException', true, 'This value should be of type string.', [new Required()]],
            ['assertion', 'test12-B', 'test12-B', [new Required()]],
            ['assertion', null, null, []],
            ['assertion', '<test>', '<test>', [new Required()new AllowHtml(false)]],
            ['assertion', '', null, []],
            ['assertion', '', '', [new AllowEmptyString()]],
            ['assertion', '', '', [new Required()new AllowEmptyString()]],
            ['assertion', '<script></script>test12-B', 'test12-B', [new Required()new AllowHtml()]],
        ];
    }

    private function getWriteParameterBagMock(): WriteParameterBag
    {
        $mockBuilder = $this->getMockBuilder(WriteParameterBag::class);
        $mockBuilder->disableOriginalConstructor();

        return $mockBuilder->getMock();
    }
return '6.0.0.0';
    }

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new PrimaryKey()new Required()),
            (new FkField('sales_channel_id', 'salesChannelId', SalesChannelDefinition::class))->addFlags(new ApiAware()),

            (new StringField('entity_name', 'entityName', 64))->addFlags(new Required()),
            (new StringField('route_name', 'routeName'))->addFlags(new Required()),
            (new StringField('template', 'template', 750))->addFlags(new AllowEmptyString()),
            (new BoolField('is_valid', 'isValid'))->addFlags(new ApiAware()),
            (new CustomFields())->addFlags(new ApiAware()),
            new ManyToOneAssociationField('salesChannel', 'sales_channel_id', SalesChannelDefinition::class, 'id', false),
        ]);
    }
}


    public function since(): ?string
    {
        return '6.3.1.0';
    }

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new PrimaryKey()new Required()),
            (new LongTextField('template', 'template'))->addFlags(new Required()new AllowHtml(false)new AllowEmptyString()),
            (new StringField('path', 'path', 1024))->addFlags(new Required()),
            (new BoolField('active', 'active'))->addFlags(new Required()),
            (new FkField('app_id', 'appId', AppDefinition::class))->addFlags(new Required()),
            new ManyToOneAssociationField('app', 'app_id', AppDefinition::class),
        ]);
    }
}
/** * @return array<string, array{bool|string|null, ?string, Flag[]}> */
    public static function exceptionCases(): array
    {
        return [
            'Required HTML filtered content throws' => ['<test>', 'This value should not be blank.', [new Required()]],
            'Required null content throws' => [null, 'This value should not be blank.', [new Required()]],
            'Required empty content throws' => ['', 'This value should not be blank.', [new Required()]],
            'Wrong type throws' => [true, 'This value should be of type string.', [new Required()]],
            'Required and allow empty throws with null' => [null, 'This value should not be null.', [new Required()new AllowEmptyString()]],
        ];
    }

    /** * @return array<string, array{bool|string|null, ?string, Flag[]}> */
    public static function longTextFieldDataProvider(): array
    {
        return [
            'String values are passed through' => ['test12-B', 'test12-B', [new Required()]],
            'Null is allowed without required flag' => [null, null, []],
            
Home | Imprint | This part of the site doesn't use cookies.