You are here

function PathautoFunctionalTestCase::testNodeEditing in Pathauto 6

Same name and namespace in other branches
  1. 6.2 pathauto.test \PathautoFunctionalTestCase::testNodeEditing()
  2. 7 pathauto.test \PathautoFunctionalTestCase::testNodeEditing()

Basic functional testing of Pathauto.

File

./pathauto.test, line 469
Functionality tests for Pathauto.

Class

PathautoFunctionalTestCase
Test basic pathauto functionality.

Code

function testNodeEditing() {

  // Create node for testing.
  $random_title = $this
    ->randomName(10);
  $title = ' Simpletest title ' . $random_title . ' [';
  $automatic_alias = 'content/simpletest-title-' . strtolower($random_title);
  $node = $this
    ->drupalCreateNode(array(
    'title' => $title,
    'type' => 'page',
  ));

  // Look for alias generated in the form.
  $this
    ->drupalGet('node/' . $node->nid . '/edit');
  $this
    ->assertFieldChecked('edit-pathauto-perform-alias');
  $this
    ->assertFieldByName('path', $automatic_alias, 'Proper automated alias generated.');

  // Check whether the alias actually works.
  $this
    ->drupalGet($automatic_alias);
  $this
    ->assertText($title, 'Node accessible through automatic alias.');

  // Manually set the node's alias.
  $manual_alias = 'content/' . $node->nid;
  $edit = array(
    'pathauto_perform_alias' => FALSE,
    'path' => $manual_alias,
  );
  $this
    ->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
  $this
    ->assertText(t('@type @title has been updated', array(
    '@type' => 'Page',
    '@title' => $title,
  )));

  // Check that the automatic alias checkbox is now unchecked by default.
  $this
    ->drupalGet('node/' . $node->nid . '/edit');
  $this
    ->assertNoFieldChecked('edit-pathauto-perform-alias');
  $this
    ->assertFieldByName('path', $manual_alias);

  // Submit the node form with the default values.
  $this
    ->drupalPost(NULL, array(), t('Save'));
  $this
    ->assertText(t('@type @title has been updated', array(
    '@type' => 'Page',
    '@title' => $title,
  )));

  // Test that the old (automatic) alias has been deleted and only accessible
  // through the new (manual) alias.
  $this
    ->drupalGet($automatic_alias);
  $this
    ->assertResponse(404, 'Node not accessible through automatic alias.');
  $this
    ->drupalGet($manual_alias);
  $this
    ->assertText($title, 'Node accessible through manual alias.');
}