getServerParameter example

'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);
        static::assertCount(1, $traces['store-api-blog::response']);
        static::assertSame('some debug information', $traces['store-api-blog::response'][0]['output'][0]);

        $expected = [
            'apiAlias' => 'store_api_blog_response',
            
'active' => true,
                'isCloseout' => true,
                'visibilities' => [
                    ['salesChannelId' => $this->ids->get('sales-channel'), 'visibility' => ProductVisibilityDefinition::VISIBILITY_ALL],
                ],
            ],
        ], Context::createDefaultContext());
    }

    private function enableAdminAccess(): void
    {
        $token = $this->browser->getServerParameter('HTTP_SW_CONTEXT_TOKEN');
        $payload = $this->getContainer()->get(SalesChannelContextPersister::class)->load($token$this->ids->get('sales-channel'));

        $payload[SalesChannelContextService::PERMISSIONS] = [ProductCartProcessor::ALLOW_PRODUCT_PRICE_OVERWRITES => true];

        $this->getContainer()->get(SalesChannelContextPersister::class)->save($token$payload$this->ids->get('sales-channel'));
    }
}


    protected function tearDown(): void
    {
        $this->resetBrowser();
    }

    public function testGetConfigMe(): void
    {
        $configKey = 'me.read';

        $contextBrowser = $this->getBrowser()->getServerParameter(PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT);
        $userId = Uuid::fromBytesToHex($contextBrowser->getSource()->getUserId());

        $this->getContainer()->get('user_config.repository')
            ->create([[
                'userId' => $userId,
                'key' => $configKey,
                'value' => ['content'],
            ]], Context::createDefaultContext());

        $this->getBrowser()->request('GET', '/api/_info/config-me', ['keys' => [$configKey]]);
        $response = $this->getBrowser()->getResponse();

        

    public function testOffCanvasWithErrorsFlash(ErrorCollection $errors, array $errorKeys, bool $testSwitchToDefault = false): void
    {
        $browser = $this->getBrowserWithLoggedInCustomer();
        $browser->followRedirects(true);

        // Clear flashback from login and/or register         /** @var Session $session */
        $session = $this->getSession();
        $session->getFlashBag()->clear();

        $browserSalesChannelId = $browser->getServerParameter('test-sales-channel-id');

        $productId = Uuid::randomHex();
        $this->createProductOnDatabase($productId, 'test.123', $browserSalesChannelId);

        foreach ($errors as $error) {
            $this->prepareErrors(
                $error,
                $browser,
                $browserSalesChannelId,
                $productId,
                $testSwitchToDefault
            );
'tax' => ['id' => $this->ids->create('tax'), 'taxRate' => 17, 'name' => 'with id'],
                'active' => true,
                'visibilities' => [
                    ['salesChannelId' => $this->ids->get('sales-channel'), 'visibility' => ProductVisibilityDefinition::VISIBILITY_ALL],
                ],
            ],
        ], Context::createDefaultContext());
    }

    private function enableAdminAccess(): void
    {
        $token = $this->browser->getServerParameter('HTTP_SW_CONTEXT_TOKEN');
        $payload = $this->getContainer()->get(SalesChannelContextPersister::class)->load($token$this->ids->get('sales-channel'));

        $payload[SalesChannelContextService::PERMISSIONS] = [ProductCartProcessor::ALLOW_PRODUCT_PRICE_OVERWRITES => true];

        $this->getContainer()->get(SalesChannelContextPersister::class)->save($token$payload$this->ids->get('sales-channel'));
    }
}
private string $userId;

    protected function setUp(): void
    {
        $gatewayRegistry = $this->getContainer()->get('shopware.increment.gateway.registry');

        $gateway = $gatewayRegistry->get(IncrementGatewayRegistry::USER_ACTIVITY_POOL);

        $this->gateway = $gateway;

        /** @var Context $context */
        $context = $this->getBrowser()->getServerParameter(PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT);

        /** @var AdminApiSource $source */
        $source = $context->getSource();
        static::assertNotNull($source->getUserId());
        $this->userId = Uuid::fromBytesToHex($source->getUserId());

        $this->gateway->reset($this->userId, 'foo');
    }

    public function testListEndpoint(): void
    {
        
static::assertArrayHasKey('foo', $response);
        static::assertEquals('bar', $response['foo']);
        static::assertSame('store_api_simple_script_response', $response['apiAlias']);
    }

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

        $ids = new IdsCollection();

        $salesChannelId = $this->browser->getServerParameter('test-sales-channel-id');

        $products = [
            (new ProductBuilder($ids, 'p1'))->visibility($salesChannelId)->price(100)->build(),
            (new ProductBuilder($ids, 'p2'))->visibility($salesChannelId)->price(200)->build(),
        ];

        $this->getContainer()->get('product.repository')->create($products, Context::createDefaultContext());

        $criteria = [
            'filter' => [
                ['type' => 'equals', 'field' => 'productNumber', 'value' => 'p1'],
            ],
'tax' => ['id' => $this->ids->create('tax'), 'taxRate' => 17, 'name' => 'with id'],
                'active' => true,
                'visibilities' => [
                    ['salesChannelId' => $this->ids->get('sales-channel'), 'visibility' => ProductVisibilityDefinition::VISIBILITY_ALL],
                ],
            ],
        ], Context::createDefaultContext());
    }

    private function enableAdminAccess(): void
    {
        $token = $this->browser->getServerParameter('HTTP_SW_CONTEXT_TOKEN');
        $payload = $this->getContainer()->get(SalesChannelContextPersister::class)->load($token$this->ids->get('sales-channel'));

        $payload[SalesChannelContextService::PERMISSIONS] = [ProductCartProcessor::ALLOW_PRODUCT_PRICE_OVERWRITES => true];

        $this->getContainer()->get(SalesChannelContextPersister::class)->save($token$payload$this->ids->get('sales-channel'));
    }
}
/** * Sets the Guzzle client. * * @param \GuzzleHttp\ClientInterface $client * The Guzzle client. * * @return $this */
  public function setClient(ClientInterface $client) {
    $this->client = $client;

    if ($this->getServerParameter('HTTP_HOST', NULL) !== NULL || $base_uri = $client->getConfig('base_uri') === NULL) {
      return $this;
    }

    $path = $base_uri->getPath();
    if ($path !== '' && $path !== '/') {
      throw new \InvalidArgumentException('Setting a path in the Guzzle "base_uri" config option is not supported by DrupalTestBrowser.');
    }

    if ($this->getServerParameter('HTTPS', NULL) === NULL && $base_uri->getScheme() === 'https') {
      $this->setServerParameter('HTTPS', 'on');
    }

    
$this->expectExceptionMessage('The "request()" method must be called before "Symfony\\Component\\BrowserKit\\AbstractBrowser::getRequest()".');

        $client = $this->getBrowser();
        $this->assertNull($client->getRequest());
    }

    public function testXmlHttpRequest()
    {
        $client = $this->getBrowser();
        $client->xmlHttpRequest('GET', 'http://example.com/', [][][], null, true);
        $this->assertSame('XMLHttpRequest', $client->getRequest()->getServer()['HTTP_X_REQUESTED_WITH']);
        $this->assertFalse($client->getServerParameter('HTTP_X_REQUESTED_WITH', false));
    }

    public function testJsonRequest()
    {
        $client = $this->getBrowser();
        $client->jsonRequest('GET', 'http://example.com/', ['param' => 1][], true);
        $this->assertSame('application/json', $client->getRequest()->getServer()['CONTENT_TYPE']);
        $this->assertSame('application/json', $client->getRequest()->getServer()['HTTP_ACCEPT']);
        $this->assertFalse($client->getServerParameter('CONTENT_TYPE', false));
        $this->assertFalse($client->getServerParameter('HTTP_ACCEPT', false));
        $this->assertSame('{"param":1}', $client->getRequest()->getContent());
    }
$browser = $this->createCart($salesChannel['id']);

        $browser->request('PATCH', $this->getRootProxyUrl('/switch-customer')[
            'salesChannelId' => $salesChannel['id'],
            'customerId' => $customerId,
        ]);

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

        $contextTokenHeaderName = $this->getContextTokenHeaderName();
        static::assertTrue($response->headers->has(PlatformRequest::HEADER_CONTEXT_TOKEN));
        static::assertEquals($browser->getServerParameter($contextTokenHeaderName)$response->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN));

        static::assertIsString($salesChannel['id']);
        // assert customer is updated in database         $payload = $this->contextPersister->load($response->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN, '')$salesChannel['id']);
        static::assertArrayHasKey('customerId', $payload);
        static::assertEquals($customerId$payload['customerId']);
    }

    public function testSwitchCustomerWithPermissions(): void
    {
        $salesChannel = $this->createSalesChannel();
        
Home | Imprint | This part of the site doesn't use cookies.