SalutationEntity example

/** * @internal * * @covers \Shopware\Core\System\Salutation\SalutationSorter */
#[Package('buyers-experience')] class SalutationSorterTest extends TestCase
{
    public function testSort(): void
    {
        $mrs = new SalutationEntity();
        $mrs->setId(Uuid::randomBytes());
        $mrs->setSalutationKey('mrs');

        $mr = new SalutationEntity();
        $mr->setId(Uuid::randomBytes());
        $mr->setSalutationKey('mr');

        $notSpecified = new SalutationEntity();
        $notSpecified->setId(Uuid::randomBytes());
        $notSpecified->setSalutationKey('not_specified');

        

        return new SalutationCollection([
            $this->createSalutationWithSalutationKey('c'),
            $this->createSalutationWithSalutationKey('a'),
            $this->createSalutationWithSalutationKey('d'),
            $this->createSalutationWithSalutationKey('b'),
        ]);
    }

    private function createSalutationWithSalutationKey(string $salutationKey): SalutationEntity
    {
        return (new SalutationEntity())->assign([
            'id' => Uuid::randomHex(),
            'salutationKey' => $salutationKey,
        ]);
    }

    private function getSalutationRoute(SalutationCollection $salutationCollection): AbstractSalutationRoute
    {
        $salutationRoute = $this->createMock(AbstractSalutationRoute::class);
        $salutationRoute->expects(static::once())
            ->method('load')
            ->willReturn(new SalutationRouteResponse(
                
static::assertEquals(RuleConstraints::uuidOperators()$constraints['operator']);
    }

    /** * @dataProvider getMatchCustomerSalutationValues * * @param list<string> $salutationIds */
    public function testCustomerSalutationRuleMatching(bool $expected, ?string $customerSalutationId, array $salutationIds, string $operator): void
    {
        $customer = new CustomerEntity();
        $salutation = new SalutationEntity();

        if ($customerSalutationId) {
            $salutation->setId($customerSalutationId);
            $customer->setSalutation($salutation);
        }

        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getCustomer')->willReturn($customer);
        $scope = new CheckoutRuleScope($context);

        $this->rule->assign(['salutationIds' => $salutationIds, 'operator' => $operator]);

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