getSalesChannelBrowser example

$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();
        }

        $browser
            ->request(
                'POST',
                '/store-api/account/login',
                [
                    'email' => $email,
                    'password' => 'shopware',
                ]
            );

        
static::assertArrayHasKey('fileName', $data[0]);
    }

    public function testReadWithoutPermissionForSalesChannelSourceWithJsonType(): void
    {
        $id = Uuid::randomHex();
        /** @var EntityRepository $repository */
        $repository = $this->getContainer()->get('product.repository');

        // when we create a salesChannelBrowser we also create a new SalesChannel,         // we need the id of the salesChannel for the visibilities         $browser = $this->getSalesChannelBrowser();
        $browser->setServerParameter('HTTP_ACCEPT', 'application/vnd.api+json');

        $data = [
            'id' => $id,
            'productNumber' => Uuid::randomHex(),
            'name' => 'test',
            'stock' => 1,
            'active' => true,
            'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 10, 'net' => 9, 'linked' => false]],
            'manufacturer' => ['name' => 'test'],
            'tax' => ['taxRate' => 13, 'name' => 'green'],
            
$this->customerRepository = $kernel->getContainer()->get('customer.repository');
        $this->customerAddressRepository = $kernel->getContainer()->get('customer_address.repository');
    }

    public function testUpdateContextWithNonExistingParameters(): void
    {
        $testId = Uuid::randomHex();

        /* * Shipping method */
        $this->getSalesChannelBrowser()->request('PATCH', '/store-api/context', ['shippingMethodId' => $testId]);
        $content = json_decode($this->getSalesChannelBrowser()->getResponse()->getContent() ?: '', true, 512, \JSON_THROW_ON_ERROR);

        static::assertEquals(
            sprintf('The "shipping_method" entity with id "%s" does not exist.', $testId),
            $content['errors'][0]['detail'] ?? null
        );

        /* * Payment method */
        $this->getSalesChannelBrowser()->request('PATCH', '/store-api/context', ['paymentMethodId' => $testId]);
        
'ce_blog_comment' => ['title', 'content', 'email'],
                'product' => ['name', 'productNumber', 'price'],
                'dal_entity_search_result' => ['elements'],
            ],
            'associations' => [
                'topSellerCascade' => [],
                'linkProductCascade' => [],
                'comments' => [],
            ],
        ];

        $browser = $this->getSalesChannelBrowser();
        $browser->request('POST', '/store-api/script/blog', $criteria);

        $response = \json_decode((string) $browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        $salesChannelId = $browser->getServerParameter('test-sales-channel-id');
        $this->getContainer()->get(Connection::class)->executeStatement('DELETE FROM sales_channel WHERE id = :id', ['id' => Uuid::fromHexToBytes($salesChannelId)]);

        static::assertSame(Response::HTTP_OK, $browser->getResponse()->getStatusCode()print_r($response, true));

        $traces = $this->getScriptTraces();
        static::assertArrayHasKey('store-api-blog::response', $traces);
        

class ScriptStoreApiRouteTest extends TestCase
{
    use AppSystemTestBehaviour;
    use IntegrationTestBehaviour;
    use SalesChannelApiTestBehaviour;

    private KernelBrowser $browser;

    protected function setUp(): void
    {
        $this->browser = $this->getSalesChannelBrowser();
    }

    public function testApiEndpoint(): void
    {
        $this->loadAppsFromDir(__DIR__ . '/_fixtures');

        $this->browser->request('POST', '/store-api/script/simple-script');
        static::assertNotFalse($this->browser->getResponse()->getContent());

        $response = \json_decode($this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        static::assertSame(Response::HTTP_OK, $this->browser->getResponse()->getStatusCode()$this->browser->getResponse()->getContent());

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