Tests alias functionality through the admin interfaces.
function testAdminAlias() {
// Create test node.
$node1 = $this
->drupalCreateNode();
// Create alias.
$edit = array();
$edit['source'] = 'node/' . $node1->nid;
$edit['alias'] = $this
->randomName(8);
$this
->drupalPost('admin/config/search/path/add', $edit, t('Save'));
// Confirm that the alias works.
$this
->drupalGet($edit['alias']);
$this
->assertText($node1
->label(), 'Alias works.');
$this
->assertResponse(200);
// Change alias to one containing "exotic" characters.
$pid = $this
->getPID($edit['alias']);
$previous = $edit['alias'];
$edit['alias'] = "- ._~!\$'\"()*@[]?&+%#,;=:" . "%23%25%26%2B%2F%3F" . "éøïвβ中國書۞";
// Characters from various non-ASCII alphabets.
$this
->drupalPost('admin/config/search/path/edit/' . $pid, $edit, t('Save'));
// Confirm that the alias works.
$this
->drupalGet($edit['alias']);
$this
->assertText($node1
->label(), 'Changed alias works.');
$this
->assertResponse(200);
drupal_container()
->get('path.alias_manager')
->cacheClear();
// Confirm that previous alias no longer works.
$this
->drupalGet($previous);
$this
->assertNoText($node1
->label(), 'Previous alias no longer works.');
$this
->assertResponse(404);
// Create second test node.
$node2 = $this
->drupalCreateNode();
// Set alias to second test node.
$edit['source'] = 'node/' . $node2->nid;
// leave $edit['alias'] the same
$this
->drupalPost('admin/config/search/path/add', $edit, t('Save'));
// Confirm no duplicate was created.
$this
->assertRaw(t('The alias %alias is already in use in this language.', array(
'%alias' => $edit['alias'],
)), 'Attempt to move alias was rejected.');
// Delete alias.
$this
->drupalPost('admin/config/search/path/edit/' . $pid, array(), t('Delete'));
$this
->drupalPost(NULL, array(), t('Confirm'));
// Confirm that the alias no longer works.
$this
->drupalGet($edit['alias']);
$this
->assertNoText($node1
->label(), 'Alias was successfully deleted.');
$this
->assertResponse(404);
// Create a really long alias.
$edit = array();
$edit['source'] = 'node/' . $node1->nid;
$alias = $this
->randomName(128);
$edit['alias'] = $alias;
// The alias is shortened to 50 characters counting the elipsis.
$truncated_alias = substr($alias, 0, 47);
$this
->drupalPost('admin/config/search/path/add', $edit, t('Save'));
$this
->assertNoText($alias, 'The untruncated alias was not found.');
// The 'truncated' alias will always be found.
$this
->assertText($truncated_alias, 'The truncated alias was found.');
}