You are here

function PathautoUnitTestCase::testUpdateActions in Pathauto 7

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

Test the different update actions in pathauto_create_alias().

File

./pathauto.test, line 235
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_node_update($node);
  $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_node_update($node);
  $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_node_update($node);
  $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_delete($older_path);
  variable_set('pathauto_update_action', PATHAUTO_UPDATE_ACTION_NO_NEW);
  $node->title = 'Fifth title';
  pathauto_node_update($node);
  $this
    ->assertEntityAlias('node', $node, 'content/fourth-title');
  $this
    ->assertNoAliasExists(array(
    'alias' => 'content/fifth-title',
  ));

  // Test PATHAUTO_UPDATE_ACTION_NO_NEW with unaliased node and 'update'.
  $this
    ->deleteAllAliases();
  pathauto_node_update($node);
  $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');
}