LegacySessionTest.php

Same filename and directory in other branches
  1. 11.x core/modules/system/tests/src/Functional/Session/LegacySessionTest.php

Namespace

Drupal\Tests\system\Functional\Session

File

core/modules/system/tests/src/Functional/Session/LegacySessionTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\system\Functional\Session;

use Drupal\Tests\BrowserTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
 * Drupal legacy session handling tests.
 */
class LegacySessionTest extends BrowserTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'session_test',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * Tests data persistence via the session_test module callbacks.
   */
  public function testLegacyDataPersistence() : void {
    $this->expectDeprecation('Storing values directly in $_SESSION is deprecated in drupal:11.2.0 and will become unsupported in drupal:12.0.0. Use $request-&gt;getSession()-&gt;set() instead. Affected keys: legacy_test_value. See https://www.drupal.org/node/3518527');
    $value = $this->randomMachineName();
    // Verify that the session value is stored.
    $this->drupalGet('session-test/legacy-set/' . $value);
    $this->assertSession()
      ->pageTextContains($value);
    // Verify that the session correctly returned the stored data for an
    // authenticated user.
    $this->drupalGet('session-test/legacy-get');
    $this->assertSession()
      ->pageTextContains($value);
  }

}

Classes

Title Deprecated Summary
LegacySessionTest Drupal legacy session handling tests.

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