Problem/Motivation

WebTestBase contains a query. And it's not necessary.

Proposed resolution

Fake a request and replace the cookies with the cURL cookies then call the session handler to read the session.

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#2 interdiff.txt898 byteschx
#2 2422257_2.patch1.24 KBchx
session_hw.patch1.25 KBchx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -711,9 +711,18 @@ protected function drupalUserIsLoggedIn($account) {
+    $session_id = $account->session_id;
+    $request_stack = $this->container->get('request_stack');
+    $request = clone $request_stack->getCurrentRequest();
+    $cookies = $request->cookies->all();
+    foreach ($this->cookies as $name => $value) {
+      $cookies[$name] = $value['value'];
+    }
+    $request->cookies->replace($cookies);
+    $request_stack->push($request);
+    $logged_in = (bool) $this->container->get('session_manager')->getSaveHandler()->read($session_id);
+    $request_stack->pop();
+    return $logged_in;

Its a little bit sad how much effort you need in order to figure this out. At least the new code does not hardcode the hashing algorithm. Note: There is a helper $request->duplicate(NULL, NULL, NULL, NULL, $cookies); which would make the code a bit easier.

chx’s picture

FileSize
1.24 KB
898 bytes

Sure.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Cool

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: 2422257_2.patch, failed testing.

chx queued 2: 2422257_2.patch for re-testing.

daffie’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC.

alexpott’s picture

Title: WebTestBase hardwires session » Remove unnecessary query against the session table in WebTestBase
Status: Reviewed & tested by the community » Fixed

Test changes are not frozen in beta. Committed e4e8f31 and pushed to 8.0.x. Thanks!

  • alexpott committed e4e8f31 on 8.0.x
    Issue #2422257 by chx: Remove unnecessary query against the session...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.