View source
<?php
namespace Drupal\Tests\tome_sync\Kernel;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\node\Entity\Node;
use Drupal\pathauto\Entity\PathautoPattern;
use Drupal\pathauto\PathautoState;
use Drupal\Tests\tome_base\Kernel\TestBase;
class PathautoTest extends TestBase {
public static $modules = [
'path_alias',
'pathauto',
'ctools',
'path',
'token',
'tome_sync',
];
public function setUp() {
parent::setUp();
$this
->installSchema('tome_sync', [
'tome_sync_content_hash',
]);
$this
->installEntitySchema('path_alias');
DateFormat::create([
'pattern' => 'D, m/d/Y - H:i',
'id' => 'fallback',
])
->save();
$pattern = PathautoPattern::create([
'id' => mb_strtolower($this
->randomMachineName()),
'type' => 'canonical_entities:node',
'pattern' => '/node/[node:title]',
]);
$pattern
->save();
}
public function testPathauto() {
$repository = \Drupal::service('entity.repository');
$importer = \Drupal::service('tome_sync.importer');
$exporter = \Drupal::service('tome_sync.exporter');
$article = Node::create([
'type' => 'article',
'title' => 'My article',
]);
$article
->save();
$source = '/' . $article
->toUrl()
->getInternalPath();
\Drupal::service('path_alias.manager')
->cacheClear($source);
$this
->assertNotEquals($source, \Drupal::service('path_alias.manager')
->getAliasByPath($source, 'en'));
$uuid = \Drupal::service('uuid')
->generate();
$article = Node::create([
'type' => 'article',
'title' => 'Another article',
'uuid' => $uuid,
'path' => [
'path' => '',
'pathauto' => PathautoState::CREATE,
],
]);
$exporter
->exportContent($article);
$importer
->importContent('node', $uuid);
$article = $repository
->loadEntityByUuid('node', $uuid);
$source = '/' . $article
->toUrl()
->getInternalPath();
\Drupal::service('path_alias.manager')
->cacheClear($source);
$this
->assertEquals($source, \Drupal::service('path_alias.manager')
->getAliasByPath($source, 'en'));
}
}