You are here

public function DrupalSelenium2Driver::setCookie in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver::setCookie()

File

core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php, line 26

Class

DrupalSelenium2Driver
Provides a driver for Selenium testing.

Namespace

Drupal\FunctionalJavascriptTests

Code

public function setCookie($name, $value = NULL) {
  if ($value === NULL) {
    $this
      ->getWebDriverSession()
      ->deleteCookie($name);
    return;
  }
  $cookieArray = [
    'name' => $name,
    'value' => urlencode($value),
    'secure' => FALSE,
    // Unlike \Behat\Mink\Driver\Selenium2Driver::setCookie we set a domain
    // and an expire date, as otherwise cookies leak from one test site into
    // another.
    'domain' => parse_url($this
      ->getWebDriverSession()
      ->url(), PHP_URL_HOST),
    'expires' => time() + 80000,
  ];
  $this
    ->getWebDriverSession()
    ->setCookie($cookieArray);
}