Hello, i hope this is the right place for my question / problem:

While testing a Drupal 8 site with behat, I am trying to create entity and terms fixtures by the "@Given :vocabulary terms:" and "@Given :type content:" step that correspond to DrupalContext->createTerms() and DrupalContext->createNodes().

Without the pathauto module i can say:

Given "foo" terms:
| name      | path |
| MyFoo    | /foo |

The path is saved as "alias" in the url_alias database table, and the term is reachable under /foo.

When pathauto is active, this no longer works, because the automated url alias is used and saved in the database. I can still call the html form on /admin/structure/taxonomy/manage/categories/add and uncheck the box (by "And I uncheck the box ..."), and then enter an alias.

I think it would help if i could set "Generate automatic URL alias" in the createTerms step, but i cannot find the fieldname to use for this, or any other way to archieve this.

Comments

JohannesR created an issue.

JohannesR’s picture

We found a workaround for the problem by patching the termCreate and entityCreate methods in Drupal/Driver/Cores/Drupal8.php:

diff --git a/src/Drupal/Driver/Cores/Drupal8.php b/src/Drupal/Driver/Cores/Drupal8.php
index c1cd9ab..cb1cb0c 100644
--- a/src/Drupal/Driver/Cores/Drupal8.php
+++ b/src/Drupal/Driver/Cores/Drupal8.php
@@ -73,6 +73,9 @@ class Drupal8 extends AbstractCore {
       }
     }
     $this->expandEntityFields('node', $node);
+    if (isset($node->path) && isset($node->pathauto)) {
+        $node->path = ['alias' => $node->path, 'pathauto' => $node->pathauto];
+    }
     $entity = entity_create('node', (array) $node);
     $entity->save();

@@ -309,6 +312,9 @@ class Drupal8 extends AbstractCore {
   public function termCreate(\stdClass $term) {
     $term->vid = $term->vocabulary_machine_name;
     $this->expandEntityFields('taxonomy_term', $term);
+    if (isset($term->path) && isset($term->pathauto)) {
+      $term->path = ['alias' => $term->path, 'pathauto' => $term->pathauto];
+    }
     $entity = Term::create((array) $term);
     $entity->save();