1.20.x path_pattern.test | PathPatternUnitTestCase::testUpdateActions() |
Test the different update actions in path_save_automatic_alias().
File
- modules/
path/ tests/ path_pattern.test, line 258 - Functionality tests for automatic path generation.
Class
- PathPatternUnitTestCase
- Unit tests for Path pattern functions.
Code
function testUpdateActions() {
$config = config('path.settings');
// Test PATH_UPDATE_ACTION_NO_NEW with a new inserted, unaliased node.
$config->set('update_action', PATH_UPDATE_ACTION_NO_NEW);
$config->set('node_page_pattern', 'content/[node:title]');
$config->save();
$node = $this->backdropCreateNode(array('title' => 'First title'));
$this->assertEntityAlias('node', $node, 'content/first-title');
// Default action is PATH_UPDATE_ACTION_DELETE.
$config->set('update_action', PATH_UPDATE_ACTION_DELETE);
$config->save();
// After each change to the node, load it again to get the latest path
// information.
$node->title = 'Second title';
$node->save();
$this->assertEntityAlias('node', $node, 'content/second-title');
$this->assertNoAliasExists(array('alias' => 'content/first-title'));
// Test PATH_UPDATE_ACTION_LEAVE
$config->set('update_action', PATH_UPDATE_ACTION_LEAVE);
$config->save();
$node->title = 'Third title';
$node->save();
$this->assertEntityAlias('node', $node, 'content/third-title');
$this->assertAliasExists(array('source' => "node/{$node->nid}", 'alias' => 'content/second-title'));
$config->set('update_action', PATH_UPDATE_ACTION_DELETE);
$config->save();
$node->title = 'Fourth title';
$node->save();
$this->assertEntityAlias('node', $node, 'content/fourth-title');
$this->assertNoAliasExists(array('alias' => 'content/third-title'));
// The older second URL alias is not deleted yet.
$older_path = $this->assertAliasExists(array('source' => "node/{$node->nid}", 'alias' => 'content/second-title'));
path_delete($older_path);
$config->set('update_action', PATH_UPDATE_ACTION_NO_NEW);
$config->save();
$node->title = 'Fifth title';
$node->save();
$this->assertEntityAlias('node', $node, 'content/fourth-title');
$this->assertNoAliasExists(array('alias' => 'content/fifth-title'));
// Test PATH_UPDATE_ACTION_NO_NEW with unaliased node and node update.
$this->deleteAllAliases();
$node->save();
$this->assertEntityAlias('node', $node, 'content/fifth-title');
// Test PATH_UPDATE_ACTION_NO_NEW with unaliased node and directly update.
$this->deleteAllAliases();
$node->title = 'Sixth title';
path_save_automatic_entity_alias($node);
$this->assertEntityAlias('node', $node, 'content/sixth-title');
}