function EntityPathAliasCreateTest::testActionExecutionWithUnsavedEntity
Tests the action execution with an unsaved entity.
@covers ::execute
File
-
tests/
src/ Unit/ Integration/ RulesAction/ EntityPathAliasCreateTest.php, line 62
Class
- EntityPathAliasCreateTest
- @coversDefaultClass \Drupal\rules\Plugin\RulesAction\EntityPathAliasCreate @group RulesAction
Namespace
Drupal\Tests\rules\Unit\Integration\RulesActionCode
public function testActionExecutionWithUnsavedEntity() {
$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(TRUE)
->shouldBeCalledTimes(1);
// Test that new entities are saved first.
$entity->save()
->shouldBeCalledTimes(1);
$this->action
->setContextValue('entity', $entity->reveal())
->setContextValue('alias', '/about');
$this->action
->execute();
}