summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/path.test
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests/path.test')
-rw-r--r--modules/simpletest/tests/path.test90
1 files changed, 90 insertions, 0 deletions
diff --git a/modules/simpletest/tests/path.test b/modules/simpletest/tests/path.test
index f99585691..7368cd1d4 100644
--- a/modules/simpletest/tests/path.test
+++ b/modules/simpletest/tests/path.test
@@ -236,3 +236,93 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase {
$this->assertIdentical($result, $final, t('Altered inbound URL %original, expected %final, and got %result.', array('%original' => $original, '%final' => $final, '%result' => $result)));
}
}
+
+/**
+ * Unit test for drupal_lookup_path().
+ */
+class PathLookupTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => t('Path lookup'),
+ 'description' => t('Tests that drupal_lookup_path() returns correct paths.'),
+ 'group' => t('Path API'),
+ );
+ }
+
+ /**
+ * Test that drupal_lookup_path() returns the correct path.
+ */
+ function testDrupalLookupPath() {
+ $account = $this->drupalCreateUser();
+ $uid = $account->uid;
+ $name = $account->name;
+
+ // Test the situation where the source is the same for multiple aliases.
+ // Start with a language-neutral alias, which we will override.
+ $path = array(
+ 'source' => "user/$uid",
+ 'alias' => 'foo',
+ );
+ path_save($path);
+ $this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Basic alias lookup works.'));
+ $this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Basic source lookup works.'));
+
+ // Create a language specific alias for the default language (English).
+ $path = array(
+ 'source' => "user/$uid",
+ 'alias' => "users/$name",
+ 'language' => 'en',
+ );
+ path_save($path);
+ $this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('English alias overrides language-neutral alias.'));
+ $this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('English source overrides language-neutral source.'));
+
+ // Create a language-neutral alias for the same path, again.
+ $path = array(
+ 'source' => "user/$uid",
+ 'alias' => 'bar',
+ );
+ path_save($path);
+ $this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a language-neutral alias.'));
+
+ // Create a language-specific (xx-lolspeak) alias for the same path.
+ $path = array(
+ 'source' => "user/$uid",
+ 'alias' => 'LOL',
+ 'language' => 'xx-lolspeak',
+ );
+ path_save($path);
+ $this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a LOLspeak alias.'));
+ // The LOLspeak alias should be returned if we really want LOLspeak.
+ $this->assertEqual(drupal_lookup_path('alias', $path['source'], 'xx-lolspeak'), 'LOL', t('LOLspeak alias returned if we specify xx-lolspeak to drupal_lookup_path().'));
+
+ // Create a new alias for this path in English, which should override the
+ // previous alias for "user/$uid".
+ $path = array(
+ 'source' => "user/$uid",
+ 'alias' => 'users/my-new-path',
+ 'language' => 'en',
+ );
+ path_save($path);
+ $this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Recently created English alias returned.'));
+ $this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Recently created English source returned.'));
+
+ // Remove the English aliases, which should cause a fallback to the most
+ // recently created language-neutral alias, 'bar'.
+ db_delete('url_alias')
+ ->condition('language', 'en')
+ ->execute();
+ drupal_clear_path_cache();
+ $this->assertEqual(drupal_lookup_path('alias', $path['source']), 'bar', t('Path lookup falls back to recently created language-neutral alias.'));
+
+ // Test the situation where the alias and language are the same, but
+ // the source differs. The newer alias record should be returned.
+ $account2 = $this->drupalCreateUser();
+ $path = array(
+ 'source' => 'user/' . $account2->uid,
+ 'alias' => 'bar',
+ );
+ path_save($path);
+ $this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Newer alias record is returned when comparing two LANGUAGE_NONE paths with the same alias.'));
+ }
+}