public function CoreIntegrationTest::testEntityPropertyPath in Rules 8.3
Tests that a complex data selector can be applied to entities.
File
- tests/
src/ Kernel/ CoreIntegrationTest.php, line 41
Class
- CoreIntegrationTest
- Test using Drupal core integration of Rules API.
Namespace
Drupal\Tests\rules\KernelCode
public function testEntityPropertyPath() {
$entity_type_manager = $this->container
->get('entity_type.manager');
$entity_type_manager
->getStorage('node_type')
->create([
'type' => 'page',
])
->save();
$node = $entity_type_manager
->getStorage('node')
->create([
'title' => 'test',
'type' => 'page',
]);
$user = $entity_type_manager
->getStorage('user')
->create([
'name' => 'test value',
]);
$user
->save();
$node
->setOwner($user);
$rule = $this->expressionManager
->createRule();
// Test that the long detailed data selector works.
$rule
->addCondition('rules_test_string_condition', ContextConfig::create()
->map('text', 'node.uid.0.entity.name.0.value'));
// Test that the shortened data selector without list indices.
$rule
->addCondition('rules_test_string_condition', ContextConfig::create()
->map('text', 'node.uid.entity.name.value'));
$rule
->addAction('rules_test_debug_log');
RulesComponent::create($rule)
->addContextDefinition('node', ContextDefinition::create('entity:node'))
->setContextValue('node', $node)
->execute();
// Test that the action logged something.
$this
->assertRulesDebugLogEntryExists('action called');
}