File
- modules/path/tests/path_pattern.test, line 904
- Functionality tests for automatic path generation.
Class
- PathPatternBulkUpdateTestCase
- Bulk update functionality tests.
Code
function testBulkUpdate() {
$this->nodes = array();
$edit = array(
'path_pattern' => 'post/[node:title]',
);
$this->backdropPost('admin/structure/types/manage/post/configure', $edit, t('Save content type'));
for ($i = 1; $i <= 5; $i++) {
$node = $this->backdropCreateNode(array('type' => 'page'));
$this->nodes[$node->nid] = $node;
}
for ($i = 1; $i <= 5; $i++) {
$node = $this->backdropCreateNode(array('type' => 'post'));
$this->nodes[$node->nid] = $node;
}
$vocabulary = new TaxonomyVocabulary(array(
'name' => 'Bulk test',
'machine_name' => 'bulk_test',
));
taxonomy_vocabulary_save($vocabulary);
$this->terms = array();
for ($i = 1; $i <= 3; $i++) {
$term = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'vocabulary' => 'tags',
'langcode' => LANGUAGE_NONE,
));
taxonomy_term_save($term);
$this->terms[$term->tid] = $term;
$this->assertEntityAlias('term', $term, 'tags/' . strtolower($term->name));
}
$this->terms = array();
for ($i = 1; $i <= 3; $i++) {
$term = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'vocabulary' => 'bulk_test',
'langcode' => LANGUAGE_NONE,
));
taxonomy_term_save($term);
$this->terms[$term->tid] = $term;
$this->assertEntityAlias('term', $term, 'bulk-test/' . strtolower($term->name));
}
$this->deleteAllAliases();
foreach ($this->nodes as $node) {
$this->assertNoEntityAliasExists('node', $node);
}
foreach ($this->terms as $term) {
$this->assertNoEntityAliasExists('term', $term);
}
$edit = array(
'update[node][base]' => TRUE,
'update[taxonomy_term][base]' => TRUE,
'update[user][base]' => TRUE,
'operations[operation]' => 'generate',
);
$this->backdropPost('admin/config/urls/path/bulk-update', $edit, t('Execute'));
$this->assertText('Generated 20 URL aliases.');
foreach ($this->nodes as $node) {
$this->assertEntityAliasExists('node', $node);
}
$this->assertEntityAliasExists('user', $this->admin_user);
$new_node = $this->backdropCreateNode(array('path' => array('alias' => '', 'auto' => FALSE)));
$this->nodes[$new_node->nid] = $new_node;
$this->backdropPost('admin/config/urls/path/bulk-update', $edit, t('Execute'));
$this->assertText('Generated 1 URL alias.');
$this->assertEntityAliasExists('node', $new_node);
$edit = array(
'update[node][base]' => TRUE,
'operations[operation]' => 'delete',
);
$this->backdropPost('admin/config/urls/path/bulk-update', $edit, t('Execute'));
$this->backdropPost(NULL, array(), t('Delete URL aliases'));
foreach ($this->nodes as $node) {
$this->assertNoEntityAliasExists('node', $node);
}
$edit = array(
'update[node][post]' => TRUE,
'operations[operation]' => 'generate',
);
$this->backdropPost('admin/config/urls/path/bulk-update', $edit, t('Execute'));
foreach ($this->nodes as $node) {
if ($node->type == 'page') {
$this->assertNoEntityAliasExists('node', $node);
}
if ($node->type == 'post') {
$this->assertEntityAliasExists('node', $node);
}
}
$edit = array(
'path_pattern' => 'changed-post/[node:title]',
);
$this->backdropPost('admin/structure/types/manage/post/configure', $edit, t('Save content type'));
$edit = array(
'update[node][page]' => TRUE,
'update[node][post]' => TRUE,
'operations[operation]' => 'update',
);
$this->backdropPost('admin/config/urls/path/bulk-update', $edit, t('Execute'));
foreach ($this->nodes as $node) {
if ($node->type == 'page') {
$this->assertNoEntityAliasExists('node', $node);
}
if ($node->type == 'post') {
$this->assertEntityAlias('node', $node, 'changed-post/' . strtolower($node->title));
}
}
$edit = array(
'update[node][post]' => TRUE,
'update[taxonomy_term][tags]' => TRUE,
'operations[operation]' => 'delete',
);
$this->backdropPost('admin/config/urls/path/bulk-update', $edit, t('Execute'));
$this->backdropPost(NULL, array(), t('Delete URL aliases'));
foreach ($this->nodes as $node) {
$this->assertNoEntityAliasExists('node', $node);
}
foreach ($this->terms as $term) {
if ($term->vocabulary == 'tags') {
$this->assertNoEntityAliasExists('taxonomy_term', $term);
}
if ($term->vocabulary == 'bulk_test') {
$this->assertEntityAliasExists('taxonomy_term', $term);
}
}
}