EntitySaveTest.php in Rules 8.3
File
tests/src/Unit/Integration/RulesAction/EntitySaveTest.php
View source
<?php
namespace Drupal\Tests\rules\Unit\Integration\RulesAction;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Tests\rules\Unit\Integration\RulesEntityIntegrationTestBase;
class EntitySaveTest extends RulesEntityIntegrationTestBase {
protected $action;
protected $entity;
protected function setUp() : void {
parent::setUp();
$this->entity = $this
->prophesizeEntity(EntityInterface::class);
$this->action = $this->actionManager
->createInstance('rules_entity_save');
}
public function testSummary() {
$this
->assertEquals('Save entity', $this->action
->summary());
}
public function testActionExecutionImmediately() {
$this->entity
->save()
->shouldBeCalledTimes(1);
$this->action
->setContextValue('entity', $this->entity
->reveal())
->setContextValue('immediate', TRUE);
$this->action
->execute();
$this
->assertEquals($this->action
->autoSaveContext(), [], 'Action returns nothing for auto saving since the entity has been saved already.');
}
public function testActionExecutionPostponed() {
$this->entity
->save()
->shouldNotBeCalled();
$this->action
->setContextValue('entity', $this->entity
->reveal());
$this->action
->execute();
$this
->assertEquals($this->action
->autoSaveContext(), [
'entity',
], 'Action returns the entity context name for auto saving.');
}
}