function PathautoUnitTestCase::testParentChildPathTokens in Pathauto 7
Test using fields for path structures.
File
- ./
pathauto.test, line 316 - Functionality tests for Pathauto.
Class
- PathautoUnitTestCase
- Unit tests for Pathauto functions.
Code
function testParentChildPathTokens() {
// First create a field which will be used to create the path. It must
// begin with a letter.
$fieldname = 'a' . drupal_strtolower($this
->randomName());
field_create_field(array(
'field_name' => $fieldname,
'type' => 'text',
));
field_create_instance(array(
'field_name' => $fieldname,
'entity_type' => 'taxonomy_term',
'bundle' => 'tags',
));
// Make the path pattern of a field use the value of this field appended
// to the parent taxonomy term's pattern if there is one.
variable_set('pathauto_taxonomy_term_tags_pattern', '[term:parents:join-path]/[term:' . $fieldname . ']');
// Start by creating a parent term.
$parent = new stdClass();
$parent->{$fieldname} = array(
LANGUAGE_NONE => array(
array(
'value' => $parent->name = $this
->randomName(),
),
),
);
$parent->vid = 1;
taxonomy_term_save($parent);
// Create the child term.
$child = new stdClass();
$child->name = $this
->randomName();
$child->{$fieldname} = array(
LANGUAGE_NONE => array(
array(
'value' => $child->name = $this
->randomName(),
),
),
);
$child->vid = 1;
$child->parent = $parent->tid;
taxonomy_term_save($child);
$this
->assertEntityAlias('taxonomy_term', $child, drupal_strtolower($parent->name . '/' . $child->name));
// Re-saving the parent term should not modify the child term's alias.
taxonomy_term_save($parent);
$this
->assertEntityAlias('taxonomy_term', $child, drupal_strtolower($parent->name . '/' . $child->name));
}