0

In a Drupal 7 site, I installed the Pathauto module. The user account I am using to log in has the permission to create new path aliases.

When I manually create a node, unselect the checkbox for automatic alias generation, and enter a custom alias (for example, qwerty), I can use drupal_lookup_path() to get the path alias.

$path = drupal_lookup_path('node/' . $node->nid);

However, using the following code in a test doesn't work.

$edit = array(
  'title' => 'asdf',
  'path[alias]' => 'qwerty',
);
$this->drupalPost("node/add/{$this->content_type}", $edit, t('Save'));

$path = drupal_lookup_path('node/' . $node->nid);

The value of $path is NULL, even when the path alias exists and $this->drupalGet('qwerty') returns a 200 status.

Why is drupal_lookup_path() failing to find the path alias only when called from a test?

1 Answer 1

1

I tracked this down to the fact that current_path(), which returns path/to/content in the browser, instead returns batch when called from within Simpletest.

Since drupal_lookup_path() uses the output of current_path() to generate the $cache[map] variable that it uses to find and store the path alias, this prevents drupal_lookup_path() from working in tests.

I have filed this as an issue on d.o.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.