AliasLinkEnhancerTest.php in Gatsby Live Preview & Incremental Builds 8
File
modules/gatsby_extras/tests/src/Kernel/AliasLinkEnhancerTest.php
View source
<?php
namespace Drupal\Tests\gatsby_extras\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
use Drupal\Tests\Traits\Core\PathAliasTestTrait;
class AliasLinkEnhancerTest extends KernelTestBase {
use PathAliasTestTrait;
use TaxonomyTestTrait;
protected static $modules = [
'filter',
'gatsby_extras',
'jsonapi',
'jsonapi_extras',
'path_alias',
'serialization',
'taxonomy',
'text',
'user',
];
protected $enhancer;
protected $term;
protected $pathAlias;
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('path_alias');
$this
->installEntitySchema('taxonomy_term');
$this->enhancer = $this->container
->get('plugin.manager.resource_field_enhancer')
->createInstance('alias_link');
$vocabulary = $this
->createVocabulary();
$this->term = $this
->createTerm($vocabulary);
$this->pathAlias = $this
->createPathAlias($this->term
->toUrl()
->toString(), $this
->randomMachineName());
$this->container
->get('path_processor_manager')
->addOutbound($this->container
->get('path_alias.path_processor'));
}
public function testTransform() {
$output = $this->enhancer
->transform([
'uri' => sprintf('entity:taxonomy_term/%s/%s', $this->term
->bundle(), $this->term
->uuid()),
]);
$this
->assertEquals($this->pathAlias
->getAlias(), $output['uri_alias']);
}
public function testUndoTransform() {
$output = $this->enhancer
->undoTransform([
'uri' => 'entity:taxonomy_term/' . $this->term
->id(),
]);
$this
->assertEquals($this->pathAlias
->getAlias(), $output['uri_alias']);
}
}