1 path.test PathTestCase::testNodeAlias()

Tests alias functionality through the node interfaces.

File

core/modules/path/tests/path.test, line 147
Tests for the Path module.

Class

PathTestCase
Provides a base class for testing the Path module.

Code

function testNodeAlias() {
  // Create test node.
  $node1 = $this->backdropCreateNode();

  // Create alias.
  $edit = array();
  $edit['path[auto]'] = FALSE;
  $edit['path[alias]'] = $this->randomName(8);
  $this->backdropPost('node/' . $node1->nid . '/edit', $edit, t('Save'));

  // Confirm that the alias works.
  $this->backdropGet($edit['path[alias]']);
  $this->assertText($node1->title, 'Alias works.');
  $this->assertResponse(200);

  // Change alias to one containing "exotic" characters.
  $edit['path[auto]'] = FALSE;
  $previous = $edit['path[alias]'];
  $edit['path[alias]'] = "- ._~!$'\"()*@[]?&+%#,;=:" . // "Special" ASCII characters.
    "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string.
    "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets.
  $this->backdropPost('node/' . $node1->nid . '/edit', $edit, t('Save'));

  // Confirm that the alias works.
  $this->backdropGet($edit['path[alias]']);
  $this->assertText($node1->title, 'Changed alias works.');
  $this->assertResponse(200);

  // Make sure that previous alias no longer works.
  $this->backdropGet($previous);
  $this->assertNoText($node1->title, 'Previous alias no longer works.');
  $this->assertResponse(404);

  // Create second test node.
  $node2 = $this->backdropCreateNode();

  // Set alias to second test node.
  // Leave $edit['path[alias]'] the same.
  $this->backdropPost('node/' . $node2->nid . '/edit', $edit, t('Save'));

  // Confirm that the alias didn't make a duplicate.
  $this->assertText(t('The alias is already in use.'), 'Attempt to moved alias was rejected.');

  // Delete alias.
  $this->backdropPost('node/' . $node1->nid . '/edit', array('path[alias]' => ''), t('Save'));

  // Confirm that the alias no longer works.
  $this->backdropGet($edit['path[alias]']);
  $this->assertNoText($node1->title, 'Alias was successfully deleted.');
  $this->assertResponse(404);
}