createAddress example

/** * @covers \Shopware\Core\Checkout\Customer\Rule\ShippingZipCodeRule * * @internal */
#[Package('business-ops')] class ShippingZipCodeRuleTest extends TestCase
{
    public function testEqualsWithSingleCode(): void
    {
        $rule = (new ShippingZipCodeRule())->assign(['zipCodes' => ['ABC123']]);
        $address = $this->createAddress('ABC123');

        $cart = new Cart('test');

        $context = $this->createMock(SalesChannelContext::class);

        $location = ShippingLocation::createFromAddress($address);

        $context
            ->method('getShippingLocation')
            ->willReturn($location);

        


        if (isset($params['defaultShippingAddress'])) {
            $params['shipping'] = $params['defaultShippingAddress'];
            unset($params['defaultShippingAddress']);
        }

        $params = $this->prepareCustomerData($params$customer);
        $params = $this->prepareAssociatedData($params$customer);
        $customer->fromArray($params);

        $billing = $this->createAddress($params['billing']) ?? new AddressModel();
        $shipping = $this->createAddress($params['shipping'] ?? null);

        $registerService = $this->getContainer()->get(RegisterServiceInterface::class);
        $context = $this->getContainer()->get(ContextServiceInterface::class)->getShopContext()->getShop();

        $context->addAttribute('sendOptinMail', new Attribute([
            'sendOptinMail' => ($params['sendOptinMail'] ?? false) === true,
        ]));

        $registerService->register($context$customer$billing$shipping);

        

        $rule = (new ShippingStreetRule())->assign(['streetName' => 'example street']);

        $cart = new Cart('test');

        $context = $this->createMock(SalesChannelContext::class);

        $context
            ->method('getShippingLocation')
            ->willReturn(
                ShippingLocation::createFromAddress(
                    $this->createAddress('example street')
                )
            );

        static::assertTrue(
            $rule->match(new CartRuleScope($cart$context))
        );
    }

    public function testCaseInsensitive(): void
    {
        $rule = (new ShippingStreetRule())->assign(['streetName' => 'ExaMple StreEt']);

        
'password' => 'shopware',
                ]
            );

        $response = $this->browser->getResponse();

        $contextToken = $response->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN) ?? '';
        static::assertNotEmpty($contextToken);

        $this->browser->setServerParameter('HTTP_SW_CONTEXT_TOKEN', $contextToken);

        $this->newAddressId = $this->createAddress();
    }

    public function testSwitchBilling(): void
    {
        $this->browser
            ->request(
                'POST',
                '/store-api/account/customer',
                []
            );

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