comparison core/tests/Drupal/Tests/SessionTestTrait.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\Tests;
4
5 use Symfony\Component\HttpFoundation\Request;
6
7 /**
8 * Provides methods to generate and get session name in tests.
9 */
10 trait SessionTestTrait {
11
12 /**
13 * The name of the session cookie.
14 *
15 * @var string
16 */
17 protected $sessionName;
18
19 /**
20 * Generates a session cookie name.
21 *
22 * @param string $data
23 * The data to generate session name.
24 */
25 protected function generateSessionName($data) {
26 $prefix = (Request::createFromGlobals()->isSecure() ? 'SSESS' : 'SESS');
27 $this->sessionName = $prefix . substr(hash('sha256', $data), 0, 32);
28 }
29
30 /**
31 * Returns the session name in use on the child site.
32 *
33 * @return string
34 * The name of the session cookie.
35 */
36 protected function getSessionName() {
37 return $this->sessionName;
38 }
39
40 }