SessionTestTrait.php

Same filename in other branches
  1. 8.9.x core/modules/simpletest/src/SessionTestTrait.php
  2. 8.9.x core/tests/Drupal/Tests/SessionTestTrait.php
  3. 10 core/tests/Drupal/Tests/SessionTestTrait.php
  4. 11.x core/tests/Drupal/Tests/SessionTestTrait.php

Namespace

Drupal\Tests

File

core/tests/Drupal/Tests/SessionTestTrait.php

View source
<?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;
    }

}

Traits

Title Deprecated Summary
SessionTestTrait Provides methods to generate and get session name in tests.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.