I am using Drupal 7, I have Pathauto enabled, and my user has permissions to create new aliases.

When I manually create a node, uncheck the checkbox for automatic alias generation, and enter a custom alias (e.g. 'qwerty'), I can use drupal_lookup_path() to return the alias. So

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

gives $path a value of 'qwerty'.

However, when I create a node in simpletest with the code

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

and then

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

$path has a value of 'NULL', even when the alias is functioning, e.g. when


returns a 200 status.

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


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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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