Skip to content
Snippets Groups Projects
Commit d00b8d70 authored by mxh's avatar mxh Committed by Jürgen Haas
Browse files

Issue #3312711 by mxh: eca_user: Condition "ID of user" is not supporting tokens

parent b365d3ee
No related branches found
Tags 1.0.4
No related merge requests found
......@@ -23,8 +23,8 @@ class CurrentUserId extends BaseUser {
// \Drupal\Core\Session\AccountInterface::id describes that an integer
// should be returned.
// We need to cast the ID to string to avoid false positives when an
// empty string value get compared to integed 0.
$result = (string) $this->configuration['user_id'] === (string) $this->currentUser->id();
// empty string value get compared to integer 0.
$result = (string) $this->tokenServices->replace($this->configuration['user_id']) === (string) $this->currentUser->id();
return $this->negationCheck($result);
}
......
......@@ -20,8 +20,8 @@ class UserId extends CurrentUserId {
public function evaluate(): bool {
if ($account = $this->loadUserAccount()) {
// We need to cast the ID to string to avoid false positives when an
// empty string value get compared to integed 0.
$result = (string) $this->configuration['user_id'] === (string) $account->id();
// empty string value get compared to integer 0.
$result = (string) $this->tokenServices->replace($this->configuration['user_id']) === (string) $account->id();
return $this->negationCheck($result);
}
return FALSE;
......
......@@ -123,6 +123,16 @@ class UserIdTest extends KernelTestBase {
'account' => '[my_user:id]',
]);
$this->assertFalse($condition->evaluate(), 'User ID 2 and account [my_user:id] must evaluate to false.');
$token_services->addTokenData('user_uid', '2');
$condition = $condition_manager->createInstance('eca_user_id', [
'user_id' => '[user_uid]',
'account' => '[my_user:uid]',
]);
$this->assertTrue($condition->evaluate(), 'Token with value 2 and account [my_user:uid] must evaluate to true.');
$token_services->addTokenData('user_uid', '3');
$this->assertFalse($condition->evaluate(), 'Token with value 3 and account [my_user:uid] must evaluate to false.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment