#1890878: Add modular authentication system, including Http Basic; deprecate global $user replaced global $user by \Drupal::request()->attributes->get('account'). However, this attribute is not available during Simpletest tests.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Xano’s picture

Assigned: Xano » Unassigned
Status: Active » Needs review
FileSize
1.37 KB
corvus_ch’s picture

Status: Needs review » Needs work
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.phpundefined
@@ -981,11 +981,14 @@ protected function prepareConfigDirectories() {
+    $this->container->get('request')->attributes->set('account', $user);

I would use the $GLOBALS['user'] notation here but I wonder where the global $user gets populated during simpletest. For we consider this deprecated, we should try to replace it instead of use it.

Xano’s picture

Status: Needs work » Needs review

UnitTestBase might not have to be altered. In that case, why is TestBase::rebuildContainer() only used by WebTestBase and nothing else? Also, should DrupalUnitTestBase also be patched to provide a request account?

Xano’s picture

I would use the $GLOBALS['user'] notation here but I wonder where the global $user gets populated during simpletest. For we consider this deprecated, we should try to replace it instead of use it.

This happens in TestBase::prepareEnvironment().

Status: Needs review » Needs work

The last submitted patch, drupal_2032553_1.patch, failed testing.

pwolanin’s picture

Title: Request account is not available during web tests » The account attribute on the Request is not available during web tests

fixing title

pwolanin’s picture

We are seeing other test failures due to this as we try to switch to using the _account attribute in patches

pwolanin’s picture

Priority: Normal » Major

bumping priority - this is blocking attempts to move access checks to use $account->hasPermission() in other patches

pwolanin’s picture

Title: The account attribute on the Request is not available during web tests » The _account attribute on the Request is not available during web tests
Status: Needs work » Needs review
FileSize
1.71 KB

Trying again with _account

Status: Needs review » Needs work

The last submitted patch, 2032553-9.patch, failed testing.

pwolanin’s picture

EntityReferenceSelectionAccessTest fails - the fix is the same as already done for patch in #26: #2004086: The Request service must be synthetic

pwolanin’s picture

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

We might could add a @todo how to remove the global user properly (i guess we want to always store the current global user on the test object?)

xjm’s picture

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Looks straight-forward enough. Committed and pushed to 8.x. Thanks!

webchick’s picture

Status: Fixed » Needs work

Ahem. And by that I meant... "no longer applies." :P

webchick’s picture

Status: Needs work » Fixed

ugh. ignore me.

Status: Fixed » Closed (fixed)

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