PathAliasCreateTest.php in Rules 8.3
File
tests/src/Unit/Integration/RulesAction/PathAliasCreateTest.php
View source
<?php
namespace Drupal\Tests\rules\Unit\Integration\RulesAction;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Tests\rules\Unit\Integration\RulesEntityIntegrationTestBase;
use Drupal\path_alias\PathAliasInterface;
class PathAliasCreateTest extends RulesEntityIntegrationTestBase {
protected $action;
protected $aliasStorage;
protected function setUp() : void {
parent::setUp();
$this
->enableModule('path_alias');
$this->aliasStorage = $this
->prophesize(EntityStorageInterface::class);
$this->entityTypeManager
->getStorage('path_alias')
->willReturn($this->aliasStorage
->reveal());
$this->action = $this->actionManager
->createInstance('rules_path_alias_create');
}
public function testSummary() {
$this
->assertEquals('Create any path alias', $this->action
->summary());
}
public function testActionExecutionWithoutLanguage() {
$path_alias = $this
->prophesizeEntity(PathAliasInterface::class);
$path_alias
->save()
->shouldBeCalledTimes(1);
$this->aliasStorage
->create([
'path' => '/node/1',
'alias' => '/about',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
])
->willReturn($path_alias
->reveal())
->shouldBeCalledTimes(1);
$this->action
->setContextValue('source', '/node/1')
->setContextValue('alias', '/about');
$this->action
->execute();
}
public function testActionExecutionWithLanguage() {
$path_alias = $this
->prophesizeEntity(PathAliasInterface::class);
$path_alias
->save()
->shouldBeCalledTimes(1);
$language = $this
->prophesize(LanguageInterface::class);
$language
->getId()
->willReturn('en');
$this->aliasStorage
->create([
'path' => '/node/1',
'alias' => '/about',
'langcode' => 'en',
])
->willReturn($path_alias
->reveal())
->shouldBeCalledTimes(1);
$this->action
->setContextValue('source', '/node/1')
->setContextValue('alias', '/about')
->setContextValue('language', $language
->reveal());
$this->action
->execute();
}
}