Index: includes/path.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/path.inc,v retrieving revision 1.26 diff -u -p -r1.26 path.inc --- includes/path.inc 12 Oct 2008 06:27:03 -0000 1.26 +++ includes/path.inc 13 Oct 2008 16:51:43 -0000 @@ -64,10 +64,15 @@ function drupal_lookup_path($action, $pa if (isset($map[$path_language][$path])) { return $map[$path_language][$path]; } + $dst = ''; // Get the most fitting result falling back with alias without language - $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language)); - $map[$path_language][$path] = $alias; - return $alias; + $result = db_query("SELECT dst, language FROM {url_alias} WHERE src = :path", array(':path' => $path)); + foreach($result AS $alias) { + if (isset($alias->language) && $alias->language == $path_language || empty($map[$path_language][$path]) && strpos($path, 'node/') == 0) { + $dst = $map[$path_language][$path] = $alias->dst; + } + } + return $dst; } // Check $no_src for this $path in case we've already determined that there // isn't a path that has this alias @@ -76,10 +81,13 @@ function drupal_lookup_path($action, $pa $src = ''; if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) { // Get the most fitting result falling back with alias without language - if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language))) { - $map[$path_language][$src] = $path; + $result = db_query("SELECT src, language FROM {url_alias} WHERE dst = :path", array(':path' => $path)); + foreach ($result AS $alias) { + if (isset($alias->language) && $alias->language == $path_language || empty($map[$path_language][$path])) { + $src = $map[$path_language][$src] = $alias->src; + } } - else { + if (empty($src)) { // We can't record anything into $map because we do not have a valid // index and there is no need because we have not learned anything // about any Drupal path. Thus cache to $no_src. Index: modules/path/path.test =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.test,v retrieving revision 1.3 diff -u -p -r1.3 path.test --- modules/path/path.test 21 Aug 2008 19:36:37 -0000 1.3 +++ modules/path/path.test 13 Oct 2008 16:51:44 -0000 @@ -138,3 +138,78 @@ class PathTestCase extends DrupalWebTest return $node; } } + +class PathLanguageTestCase extends DrupalWebTestCase { + function getInfo() { + return array( + 'name' => t('Path aliases with translated nodes'), + 'description' => t('Confirm that paths work with translated nodes'), + 'group' => t('Path'), + ); + } + + /** + * Create user, setup permissions, log user in, and create a node. + */ + function setUp() { + parent::setUp('path', 'locale', 'translation'); + // create and login user + $web_user = $this->drupalCreateUser(array('edit own page content', 'create page content', 'administer url aliases', 'create url aliases', 'administer languages', 'translate content', 'access administration pages')); + $this->drupalLogin($web_user); + } + + /** + * Test alias functionality through the admin interfaces. + */ + function testAliasTranslation() { + // Enable French language. + $edit = array(); + $edit['langcode'] = 'fr'; + + $this->drupalPost('admin/settings/language/add', $edit, t('Add language')); + + // Set 'page' content type to enable translation. + variable_set('language_content_type_page', 2); + + // Create a page in English. + $edit = array(); + $edit['title'] = $this->randomName(); + $edit['body'] = $this->randomName(); + $edit['language'] = 'en'; + $edit['path'] = $this->randomName(); + + $this->drupalPost('node/add/page', $edit, t('Save')); + + // Check to make sure the node was created. + $english_node = node_load(array('title' => $edit['title'])); + $this->assertTrue(($english_node), 'Node found in database.'); + + // Confirm that the alias works. + $this->drupalGet($edit['path']); + $this->assertText($english_node->title, 'Alias works.'); + + // Translate the node into French. + $this->drupalGet('node/' . $english_node->nid . '/translate'); + $this->clickLink(t('add translation')); + $edit = array(); + $edit['title'] = $this->randomName(); + $edit['body'] = $this->randomName(); + $edit['path'] = $this->randomName(); + $this->drupalPost(NULL, $edit, t('Save')); + + // Ensure the node was created. + // Check to make sure the node was created. + $french_node = node_load(array('title' => $edit['title'])); + $this->assertTrue(($french_node), 'Node found in database.'); + + // Confirm that the alias works. + $this->drupalGet($edit['path']); + $this->assertText($french_node->title, 'Alias for French translation works.'); + + // Confirm that the alias is returned by url(). + $languages = language_list(); + $url = url('node/' . $french_node->nid, array('language' => $languages[$french_node->language])); + $this->assertTrue(strpos($url, $edit['path']), t('URL contains the path alias.')); + } +} +