- Issue created by @f1mishutka
- Merge request !14Issue #3469734: Call to undefined method MetadataBag::getMasquerade() at MasqueradeCacheContext.php → (Open) created by f1mishutka
- Issue was unassigned.
- Status changed to Needs review
3 months ago 2:48pm 22 August 2024 - Status changed to Needs work
3 months ago 4:21pm 22 August 2024 - 🇫🇷France andypost
Curious why the bag is different but better replace check for bag classname
- Status changed to Needs review
3 months ago 6:32pm 22 August 2024 - 🇧🇾Belarus f1mishutka Minsk
Curious why the bag is different
This is hidden somewhere deep in Drupal core I think. We do bootstrap Drupal core with custom code (similar to index.php) for bunch of our specific integrational tests. So I did not dig to deep about masquerade and core interaction :)
better replace check for bag classname
Done: check replaced to
instanceof
. - 🇧🇾Belarus f1mishutka Minsk
Any chance to have this merged at least to
-dev
branch?
Thanks. - 🇦🇺Australia mstrelan
Experiencing the same issue with Drupal Test Traits, the MR fixes it.
- 🇦🇺Australia acbramley
Would be good to get this committed, nice n simple fix.
- 🇫🇷France andypost
This simple fix points out to bugs in tests because this check means that service is not decorated, moreover all other parts of code supposing that metadatabag is decorated and then it should be fixed in all places
So instead of "wont't fix" I wanna get more opinions why unit tests should be able to partially mock functionality?
Seemasquerade.services.yml
masquerade.session_manager.metadata_bag: class: Drupal\masquerade\Session\MetadataBag decorates: session_manager.metadata_bag parent: session_manager.metadata_bag public: false
- 🇦🇺Australia mstrelan
I did some digging, and while I don't have any answers I do have some further information.
The test that was triggering the error looks like this:
$this->setCurrentUser($this->createUser()->addRole('regional_manager')); $url = Url::fromRoute('my_module.my_route'); $request = Request::create($url->toString(), 'HEAD'); $response = \Drupal::service('http_kernel')->handle($request);
But if I change this to use
::drupalLogin
and::drupalGet
then the bag is decorated correctly.Similarly, If I remove the
access toolbar
permission from the role and revert to the original test, thenMasqueradeCacheContext::getContext
does not get invoked and the test passes.Finally, if I remove the
masquerade_switch_back
item frommasquerade_toolbar
then again the test passes.Hopefully that helps to explain this.