summaryrefslogtreecommitdiff
path: root/modules/path
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-10-15 17:53:34 +0000
committerDries Buytaert <dries@buytaert.net>2009-10-15 17:53:34 +0000
commit977d635bb1705ecebae8783a5e629214986eaddf (patch)
tree5da3fbe936ec79ca2ee9d8131c0e12f36bb7670c /modules/path
parente1642603eac05665d959c3d63ea8d1efbe9e431a (diff)
downloadbrdo-977d635bb1705ecebae8783a5e629214986eaddf.tar.gz
brdo-977d635bb1705ecebae8783a5e629214986eaddf.tar.bz2
- Patch #332333 by dmitrig01, alexw: add a real API to path.module.
Diffstat (limited to 'modules/path')
-rw-r--r--modules/path/path.admin.inc103
-rw-r--r--modules/path/path.module269
-rw-r--r--modules/path/path.test39
3 files changed, 228 insertions, 183 deletions
diff --git a/modules/path/path.admin.inc b/modules/path/path.admin.inc
index 67d7915e7..aca185136 100644
--- a/modules/path/path.admin.inc
+++ b/modules/path/path.admin.inc
@@ -19,8 +19,8 @@ function path_admin_overview($keys = NULL) {
$multilanguage = (module_exists('locale') || $alias_exists);
$header = array(
- array('data' => t('Alias'), 'field' => 'dst', 'sort' => 'asc'),
- array('data' => t('System'), 'field' => 'src'),
+ array('data' => t('Alias'), 'field' => 'alias', 'sort' => 'asc'),
+ array('data' => t('System'), 'field' => 'source'),
array('data' => t('Operations'), 'colspan' => '2')
);
if ($multilanguage) {
@@ -30,7 +30,7 @@ function path_admin_overview($keys = NULL) {
$query = db_select('url_alias')->extend('PagerDefault')->extend('TableSort');
if ($keys) {
// Replace wildcards with PDO wildcards.
- $query->condition('dst', '%' . preg_replace('!\*+!', '%', $keys) . '%', 'LIKE');
+ $query->condition('alias', '%' . preg_replace('!\*+!', '%', $keys) . '%', 'LIKE');
}
$result = $query
->fields('url_alias')
@@ -43,15 +43,15 @@ function path_admin_overview($keys = NULL) {
foreach ($result as $data) {
$row = array(
'data' => array(
- l($data->dst, $data->src),
- l($data->src, $data->src, array('alias' => TRUE)),
+ l($data->alias, $data->source),
+ l($data->source, $data->source, array('alias' => TRUE)),
l(t('edit'), "admin/config/search/path/edit/$data->pid", array('query' => $destination)),
l(t('delete'), "admin/config/search/path/delete/$data->pid", array('query' => $destination)),
),
);
// If the system path maps to a different URL alias, highlight this table
// row to let the user know of old aliases.
- if ($data->dst != drupal_get_path_alias($data->src, $data->language)) {
+ if ($data->alias != drupal_get_path_alias($data->source, $data->language)) {
$row['class'] = array('warning');
}
if ($multilanguage) {
@@ -78,11 +78,10 @@ function path_admin_overview($keys = NULL) {
/**
* Menu callback; handles pages for creating and editing URL aliases.
*/
-function path_admin_edit($pid = 0) {
- if ($pid) {
- $alias = path_load($pid);
- drupal_set_title($alias['dst']);
- $output = drupal_get_form('path_admin_form', $alias);
+function path_admin_edit($path = array()) {
+ if ($path) {
+ drupal_set_title($path['alias']);
+ $output = drupal_get_form('path_admin_form', $path);
}
else {
$output = drupal_get_form('path_admin_form');
@@ -98,41 +97,48 @@ function path_admin_edit($pid = 0) {
* @see path_admin_form_validate()
* @see path_admin_form_submit()
*/
-function path_admin_form($form, &$form_state, $edit = array('src' => '', 'dst' => '', 'language' => '', 'pid' => NULL)) {
-
- $form['#alias'] = $edit;
-
- $form['src'] = array(
+function path_admin_form($form, &$form_state, $path = array('source' => '', 'alias' => '', 'language' => '', 'pid' => NULL)) {
+ $form['source'] = array(
'#type' => 'textfield',
'#title' => t('Existing system path'),
- '#default_value' => $edit['src'],
+ '#default_value' => $path['source'],
'#maxlength' => 255,
'#size' => 45,
'#description' => t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.'),
'#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
'#required' => TRUE,
);
- $form['dst'] = array(
+ $form['alias'] = array(
'#type' => 'textfield',
'#title' => t('Path alias'),
- '#default_value' => $edit['dst'],
+ '#default_value' => $path['alias'],
'#maxlength' => 255,
'#size' => 45,
'#description' => t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'),
'#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
'#required' => TRUE,
);
- // This will be a hidden value unless locale module is enabled
+
+ // This will be a hidden value unless locale module is enabled.
$form['language'] = array(
'#type' => 'value',
- '#value' => $edit['language']
+ '#value' => $path['language']
);
- if ($edit['pid']) {
- $form['pid'] = array('#type' => 'hidden', '#value' => $edit['pid']);
- $form['submit'] = array('#type' => 'submit', '#value' => t('Update alias'));
+ if ($path['pid']) {
+ $form['pid'] = array(
+ '#type' => 'hidden',
+ '#value' => $path['pid'],
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Update alias'),
+ );
}
else {
- $form['submit'] = array('#type' => 'submit', '#value' => t('Create new alias'));
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Create new alias'),
+ );
}
return $form;
@@ -140,37 +146,42 @@ function path_admin_form($form, &$form_state, $edit = array('src' => '', 'dst' =
/**
- * Verify that a new URL alias is valid
+ * Verify that a URL alias is valid
*/
function path_admin_form_validate($form, &$form_state) {
- $src = $form_state['values']['src'];
- $dst = $form_state['values']['dst'];
+ $source = $form_state['values']['source'];
+ $alias = $form_state['values']['alias'];
$pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0;
// Language is only set if locale module is enabled, otherwise save for all languages.
$language = isset($form_state['values']['language']) ? $form_state['values']['language'] : '';
- $has_alias = db_query("SELECT COUNT(dst) FROM {url_alias} WHERE pid <> :pid AND dst = :dst AND language = :language", array(
- ':pid' => $pid,
- ':dst' => $dst,
+ $has_alias = db_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND language = :language", array(
+ ':pid' => $pid,
+ ':alias' => $alias,
':language' => $language,
))
->fetchField();
if ($has_alias) {
- form_set_error('dst', t('The alias %alias is already in use in this language.', array('%alias' => $dst)));
+ form_set_error('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias)));
}
- $item = menu_get_item($src);
+ $item = menu_get_item($source);
if (!$item || !$item['access']) {
- form_set_error('src', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $src)));
+ form_set_error('source', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $source)));
}
}
/**
- * Save a new URL alias to the database.
+ * Save a URL alias to the database.
*/
function path_admin_form_submit($form, &$form_state) {
- // Language is only set if locale module is enabled
- path_set_alias($form_state['values']['src'], $form_state['values']['dst'], isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0, isset($form_state['values']['language']) ? $form_state['values']['language'] : '');
+ $path = array();
+ foreach (array('source', 'alias', 'pid', 'language') as $key) {
+ if (isset($form_state['values'][$key])) {
+ $path[$key] = $form_state['values'][$key];
+ }
+ }
+ path_save($path);
drupal_set_message(t('The alias has been saved.'));
$form_state['redirect'] = 'admin/config/search/path';
@@ -180,15 +191,17 @@ function path_admin_form_submit($form, &$form_state) {
/**
* Menu callback; confirms deleting an URL alias
*/
-function path_admin_delete_confirm($form, $form_state, $pid) {
- $path = path_load($pid);
+function path_admin_delete_confirm($form, &$form_state, $path) {
if (user_access('administer url aliases')) {
- $form['pid'] = array('#type' => 'value', '#value' => $pid);
- $output = confirm_form($form,
- t('Are you sure you want to delete path alias %title?', array('%title' => $path['dst'])),
- 'admin/config/search/path');
+ $form_state['path'] = $path;
+ return confirm_form(
+ $form,
+ t('Are you sure you want to delete path alias %title?',
+ array('%title' => $path['alias'])),
+ 'admin/config/search/path'
+ );
}
- return $output;
+ return array();
}
/**
@@ -196,7 +209,7 @@ function path_admin_delete_confirm($form, $form_state, $pid) {
*/
function path_admin_delete_confirm_submit($form, &$form_state) {
if ($form_state['values']['confirm']) {
- path_admin_delete($form_state['values']['pid']);
+ path_delete($form_state['path']['pid']);
$form_state['redirect'] = 'admin/config/search/path';
return;
}
diff --git a/modules/path/path.module b/modules/path/path.module
index 81ae6f49c..c2915bc42 100644
--- a/modules/path/path.module
+++ b/modules/path/path.module
@@ -40,17 +40,18 @@ function path_menu() {
'access arguments' => array('administer url aliases'),
'file' => 'path.admin.inc',
);
- $items['admin/config/search/path/edit'] = array(
+ $items['admin/config/search/path/edit/%path'] = array(
'title' => 'Edit alias',
'page callback' => 'path_admin_edit',
+ 'page arguments' => array(5),
'access arguments' => array('administer url aliases'),
'type' => MENU_CALLBACK,
'file' => 'path.admin.inc',
);
- $items['admin/config/search/path/delete'] = array(
+ $items['admin/config/search/path/delete/%path'] = array(
'title' => 'Delete alias',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('path_admin_delete_confirm'),
+ 'page arguments' => array('path_admin_delete_confirm', 5),
'access arguments' => array('administer url aliases'),
'type' => MENU_CALLBACK,
'file' => 'path.admin.inc',
@@ -72,79 +73,87 @@ function path_menu() {
}
/**
- * Post-confirmation; delete an URL alias.
+ * Fetch a specific URL alias from the database.
+ *
+ * @param $criteria
+ * A string representing the source, a number representing the pid, or an
+ * array of criteria.
*/
-function path_admin_delete($pid = 0) {
- db_delete('url_alias')
- ->condition('pid', $pid)
- ->execute();
- drupal_set_message(t('The alias has been deleted.'));
+function path_load($criteria) {
+ if (is_numeric($criteria)) {
+ $criteria = array('pid' => $criteria);
+ }
+ else if (is_string($criteria)) {
+ $criteria = array('source' => $criteria);
+ }
+ else if (!is_array($criteria)) {
+ return FALSE;
+ }
+ $select = db_select('url_alias');
+ foreach ($criteria as $field => $value) {
+ $select->condition($field, $value);
+ }
+ return $select
+ ->fields('url_alias', array('source', 'alias', 'language', 'pid'))
+ ->execute()
+ ->fetchAssoc();
}
/**
- * Set an aliased path for a given Drupal path, preventing duplicates.
+ * Save a path alias to the database.
+ *
+ * @param $path
+ * A path array containing the following keys:
+ * - source: the initial path.
+ * - alias: the aliased path.
+ * - language: the language of the alias.
+ * - pid: unique path alias identifier (optional).
*/
-function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '') {
- $path = urldecode($path);
- $alias = urldecode($alias);
- // First we check if we deal with an existing alias and delete or modify it based on pid.
- if ($pid) {
- // An existing alias.
- if (!$path || !$alias) {
- // Delete the alias based on pid.
- db_delete('url_alias')
- ->condition('pid', $pid)
- ->execute();
- }
- else {
- // Update the existing alias.
- db_update('url_alias')
- ->fields(array(
- 'src' => $path,
- 'dst' => $alias,
- 'language' => $language))
- ->condition('pid', $pid)
- ->execute();
- }
+function path_save($path) {
+ $path += array('language' => '', 'pid' => 0);
+ $pid = empty($path['pid']) ? 0 : $path['pid'];
+ $new = (bool) $pid;
+ unset($path['pid']);
+ // Make sure that this combination of source, alias, language wasn't save before.
+ $loaded_path = path_load($path);
+ if ($loaded_path) {
+ return $loaded_path;
}
- elseif ($path && $alias) {
- // Check for existing aliases.
- if ($alias == drupal_get_path_alias($path, $language)) {
- // There is already such an alias, neutral or in this language.
- // Update the alias based on alias; setting the language if not yet done.
- db_update('url_alias')
- ->fields(array(
- 'src' => $path,
- 'dst' => $alias,
- 'language' => $language
- ))
- ->condition('dst', $alias)
- ->execute();
- }
- else {
- // A new alias. Add it to the database.
- db_insert('url_alias')
- ->fields(array(
- 'src' => $path,
- 'dst' => $alias,
- 'language' => $language,
- ))
- ->execute();
- }
+ if ($pid) {
+ db_update('url_alias')
+ ->fields($path)
+ ->condition('pid', $pid)
+ ->execute();
}
else {
- // Delete the alias.
- if ($alias) {
- db_delete('url_alias')
- ->condition('dst', $alias)
- ->execute();
- }
- else {
- db_delete('url_alias')
- ->condition('src', $path)
- ->execute();
- }
+ $pid = db_insert('url_alias')
+ ->fields($path)
+ ->execute();
}
+ $path['pid'] = $pid;
+ module_invoke_all('path_' . ($new ? 'insert' : 'update'), $path);
+
+ drupal_clear_path_cache();
+ return $path;
+}
+
+/**
+ * Delete a URL alias.
+ *
+ * @param $criteria
+ * A number representing the pid or an array of criteria.
+ */
+function path_delete($criteria) {
+ if (!is_array($criteria)) {
+ $criteria = array('pid' => $criteria);
+ }
+ $path = path_load($criteria);
+ $delete = db_delete('url_alias');
+ foreach ($criteria as $field => $value) {
+ $delete->condition($field, $value);
+ }
+ $delete->execute();
+ module_invoke_all('path_delete', $path);
drupal_clear_path_cache();
}
@@ -154,16 +163,18 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = ''
function path_node_validate($node, $form) {
if (user_access('create url aliases') || user_access('administer url aliases')) {
if (isset($node->path)) {
- $language = isset($node->language) ? $node->language : '';
- $node->path = trim($node->path);
- $has_alias = db_query("SELECT COUNT(dst) FROM {url_alias} WHERE src <> :src AND dst = :dst AND language = :language", array(
- ':src' => "node/$node->nid",
- ':dst' => $node->path,
- ':language' => $language,
- ))
- ->fetchField();
-
- if ($has_alias) {
+ if (!is_array($node->path)) {
+ $node->path = array('alias' => $node->path);
+ }
+ $select = db_select('url_alias')->condition('alias', trim($node->path['alias']));
+ $select->addExpression('COUNT(alias)');
+ if ($node->nid) {
+ $select->condition('source', 'node/' . $node->nid, '<>');
+ }
+ if (isset($node->language)) {
+ $select->condition('language', $node->language);
+ }
+ if ($select->execute()->fetchField()) {
form_set_error('path', t('The path is already in use.'));
}
}
@@ -175,10 +186,12 @@ function path_node_validate($node, $form) {
*/
function path_node_load($nodes, $types) {
foreach ($nodes as $node) {
- $language = isset($node->language) ? $node->language : '';
- $path = 'node/' . $node->nid;
- $alias = drupal_get_path_alias($path, $language);
- if ($path != $alias) {
+ $criteria = array('source' => 'node/' . $node->nid);
+ if (isset($node->language)) {
+ $criteria['language'] = $node->language;
+ }
+ $alias = path_load($criteria);
+ if ($alias) {
$node->path = $alias;
}
}
@@ -188,13 +201,16 @@ function path_node_load($nodes, $types) {
* Implement hook_node_insert().
*/
function path_node_insert($node) {
- if (user_access('create url aliases') || user_access('administer url aliases')) {
- $language = isset($node->language) ? $node->language : '';
- // Don't try to insert if path is NULL. We may have already set
- // the alias ahead of time.
- if (isset($node->path)) {
- path_set_alias('node/' . $node->nid, $node->path, NULL, $language);
+ if ((user_access('create url aliases') || user_access('administer url aliases')) && isset($node->path)) {
+ if (!is_array($node->path)) {
+ $node->path = array('alias' => $node->path);
}
+
+ $node->path += array(
+ 'source' => 'node/' . $node->nid,
+ 'language' => isset($node->language) ? $node->language : '',
+ );
+ $node->path = path_save($node->path);
}
}
@@ -202,9 +218,18 @@ function path_node_insert($node) {
* Implement hook_node_update().
*/
function path_node_update($node) {
- if (user_access('create url aliases') || user_access('administer url aliases')) {
- $language = isset($node->language) ? $node->language : '';
- path_set_alias('node/' . $node->nid, isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language);
+ if ((user_access('create url aliases') || user_access('administer url aliases')) && isset($node->path)) {
+ if (!is_array($node->path)) {
+ $node->path = array('alias' => $node->path);
+ }
+ if (isset($node->pid)) {
+ $node->path['pid'] = $node->pid;
+ }
+ $node->path += array(
+ 'source' => 'node/' . $node->nid,
+ 'language' => isset($node->language) ? $node->language : '',
+ );
+ path_save($node->path);
}
}
@@ -212,14 +237,20 @@ function path_node_update($node) {
* Implement hook_node_delete().
*/
function path_node_delete($node) {
- path_set_alias('node/' . $node->nid);
+ if (isset($node->path)) {
+ if (!is_array($node->path)) {
+ $node->path = path_load(array('alias' => $node->path));
+ }
+ path_delete($node->path['pid']);
+ unset($node->path);
+ }
}
/**
* Implement hook_taxonomy_term_delete().
*/
function path_taxonomy_term_delete($term) {
- path_set_alias('taxonomy/term/' . $term->tid);
+ path_delete(path_load('taxonomy/term/' . $term->tid));
}
/**
@@ -227,7 +258,15 @@ function path_taxonomy_term_delete($term) {
*/
function path_form_alter(&$form, $form_state, $form_id) {
if (!empty($form['#node_edit_form'])) {
- $path = isset($form['#node']->path) ? $form['#node']->path : NULL;
+ $path = NULL;
+ if (isset($form['#node']->path)) {
+ if (is_array($form['#node']->path)) {
+ $path = $form['#node']->path['alias'];
+ }
+ else {
+ $path = $form['#node']->path;
+ }
+ }
$form['path'] = array(
'#type' => 'fieldset',
'#title' => t('URL path settings'),
@@ -252,11 +291,7 @@ function path_form_alter(&$form, $form_state, $form_id) {
if ($path) {
$form['path']['pid'] = array(
'#type' => 'value',
- '#value' => db_query("SELECT pid FROM {url_alias} WHERE dst = :dst AND language = :language", array(
- ':dst' => $path,
- ':language' => $form['#node']->language
- ))
- ->fetchField(),
+ '#value' => $form['#node']->path['pid'],
);
}
}
@@ -271,13 +306,14 @@ function path_form_taxonomy_form_term_alter(&$form, $form_state) {
// After a new term is added, populate the path field if it was set.
if (!empty($form['#term']['path'])) {
$path = $form['#term']['path'];
+ if (!is_array($path)) {
+ $path = path_load(array('alias' => $path));
+ }
}
else {
- $url = 'taxonomy/term/' . $form['#term']['tid'];
- $alias = drupal_get_path_alias($url);
-
+ $alias = path_load('taxonomy/term/' . $form['#term']['tid']);
// Since drupal_get_path_alias() can return the default path, check if we really have an alias.
- if ($alias != $url) {
+ if ($alias['alias'] != 'taxonomy/term/' . $form['#term']['tid']) {
$path = $alias;
}
else {
@@ -289,7 +325,7 @@ function path_form_taxonomy_form_term_alter(&$form, $form_state) {
$form['identification']['path'] = array(
'#type' => 'textfield',
'#title' => t('URL alias'),
- '#default_value' => $path,
+ '#default_value' => $path['alias'],
'#maxlength' => 255,
'#weight' => 0,
'#access' => (user_access('create url aliases') || user_access('administer url aliases')),
@@ -300,7 +336,7 @@ function path_form_taxonomy_form_term_alter(&$form, $form_state) {
$form['identification']['path']['pid'] = array(
'#type' => 'value',
'#access' => (user_access('create url aliases') || user_access('administer url aliases')),
- '#value' => db_query("SELECT pid FROM {url_alias} WHERE dst = :dst", array(':dst' => $path))->fetchField(),
+ '#value' => db_query("SELECT pid FROM {url_alias} WHERE alias = :alias", array(':alias' => $path['alias']))->fetchField(),
);
}
}
@@ -310,13 +346,13 @@ function path_form_taxonomy_form_term_alter(&$form, $form_state) {
* Path validation callback for taxonomy_form_term.
*/
function path_taxonomy_term_validate($form, &$form_state) {
- $pid = db_query("SELECT pid FROM {url_alias} WHERE dst = :dst", array(':dst' => $form_state['values']['path']))->fetchField();
- if ($pid) {
+ $path = path_load(array('alias' => $form_state['values']['path']));
+ if ($path) {
// If the pid matches the one in use for this term then we are fine.
- if (isset($form_state['values']['pid']) && $pid == $form_state['values']['pid']) {
+ if (isset($form_state['values']['pid']) && $path['pid'] == $form_state['values']['pid']) {
return;
}
- form_set_error('path', 'The URL alias is already in use.');
+ form_set_error('path', t('The URL alias is already in use.'));
}
}
@@ -326,10 +362,12 @@ function path_taxonomy_term_validate($form, &$form_state) {
function path_taxonomy_term_submit($form, &$form_state) {
// Make sure this is not triggered on the delete confirmation form.
if (empty($form_state['confirm_delete'])) {
- $url = 'taxonomy/term/' . $form_state['tid'];
- $alias = isset($form_state['values']['path']) ? $form_state['values']['path'] : NULL;
- $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : NULL;
- path_set_alias($url, $alias, $pid);
+ $path = array(
+ 'source' => 'taxonomy/term/' . $form_state['tid'],
+ 'alias' => isset($form_state['values']['path']) ? $form_state['values']['path'] : NULL,
+ 'pid' => isset($form_state['values']['pid']) ? $form_state['values']['pid'] : NULL,
+ );
+ path_save($path);
}
}
@@ -348,10 +386,3 @@ function path_permission() {
),
);
}
-
-/**
- * Fetch a specific URL alias from the database.
- */
-function path_load($pid) {
- return db_query('SELECT * FROM {url_alias} WHERE pid = :pid', array(':pid' => $pid))->fetchAssoc();
-}
diff --git a/modules/path/path.test b/modules/path/path.test
index 974ffb96d..84ce3b0c9 100644
--- a/modules/path/path.test
+++ b/modules/path/path.test
@@ -35,20 +35,20 @@ class PathTestCase extends DrupalWebTestCase {
// Create alias.
$edit = array();
- $edit['src'] = 'node/' . $node1->nid;
- $edit['dst'] = $this->randomName(8);
+ $edit['source'] = 'node/' . $node1->nid;
+ $edit['alias'] = $this->randomName(8);
$this->drupalPost('admin/config/search/path/add', $edit, t('Create new alias'));
// Visit the system path for the node and confirm a cache entry is
// created.
cache_clear_all('*', 'cache_path', TRUE);
- $this->drupalGet($edit['src']);
- $this->assertTrue(cache_get($edit['src'], 'cache_path'), t('Cache entry was created.'));
+ $this->drupalGet($edit['source']);
+ $this->assertTrue(cache_get($edit['source'], 'cache_path'), t('Cache entry was created.'));
// Visit the alias for the node and confirm a cache entry is created.
cache_clear_all('*', 'cache_path', TRUE);
- $this->drupalGet($edit['dst']);
- $this->assertTrue(cache_get($edit['src'], 'cache_path'), t('Cache entry was created.'));
+ $this->drupalGet($edit['alias']);
+ $this->assertTrue(cache_get($edit['source'], 'cache_path'), t('Cache entry was created.'));
}
/**
@@ -60,25 +60,26 @@ class PathTestCase extends DrupalWebTestCase {
// Create alias.
$edit = array();
- $edit['src'] = 'node/' . $node1->nid;
- $edit['dst'] = $this->randomName(8);
+ $edit['source'] = 'node/' . $node1->nid;
+ $edit['alias'] = $this->randomName(8);
$this->drupalPost('admin/config/search/path/add', $edit, t('Create new alias'));
// Confirm that the alias works.
- $this->drupalGet($edit['dst']);
+ $this->drupalGet($edit['alias']);
$this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], 'Alias works.');
// Change alias.
- $pid = $this->getPID($edit['dst']);
+ $pid = $this->getPID($edit['alias']);
- $previous = $edit['dst'];
- $edit['dst'] = $this->randomName(8);
+ $previous = $edit['alias'];
+ $edit['alias'] = $this->randomName(8);
$this->drupalPost('admin/config/search/path/edit/' . $pid, $edit, t('Update alias'));
// Confirm that the alias works.
- $this->drupalGet($edit['dst']);
+ $this->drupalGet($edit['alias']);
$this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], 'Changed alias works.');
+ drupal_static_reset('drupal_lookup_path');
// Confirm that previous alias no longer works.
$this->drupalGet($previous);
$this->assertNoText($node1->title, 'Previous alias no longer works.');
@@ -88,18 +89,18 @@ class PathTestCase extends DrupalWebTestCase {
$node2 = $this->drupalCreateNode();
// Set alias to second test node.
- $edit['src'] = 'node/' . $node2->nid;
- // leave $edit['dst'] the same
+ $edit['source'] = 'node/' . $node2->nid;
+ // leave $edit['alias'] the same
$this->drupalPost('admin/config/search/path/add', $edit, t('Create new alias'));
// Confirm no duplicate was created.
- $this->assertRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['dst'])), 'Attempt to move alias was rejected.');
+ $this->assertRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['alias'])), 'Attempt to move alias was rejected.');
// Delete alias.
$this->drupalPost('admin/config/search/path/delete/' . $pid, array(), t('Confirm'));
// Confirm that the alias no longer works.
- $this->drupalGet($edit['dst']);
+ $this->drupalGet($edit['alias']);
$this->assertNoText($node1->title, 'Alias was successfully deleted.');
}
@@ -151,8 +152,8 @@ class PathTestCase extends DrupalWebTestCase {
$this->assertNoText($node1->title, 'Alias was successfully deleted.');
}
- function getPID($dst) {
- return db_query("SELECT pid FROM {url_alias} WHERE dst = :dst", array(':dst' => $dst))->fetchField();
+ function getPID($alias) {
+ return db_query("SELECT pid FROM {url_alias} WHERE alias = :alias", array(':alias' => $alias))->fetchField();
}
}