Namespace
Drupal\Tests\rules\Unit\Integration\RulesAction
File
-
tests/src/Unit/Integration/RulesAction/EntityFetchByIdTest.php
View source
<?php
namespace Drupal\Tests\rules\Unit\Integration\RulesAction;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Tests\rules\Unit\Integration\RulesEntityIntegrationTestBase;
class EntityFetchByIdTest extends RulesEntityIntegrationTestBase {
protected $action;
protected function setUp() : void {
parent::setUp();
$this->action = $this->actionManager
->createInstance('rules_entity_fetch_by_id');
}
public function testSummary() {
$this->assertEquals('Fetch entity by id', $this->action
->summary());
}
public function testActionExecution() {
$entity_type = 'entity_test';
$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);
$this->action
->setContextValue('type', $entity_type)
->setContextValue('entity_id', 1)
->execute();
$this->assertEquals($entity->reveal(), $this->action
->getProvidedContext('entity_fetched')
->getContextValue('entity_fetched'), 'Action returns the loaded entity for fetching entity by id.');
}
public function testRefiningContextDefinitions() {
$this->action
->setContextValue('type', 'entity_test');
$this->action
->refineContextDefinitions([]);
$this->assertEquals($this->action
->getProvidedContextDefinition('entity_fetched')
->getDataType(), 'entity:entity_test');
}
}
Classes
| Title |
Deprecated |
Summary |
| EntityFetchByIdTest |
|
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\EntityFetchById[[api-linebreak]]
@group RulesAction |