1.20.x path.test | PathTaxonomyTermTestCase::testTermAlias() |
Tests alias functionality through the admin interfaces.
File
- modules/
path/ tests/ path.test, line 251 - Tests for the Path module.
Class
- PathTaxonomyTermTestCase
- Tests URL aliases for taxonomy terms.
Code
function testTermAlias() {
// Create a term in the default 'Tags' vocabulary with URL alias.
$vocabulary = taxonomy_vocabulary_load('tags');
$description = $this->randomName();
$edit = array();
$edit['name'] = $this->randomName();
$edit['description[value]'] = $description;
$edit['path[alias]'] = $this->randomName();
$edit['path[auto]'] = FALSE;
$this->backdropPost('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add', $edit, t('Save'));
// Confirm that the alias works.
$this->backdropGet($edit['path[alias]']);
$this->assertText($description, 'Term can be accessed on URL alias.');
// Change the term's URL alias.
$tid = db_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
$edit2 = array();
$edit2['path[alias]'] = $this->randomName();
$edit2['path[auto]'] = FALSE;
$this->backdropPost('taxonomy/term/' . $tid . '/edit', $edit2, t('Save'));
// Confirm that the changed alias works.
$this->backdropGet($edit2['path[alias]']);
$this->assertText($description, 'Term can be accessed on changed URL alias.');
// Confirm that the old alias no longer works.
$this->backdropGet($edit['path[alias]']);
$this->assertNoText($description, 'Old URL alias has been removed after altering.');
$this->assertResponse(404, 'Old URL alias returns 404.');
// Remove the term's URL alias.
$edit3 = array();
$edit3['path[alias]'] = '';
$this->backdropPost('taxonomy/term/' . $tid . '/edit', $edit3, t('Save'));
// Confirm that the alias no longer works.
$this->backdropGet($edit2['path[alias]']);
$this->assertNoText($description, 'Old URL alias has been removed after altering.');
$this->assertResponse(404, 'Old URL alias returns 404.');
}