Type example

yield 'element config with type string' => [
            'elementConfig' => [
                'required' => true,
                'dataType' => 'string',
                'minLength' => 1,
                'maxLength' => 255,
            ],
            'expected' => [
                new Assert\Length(['min' => 1]),
                new Assert\Length(['max' => 255]),
                new Assert\Type('string'),
                new Assert\NotBlank(),
            ],
        ];

        yield 'element config with type int' => [
            'elementConfig' => [
                'required' => true,
                'dataType' => 'int',
                'min' => 1,
                'max' => 100,
            ],
            
return FloatComparator::cast($this->taxRate);
    }

    public function getPercentage(): float
    {
        return FloatComparator::cast($this->percentage);
    }

    public static function getConstraints(): array
    {
        return [
            'taxRate' => [new NotBlank()new Type('numeric')],
            'percentage' => [new Type('numeric')],
        ];
    }

    public function getApiAlias(): string
    {
        return 'cart_tax_rule';
    }
}
$token = $this->downloadService->regenerateToken($context$fileId);

        return new JsonResponse(['accessToken' => $token]);
    }

    #[Route(path: '/api/_action/import-export/file/download', name: 'api.action.import_export.file.download', defaults: ['auth_required' => false], methods: ['GET'])]     public function download(Request $request, Context $context): Response
    {
        /** @var array<string> $params */
        $params = $request->query->all();
        $definition = new DataValidationDefinition();
        $definition->add('fileId', new NotBlank()new Type('string'));
        $definition->add('accessToken', new NotBlank()new Type('string'));
        $this->dataValidator->validate($params$definition);

        return $this->downloadService->createFileResponse($context$params['fileId']$params['accessToken']);
    }

    #[Route(path: '/api/_action/import-export/cancel', name: 'api.action.import_export.cancel', methods: ['POST'])]     public function cancel(Request $request, Context $context): Response
    {
        $logId = $request->request->get('logId');

        


    /** * @return iterable<string, array<int|string|array<int, Constraint>|bool|null>> */
    public static function encodeProvider(): iterable
    {
        $minPasswordLength = 8;

        $notBlankConstraints = [
            new NotBlank(),
            new Type('string'),
        ];

        $minLengthConstraints = [
            new NotBlank(),
            new Type('string'),
            new Length(['min' => $minPasswordLength]),
        ];

        yield 'with null value without min length required' => [
            PasswordField::FOR_ADMIN,
            0,
            
$ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('operator', $ruleConstraints, 'Constraint operator not found in Rule');
        $operators = $ruleConstraints['operator'];
        static::assertEquals(new NotBlank()$operators[0]);
        static::assertEquals(new Choice($expectedOperators)$operators[1]);

        $this->rule->assign(['operator' => Rule::OPERATOR_EQ]);
        static::assertArrayHasKey('streetName', $ruleConstraints, 'Constraint streetName not found in Rule');
        $streetName = $ruleConstraints['streetName'];
        static::assertEquals(new NotBlank()$streetName[0]);
        static::assertEquals(new Type('string')$streetName[1]);
    }

    /** * @dataProvider getMatchValues */
    public function testRuleMatching(string $operator, bool $isMatching, string $shippingStreet, bool $noAddress = false): void
    {
        $streetName = 'kyln123';
        $salesChannelContext = $this->createMock(SalesChannelContext::class);

        $customerAddress = new CustomerAddressEntity();
        
new Choice([
                    Rule::OPERATOR_EQ,
                    Rule::OPERATOR_LTE,
                    Rule::OPERATOR_GTE,
                    Rule::OPERATOR_NEQ,
                    Rule::OPERATOR_GT,
                    Rule::OPERATOR_LT,
                ]),
            ],
            'stock' => [
                new NotBlank(),
                new Type('int'),
            ],
        ]$constraints);
    }

    public function testConfigUsesOperatorSetNumbers(): void
    {
        $config = (new LineItemStockRule())->getConfig();
        $configData = $config->getData();

        static::assertArrayHasKey('operatorSet', $configData);
        static::assertEquals([
            

        static::assertSame('cartLineItemPromoted', $this->rule->getName());
    }

    /** * This test verifies that we have the correct constraint * and that no NotBlank is existing - only 1 BOOL constraint. * Otherwise a FALSE value would not work when saving in the administration. */
    public function testConstraints(): void
    {
        $expectedType = new Type(['type' => 'bool']);

        $ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('isPromoted', $ruleConstraints, 'Constraint isPromoted not found in Rule');
        static::assertCount(1, $ruleConstraints['isPromoted']);
        static::assertEquals($expectedType$ruleConstraints['isPromoted'][0]);
    }

    /** * @return array<boolean[]> */
    

        $faker = Factory::create();

        // test with no constraints added         $profileDefinition = new DataValidationDefinition();
        $expected = new DataValidationDefinition('customer.create');
        self::addConstraints($expected);

        yield [$profileDefinition$expected];

        // test merge         $profileDefinition->add('email', new Type('string'));
        $expected->set('email', new Type('string')new NotBlank()new Email());

        yield [$profileDefinition$expected];

        // test with randomized data         for ($i = 0; $i < 10; ++$i) {
            $profileDefinition = new DataValidationDefinition();

            $notBlankName = $faker->name();
            $profileDefinition->add($notBlankNamenew NotBlank());

            
$ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('operator', $ruleConstraints, 'Constraint operator not found in Rule');
        $operators = $ruleConstraints['operator'];
        static::assertEquals(new NotBlank()$operators[0]);
        static::assertEquals(new Choice($expectedOperators)$operators[1]);

        $this->rule->assign(['operator' => Rule::OPERATOR_EQ]);
        static::assertArrayHasKey('streetName', $ruleConstraints, 'Constraint streetName not found in Rule');
        $streetName = $ruleConstraints['streetName'];
        static::assertEquals(new NotBlank()$streetName[0]);
        static::assertEquals(new Type('string')$streetName[1]);
    }

    public function testUnsupportedValue(): void
    {
        try {
            $rule = new BillingStreetRule();
            $salesChannelContext = $this->createMock(SalesChannelContext::class);
            $customer = new CustomerEntity();
            $customer->setActiveBillingAddress(new CustomerAddressEntity());
            $salesChannelContext->method('getCustomer')->willReturn($customer);
            $rule->match(new CheckoutRuleScope($salesChannelContext));
            
 $config->getData());
    }

    public function testGetConstraints(): void
    {
        $rule = new OrderCreatedByAdminRule();
        $constraints = $rule->getConstraints();

        static::assertArrayHasKey('shouldOrderBeCreatedByAdmin', $constraints, 'Constraint shouldOrderBeCreatedByAdmin not found in Rule');
        static::assertEquals($constraints['shouldOrderBeCreatedByAdmin'][
            new NotNull(),
            new Type(['type' => 'bool']),
        ]);
    }

    public function testMatchWithWrongRuleScope(): void
    {
        $scope = $this->createMock(TestRuleScope::class);

        $match = $this->rule->match($scope);

        static::assertFalse($match);
    }

    

class CustomerLoggedInRuleTest extends TestCase
{
    public function testGetConstraints(): void
    {
        $rule = new CustomerLoggedInRule();
        $constraints = $rule->getConstraints();

        static::assertArrayHasKey('isLoggedIn', $constraints, 'Constraint isLoggedIn not found in Rule');
        static::assertEquals($constraints['isLoggedIn'][
            new NotNull(),
            new Type(['type' => 'bool']),
        ]);
    }

    public function testName(): void
    {
        $rule = new CustomerLoggedInRule();
        static::assertSame('customerLoggedIn', $rule->getName());
    }

    public function testGetConfig(): void
    {
        
$data['type'] = $this->getType();

        return $data;
    }

    /** * @return array<string, Constraint[]> */
    public static function getConstraints(): array
    {
        return [
            'percentage' => [new NotBlank()new Type('numeric')],
        ];
    }

    public function getApiAlias(): string
    {
        return 'cart_price_percentage';
    }
}
$ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('operator', $ruleConstraints, 'Constraint operator not found in Rule');
        $operators = $ruleConstraints['operator'];
        static::assertEquals(new NotBlank()$operators[0]);
        static::assertEquals(new Choice($expectedOperators)$operators[1]);

        $this->rule->assign(['operator' => Rule::OPERATOR_EQ]);
        static::assertArrayHasKey('amount', $ruleConstraints, 'Constraint amount not found in Rule');
        $amount = $ruleConstraints['amount'];
        static::assertEquals(new NotBlank()$amount[0]);
        static::assertEquals(new Type('numeric')$amount[1]);
    }

    private static function createLineItemWithWidth(?float $width): LineItem
    {
        return self::createLineItemWithDeliveryInfo(false, 1, 50.0, null, $width);
    }
}


        $ruleConstraints = $this->rule->getConstraints();

        static::assertArrayHasKey('lineItemCreationDate', $ruleConstraints, 'Constraint lineItemCreationDate not found in Rule');
        static::assertArrayHasKey('operator', $ruleConstraints, 'Constraint operator not found in Rule');

        $date = $ruleConstraints['lineItemCreationDate'];
        $operators = $ruleConstraints['operator'];

        static::assertEquals(new NotBlank()$date[0]);
        static::assertEquals(new Type(['type' => 'string'])$date[1]);

        static::assertEquals(new NotBlank()$operators[0]);
        static::assertEquals(new Choice($expectedOperators)$operators[1]);
    }

    /** * @return array<string, array<bool|string>> */
    public static function getMatchValues(): array
    {
        return [
            

    private function buildConstraintsWithConfigs(array $elementConfig): array
    {
        /** @var array<string, callable(mixed): Constraint> $constraints */
        $constraints = [
            'minLength' => fn (mixed $ruleValue) => new Assert\Length(['min' => $ruleValue]),
            'maxLength' => fn (mixed $ruleValue) => new Assert\Length(['max' => $ruleValue]),
            'min' => fn (mixed $ruleValue) => new Assert\Range(['min' => $ruleValue]),
            'max' => fn (mixed $ruleValue) => new Assert\Range(['max' => $ruleValue]),
            'dataType' => fn (mixed $ruleValue) => new Assert\Type($ruleValue),
            'required' => fn (mixed $ruleValue) => new Assert\NotBlank(),
        ];

        $constraintsResult = [];

        foreach ($constraints as $ruleName => $constraint) {
            if (!\array_key_exists($ruleName$elementConfig)) {
                continue;
            }

            $ruleValue = $elementConfig[$ruleName];

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