function PathTestCase::testAdminAlias
Tests alias functionality through the admin interfaces.
File
-
modules/
path/ path.test, line 56
Class
- PathTestCase
- Provides a base class for testing the Path module.
Code
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->title, '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->title, 'Changed alias works.');
$this->assertResponse(200);
drupal_static_reset('drupal_lookup_path');
// Confirm that previous alias no longer works.
$this->drupalGet($previous);
$this->assertNoText($node1->title, '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->title, 'Alias was successfully deleted.');
$this->assertResponse(404);
// Create third and fourth test node.
$node3 = $this->drupalCreateNode();
$node4 = $this->drupalCreateNode();
// Give the node aliases a common first part.
$name = $this->randomName(4);
// Create aliases containing a slash.
$edit = array();
$edit['source'] = 'node/' . $node3->nid;
$alias3 = $name . '/' . $this->randomName(5);
$edit['alias'] = $alias3;
$this->drupalPost('admin/config/search/path/add', $edit, t('Save'));
$edit['source'] = 'node/' . $node4->nid;
$alias4 = $name . '/' . $this->randomName(4);
$edit['alias'] = $alias4;
$this->drupalPost('admin/config/search/path/add', $edit, t('Save'));
// Confirm that the aliases work.
$this->drupalGet($alias3);
$this->assertText($node3->title, 'Alias works.');
$this->assertResponse(200);
$this->drupalGet($alias4);
$this->assertText($node4->title, 'Alias works.');
$this->assertResponse(200);
// Confirm that filters containing slashes work.
$this->drupalGet('admin/config/search/path/list/' . $alias3);
$this->assertFieldByName('filter', $alias3);
$this->assertText($alias3, 'Searched-for alias with slash found.');
$this->assertNoText($alias4, 'Different alias with slash not found.');
$this->assertResponse(200);
// Delete aliases.
$pid = $this->getPID($alias3);
$this->drupalPost('admin/config/search/path/edit/' . $pid, array(), t('Delete'));
$this->drupalPost(NULL, array(), t('Confirm'));
$pid = $this->getPID($alias4);
$this->drupalPost('admin/config/search/path/edit/' . $pid, array(), t('Delete'));
$this->drupalPost(NULL, array(), t('Confirm'));
// Confirm that the aliases no longer work.
$this->drupalGet($alias3);
$this->assertNoText($node3->title, 'Alias was successfully deleted.');
$this->assertResponse(404);
$this->drupalGet($alias4);
$this->assertNoText($node4->title, 'Alias was successfully deleted.');
$this->assertResponse(404);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.