responseHeaderNotContains example

$this->submitForm($edit, 'Search');
    $this->assertSession()->pageTextContains('Your search yielded no results.');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:search.page.node_search');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'search_index');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'search_index:node_search');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'node_list');

    // Initial page for searching users.     $this->drupalGet('search/user');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:search.page.user_search');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'user_list');
    $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index');
    $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index:user_search');

    // User search results.     $edit['keys'] = $this->searchingUser->getAccountName();
    $this->drupalGet('search/user');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:search.page.user_search');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'user_list');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'user:2');
    $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index');
    $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index:user_search');
  }
    $this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response'));
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Hello world!');
    $this->drupalGet(Url::fromRoute('early_rendering_controller_test.ajax_response.early'));
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Hello world!');

    // Basic Response object: non-early & early.     $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response'));
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Hello world!');
    $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
    $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response.early'));
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Hello world!');
    $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');

    // Response object with attachments: non-early & early.     $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments'));
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Hello world!');
    $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'foo');
    $this->drupalGet(Url::fromRoute('early_rendering_controller_test.response-with-attachments.early'));
    
'settings' => [
        'image_link' => 'file',
        'responsive_image_style' => 'style_one',
      ],
    ];
    $display = $display_repository->getViewDisplay('node', 'article');
    $display->setComponent($field_name$display_options)
      ->save();

    $this->drupalGet('node/' . $nid);
    // No image style cache tag should be found.     $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');

    $this->assertSession()->responseMatches('/<a(.*?)href="' . preg_quote($this->fileUrlGenerator->generateString($image_uri), '/') . '"(.*?)>\s*<picture/');
    // Verify that the image can be downloaded.     $this->assertEquals(file_get_contents($test_image->uri)$this->drupalGet($this->fileUrlGenerator->generateAbsoluteString($image_uri)), 'File was downloaded successfully.');
    if ($scheme == 'private') {
      // Only verify HTTP headers when using private scheme and the headers are       // sent by Drupal.       $this->assertSession()->responseHeaderEquals('Content-Type', 'image/png');
      $this->assertSession()->responseHeaderContains('Cache-Control', 'private');

      // Log out and ensure the file cannot be accessed.
class BlockInstallTest extends BrowserTestBase {

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  public function testCacheTagInvalidationUponInstallation() {
    // Warm the page cache.     $this->drupalGet('');
    $this->assertSession()->pageTextNotContains('Powered by Drupal');
    $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'config:block_list');

    // Install the block module, and place the "Powered by Drupal" block.     $this->container->get('module_installer')->install(['block', 'shortcut']);
    $this->rebuildContainer();
    $this->drupalPlaceBlock('system_powered_by_block');

    // Check the same page, block.module's hook_install() should have     // invalidated the 'rendered' cache tag to make blocks show up.     $this->drupalGet('');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:block_list');
    $this->assertSession()->pageTextContains('Powered by Drupal');
  }
/** * The use of responseHeaderNotContains() is not available. * * @param string $name * The name of the header. * @param string $value * The value to check the header against. */
  public function responseHeaderNotContains($name$value) {
    @trigger_error('Support for responseHeaderNotContains is to be dropped from JavaScript tests. See https://www.drupal.org/node/2857562.');
    parent::responseHeaderNotContains($name$value);
  }

  /** * The use of responseHeaderMatches() is not available. * * @param string $name * The name of the header. * @param string $regex * The value to check the header against. */
  public function responseHeaderMatches($name$regex) {
    @

      else {
        // Check for PNG-Signature         // (cf. http://www.libpng.org/pub/png/book/chapter08.html#png.ch08.div.2)         // in the response body.         $raw = $this->getSession()->getPage()->getContent();
        $this->assertStringNotContainsString(chr(137) . chr(80) . chr(78) . chr(71) . chr(13) . chr(10) . chr(26) . chr(10)$raw);
      }
    }
    else {
      $this->assertSession()->responseHeaderEquals('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
      $this->assertSession()->responseHeaderNotContains('Cache-Control', 'no-cache');

      if ($clean_url) {
        // Add some extra chars to the token.         $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', IMAGE_DERIVATIVE_TOKEN . '=Zo', $generate_url));
        $this->assertSession()->statusCodeEquals(200);
      }
    }

    // Allow insecure image derivatives to be created for the remainder of this     // test.     $this->config('image.settings')
      
$this->drupalGet('error-test/trigger-renderer-exception');
    $this->assertSession()->statusCodeEquals(500);
    $this->assertErrorMessage($error_renderer_exception);

    // Disable error reporting, ensure that 5xx responses are not cached.     $this->config('system.logging')
      ->set('error_level', ERROR_REPORTING_HIDE)
      ->save();

    $this->drupalGet('error-test/trigger-exception');
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
    $this->assertSession()->responseHeaderNotContains('Cache-Control', 'public');
    $this->assertSession()->statusCodeEquals(500);
    $this->assertNoErrorMessage($error_exception);
  }

  /** * Helper function: assert that the error message is found. * * @internal */
  public function assertErrorMessage(array $error): void {
    $message = new FormattableMarkup('%type: @message in %function (line ', $error);
    
'#width' => 40,
      '#height' => 20,
      '#alt' => $alt,
      '#attributes' => ['loading' => 'lazy'],
    ];
    $default_output = '<a href="' . $file->createFileUrl() . '">' . $renderer->renderRoot($image) . '</a>';
    $this->drupalGet('node/' . $nid);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
    // @todo Remove in https://www.drupal.org/node/2646744.     $this->assertCacheContext('url.site');
    // Verify that no image style cache tags are found.     $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');
    $this->assertSession()->responseContains($default_output);
    // Verify that the image can be downloaded.     $this->assertEquals(file_get_contents($test_image->uri)$this->drupalGet($file->createFileUrl(FALSE)), 'File was downloaded successfully.');
    if ($scheme == 'private') {
      // Only verify HTTP headers when using private scheme and the headers are       // sent by Drupal.       $this->assertSession()->responseHeaderEquals('Content-Type', 'image/png');
      $this->assertSession()->responseHeaderContains('Cache-Control', 'private');

      // Log out and ensure the file cannot be accessed.       $this->drupalLogout();
      
// Enable CORS with the default options.     $cors_config['enabled'] = TRUE;

    $this->setContainerParameter('cors.config', $cors_config);
    $this->rebuildContainer();

    // Fire off a request.     $this->drupalGet('/test-page', []['Origin' => 'http://example.com']);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
    $this->assertSession()->responseHeaderEquals('Access-Control-Allow-Origin', '*');
    $this->assertSession()->responseHeaderNotContains('Vary', 'Origin');

    // Fire the same exact request. This time it should be cached.     $this->drupalGet('/test-page', []['Origin' => 'http://example.com']);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');
    $this->assertSession()->responseHeaderEquals('Access-Control-Allow-Origin', '*');
    $this->assertSession()->responseHeaderNotContains('Vary', 'Origin');

    // Fire a request for a different origin. Verify the CORS header.     $this->drupalGet('/test-page', []['Origin' => 'http://example.org']);
    $this->assertSession()->statusCodeEquals(200);
    
// Check replacing default headers.     $this->drupalGet('system-test/set-header', ['query' => ['name' => 'Expires', 'value' => 'Fri, 19 Nov 2008 05:00:00 GMT']]);
    $this->assertSession()->responseHeaderEquals('Expires', 'Fri, 19 Nov 2008 05:00:00 GMT');
    $this->drupalGet('system-test/set-header', ['query' => ['name' => 'Vary', 'value' => 'User-Agent']]);
    $this->assertSession()->responseHeaderContains('Vary', 'user-agent');

    // Check that authenticated users bypass the cache.     $user = $this->drupalCreateUser();
    $this->drupalLogin($user);
    $this->drupalGet('system-test/set-header', ['query' => ['name' => 'Foo', 'value' => 'bar']]);
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
    $this->assertSession()->responseHeaderNotContains('Vary', 'cookie');
    $this->assertSession()->responseHeaderEquals('Cache-Control', 'must-revalidate, no-cache, private');
    $this->assertSession()->responseHeaderEquals('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
    $this->assertSession()->responseHeaderEquals('Foo', 'bar');

    // Until bubbling of max-age up to the response is supported, verify that     // a custom #cache max-age set on an element does not affect page max-age.     $this->drupalLogout();
    $this->drupalGet('system-test/cache_maxage_page');
    $this->assertSession()->responseHeaderEquals('Cache-Control', 'max-age=300, public');
  }

  
$connection = Database::getConnection();
    $log_count = $connection->select('watchdog')->countQuery()->execute()->fetchField();

    // By not calling performMetaRefresh() here, we simulate JavaScript being     // enabled, because as far as the BigPipe module is concerned, JavaScript is     // enabled in the browser as long as the BigPipe no-JS cookie is *not* set.     // @see setUp()     // @see performMetaRefresh()
    $this->drupalGet(Url::fromRoute('big_pipe_test'));
    $this->assertBigPipeResponseHeadersPresent();
    $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'cache_tag_set_in_lazy_builder');

    $this->setCsrfTokenSeedInTestEnvironment();
    $cases = $this->getTestCases();
    $this->assertBigPipeNoJsPlaceholders([
      $cases['edge_case__invalid_html']->bigPipeNoJsPlaceholder     => $cases['edge_case__invalid_html']->embeddedHtmlResponse,
      $cases['html_attribute_value']->bigPipeNoJsPlaceholder        => $cases['html_attribute_value']->embeddedHtmlResponse,
      $cases['html_attribute_value_subset']->bigPipeNoJsPlaceholder => $cases['html_attribute_value_subset']->embeddedHtmlResponse,
    ]);
    $this->assertBigPipePlaceholders([
      $cases['html']->bigPipePlaceholderId                             => Json::encode($cases['html']->embeddedAjaxResponseCommands),
      $cases['edge_case__html_non_lazy_builder']->bigPipePlaceholderId => Json::encode($cases['edge_case__html_non_lazy_builder']->embeddedAjaxResponseCommands),
      
$account = $this->drupalCreateUser();
    $url = Url::fromRoute('router_test.11');

    // Ensure we can log in with valid authentication details.     $this->basicAuthGet($url$account->getAccountName()$account->pass_raw);
    $this->assertSession()->pageTextContains($account->getAccountName());
    $this->assertSession()->statusCodeEquals(200);
    $this->mink->resetSessions();
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
    // Check that Cache-Control is not set to public.     $this->assertSession()->responseHeaderNotContains('Cache-Control', 'public');

    // Ensure that invalid authentication details give access denied.     $this->basicAuthGet($url$account->getAccountName()$this->randomMachineName());
    $this->assertSession()->pageTextNotContains($account->getAccountName());
    $this->assertSession()->statusCodeEquals(403);
    $this->mink->resetSessions();

    // Ensure that the user is prompted to authenticate if they are not yet     // authenticated and the route only allows basic auth.     $this->drupalGet($url);
    $this->assertSession()->responseHeaderEquals('WWW-Authenticate', 'Basic realm="' . \Drupal::config('system.site')->get('name') . '"');
    
Home | Imprint | This part of the site doesn't use cookies.