? patches Index: pathauto.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.inc,v retrieving revision 1.77 diff -u -p -r1.77 pathauto.inc --- pathauto.inc 5 Jul 2010 14:29:51 -0000 1.77 +++ pathauto.inc 22 Jul 2010 07:00:20 -0000 @@ -94,33 +94,36 @@ function _pathauto_alias_exists($alias, * * @param $source * A string that is the internal path. + * @param $language + * A string containing the language code to check against. * @return * An array with the keys "pid" and "old_alias" containing * the "pid" and old "alias", respectively, of the old alias. */ -function _pathauto_existing_alias_data($source) { +function _pathauto_existing_alias_data($source, $language = LANGUAGE_NONE) { $output = array( 'pid' => '', 'old_alias' => '' ); - $result = db_query("SELECT pid, alias FROM {url_alias} WHERE source = :source", array(':source' => $source)); - if ($data = $result->fetchObject()) { + + $existing = db_query_range("SELECT pid, alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", 0, 1, array(':source' => $source, ':language' => $language, ':language_none' => LANGUAGE_NONE))->fetchObject(); + if ($existing) { // The item is already aliased, check what to do... switch (variable_get('pathauto_update_action', PATHAUTO_UPDATE_ACTION_DELETE)) { - // Replace old alias - remember the pid to update case PATHAUTO_UPDATE_ACTION_DELETE: case PATHAUTO_UPDATE_ACTION_REDIRECT: - $output['pid'] = $data->pid; - // Add new alias in addition to old one + // Replace old alias - remember the pid to update + $output['pid'] = $existing->pid; case PATHAUTO_UPDATE_ACTION_LEAVE: - $output['old_alias'] = $data->alias; + // Add new alias in addition to old one + $output['old_alias'] = $existing->alias; break; - // Do nothing case PATHAUTO_UPDATE_ACTION_NO_NEW: - default: + // Do nothing break; } } + return $output; } @@ -319,7 +322,7 @@ function pathauto_create_alias($module, $term_path = 'taxonomy/term/' . $data['term']->tid; if ($term_path != $source) { // Quietly alias 'taxonomy/term/[tid]' with proper path for term. - $update_data = _pathauto_existing_alias_data($source); + $update_data = _pathauto_existing_alias_data($source, $language); _pathauto_set_alias($source, $term_path, $update_data['pid'], FALSE, $update_data['old_alias'], $language); // Set $source as proper path. $source = $term_path; @@ -334,7 +337,8 @@ function pathauto_create_alias($module, // Do nothing return ''; } - $update_data = _pathauto_existing_alias_data($source); + $update_data = _pathauto_existing_alias_data($source, $language); + debug($update_data); $pid = $update_data['pid']; $old_alias = $update_data['old_alias']; } @@ -390,11 +394,11 @@ function pathauto_create_alias($module, // For forums and taxonomies, the source doesn't always form the base of the rss feed (ie. image galleries) if (($module == 'taxonomy' || $module == 'forum') && isset($data['term'])) { $tid = $data['term']->tid; - $update_data = _pathauto_existing_alias_data("taxonomy/term/$tid/$feedappend"); + $update_data = _pathauto_existing_alias_data("taxonomy/term/$tid/$feedappend", $language); _pathauto_set_alias("taxonomy/term/$tid/$feedappend", "$alias/feed", $update_data['pid'], $verbose, $update_data['old_alias'], $language); } else { - $update_data = _pathauto_existing_alias_data("$source/$feedappend"); + $update_data = _pathauto_existing_alias_data("$source/$feedappend", $language); _pathauto_set_alias("$source/$feedappend", "$alias/feed", $update_data['pid'], $verbose, $update_data['old_alias'], $language); } } Index: pathauto.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.test,v retrieving revision 1.20 diff -u -p -r1.20 pathauto.test --- pathauto.test 22 Jul 2010 04:59:34 -0000 1.20 +++ pathauto.test 22 Jul 2010 07:00:20 -0000 @@ -137,12 +137,41 @@ class PathautoTestHelper extends DrupalW $this->drupalLogin($this->admin_user); } - function assertEntityAlias($entity_type, $entity, $expected_alias) { - $path = entity_uri($entity_type, $entity); - drupal_clear_path_cache($path['path']); - $alias = drupal_get_path_alias($path['path']); + function saveAlias($source, $alias, $language = LANGUAGE_NONE) { + $alias = array( + 'source' => $source, + 'alias' => $alias, + 'language' => $language, + ); + path_save($alias); + } + + function saveEntityAlias($entity_type, $entity, $alias, $language = LANGUAGE_NONE) { + $uri = entity_uri($entity_type, $entity); + $this->saveAlias($uri['path'], $alias, $language); + } + + function assertEntityAlias($entity_type, $entity, $expected_alias, $language = LANGUAGE_NONE) { + $uri = entity_uri($entity_type, $entity); + drupal_clear_path_cache($uri['path']); + $alias = drupal_get_path_alias($uri['path'], $language); $this->assertIdentical($alias, $expected_alias); } + + function assertNoEntityAlias($entity_type, $entity, $expected_alias, $langauge = LANGAUGE_NONE) { + $uri = entity_uri($entity_type, $entity); + $this->assertEntityAlias($entity_type, $entity, $uri['path'], $language); + } + + function assertAlias(array $conditions) { + $alias = path_load($conditions); + $this->assertTrue($alias, t('Alias with conditions @conditions found.', array('@conditions' => var_export($conditions, TRUE)))); + } + + function assertNoAlias(array $conditions) { + $alias = path_load($conditions); + $this->assertFalse($alias, t('Alias with conditions @conditions not found.', array('@conditions' => var_export($conditions, TRUE)))); + } } /** @@ -280,3 +309,37 @@ class PathautoFunctionalTestCase extends $this->assertNoText('The configuration options have been saved.'); } } + +class PathautoLocaleTestCase extends PathautoTestHelper { + public static function getInfo() { + return array( + 'name' => 'Pathauto localization tests', + 'description' => 'Test pathauto functionality with localization and translation.', + 'group' => 'Pathauto', + ); + } + + function setUp() { + parent::setUp(array('locale', 'translation'), array('administer languages')); + + // Add predefined French language and reset the locale cache. + require_once DRUPAL_ROOT . '/includes/locale.inc'; + locale_add_language('fr', NULL, NULL, LANGUAGE_LTR, '', 'fr'); + drupal_language_initialize(); + } + + /** + * Test that when an english node is updated, its old english alias is + * deleted and its french alias is left intact. + */ + function testLanguageAliases() { + $node = $this->drupalCreateNode(array('path' => array('alias' => 'english-node', 'pathauto_perform_alias' => FALSE), 'title' => 'English node')); + $node->language = 'en'; + $this->saveEntityAlias('node', $node, 'french-node', 'fr'); + + pathauto_node_update_alias($node, 'update'); + $this->assertEntityAlias('node', $node, 'content/english-node', 'en'); + $this->assertEntityAlias('node', $node, 'french-node', 'fr'); + $this->assertNoAlias(array('alias' => 'english-node')); + } +}