public function MetadataAssertionTest::testAssertingOfNegatedConditions in Rules 8.3
Tests asserted metadata of negated conditions is ignored.
File
- tests/
src/ Kernel/ Engine/ MetadataAssertionTest.php, line 143
Class
- MetadataAssertionTest
- Tests asserting metadata works correctly.
Namespace
Drupal\Tests\rules\Kernel\EngineCode
public function testAssertingOfNegatedConditions() {
// Negate the condition only and make sure it is ignored.
$rule = $this->expressionManager
->createRule();
$rule
->addCondition('rules_entity_is_of_bundle', ContextConfig::create()
->map('entity', 'node')
->setValue('type', 'node')
->setValue('bundle', 'page'))
->negate(TRUE);
$rule
->addAction('rules_system_message', ContextConfig::create()
->map('message', 'node.field_text.value')
->setValue('type', 'status'));
$violation_list = RulesComponent::create($rule)
->addContextDefinition('node', ContextDefinition::create('entity:node'))
->checkIntegrity();
$this
->assertEquals(1, iterator_count($violation_list));
// Add an negated AND and make sure it is ignored.
$rule = $this->expressionManager
->createRule();
$and = $this->expressionManager
->createAnd();
$and
->addCondition('rules_entity_is_of_bundle', ContextConfig::create()
->map('entity', 'node')
->setValue('type', 'node')
->setValue('bundle', 'page'));
$and
->negate(TRUE);
$rule
->addExpressionObject($and);
$rule
->addAction('rules_system_message', ContextConfig::create()
->map('message', 'node.field_text.value')
->setValue('type', 'status'));
$violation_list = RulesComponent::create($rule)
->addContextDefinition('node', ContextDefinition::create('entity:node'))
->checkIntegrity();
$this
->assertEquals(1, iterator_count($violation_list));
}