Mercurial > hg > isophonics-drupal-site
diff core/tests/Drupal/Tests/SessionTestTrait.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/tests/Drupal/Tests/SessionTestTrait.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,40 @@ +<?php + +namespace Drupal\Tests; + +use Symfony\Component\HttpFoundation\Request; + +/** + * Provides methods to generate and get session name in tests. + */ +trait SessionTestTrait { + + /** + * The name of the session cookie. + * + * @var string + */ + protected $sessionName; + + /** + * Generates a session cookie name. + * + * @param string $data + * The data to generate session name. + */ + protected function generateSessionName($data) { + $prefix = (Request::createFromGlobals()->isSecure() ? 'SSESS' : 'SESS'); + $this->sessionName = $prefix . substr(hash('sha256', $data), 0, 32); + } + + /** + * Returns the session name in use on the child site. + * + * @return string + * The name of the session cookie. + */ + protected function getSessionName() { + return $this->sessionName; + } + +}