responseHeaderMatches example

// Enable sessions.     $this->sessionReset();

    // Make sure the session cookie is set as HttpOnly. We can only test this in     // the header, with the test setup     // \GuzzleHttp\Cookie\SetCookie::getHttpOnly() always returns FALSE.     // Start a new session by setting a message.     $this->drupalGet('session-test/set-message');
    $this->assertSessionCookie(TRUE);
    // Verify that the session cookie is set as HttpOnly.     $this->assertSession()->responseHeaderMatches('Set-Cookie', '/HttpOnly/i');

    // Verify that the session is regenerated if a module calls exit     // in hook_user_login().     $user->name = 'session_test_user';
    $user->save();
    $this->drupalGet('session-test/id');
    $matches = [];
    preg_match('/\s*session_id:(.*)\n/', $this->getSession()->getPage()->getContent()$matches);
    $this->assertNotEmpty($matches[1], 'Found session ID before logging in.');
    $original_session = $matches[1];

    
$this->assertSession()->buttonExists('Export');

    // Submit the export form and verify response. This will create a file in     // temporary directory with the default name config.tar.gz.     $this->drupalGet('admin/config/development/configuration/full/export');
    $this->submitForm([], 'Export');
    $this->assertSession()->statusCodeEquals(200);

    // Test if header contains file name with hostname and timestamp.     $request = \Drupal::request();
    $hostname = str_replace('.', '-', $request->getHttpHost());
    $this->assertSession()->responseHeaderMatches('content-disposition', '/attachment; filename="config-' . preg_quote($hostname) . '-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}\.tar\.gz"/');

    // Extract the archive and verify it's not empty.     $file_system = \Drupal::service('file_system');
    assert($file_system instanceof FileSystemInterface);
    $temp_directory = $file_system->getTempDirectory();
    $file_path = $temp_directory . '/config.tar.gz';
    $archiver = new Tar($file_path);
    $archive_contents = $archiver->listContents();
    $this->assertNotEmpty($archive_contents, 'Downloaded archive file is not empty.');

    // Prepare the list of config files from active storage, see
/** * 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) {
    @trigger_error('Support for responseHeaderMatches is to be dropped from JavaScript tests. See https://www.drupal.org/node/2857562.');
    parent::responseHeaderMatches($name$regex);
  }

  /** * The use of responseHeaderNotMatches() is not available. * * @param string $name * The name of the header. * @param string $regex * The value to check the header against. */
  public function responseHeaderNotMatches($name$regex) {
    @
$this->commandProcess->run();
    return $this->commandProcess;
  }

  /** * Helper function to assert that the last visit was a Drupal site. * * This method asserts that the X-Generator header shows that the site is a * Drupal site. */
  public function assertDrupalVisit() {
    $this->getMink()->assertSession()->responseHeaderMatches('X-Generator', '/Drupal \d+ \(https:\/\/www.drupal.org\)/');
  }

  /** * Visit a URI on the HTTP server. * * The concept here is that there could be multiple potential docroots in the * workspace, so you can use whichever ones you want. * * @param string $request_uri * (optional) The non-host part of the URL. Example: /some/path?foo=bar. * Defaults to visiting the homepage. * @param string $working_dir * (optional) Relative path within the test workspace file system that will * be the docroot for the request. Defaults to the workspace directory. * * @return \Behat\Mink\Mink * The Mink object. Perform assertions against this. * * @throws \InvalidArgumentException * Thrown when $request_uri does not start with a slash. */
Home | Imprint | This part of the site doesn't use cookies.