You are here

function RedirectFunctionalTest::testPathChangeRedirects in Redirect 7

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

File

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

Class

RedirectFunctionalTest

Code

function testPathChangeRedirects() {

  // Create an initial article node with a path alias.
  $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/{$node->nid}/edit", array(
    'path[alias]' => 'second-alias',
  ), t('Save'));
  $this
    ->drupalGet('first-alias');
  $this
    ->assertText($node->title);
  $this
    ->drupalPost("node/{$node->nid}/edit", array(
    'path[alias]' => 'first-alias',
  ), t('Save'));
  $this
    ->assertResponse(200, "Changing node's alias back to 'first-alias' does not break page load with a circular redirect.");
  $this
    ->assertNoText('Infinite redirect loop prevented.');
  $this
    ->drupalGet('second-alias');
  $this
    ->assertText($node->title);
  $this
    ->drupalPost("node/{$node->nid}/edit", array(
    'path[alias]' => 'second-alias',
  ), t('Save'));
  $this
    ->assertResponse(200, "Changing node's alias back to 'second-alias' does not break page load with a circular redirect.");
  $this
    ->assertNoText('Infinite redirect loop prevented.');

  // Check that first-alias redirect has been re-enabled.
  $this
    ->drupalGet('first-alias');
  $this
    ->assertText($node->title);
}