function EntityFetchByIdTest::testActionExecution
Tests the action execution.
@covers ::execute
File
-
tests/
src/ Unit/ Integration/ RulesAction/ EntityFetchByIdTest.php, line 45
Class
- EntityFetchByIdTest
- @coversDefaultClass \Drupal\rules\Plugin\RulesAction\EntityFetchById @group RulesAction
Namespace
Drupal\Tests\rules\Unit\Integration\RulesActionCode
public function testActionExecution() {
$entity_type = 'entity_test';
// Prepare entity storage to return dummy entity on the 'load' execution.
$entity = $this->prophesize(EntityInterface::class);
$entity_storage = $this->prophesize(EntityStorageInterface::class);
$entity_storage->load(1)
->willReturn($entity->reveal())
->shouldBeCalledTimes(1);
$this->entityTypeManager
->getStorage($entity_type)
->willReturn($entity_storage->reveal())
->shouldBeCalledTimes(1);
// Set context values for EntityFetchByField action and execute.
$this->action
->setContextValue('type', $entity_type)
->setContextValue('entity_id', 1)
->execute();
// Test that entity load with type 'test' and id '1' should return the
// dummy entity.
$this->assertEquals($entity->reveal(), $this->action
->getProvidedContext('entity_fetched')
->getContextValue('entity_fetched'), 'Action returns the loaded entity for fetching entity by id.');
}