You are here

function PathautoUnitTestCase::testUpdateActions in Pathauto 6

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

Test the different update actions in pathauto_create_alias().

File

./pathauto.test, line 296
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', 0);
  $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', 2);
  $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', 1);
  $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', 2);
  $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', 0);
  $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');
}