TaxonomyTermCoderTest.php in Facets Pretty Paths 8
File
tests/src/Kernel/TaxonomyTermCoderTest.php
View source
<?php
namespace Drupal\Tests\facets_pretty_paths\Kernel;
use Drupal\facets\Entity\Facet;
use Drupal\KernelTests\KernelTestBase;
class TaxonomyTermCoderTest extends KernelTestBase {
protected static $modules = [
'system',
'token',
'text',
'taxonomy',
'path_alias',
'pathauto',
'facets',
'facets_pretty_paths',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('taxonomy_term');
$this
->installConfig([
'system',
'pathauto',
]);
}
public function testTaxonomyTermCoder() {
$entity_type_manager = $this->container
->get('entity_type.manager');
$entity_type_manager
->getStorage('taxonomy_vocabulary')
->create([
'name' => 'Tags',
'vid' => 'tags',
])
->save();
$entity_type_manager
->getStorage('pathauto_pattern')
->create([
'id' => 'terms',
'label' => 'Terms',
'type' => 'canonical_entities:taxonomy_term',
'pattern' => '[term:name]',
])
->save();
$entity_type_manager
->getStorage('taxonomy_term')
->create([
'name' => 'My term',
'vid' => 'tags',
])
->save();
$facet_mock = $this
->getMockBuilder(Facet::class)
->disableOriginalConstructor()
->getMock();
$coder = $this->container
->get('plugin.manager.facets_pretty_paths.coder')
->createInstance('taxonomy_term_coder', [
'facet' => $facet_mock,
]);
$this
->assertEquals('my-term-1', $coder
->encode(1));
$this
->assertEquals('1', $coder
->decode('my-term-1'));
}
}