responseHeaderContains example

/** * Tests cache headers. */
  public function testPageCache() {
    $config = $this->config('system.performance');
    $config->set('cache.page.max_age', 300);
    $config->save();

    // Fill the cache.     $this->drupalGet('system-test/set-header', ['query' => ['name' => 'Foo', 'value' => 'bar']]);
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
    $this->assertSession()->responseHeaderContains('Vary', 'cookie');
    // Symfony's Response logic determines a specific order for the subvalues     // of the Cache-Control header, even if they are explicitly passed in to     // the response header bag in a different order.     $this->assertSession()->responseHeaderEquals('Cache-Control', 'max-age=300, public');
    $this->assertSession()->responseHeaderEquals('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
    $this->assertSession()->responseHeaderEquals('Foo', 'bar');

    // Check cache.     $this->drupalGet('system-test/set-header', ['query' => ['name' => 'Foo', 'value' => 'bar']]);
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');
    $this->assertSession()->responseHeaderContains('Vary', 'cookie');
    
$build = $list_builder->render();
    $this->container->get('renderer')->renderRoot($build);

    $this->assertEqualsCanonicalizing(['entity_test_view_grants', 'languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url.query_args.pagers:0', 'user.permissions']$build['#cache']['contexts']);
  }

  /** * Tests if the list cache tags are set. */
  public function testCacheTags() {
    $this->drupalGet('entity_test/list');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'entity_test_list');
  }

}
$node_auth_1->save();

    $favorite_animal_test_url = Url::fromRoute('jsonapi.user--user.collection')->setOption('query', ['filter[field_favorite_animal]' => 'stegosaurus']);

    // Test.     $collection_url = Url::fromRoute('jsonapi.node--x.collection');
    $request_options = [];
    $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
    $request_options = NestedArray::mergeDeep($request_options$this->getAuthenticationRequestOptions());
    // ?filter[uid.id]=OWN_UUID requires no permissions: 1 result.     $response = $this->request('GET', $collection_url->setOption('query', ['filter[uid.id]' => $this->account->uuid()])$request_options);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Contexts', 'user.permissions');
    $doc = Json::decode((string) $response->getBody());
    $this->assertCount(1, $doc['data']);
    $this->assertSame($node_auth_1->uuid()$doc['data'][0]['id']);
    // ?filter[uid.id]=ANONYMOUS_UUID: 0 results.     $response = $this->request('GET', $collection_url->setOption('query', ['filter[uid.id]' => User::load(0)->uuid()])$request_options);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Contexts', 'user.permissions');
    $doc = Json::decode((string) $response->getBody());
    $this->assertCount(0, $doc['data']);
    // ?filter[uid.name]=A: 0 results.     $response = $this->request('GET', $collection_url->setOption('query', ['filter[uid.name]' => 'A'])$request_options);
    $doc = Json::decode((string) $response->getBody());
    
/** * Tests selecting the variant and passing configuration. */
  public function testPageDisplayVariantSelectionEvent() {
    // Tests that our display variant was selected, and that its configuration     // was passed correctly. If the configuration wasn't passed, we'd get an     // error page here.     $this->drupalGet('<front>');
    $this->assertSession()->pageTextContains('A very important, required value.');
    $this->assertSession()->pageTextContains('Explicitly passed in context.');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'custom_cache_tag');
  }

}
$this->drupalGet('node/add/' . $type->id());
    $this->assertSession()->statusCodeEquals(200);

    // Create a content type via the user interface.     $web_user = $this->drupalCreateUser([
      'bypass node access',
      'administer content types',
    ]);
    $this->drupalLogin($web_user);

    $this->drupalGet('node/add');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:node_type_list');
    $this->assertCacheContext('user.permissions');
    $elements = $this->cssSelect('dl dt');
    $this->assertCount(3, $elements);

    $edit = [
      'name' => 'foo',
      'title_label' => 'title for foo',
      'type' => 'foo',
    ];
    $this->drupalGet('admin/structure/types/add');
    $this->submitForm($edit, 'Save and manage fields');
    
$this->checkBookNode($nodes[0][$nodes[1]$nodes[2]]$book$book$nodes[1][$book]);
    $this->checkBookNode($nodes[1], NULL, $nodes[0]$nodes[0]$nodes[2][$book$nodes[0]]);
    $this->checkBookNode($nodes[2], NULL, $nodes[1]$nodes[0]$nodes[3][$book$nodes[0]]);
    $this->checkBookNode($nodes[3], NULL, $nodes[2]$book$nodes[4][$book]);
    $this->checkBookNode($nodes[4], NULL, $nodes[3]$book, FALSE, [$book]);

    $this->drupalLogout();
    $this->drupalLogin($this->bookAuthor);

    // Check the presence of expected cache tags.     $this->drupalGet('node/add/book');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:book.settings');

    /* * Add Node 5 under Node 3. * Book * |- Node 0 * |- Node 1 * |- Node 2 * |- Node 3 * |- Node 5 * |- Node 4 */
    
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
  }

  /** * Tests the presence of the expected cache tag in various situations. */
  public function testSearchText() {
    $this->drupalLogin($this->searchingUser);

    // Initial page for searching nodes.     $this->drupalGet('search/node');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:search.page.node_search');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'search_index:node_search');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'node_list');

    // Node search results.     $edit = [];
    $edit['keys'] = 'bike shed';
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->pageTextContains('bike shed shop');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:search.page.node_search');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'search_index');
    
/** * Tests forum functionality through the admin and user interfaces. */
  public function testForum() {
    // Check that the basic forum install creates a default forum topic     $this->drupalGet('/forum');
    // Look for the "General discussion" default forum     $this->assertSession()->linkExists('General discussion');
    $this->assertSession()->linkByHrefExists('/forum/1');
    // Check the presence of expected cache tags.     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:forum.settings');

    $this->drupalGet(Url::fromRoute('forum.page', ['taxonomy_term' => 1]));
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:forum.settings');

    // Do the admin tests.     $this->doAdminTests($this->adminUser);

    // Check display order.     $display = EntityViewDisplay::load('node.forum.default');
    $body = $display->getComponent('body');
    $comment = $display->getComponent('comment_forum');
    
$this->assertSession()->responseHeaderEquals('Content-Type', $image->getMimeType());
    $this->assertSession()->responseHeaderEquals('Content-Length', (string) $image->getFileSize());

    // Check that we did not download the original file.     $original_image = $this->container->get('image.factory')
      ->get($original_uri);
    $this->assertSession()->responseHeaderNotEquals('Content-Length', (string) $original_image->getFileSize());

    if ($scheme == 'private') {
      $this->assertSession()->responseHeaderEquals('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
      // Check that Cache-Control header contains 'no-cache' to prevent caching.       $this->assertSession()->responseHeaderContains('Cache-Control', 'no-cache');
      $this->assertSession()->responseHeaderEquals('X-Image-Owned-By', 'image_module_test');

      // Make sure that a second request to the already existing derivative       // works too.       $this->drupalGet($generate_url);
      $this->assertSession()->statusCodeEquals(200);

      // Check that the second request also returned the generated image.       $this->assertSession()->responseHeaderEquals('Content-Length', (string) $image->getFileSize());

      // Check that we did not download the original file.
// Configure the CORS stack to allow a specific set of origins.     $cors_config['allowedOrigins'] = ['http://example.com', 'https://drupal.org'];

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

    // Fire a request from an origin that isn't allowed.     /** @var \Symfony\Component\HttpFoundation\Response $response */
    $this->drupalGet('/test-page', []['Origin' => 'http://non-valid.com']);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->responseHeaderEquals('Access-Control-Allow-Origin', NULL);
    $this->assertSession()->responseHeaderContains('Vary', 'Origin');

    // Specify a valid origin.     $this->drupalGet('/test-page', []['Origin' => 'http://example.com']);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->responseHeaderEquals('Access-Control-Allow-Origin', 'http://example.com');
    $this->assertSession()->responseHeaderContains('Vary', 'Origin');

    // Specify a valid origin.     $this->drupalGet('/test-page', []['Origin' => 'https://drupal.org']);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->responseHeaderEquals('Access-Control-Allow-Origin', 'https://drupal.org');
    
'administer contact forms',
      'administer users',
      'administer account settings',
      'administer contact_message display',
      'administer contact_message fields',
      'administer contact_message form display',
    ]);
    $this->drupalLogin($admin_user);

    // Check the presence of expected cache tags.     $this->drupalGet('contact');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:contact.settings');

    $flood_limit = 3;
    $this->config('contact.settings')
      ->set('flood.limit', $flood_limit)
      ->set('flood.interval', 600)
      ->save();

    // Set settings.     $edit = [];
    $edit['contact_default_status'] = TRUE;
    $this->drupalGet('admin/config/people/accounts');
    
/** * Tests if config overrides correctly set cacheability metadata. */
  public function testConfigOverride() {
    // Check the default (disabled) state of the cache context. The block label     // should not be overridden.     $this->drupalGet('<front>');
    $this->assertSession()->pageTextNotContains('Overridden block label');

    // Both the cache context and tag should be present.     $this->assertCacheContext('config_override_integration_test');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config_override_integration_test_tag');

    // Flip the state of the cache context. The block label should now be     // overridden.     \Drupal::state()->set('config_override_integration_test.enabled', TRUE);
    $this->drupalGet('<front>');
    $this->assertSession()->pageTextContains('Overridden block label');

    // Both the cache context and tag should still be present.     $this->assertCacheContext('config_override_integration_test');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config_override_integration_test_tag');
  }

}
$item = $this->addMenuLink('', '/node/' . $node->id());
    $this->modifyMenuLink($item);

    // Test that a user with 'administer menu' but without 'bypass node access'     // cannot see the menu item.     $this->drupalLogout();
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/structure/menu/manage/' . $item->getMenuName());
    $this->assertSession()->pageTextNotContains($item->getTitle());
    // The cache contexts associated with the (in)accessible menu links are     // bubbled. See DefaultMenuLinkTreeManipulators::menuLinkCheckAccess().     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Contexts', 'user.permissions');
  }

  /** * Adds a menu link using the UI. * * @param string $parent * Optional parent menu link id. * @param string $path * The path to enter on the form. Defaults to the front page. * @param string $menu_name * Menu name. Defaults to 'tools'. * @param bool $expanded * Whether or not this menu link is expanded. Setting this to TRUE should * test whether it works when we do the authenticatedUser tests. Defaults * to FALSE. * @param string $weight * Menu weight. Defaults to 0. * * @return \Drupal\menu_link_content\Entity\MenuLinkContent * A menu link entity. */
/** * The use of responseHeaderContains() is not available. * * @param string $name * The name of the header. * @param string $value * The value to check the header against. */
  public function responseHeaderContains($name$value) {
    @trigger_error('Support for responseHeaderContains is to be dropped from JavaScript tests. See https://www.drupal.org/node/2857562.');
    parent::responseHeaderContains($name$value);
  }

  /** * 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) {
    @
$this->getTranslatePermission(),
        "$current_op content translations",
        'view test entity',
      ]);
      $this->drupalLogin($user);
      $this->drupalGet($translations_url);

      // Make sure that the user.permissions cache context and the cache tags       // for the entity are present.       $this->assertCacheContext('user.permissions');
      foreach ($this->entity->getCacheTags() as $cache_tag) {
        $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $cache_tag);
      }

      foreach ($ops as $op => $label) {
        if ($op != $current_op) {
          $this->assertSession()->linkNotExists($labelnew FormattableMarkup('No %op link found.', ['%op' => $label]));
        }
        else {
          $this->assertSession()->linkExists($label, 0, new FormattableMarkup('%op link found.', ['%op' => $label]));
        }
      }
    }

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