1 path.test | UrlAlterFunctionalTest::testUrlAlter() |
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->backdropCreateUser(array('administer url aliases'));
// Remove the default alias if set.
$account->path['auto'] = FALSE;
$account->path['alias'] = '';
$account->save();
$this->backdropLogin($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->backdropPost('admin/config/urls/path/add', $edit, 'Save URL 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-existent user is not altered.
$uid++;
$this->assertUrlInboundAlter("user/$uid", "user/$uid");
$this->assertUrlOutboundAlter("user/$uid", "user/$uid");
}