You are here

public function PathautoFunctionalTestCase::testNodeState in Pathauto 7

@todo Merge this with existing node test methods?

File

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

Class

PathautoFunctionalTestCase
Test basic pathauto functionality.

Code

public function testNodeState() {
  $nodeNoAliasUser = $this
    ->drupalCreateUser(array(
    'bypass node access',
  ));
  $nodeAliasUser = $this
    ->drupalCreateUser(array(
    'bypass node access',
    'create url aliases',
  ));
  $node = $this
    ->drupalCreateNode(array(
    'title' => 'Node version one',
    'type' => 'page',
    'path' => array(
      'pathauto' => FALSE,
    ),
  ));
  $this
    ->assertNoEntityAlias('node', $node);

  // Set a manual path alias for the node.
  $node->path['alias'] = 'test-alias';
  node_save($node);

  // Ensure that the pathauto field was saved to the database.
  $node = node_load($node->nid, NULL, TRUE);
  $this
    ->assertFalse($node->path['pathauto']);

  // Ensure that the manual path alias was saved and an automatic alias was not generated.
  $this
    ->assertEntityAlias('node', $node, 'test-alias');
  $this
    ->assertNoEntityAliasExists('node', $node, 'content/node-version-one');

  // Save the node as a user who does not have access to path fieldset.
  $this
    ->drupalLogin($nodeNoAliasUser);
  $this
    ->drupalGet('node/' . $node->nid . '/edit');
  $this
    ->assertNoFieldByName('path[pathauto]');
  $edit = array(
    'title' => 'Node version two',
  );
  $this
    ->drupalPost(NULL, $edit, 'Save');
  $this
    ->assertText('Basic page Node version two has been updated.');
  $this
    ->assertEntityAlias('node', $node, 'test-alias');
  $this
    ->assertNoEntityAliasExists('node', $node, 'content/node-version-one');
  $this
    ->assertNoEntityAliasExists('node', $node, 'content/node-version-two');

  // Load the edit node page and check that the Pathauto checkbox is unchecked.
  $this
    ->drupalLogin($nodeAliasUser);
  $this
    ->drupalGet('node/' . $node->nid . '/edit');
  $this
    ->assertNoFieldChecked('edit-path-pathauto');

  // Edit the manual alias and save the node.
  $edit = array(
    'title' => 'Node version three',
    'path[alias]' => 'manually-edited-alias',
  );
  $this
    ->drupalPost(NULL, $edit, 'Save');
  $this
    ->assertText('Basic page Node version three has been updated.');
  $this
    ->assertEntityAlias('node', $node, 'manually-edited-alias');
  $this
    ->assertNoEntityAliasExists('node', $node, 'test-alias');
  $this
    ->assertNoEntityAliasExists('node', $node, 'content/node-version-one');
  $this
    ->assertNoEntityAliasExists('node', $node, 'content/node-version-two');
  $this
    ->assertNoEntityAliasExists('node', $node, 'content/node-version-three');

  // Programatically save the node with an automatic alias.
  $node = node_load($node->nid, NULL, TRUE);
  $node->path['pathauto'] = TRUE;
  node_save($node);

  // Ensure that the pathauto field was saved to the database.
  $node = node_load($node->nid, NULL, TRUE);
  $this
    ->assertTrue($node->path['pathauto']);
  $this
    ->assertEntityAlias('node', $node, 'content/node-version-three');
  $this
    ->assertNoEntityAliasExists('node', $node, 'manually-edited-alias');
  $this
    ->assertNoEntityAliasExists('node', $node, 'test-alias');
  $this
    ->assertNoEntityAliasExists('node', $node, 'content/node-version-one');
  $this
    ->assertNoEntityAliasExists('node', $node, 'content/node-version-two');
}