1 path_pattern.test PathPatternLocaleTestCase::testLanguageAliases()

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

File

core/modules/path/tests/path_pattern.test, line 836
Functionality tests for automatic path generation.

Class

PathPatternLocaleTestCase

Code

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

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

  // Add a URL alias with the soon-to-be generated alias, causing the upcoming
  // URL alias update to generate a unique URL 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['auto'] = TRUE;
  $node->save();

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