function UrlAlterFunctionalTest::testUrlAlter in SimpleTest 7
Test that URL altering works and that it occurs in the correct order.
File
Class
- UrlAlterFunctionalTest
- Tests hook_url_alter functions.
Code
function testUrlAlter() {
$account = $this
->drupalCreateUser(array(
'administer url aliases',
));
$this
->drupalLogin($account);
$uid = $account->uid;
$name = $account->name;
// Test a single altered path.
$this
->assertUrlInboundAlter("user/{$name}", "user/{$uid}");
$this
->assertUrlOutboundAlter("user/{$uid}", "user/{$name}");
// Test that a path always uses its alias.
$path = array(
'source' => "user/{$uid}/test1",
'alias' => 'alias/test1',
);
path_save($path);
$this
->assertUrlInboundAlter('alias/test1', "user/{$uid}/test1");
$this
->assertUrlOutboundAlter("user/{$uid}/test1", 'alias/test1');
// Test that alias source paths are normalized in the interface.
$edit = array(
'source' => "user/{$name}/edit",
'alias' => 'alias/test2',
);
$this
->drupalPost('admin/config/search/path/add', $edit, t('Create new alias'));
$this
->assertText(t('The alias has been saved.'));
// Test that a path always uses its alias.
$this
->assertUrlInboundAlter('alias/test2', "user/{$uid}/edit");
$this
->assertUrlOutboundAlter("user/{$uid}/edit", 'alias/test2');
// Test a non-existant user is not altered.
$uid++;
$this
->assertUrlInboundAlter("user/{$uid}", "user/{$uid}");
$this
->assertUrlOutboundAlter("user/{$uid}", "user/{$uid}");
// Test that 'forum' is altered to 'community' correctly.
$this
->assertUrlInboundAlter('community', 'forum');
$this
->assertUrlOutboundAlter('forum', 'community');
// Add a forum to test url altering.
$forum_vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module = 'forum'")
->fetchField();
$tid = db_insert('taxonomy_term_data')
->fields(array(
'name' => $this
->randomName(),
'vid' => $forum_vid,
))
->execute();
// Test that a existing forum URL is altered.
$this
->assertUrlInboundAlter("community/{$tid}", "forum/{$tid}");
$this
->assertUrlOutboundAlter("taxonomy/term/{$tid}", "community/{$tid}");
// Test that a non-existant forum URL is not altered.
$tid++;
$this
->assertUrlInboundAlter("taxonomy/term/{$tid}", "taxonomy/term/{$tid}");
$this
->assertUrlOutboundAlter("taxonomy/term/{$tid}", "taxonomy/term/{$tid}");
}