class RulesSessionTest in Rules Session Variables 2.0.x
Same name and namespace in other branches
- 2.x tests/src/Kernel/RulesSessionTest.php \Drupal\Tests\rules_session_vars\Kernel\RulesSessionTest
Test using the Rules API to create and evaluate session tests.
@group rules_session_vars
Hierarchy
- class \Drupal\Tests\rules_session_vars\Kernel\RulesSessionTest extends \Drupal\Tests\rules\Kernel\RulesKernelTestBase
Expanded class hierarchy of RulesSessionTest
File
- tests/
src/ Kernel/ RulesSessionTest.php, line 14
Namespace
Drupal\Tests\rules_session_vars\KernelView source
class RulesSessionTest extends RulesKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'rules_session_vars',
];
/**
* Tests session rules.
*/
public function testSessionRules() {
$request_stack = $this->container
->get('request_stack');
$session = $this
->prophesize(SessionInterface::class);
$session
->get('test_key')
->willReturn('test_value');
$request_stack
->getCurrentRequest()
->setSession($session
->reveal());
// Session exists.
$condition = $this->expressionManager
->createAnd()
->addCondition('session_key_exists', ContextConfig::create()
->setValue('session_key', 'test_key'));
$this
->assertTrue($condition
->execute());
// Session equals.
$condition = $this->expressionManager
->createAnd()
->addCondition('session_data_comparison', ContextConfig::create()
->setValue('session_key', 'test_key')
->setValue('operation', '==')
->setValue('session_value', 'test_value'));
$this
->assertTrue($condition
->execute());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RulesSessionTest:: |
public static | property | ||
RulesSessionTest:: |
public | function | Tests session rules. |