You are here

function PathautoLocaleTestCase::testLanguageAliases in Pathauto 7

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

Test that when an English node is updated, its old English alias is updated and its newer French alias is left intact.

File

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

Class

PathautoLocaleTestCase

Code

function testLanguageAliases() {
  $node = array(
    'title' => 'English node',
    'language' => 'en',
    'body' => array(
      'en' => array(
        array(),
      ),
    ),
    'path' => array(
      'alias' => 'english-node',
      'pathauto' => FALSE,
    ),
  );
  $node = $this
    ->drupalCreateNode($node);
  $english_alias = path_load(array(
    'alias' => 'english-node',
    'language' => 'en',
  ));
  $this
    ->assertTrue($english_alias, 'Alias created with proper language.');

  // Also save a French alias that should not be left alone, even though
  // it is the newer alias.
  $this
    ->saveEntityAlias('node', $node, 'french-node', 'fr');

  // Add an alias with the soon-to-be generated alias, causing the upcoming
  // alias update to generate a unique alias with the '-0' suffix.
  $this
    ->saveAlias('node/invalid', 'content/english-node', LANGUAGE_NONE);

  // Update the node, triggering a change in the English alias.
  $node->path['pathauto'] = TRUE;
  pathauto_node_update($node);

  // Check that the new English alias replaced the old one.
  $this
    ->assertEntityAlias('node', $node, 'content/english-node-0', 'en');
  $this
    ->assertEntityAlias('node', $node, 'french-node', 'fr');
  $this
    ->assertAliasExists(array(
    'pid' => $english_alias['pid'],
    'alias' => 'content/english-node-0',
  ));

  // Create a new node with the same title as before but without
  // specifying a language.
  $node = $this
    ->drupalCreateNode(array(
    'title' => 'English node',
  ));

  // Check that the new node had a unique alias generated with the '-1'
  // suffix.
  $this
    ->assertEntityAlias('node', $node, 'content/english-node-1');
}