You are here

function PathModuleTestCase::testNodeAlias in SimpleTest 6

Test alias functionality through the node interfaces.

File

tests/path_module.test, line 81

Class

PathModuleTestCase

Code

function testNodeAlias() {

  // create test node
  $node1 = $this
    ->createNode();

  // create alias
  $edit = array();
  $edit['path'] = $this
    ->randomName(8);
  $this
    ->drupalPost('node/' . $node1->nid . '/edit', $edit, 'Save');

  // confirm that the alias works
  $this
    ->drupalGet($edit['path']);
  $this
    ->assertText($node1->title, 'Alias works.');

  // change alias
  $previous = $edit['path'];
  $edit['path'] = $this
    ->randomName(8);
  $this
    ->drupalPost('node/' . $node1->nid . '/edit', $edit, 'Save');

  // confirm that the alias works
  $this
    ->drupalGet($edit['path']);
  $this
    ->assertText($node1->title, 'Changed alias works.');

  // make sure that previous alias no longer works
  $this
    ->drupalGet($previous);
  $this
    ->assertNoText($node1->title, 'Previous alias no longer works.');
  $this
    ->assertTitle(new PatternExpectation('/Page not found/'), 'We get page  not found error');

  // create second test node
  $node2 = $this
    ->createNode();

  // set alias to second test node
  // leave $edit['path'] the same
  $this
    ->drupalPost('node/' . $node2->nid . '/edit', $edit, 'Save');

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

  // delete alias
  $this
    ->drupalPost('node/' . $node1->nid . '/edit', array(
    'path' => '',
  ), 'Save');

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