function EntityFetchByFieldTest::testActionExecutionWithNoLimit

Tests action execution when no value for limit is provided.

@covers ::execute

File

tests/src/Unit/Integration/RulesAction/EntityFetchByFieldTest.php, line 46

Class

EntityFetchByFieldTest
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\EntityFetchByField @group RulesAction

Namespace

Drupal\Tests\rules\Unit\Integration\RulesAction

Code

public function testActionExecutionWithNoLimit() {
    // Create variables for action context values.
    $entity_type = 'entity_test';
    $field_name = 'test_field';
    $field_value = 'llama';
    // Create an array of dummy entities.
    $entities = [];
    for ($i = 0; $i < 2; $i++) {
        $entity = $this->prophesize(EntityInterface::class);
        $entities[] = $entity->reveal();
    }
    // Create dummy entity storage object.
    $entity_storage = $this->prophesize(EntityStorageInterface::class);
    $entity_storage->loadByProperties([
        $field_name => $field_value,
    ])
        ->willReturn($entities);
    $this->entityTypeManager
        ->getStorage($entity_type)
        ->willReturn($entity_storage->reveal());
    // Set context values for EntityFetchByField action and execute.
    $this->action
        ->setContextValue('type', $entity_type)
        ->setContextValue('field_name', $field_name)
        ->setContextValue('field_value', $field_value)
        ->execute();
    // Test that executing action without a value for limit returns the dummy
    // entities array.
    $this->assertEquals($entities, $this->action
        ->getProvidedContext('entity_fetched')
        ->getContextValue('entity_fetched'));
}