responseHeaderExists example

    $this->assertSession()->pageTextContains('Test page text.');

    // Check that returned plain text is correct.     $text = $this->getTextContent();
    $this->assertStringContainsString('Test page text.', $text);
    $this->assertStringNotContainsString('</html>', $text);
    // Ensure Drupal Javascript settings are not part of the page text.     $this->assertArrayHasKey('currentPathIsAdmin', $this->getDrupalSettings()['path']);
    $this->assertStringNotContainsString('currentPathIsAdmin', $text);

    // Response includes cache tags that we can assert.     $this->assertSession()->responseHeaderExists('X-Drupal-Cache-Tags');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'http_response rendered');

    // Test that we can read the JS settings.     $js_settings = $this->getDrupalSettings();
    $this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);

    // Test drupalGet with a URL object.     $url = Url::fromRoute('test_page_test.render_title');
    $this->drupalGet($url);
    $this->assertSession()->statusCodeEquals(200);

    

  protected $defaultTheme = 'stark';

  /** * Tests WebAssert::responseHeaderExists(). * * @covers ::responseHeaderExists */
  public function testResponseHeaderExists() {
    $this->drupalGet('test-null-header');
    $this->assertSession()->responseHeaderExists('Null-Header');

    $this->expectException(AssertionFailedError::class);
    $this->expectExceptionMessage("Failed asserting that the response has a 'does-not-exist' header.");
    $this->assertSession()->responseHeaderExists('does-not-exist');
  }

  /** * Tests WebAssert::responseHeaderDoesNotExist(). * * @covers ::responseHeaderDoesNotExist */
  
    $this->drupalGet('router_test/test21');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Contexts', '');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'http_response');
    // 6. controller result: CacheableResponse object, per-role cacheable route access.     $this->drupalGet('router_test/test22');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Contexts', 'user.roles');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'http_response');

    // Finally, verify that the X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags     // headers are not sent when their container parameter is set to FALSE.     $this->drupalGet('router_test/test18');
    $this->assertSession()->responseHeaderExists('X-Drupal-Cache-Contexts');
    $this->assertSession()->responseHeaderExists('X-Drupal-Cache-Tags');
    $this->assertSession()->responseHeaderExists('X-Drupal-Cache-Max-Age');
    $this->setContainerParameter('http.response.debug_cacheability_headers', FALSE);
    $this->rebuildContainer();
    $this->resetAll();
    $this->drupalGet('router_test/test18');
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache-Contexts');
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache-Tags');
    $this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache-Max-Age');
  }

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