1.20.x taxonomy.test | TaxonomyTermTestCase::testTermInterface() |
Save, edit and delete a term using the user interface.
File
- modules/
taxonomy/ tests/ taxonomy.test, line 705 - Tests for taxonomy.module.
Class
- TaxonomyTermTestCase
- Tests for taxonomy term functions.
Code
function testTermInterface() {
$edit = array(
'name' => $this->randomName(12),
'description[value]' => $this->randomName(100),
);
// Explicitly set the parents field to 'root', to ensure that
// taxonomy_form_term_submit() handles the invalid term ID correctly.
$edit['parent[]'] = array(0);
// Create the term to edit.
$this->backdropPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add', $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name']);
$term = reset($terms);
$this->assertNotNull($term, 'Term found in database.');
// Submitting a term takes us to the add page; we need the List page.
$this->backdropGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name);
// Test edit link as accessed from Taxonomy administration pages.
// Because Simpletest creates its own database when running tests, we know
// the first edit link found on the listing page is to our term.
$this->clickLink(t('Edit'), 0);
$this->assertRaw($edit['name'], 'The randomly generated term name is present.');
$this->assertText($edit['description[value]'], 'The randomly generated term description is present.');
$edit = array(
'name' => $this->randomName(14),
'description[value]' => $this->randomName(102),
);
// Edit the term.
$this->backdropPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save'));
// Check that the term is still present at admin UI after edit.
$this->backdropGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name);
$this->assertText($edit['name'], 'The randomly generated term name is present.');
$this->assertLink(t('Edit'));
// View the term and check that it is correct.
$this->backdropGet('taxonomy/term/' . $term->tid);
$this->assertText($edit['name'], 'The randomly generated term name is present.');
$this->assertText($edit['description[value]'], 'The randomly generated term description is present.');
// Did this page request display a 'term-listing-heading'?
$this->assertPattern('|class="taxonomy-term-description"|', 'Term page displayed the term description element.');
// Check that it does NOT show a description when description is blank.
$term->description = '';
taxonomy_term_save($term);
$this->backdropGet('taxonomy/term/' . $term->tid);
$this->assertNoPattern('|class="taxonomy-term-description"|', 'Term page did not display the term description when description was blank.');
// Check that the term feed page is working.
$this->backdropGet('taxonomy/term/' . $term->tid . '/feed');
// Check that the term edit page does not try to interpret additional path
// components as arguments for taxonomy_form_term().
$this->backdropGet('taxonomy/term/' . $term->tid . '/edit/' . $this->randomName());
// Delete the term.
$this->backdropPost('taxonomy/term/' . $term->tid . '/edit', array(), t('Delete'));
$this->backdropPost(NULL, NULL, t('Delete'));
// Assert that the term no longer exists.
$this->backdropGet('taxonomy/term/' . $term->tid);
$this->assertResponse(404, 'The taxonomy term page was not found.');
}