request example

$this->rawCookieName = $config->cookieName;

        if ($this->isCSRFCookie()) {
            $cookie = config(CookieConfig::class);

            $this->configureCookie($cookie);
        } else {
            // Session based CSRF protection             $this->configureSession();
        }

        $this->request      = Services::request();
        $this->hashInCookie = $this->request->getCookie($this->cookieName);

        $this->restoreHash();
        if ($this->hash === null) {
            $this->generateHash();
        }
    }

    private function isCSRFCookie(): bool
    {
        return $this->config->csrfProtection === self::CSRF_PROTECTION_COOKIE;
    }

  public function getExposedInput() {
    // Fill our input either from \Drupal::request()->query or from something     // previously set on the view.     if (empty($this->exposed_input)) {
      // Ensure that we can call the method at any point in time.       $this->initDisplay();

      $this->exposed_input = \Drupal::request()->query->all();
      // unset items that are definitely not our input:       foreach (['page', 'q', 'ajax_page_state'] as $key) {
        if (isset($this->exposed_input[$key])) {
          unset($this->exposed_input[$key]);
        }
      }

      // If we have no input at all, check for remembered input via session.       if (empty($this->exposed_input) && $this->request->hasSession()) {
        $session = \Drupal::request()->getSession();
        // If filters are not overridden, store the 'remember' settings on the

class AppUrlChangeControllerTest extends TestCase
{
    use AdminApiTestBehaviour;
    use AppSystemTestBehaviour;
    use IntegrationTestBehaviour;

    public function testGetAvailableStrategies(): void
    {
        $url = '/api/app-system/app-url-change/strategies';
        $this->getBrowser()->request('GET', $url);
        static::assertNotFalse($this->getBrowser()->getResponse()->getContent());

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

        static::assertEquals(200, $this->getBrowser()->getResponse()->getStatusCode());

        $appUrlChangeResolver = $this->getContainer()->get(Resolver::class);
        static::assertEquals($appUrlChangeResolver->getAvailableStrategies()$response);
    }

    public function testResolveWithExistingStrategy(): void
    {
private TestDataCollection $ids;

    protected function setUp(): void
    {
        $this->ids = new TestDataCollection();

        $this->createData();
    }

    public function testNavigationPageLoadedHookScriptsAreExecuted(): void
    {
        $response = $this->request('GET', '/', []);
        static::assertEquals(200, $response->getStatusCode());

        $traces = $this->getContainer()->get(ScriptTraces::class)->getTraces();

        static::assertArrayHasKey(NavigationPageLoadedHook::HOOK_NAME, $traces);
    }

    public function testNavigationPageLoadedHookScriptsAreExecutedForCategory(): void
    {
        $response = $this->request('GET', '/navigation/' . $this->ids->get('category')[]);
        static::assertEquals(200, $response->getStatusCode());

        

    protected $request;

    /** * Constructor. */
    public function __construct(?RequestInterface $request = null)
    {
        if ($request === null) {
            $request = Services::request();
        }

        assert($request instanceof IncomingRequest || $request instanceof CLIRequest);

        $this->request = $request;
    }

    /** * Verifies that $name is the name of a valid uploaded file. */
    public function uploaded(?string $blank, string $name): bool
    {

        'input' => 'javascript:alert(0)',
        'output' => 'javascript:alert(0)',
        'message' => 'JavaScript URL is allowed because it is treated as an internal URL.',
      ],
    ];
    foreach ($test_cases as $test_case) {
      // Test $_GET['destination'].       $this->drupalGet('system-test/get-destination', ['query' => ['destination' => $test_case['input']]]);
      $this->assertSame($test_case['output']$session->getPage()->getContent()$test_case['message']);
      // Test $_REQUEST['destination'].       $post_output = $http_client->request('POST', $this->buildUrl('system-test/request-destination')[
        'form_params' => ['destination' => $test_case['input']],
      ]);
      $this->assertSame($test_case['output'](string) $post_output->getBody()$test_case['message']);
    }

    // Make sure that 404 pages do not populate $_GET['destination'] with     // external URLs.     \Drupal::configFactory()->getEditable('system.site')->set('page.404', '/system-test/get-destination')->save();
    $this->drupalGet('http://example.com', ['external' => FALSE]);
    $this->assertSession()->statusCodeEquals(404);
    $this->assertSame(Url::fromRoute('<front>')->toString()$session->getPage()->getContent(), 'External URL is not allowed on 404 pages.');
  }
protected function setUp(): void
    {
        parent::setUp();

        $this->orderRepository = $this->getContainer()->get('order.repository');
        $this->customerRepository = $this->getContainer()->get('customer.repository');
        $this->stateMachineHistoryRepository = $this->getContainer()->get('state_machine_history.repository');
    }

    public function testOrderNotFoundException(): void
    {
        $this->getBrowser()->request('GET', '/api/order/' . Uuid::randomHex() . '/actions/state');

        $response = $this->getBrowser()->getResponse()->getContent();
        static::assertIsString($response);
        $response = json_decode($response, true, 512, \JSON_THROW_ON_ERROR);

        static::assertEquals(Response::HTTP_NOT_FOUND, $this->getBrowser()->getResponse()->getStatusCode());
        static::assertArrayHasKey('errors', $response);
    }

    public function testGetAvailableStates(): void
    {
        
$this->repository = $this->getContainer()->get('import_export_file.repository');
        $this->connection = $this->getContainer()->get(Connection::class);
        $this->context = Context::createDefaultContext();
    }

    public function testImportExportFileCreateSuccess(): void
    {
        $num = 3;
        $data = $this->prepareImportExportFileTestData($num);

        foreach ($data as $entry) {
            $this->getBrowser()->request('POST', $this->prepareRoute()[][][]json_encode($entry, \JSON_THROW_ON_ERROR));
            $response = $this->getBrowser()->getResponse();
            static::assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()$response->getContent());
        }
        $records = $this->connection->fetchAllAssociative('SELECT * FROM import_export_file');

        static::assertCount($num$records);
        foreach ($records as $record) {
            $expect = $data[$record['id']];
            static::assertSame($expect['originalName']$record['original_name']);
            static::assertSame($expect['path']$record['path']);
            static::assertEquals(strtotime((string) $expect['expireDate'])strtotime((string) $record['expire_date']));
            
$this->token = $token;
        parent::__construct($client$dispatcher);
    }

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof ChatMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class$message);
        }

        $endpoint = sprintf('https://%s/api/notify', $this->getEndpoint());
        $response = $this->client->request('POST', $endpoint[
            'auth_bearer' => $this->token,
            'query' => [
                'message' => $message->getSubject(),
            ],
        ]);

        try {
            $statusCode = $response->getStatusCode();
        } catch (TransportException $e) {
            throw new TransportException('Could not reach the remote Line server.', $response, 0, $e);
        }

        
'id' => $this->ids->create('sales-channel'),
        ]);
        $this->assignSalesChannelContext($this->browser);

        $email = Uuid::randomHex() . '@example.com';
        $this->customerId = $this->createCustomer($email);

        $this->systemConfigService = $this->getContainer()->get(SystemConfigService::class);
        $this->systemConfigService->set('core.cart.wishlistEnabled', true);

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

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

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

class AuthControllerTest extends TestCase
{
    use AdminFunctionalTestBehaviour;
    use AppSystemTestBehaviour;

    public function testRequiresAuthentication(): void
    {
        $client = $this->getBrowser();
        $client->setServerParameter('HTTP_Authorization', '');
        $client->request('GET', '/api/tax');
        static::assertNotFalse($client->getResponse()->getContent());

        static::assertEquals(Response::HTTP_UNAUTHORIZED, $client->getResponse()->getStatusCode()$client->getResponse()->getContent());

        static::assertNotFalse($client->getResponse()->getContent());
        $response = \json_decode($client->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertArrayHasKey('errors', $response);
        static::assertCount(1, $response['errors']);
        static::assertEquals(Response::HTTP_UNAUTHORIZED, $response['errors'][0]['status']);
        static::assertEquals(
            
if (empty($validateUrl)) {
            return new ArrayStruct();
        }

        $payload = $this->buildValidatePayload($cart$requestDataBag$context);
        $app = $appPaymentMethod->getApp();
        if ($app === null) {
            throw PaymentException::validatePreparedPaymentInterrupted('App not defined');
        }

        try {
            $response = $this->payloadService->request($validateUrl$payload$app, ValidateResponse::class$context->getContext());
        } catch (ClientExceptionInterface $exception) {
            throw PaymentException::validatePreparedPaymentInterrupted(sprintf('App error: %s', $exception->getMessage()));
        }

        if (!$response instanceof ValidateResponse) {
            throw PaymentException::validatePreparedPaymentInterrupted('Invalid app response');
        }

        if ($response->getMessage()) {
            throw PaymentException::validatePreparedPaymentInterrupted($response->getMessage());
        }

        
/** @var RedirectResponse $response */
        $response = $registerController->confirmRegistration($this->salesChannelContext, $queryData);

        static::assertEquals(302, $response->getStatusCode());
        static::assertInstanceOf(RedirectResponse::class$response);
        static::assertEquals('/checkout/confirm', $response->getTargetUrl());
    }

    public function testAccountRegisterPageLoadedHookScriptsAreExecuted(): void
    {
        $response = $this->request('GET', '/account/register', []);
        static::assertEquals(200, $response->getStatusCode());

        $traces = $this->getContainer()->get(ScriptTraces::class)->getTraces();

        static::assertArrayHasKey(AccountRegisterPageLoadedHook::HOOK_NAME, $traces);
    }

    public function testCustomerGroupRegistrationPageLoadedHookScriptsAreExecuted(): void
    {
        $ids = new TestDataCollection();
        $this->createCustomerGroup($ids);

        

class UrlAlterTest extends KernelTestBase {

  /** * {@inheritdoc} */
  protected static $modules = ['path', 'url_alter_test', 'user'];

  public function testUrlWithQueryString() {
    // Test outbound query string altering.     $url = Url::fromRoute('user.login');
    $this->assertEquals(\Drupal::request()->getBaseUrl() . '/user/login?foo=bar', $url->toString());
  }

}

            ]
        );
    }

    public function testEmptyLanguageIdError(): void
    {
        $baseResource = '/api/category';
        $headerName = $this->getLangHeaderName();
        $langId = '';

        $this->getBrowser()->request('GET', $baseResource[][][$headerName => $langId]);
        $response = $this->getBrowser()->getResponse();
        static::assertEquals(412, $response->getStatusCode()$response->getContent());

        $data = json_decode($response->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        static::assertEquals(LanguageNotFoundException::LANGUAGE_NOT_FOUND_ERROR, $data['errors'][0]['code']);
    }

    public function testInvalidUuidLanguageIdError(): void
    {
        $baseResource = '/api/category';
        $headerName = $this->getLangHeaderName();
        
Home | Imprint | This part of the site doesn't use cookies.