function EntityIsOfTypeTest::testConditionEvaluation

Tests evaluating the condition.

@covers ::evaluate

File

tests/src/Unit/Integration/Condition/EntityIsOfTypeTest.php, line 35

Class

EntityIsOfTypeTest
@coversDefaultClass \Drupal\rules\Plugin\Condition\EntityIsOfType @group RulesCondition

Namespace

Drupal\Tests\rules\Unit\Integration\Condition

Code

public function testConditionEvaluation() {
    $entity = $this->prophesizeEntity(EntityInterface::class);
    $entity->getEntityTypeId()
        ->willReturn('node')
        ->shouldBeCalledTimes(2);
    // Add the test node to our context as the evaluated entity, along with an
    // explicit entity type string.
    // First, test with a value that should evaluate TRUE.
    $this->condition
        ->setContextValue('entity', $entity->reveal())
        ->setContextValue('type', 'node');
    $this->assertTrue($this->condition
        ->evaluate());
    // Then test with values that should evaluate FALSE.
    $this->condition
        ->setContextValue('type', 'taxonomy_term');
    $this->assertFalse($this->condition
        ->evaluate());
}