function EntityHasFieldTest::testConditionEvaluation
Tests evaluating the condition.
@covers ::evaluate
File
-
tests/
src/ Unit/ Integration/ Condition/ EntityHasFieldTest.php, line 35
Class
- EntityHasFieldTest
- @coversDefaultClass \Drupal\rules\Plugin\Condition\EntityHasField @group RulesCondition
Namespace
Drupal\Tests\rules\Unit\Integration\ConditionCode
public function testConditionEvaluation() {
$entity = $this->prophesizeEntity(ContentEntityInterface::class);
$entity->hasField('existing-field')
->willReturn(TRUE)
->shouldBeCalledTimes(1);
$entity->hasField('non-existing-field')
->willReturn(FALSE)
->shouldBeCalledTimes(1);
$this->condition
->setContextValue('entity', $entity->reveal());
// Test with an existing field.
$this->condition
->setContextValue('field', 'existing-field');
$this->assertTrue($this->condition
->evaluate());
// Test with a non-existing field.
$this->condition
->setContextValue('field', 'non-existing-field');
$this->assertFalse($this->condition
->evaluate());
}