You are here

function RedirectFunctionalTest::testPathAddOverwriteRedirects in Redirect 7

Same name and namespace in other branches
  1. 7.2 redirect.test \RedirectFunctionalTest::testPathAddOverwriteRedirects()

File

./redirect.test, line 307
Unit tests for the redirect module.

Class

RedirectFunctionalTest

Code

function testPathAddOverwriteRedirects() {

  // Create an initial article node with a path alias.
  $first_node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'path' => array(
      'alias' => 'first-alias',
    ),
  ));

  // Change the node's alias will create an automatic redirect from 'first-alias' to the node.
  $this
    ->drupalPost("node/{$first_node->nid}/edit", array(
    'path[alias]' => 'second-alias',
  ), t('Save'));

  // Now create a second article node with the same alias as the redirect
  // created above.
  $second_node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'path' => array(
      'alias' => 'first-alias',
    ),
  ));

  // Visit the path 'first-alias' which should be an alias for $second_node.
  $this
    ->drupalGet('first-alias');
  $this
    ->assertNoText($first_node->title, 'Adding a new path alias that matches an existing redirect disables the redirect.');
  $this
    ->assertText($second_node->title, 'Adding a new path alias that matches an existing redirect disables the redirect.');
}