public function RulesSessionTest::testSessionRules 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::testSessionRules()
Tests session rules.
File
- tests/
src/ Kernel/ RulesSessionTest.php, line 24
Class
- RulesSessionTest
- Test using the Rules API to create and evaluate session tests.
Namespace
Drupal\Tests\rules_session_vars\KernelCode
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());
}