function UserHasRoleTest::testInvalidOperationException
Test the behavior with unsupported operations.
@covers ::execute
File
-
tests/
src/ Unit/ Integration/ Condition/ UserHasRoleTest.php, line 92
Class
- UserHasRoleTest
- @coversDefaultClass \Drupal\rules\Plugin\Condition\UserHasRole @group RulesCondition
Namespace
Drupal\Tests\rules\Unit\Integration\ConditionCode
public function testInvalidOperationException() {
// Set the expected exception class and message.
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Either use "AND" or "OR". Leave empty for default "AND" behavior.');
// Set-up a mock object with roles 'authenticated' and 'editor', but not
// 'administrator'.
$account = $this->prophesizeEntity(UserInterface::class);
$account->getRoles()
->willReturn([
'authenticated',
'editor',
]);
$this->condition
->setContextValue('user', $account->reveal());
$authenticated = $this->prophesize(RoleInterface::class);
$authenticated->id()
->willReturn('authenticated');
// Now test INVALID as operation. An exception must be thrown.
$this->condition
->setContextValue('roles', [
$authenticated->reveal(),
]);
$this->condition
->setContextValue('operation', 'INVALID');
$this->condition
->evaluate();
}