You are here

function PathautoUnitTestCase::testUpdateActions in Pathauto 6.2

Same name and namespace in other branches
  1. 6 pathauto.test \PathautoUnitTestCase::testUpdateActions()
  2. 7 pathauto.test \PathautoUnitTestCase::testUpdateActions()

Test the different update actions in pathauto_create_alias().

File

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

Class

PathautoUnitTestCase
Unit tests for Pathauto functions.

Code

function testUpdateActions() {

  // Test PATHAUTO_UPDATE_ACTION_NO_NEW with unaliased node and 'insert'.
  variable_set('pathauto_update_action', PATHAUTO_UPDATE_ACTION_NO_NEW);
  $node = $this
    ->drupalCreateNode(array(
    'title' => 'First title',
  ));
  $this
    ->assertEntityAlias('node', $node, 'content/first-title');

  // Default action is PATHAUTO_UPDATE_ACTION_DELETE.
  variable_set('pathauto_update_action', PATHAUTO_UPDATE_ACTION_DELETE);
  $node->title = 'Second title';
  pathauto_nodeapi($node, 'update');
  $this
    ->assertEntityAlias('node', $node, 'content/second-title');
  $this
    ->assertNoAliasExists(array(
    'alias' => 'content/first-title',
  ));

  // Test PATHAUTO_UPDATE_ACTION_LEAVE
  variable_set('pathauto_update_action', PATHAUTO_UPDATE_ACTION_LEAVE);
  $node->title = 'Third title';
  pathauto_nodeapi($node, 'update');
  $this
    ->assertEntityAlias('node', $node, 'content/third-title');
  $this
    ->assertAliasExists(array(
    'source' => "node/{$node->nid}",
    'alias' => 'content/second-title',
  ));
  variable_set('pathauto_update_action', PATHAUTO_UPDATE_ACTION_DELETE);
  $node->title = 'Fourth title';
  pathauto_nodeapi($node, 'update');
  $this
    ->assertEntityAlias('node', $node, 'content/fourth-title');
  $this
    ->assertNoAliasExists(array(
    'alias' => 'content/third-title',
  ));

  // The older second alias is not deleted yet.
  $older_path = $this
    ->assertAliasExists(array(
    'source' => "node/{$node->nid}",
    'alias' => 'content/second-title',
  ));
  path_set_alias(NULL, NULL, $older_path['pid']);
  variable_set('pathauto_update_action', PATHAUTO_UPDATE_ACTION_NO_NEW);
  $node->title = 'Fifth title';
  pathauto_nodeapi($node, 'update');
  $this
    ->assertEntityAlias('node', $node, 'content/fourth-title');
  $this
    ->assertNoAliasExists(array(
    'alias' => 'content/fith-title',
  ));

  // Test PATHAUTO_UPDATE_ACTION_NO_NEW with unaliased node and 'update'.
  $this
    ->deleteAllAliases();
  pathauto_nodeapi($node, 'update');
  $this
    ->assertEntityAlias('node', $node, 'content/fifth-title');

  // Test PATHAUTO_UPDATE_ACTION_NO_NEW with unaliased node and 'bulkupdate'.
  $this
    ->deleteAllAliases();
  $node->title = 'Sixth title';
  pathauto_node_update_alias($node, 'bulkupdate');
  $this
    ->assertEntityAlias('node', $node, 'content/sixth-title');
}