public function EventIntegrationTest::testEntityOriginal in Rules 8.3
Tests that the entity presave/update events work with original entities.
@dataProvider providerTestEntityOriginal
Parameters
string $event_name: The event name that should be configured in the test rule.
File
- tests/
src/ Kernel/ EventIntegrationTest.php, line 269
Class
- EventIntegrationTest
- Test for the Symfony event mapping to Rules events.
Namespace
Drupal\Tests\rules\KernelCode
public function testEntityOriginal($event_name) {
// Create a node that we will change and save later.
$entity_type_manager = $this->container
->get('entity_type.manager');
$entity_type_manager
->getStorage('node_type')
->create([
'type' => 'page',
'display_submitted' => FALSE,
])
->save();
$node = $entity_type_manager
->getStorage('node')
->create([
'title' => 'test',
'type' => 'page',
]);
$node
->save();
// Create a rule with a condition to compare the changed node title. If the
// title has changed the action is executed.
$rule = $this->expressionManager
->createRule();
$rule
->addCondition('rules_data_comparison', ContextConfig::create()
->map('data', 'node.title.value')
->map('value', 'node_unchanged.title.value')
->negateResult());
$rule
->addAction('rules_test_debug_log');
$config_entity = $this->storage
->create([
'id' => 'test_rule',
'events' => [
[
'event_name' => $event_name,
],
],
'expression' => $rule
->getConfiguration(),
]);
$config_entity
->save();
// The logger instance has changed, refresh it.
$this->logger = $this->container
->get('logger.channel.rules_debug');
$this->logger
->addLogger($this->debugLog);
// Now change the title and trigger the presave event by saving the node.
$node
->setTitle('new title');
$node
->save();
$this
->assertRulesDebugLogEntryExists('action called');
}