public function PathautoKernelTest::testProgrammaticEntityCreation in Pathauto 8
Test programmatic entity creation for aliases.
File
- tests/
src/ Kernel/ PathautoKernelTest.php, line 455
Class
- PathautoKernelTest
- Unit tests for Pathauto functions.
Namespace
Drupal\Tests\pathauto\KernelCode
public function testProgrammaticEntityCreation() {
$node = $this
->drupalCreateNode([
'title' => 'Test node',
'path' => [
'pathauto' => TRUE,
],
]);
$this
->assertEntityAlias($node, '/content/test-node');
// Check the case when the pathauto widget is hidden, so it can not populate
// the 'pathauto' property, and
// \Drupal\path\Plugin\Field\FieldType\PathFieldItemList::computeValue()
// populates the 'path' field with a 'langcode' property, for example during
// an AJAX call on the entity form.
$node = $this
->drupalCreateNode([
'title' => 'Test node 2',
'path' => [
'langcode' => 'en',
],
]);
$this
->assertEntityAlias($node, '/content/test-node-2');
$this
->createPattern('taxonomy_term', '/[term:vocabulary]/[term:name]');
$vocabulary = $this
->addVocabulary([
'name' => 'Tags',
]);
$term = $this
->addTerm($vocabulary, [
'name' => 'Test term',
'path' => [
'pathauto' => TRUE,
],
]);
$this
->assertEntityAlias($term, '/tags/test-term');
$edit['name'] = 'Test user';
$edit['mail'] = 'test-user@example.com';
$edit['pass'] = user_password();
$edit['path'] = [
'pathauto' => TRUE,
];
$edit['status'] = 1;
$account = User::create($edit);
$account
->save();
$this
->assertEntityAlias($account, '/users/test-user');
}