Switching themes in a functionaljavascript test causes backend code to run as anonymous

Created on 3 November 2025, 12 days ago

Problem/Motivation

If your functionaljavascript test does a browser login, it used to retain the logged-in user for code that also runs in the backend. Now it runs as anonymous.

Steps to reproduce

Install drupal 11.x-dev at this commit or later: https://github.com/drupal/core/commit/aa12cc60d44f1. Here's a minimal unit test. The \Drupal::currentUser() call should return the rootUser, but it's anonymous.

use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
 * Tests the thing
 */
#[Group('Aaa')]
#[RunTestsInSeparateProcesses]
class AaaTest extends WebDriverTestBase {

  // It doesn't matter what we put here we get the same problem, but this field is required. The problem is the call to update it down below.
  protected $defaultTheme = 'olivero';

  /**
   * Tests the thing
   */
  public function testAaa(): void {
    \Drupal::service('theme_installer')->install(['olivero', 'claro']);
    $this->config('system.theme')
      ->set('default', 'olivero')
      ->set('admin', 'claro')
      ->save();

    $this->drupalLogin($this->rootUser);
    $this->assertNotEmpty(\Drupal::currentUser()->id());
  }

Proposed resolution

I'm not sure. The theme setting code in the unit test above is something we've been using for 5 years, and seems similar to code I see in some core functionaljavascript tests so still seems right. Is there some hook the above-mentioned core commit is missing?

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.3 🔥

Component

phpunit

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024