// Now, log out and repeat with a non-403 page.
$this->drupalLogout(); $this->drupalGet('filter/tips'); $this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'MISS'); $this->submitForm($edit, 'Log in'); $this->assertSession()->pageTextNotContains('User login'); // Verify that we are still on the same page after login for allowed page.
$this->assertSession()->responseMatches('!<title.*?Compose tips.*?</title>!');
// Log out again and repeat with a non-403 page including query arguments.
$this->drupalLogout(); $this->drupalGet('filter/tips', ['query' => ['foo' => 'bar']]); $this->assertSession()->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT'); $this->submitForm($edit, 'Log in'); $this->assertSession()->pageTextNotContains('User login');
protected$defaultTheme = 'stark';
/**
* Tests rendering of ['#attached'].
*/ publicfunctiontestAttachments(){ // Test ['#attached']['http_header] = ['Status', $code].
$this->drupalGet('/render_attached_test/teapot'); $this->assertSession()->statusCodeEquals(418); $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS'); // Repeat for the cache.
$this->drupalGet('/render_attached_test/teapot'); $this->assertSession()->statusCodeEquals(418); $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');
// Test ['#attached']['http_header'] with various replacement rules.
$this->drupalGet('/render_attached_test/header'); $this->assertTeapotHeaders(); $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS'); // Repeat for the cache.
$this->drupalGet('/render_attached_test/header');
/**
* Tests the cacheability of the table display.
*/ publicfunctiontestTableCacheability(){ \Drupal::service('module_installer')->uninstall(['page_cache']);
/**
* Asserts the cache context for the wrapper format is always present.
*/ publicfunctiontestWrapperFormatCacheContext(){ $this->drupalGet('common-test/type-link-active-class'); $this->assertStringStartsWith("<!DOCTYPE html>\n<html", $this->getSession()->getPage()->getContent()); $this->assertSession()->responseHeaderEquals('Content-Type', 'text/html; charset=UTF-8'); $this->assertSession()->titleEquals('Test active link class | Drupal'); $this->assertCacheContext('url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT);
/**
* Tests that SVGZ files are served with Content-Encoding: gzip.
*/ publicfunctiontestSvgzContentEncoding(){ $this->drupalGet('core/modules/system/tests/logo.svgz'); $this->assertSession()->statusCodeEquals(200);
// Use x-encoded-content-encoding because of Content-Encoding responses
// (gzip, deflate, etc.) are automatically decoded by Guzzle.
$this->assertSession()->responseHeaderEquals('x-encoded-content-encoding', 'gzip'); }
}
protectedfunctiongetFormBuildId(){ // Ensure the hidden 'form_build_id' field is unique.
$this->assertSession()->elementsCount('xpath', '//input[@name="form_build_id"]', 1); return(string)$this->assertSession()->hiddenFieldExists('form_build_id')->getAttribute('value'); }
/**
* Build-id is regenerated when validating cached form.
*/ publicfunctiontestValidateFormStorageOnCachedPage(){ $this->drupalGet('form-test/form-storage-page-cache'); $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS'); $this->assertSession()->pageTextContains('No old build id'); $build_id_initial = $this->getFormBuildId();
// Trigger validation error by submitting an empty title.
$edit = ['title' => '']; $this->submitForm($edit, 'Save'); $this->assertSession()->pageTextContains('No old build id'); $build_id_first_validation = $this->getFormBuildId(); $this->assertNotEquals($build_id_initial, $build_id_first_validation, 'Build id changes when form validation fails');
// Trigger validation error by again submitting an empty title.
// Fetch the URL that generates the file.
$this->drupalGet($generate_url); $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($generated_uri); // assertRaw can't be used with string containing non UTF-8 chars.
$this->assertNotEmpty(file_get_contents($generated_uri), 'URL returns expected file.'); $image = $this->container->get('image.factory')->get($generated_uri); $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');
// Find the given content.
foreach((array)$expected_contentas$content){ $assert_session->pageTextContains($content); } if($expected_cache_contexts){ $assert_session->responseHeaderContains('X-Drupal-Cache-Contexts', $expected_cache_contexts); } if($expected_cache_tags){ $assert_session->responseHeaderContains('X-Drupal-Cache-Tags', $expected_cache_tags); } $assert_session->responseHeaderEquals('X-Drupal-Dynamic-Cache', $expected_dynamic_cache); }
/**
* Creates a node with a section field.
*
* @param array $section_values
* An array of values for a section field.
*
* @return \Drupal\node\NodeInterface
* The node object.
*/