createContext example

public function testStartFrw(): void
    {
        $this->firstRunWizardService->expects(static::once())
            ->method('startFrw');

        $frwController = new FirstRunWizardController(
            $this->firstRunWizardService,
            new StaticEntityRepository([]),
            new StaticEntityRepository([]),
        );

        $response = $frwController->frwStart($this->createContext());

        static::assertSame(SymfonyResponse::HTTP_OK, $response->getStatusCode());
    }

    public function testTryingToStartFrwFails(): void
    {
        $exceptionMessage = 'frwService::frwStart failed';
        $this->firstRunWizardService->expects(static::once())
            ->method('startFrw')
            ->willThrowException($this->createClientException($exceptionMessage));

        
return $salesChannelApiBrowser;
    }

    /** * @param array<mixed> $salesChannelOverride * @param array<mixed> $options */
    public function createSalesChannelContext(array $salesChannelOverride = [], array $options = []): SalesChannelContext
    {
        $salesChannel = $this->createSalesChannel($salesChannelOverride);

        return $this->createContext($salesChannel$options);
    }

    public function login(?KernelBrowser $browser = null): string
    {
        $email = Uuid::randomHex() . '@example.com';
        $customerId = $this->createCustomer($email);

        if (!$browser) {
            $browser = $this->getSalesChannelBrowser();
        }

        

                ],
            ],
        ];

        $this->repository->create($data, Context::createDefaultContext());

        $criteria = new Criteria();
        $criteria->addSorting(new FieldSorting('product.prices.price', FieldSorting::ASCENDING));
        $criteria->addFilter(new EqualsFilter('product.ean', $filterId));

        $context = $this->createContext([$ruleA]);

        $products = $this->repository->searchIds($criteria$context);

        static::assertSame(
            [$id2$id3$id],
            $products->getIds()
        );

        $criteria = new Criteria();
        $criteria->addSorting(new FieldSorting('product.prices.price', FieldSorting::DESCENDING));
        $criteria->addFilter(new EqualsFilter('product.ean', $filterId));

        
public function __construct(ExecutionContextFactoryInterface $contextFactory, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory, array $objectInitializers = [])
    {
        $this->contextFactory = $contextFactory;
        $this->metadataFactory = $metadataFactory;
        $this->validatorFactory = $validatorFactory;
        $this->objectInitializers = $objectInitializers;
    }

    public function startContext(mixed $root = null): ContextualValidatorInterface
    {
        return new RecursiveContextualValidator(
            $this->contextFactory->createContext($this$root),
            $this->metadataFactory,
            $this->validatorFactory,
            $this->objectInitializers
        );
    }

    public function inContext(ExecutionContextInterface $context): ContextualValidatorInterface
    {
        return new RecursiveContextualValidator(
            $context,
            $this->metadataFactory,
            
$used = false;

        $expressionLanguage->method('evaluate')
            ->willReturnCallback(function D) use (&$used) {
                $used = true;

                return true;
            });

        $validator = new ExpressionValidator($expressionLanguage);
        $validator->initialize($this->createContext());
        $validator->validate(null, $constraint);

        $this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.');
    }

    public function testPassingCustomValues()
    {
        $constraint = new Expression([
            'expression' => 'value + custom == 2',
            'values' => [
                'custom' => 1,
            ],
public function __construct(ExecutionContextFactoryInterface $contextFactory, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory, array $objectInitializers = [])
    {
        $this->contextFactory = $contextFactory;
        $this->metadataFactory = $metadataFactory;
        $this->validatorFactory = $validatorFactory;
        $this->objectInitializers = $objectInitializers;
    }

    public function startContext(mixed $root = null): ContextualValidatorInterface
    {
        return new RecursiveContextualValidator(
            $this->contextFactory->createContext($this$root),
            $this->metadataFactory,
            $this->validatorFactory,
            $this->objectInitializers
        );
    }

    public function inContext(ExecutionContextInterface $context): ContextualValidatorInterface
    {
        return new RecursiveContextualValidator(
            $context,
            $this->metadataFactory,
            
static::assertIsArray($customFields);
        static::assertCount(2, $customFields);
        static::assertSame('Example', $customFields['custom_test_text']);
        static::assertNull($customFields['custom_test_check']);
    }

    public function testCustomFieldHydrationWithTranslationWithInheritance(): void
    {
        $definition = $this->definitionInstanceRegistry->get(CustomFieldTestDefinition::class);

        $id = Uuid::randomBytes();
        $context = $this->createContext();

        $rows = [
            [
                'test.id' => $id,
                'test.name' => 'example',
                'test.customTranslated' => '{"custom_test_text": null, "custom_test_check": "0"}',
                'test.translation.customTranslated' => '{"custom_test_text": null, "custom_test_check": "0"}',
                'test.translation.fallback_1.customTranslated' => '{"custom_test_text": null, "custom_test_check": null}',
                'test.parent.translation.customTranslated' => '{"custom_test_text": "PARENT DEUTSCH"}',
                'test.parent.translation.fallback_1.customTranslated' => '{"custom_test_text": "PARENT ENGLISH", "custom_test_check": "1"}',
            ],
        ];
/** * @dataProvider formattingParameterProvider */
    public function testFormatCurrencyByLanguageWillUseProvidedDecimalPlaces(float $price, int $decimalPlaces, string $localeCode, string $expectedSeparator, string $currencyISO): void
    {
        $this->localeProvider->expects(static::once())->method('getLocaleForLanguageId')->willReturn($localeCode);
        $pattern = sprintf('/\%s\d{%s}/', $expectedSeparator(string) $decimalPlaces);
        $formattedPrice = $this->formatter->formatCurrencyByLanguage(
            $price,
            $currencyISO,
            Uuid::randomHex(),
            $this->createContext($decimalPlaces),
            3
        );

        static::assertMatchesRegularExpression($pattern$formattedPrice);
    }

    /** * @dataProvider formattingParameterProvider */
    public function testFormatCurrencyByLanguageWillWriteCorrectCurrencySymbol(float $price, int $decimalPlaces, string $localeCode, string $expectedSeparator, string $currencyISO, string $expectedCurrencySymbol): void
    {
        
$this->group = 'MyGroup';
        $this->metadata = null;
        $this->object = null;
        $this->value = 'InvalidValue';
        $this->root = 'root';
        $this->propertyPath = 'property.path';

        // Initialize the context with some constraint so that we can         // successfully build a violation.         $this->constraint = new NotNull();

        $this->context = $this->createContext();
        $this->validator = $this->createValidator();
        $this->validator->initialize($this->context);

        $this->defaultLocale = \Locale::getDefault();
        \Locale::setDefault('en');

        $this->expectedViolations = [];
        $this->call = 0;

        $this->setDefaultTimezone('UTC');
    }

    

        $validator = new NotCompromisedPasswordValidator($this->createHttpClientStub(), 'ISO-8859-5');
        $validator->validate(mb_convert_encoding(self::PASSWORD_NON_UTF8_NOT_LEAKED, 'ISO-8859-5', 'UTF-8')new NotCompromisedPassword());

        $this->assertNoViolation();
    }

    public function testNonUtf8CharsetInvalid()
    {
        $constraint = new NotCompromisedPassword();

        $this->context = $this->createContext();

        $validator = new NotCompromisedPasswordValidator($this->createHttpClientStub(), 'ISO-8859-5');
        $validator->initialize($this->context);
        $validator->validate(mb_convert_encoding(self::PASSWORD_NON_UTF8_LEAKED, 'ISO-8859-5', 'UTF-8')$constraint);

        $this->buildViolation($constraint->message)
            ->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR)
            ->assertRaised();
    }

    public function testInvalidPasswordCustomEndpoint()
    {
'countryVersionId' => Defaults::LIVE_VERSION,
            'currencies' => [['id' => Defaults::CURRENCY]],
            'languages' => [['id' => Defaults::LANGUAGE_SYSTEM]],
            'paymentMethods' => [['id' => $paymentMethodId]],
            'shippingMethods' => [['id' => $shippingMethodId]],
            'countries' => [['id' => $countryId]],
            'domains' => [
                ['url' => 'http://test.com/' . Uuid::randomHex(), 'currencyId' => Defaults::CURRENCY, 'languageId' => Defaults::LANGUAGE_SYSTEM, 'snippetSetId' => $snippetSetId],
            ],
        ];

        return $this->createContext($data[]);
    }

    protected function createSalesChannelContextWithLoggedInCustomerAndWithNavigation(): SalesChannelContext
    {
        $paymentMethodId = $this->getValidPaymentMethodId();
        $shippingMethodId = $this->getAvailableShippingMethod()->getId();
        $countryId = $this->getValidCountryId();
        $snippetSetId = $this->getSnippetSetIdForLocale('en-GB');
        $data = [
            'typeId' => Defaults::SALES_CHANNEL_TYPE_STOREFRONT,
            'name' => 'store front',
            

  public function __construct(ExecutionContextFactoryInterface $context_factory, ConstraintValidatorFactoryInterface $validator_factory, TypedDataManagerInterface $typed_data_manager) {
    $this->contextFactory = $context_factory;
    $this->constraintValidatorFactory = $validator_factory;
    $this->typedDataManager = $typed_data_manager;
  }

  /** * {@inheritdoc} */
  public function startContext($root = NULL): ContextualValidatorInterface {
    return new RecursiveContextualValidator($this->contextFactory->createContext($this$root)$this$this->constraintValidatorFactory, $this->typedDataManager);
  }

  /** * {@inheritdoc} */
  public function inContext(ExecutionContextInterface $context): ContextualValidatorInterface {
    return new RecursiveContextualValidator($context$this$this->constraintValidatorFactory, $this->typedDataManager);
  }

  /** * {@inheritdoc} * * @param \Drupal\Core\TypedData\TypedDataInterface $typed_data * A typed data object containing the value to validate. */
$conditions = $streamRepo->unserialize($conditions);

                foreach ($conditions as $condition) {
                    $criteria->addCondition($condition);
                }
            }

            $criteria->offset($this->Request()->getParam('start', 0));
            $criteria->limit($this->Request()->getParam('limit', 20));

            $context = $this->createContext(
                (int) $this->Request()->getParam('shopId'),
                (int) $this->Request()->getParam('currencyId'),
                $this->Request()->getParam('customerGroupKey')
            );

            $criteria->addBaseCondition(
                new CustomerGroupCondition([$context->getCurrentCustomerGroup()->getId()])
            );

            $category = $context->getShop()->getCategory()->getId();
            $criteria->addBaseCondition(
                
$this->group = 'MyGroup';
        $this->metadata = null;
        $this->object = null;
        $this->value = 'InvalidValue';
        $this->root = 'root';
        $this->propertyPath = 'property.path';

        // Initialize the context with some constraint so that we can         // successfully build a violation.         $this->constraint = new NotNull();

        $this->context = $this->createContext();
        $this->validator = $this->createValidator();
        $this->validator->initialize($this->context);

        $this->defaultLocale = \Locale::getDefault();
        \Locale::setDefault('en');

        $this->expectedViolations = [];
        $this->call = 0;

        $this->setDefaultTimezone('UTC');
    }

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