SessionTestTrait.php 811 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Drupal\Tests;
  3. use Symfony\Component\HttpFoundation\Request;
  4. /**
  5. * Provides methods to generate and get session name in tests.
  6. */
  7. trait SessionTestTrait {
  8. /**
  9. * The name of the session cookie.
  10. *
  11. * @var string
  12. */
  13. protected $sessionName;
  14. /**
  15. * Generates a session cookie name.
  16. *
  17. * @param string $data
  18. * The data to generate session name.
  19. */
  20. protected function generateSessionName($data) {
  21. $prefix = (Request::createFromGlobals()->isSecure() ? 'SSESS' : 'SESS');
  22. $this->sessionName = $prefix . substr(hash('sha256', $data), 0, 32);
  23. }
  24. /**
  25. * Returns the session name in use on the child site.
  26. *
  27. * @return string
  28. * The name of the session cookie.
  29. */
  30. protected function getSessionName() {
  31. return $this->sessionName;
  32. }
  33. }