You are here

public function EntityPathAliasCreateTest::testActionExecutionWithSavedEntity in Rules 8.3

Tests the action execution with a saved entity.

@covers ::execute

File

tests/src/Unit/Integration/RulesAction/EntityPathAliasCreateTest.php, line 92

Class

EntityPathAliasCreateTest
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\EntityPathAliasCreate @group RulesAction

Namespace

Drupal\Tests\rules\Unit\Integration\RulesAction

Code

public function testActionExecutionWithSavedEntity() {
  $path_alias = $this
    ->prophesizeEntity(PathAliasInterface::class);

  // Test that the alias is only saved once.
  $path_alias
    ->save()
    ->shouldBeCalledTimes(1);
  $this->aliasStorage
    ->create([
    'path' => '/test/1',
    'alias' => '/about',
    'langcode' => 'en',
  ])
    ->willReturn($path_alias
    ->reveal())
    ->shouldBeCalledTimes(1);
  $entity = $this
    ->getMockEntity();
  $entity
    ->isNew()
    ->willReturn(FALSE)
    ->shouldBeCalledTimes(1);

  // Test that existing entities are not saved again.
  $entity
    ->save()
    ->shouldNotBeCalled();
  $this->action
    ->setContextValue('entity', $entity
    ->reveal())
    ->setContextValue('alias', '/about');
  $this->action
    ->execute();
}