public function testConditions() { // Grab the user role condition and configure it to check against
// authenticated user roles.
/** @var \Drupal\Core\Condition\ConditionInterface $condition */
$condition =
$this->manager->
createInstance('user_role'
) ->
setConfig('roles',
[RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID
]) ->
setContextValue('user',
$this->anonymous
);
$this->
assertFalse($condition->
execute(), 'Anonymous users fail role checks for authenticated.'
);
// Check for the proper summary.
// Summaries require an extra space due to negate handling in summary().
$this->
assertEquals('The user is a member of Authenticated user',
$condition->
summary());
// Set the user role to anonymous.
$condition->
setConfig('roles',
[RoleInterface::ANONYMOUS_ID => RoleInterface::ANONYMOUS_ID
]);
$this->
assertTrue($condition->
execute(), 'Anonymous users pass role checks for anonymous.'
);
// Check for the proper summary.
$this->
assertEquals('The user is a member of Anonymous user',
$condition->
summary());
// Set the user role to check anonymous or authenticated.
$condition->
setConfig('roles',
[RoleInterface::ANONYMOUS_ID => RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID
]);
$this->
assertTrue($condition->
execute(), 'Anonymous users pass role checks for anonymous or authenticated.'
);
// Check for the proper summary.