function UrlAlterFunctionalTest::testUrlAlter
Same name in other branches
- 9 core/modules/path_alias/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\path_alias\Functional\UrlAlterFunctionalTest::testUrlAlter()
- 8.9.x core/modules/path_alias/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\path_alias\Functional\UrlAlterFunctionalTest::testUrlAlter()
- 10 core/modules/path_alias/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\path_alias\Functional\UrlAlterFunctionalTest::testUrlAlter()
- 10 core/modules/forum/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\forum\Functional\UrlAlterFunctionalTest::testUrlAlter()
- 11.x core/modules/path_alias/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\path_alias\Functional\UrlAlterFunctionalTest::testUrlAlter()
- 11.x core/modules/forum/tests/src/Functional/UrlAlterFunctionalTest.php \Drupal\Tests\forum\Functional\UrlAlterFunctionalTest::testUrlAlter()
Test that URL altering works and that it occurs in the correct order.
File
-
modules/
simpletest/ tests/ path.test, line 148
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('Save'));
$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}");
// Test that 'forum' is altered to 'community' correctly, both at the root
// level and for a specific existing forum.
$this->assertUrlInboundAlter('community', 'forum');
$this->assertUrlOutboundAlter('forum', 'community');
$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();
$this->assertUrlInboundAlter("community/{$tid}", "forum/{$tid}");
$this->assertUrlOutboundAlter("forum/{$tid}", "community/{$tid}");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.