function TaxonomyHooksTestCase::testTaxonomyTermHooks
Test that hooks are run correctly on creating, editing, viewing, and deleting a term.
See also
File
-
modules/
taxonomy/ taxonomy.test, line 1490
Class
- TaxonomyHooksTestCase
- Tests for taxonomy hook invocation.
Code
function testTaxonomyTermHooks() {
$vocabulary = $this->createVocabulary();
// Create a term with one antonym.
$edit = array(
'name' => $this->randomName(),
'antonym' => 'Long',
);
$this->drupalPost('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add', $edit, t('Save'));
$terms = taxonomy_get_term_by_name($edit['name']);
$term = reset($terms);
$this->assertEqual($term->antonym, $edit['antonym'], 'Antonym was loaded into the term object.');
// Update the term with a different antonym.
$edit = array(
'name' => $this->randomName(),
'antonym' => 'Short',
);
$this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save'));
taxonomy_terms_static_reset();
$term = taxonomy_term_load($term->tid);
$this->assertEqual($edit['antonym'], $term->antonym, 'Antonym was successfully edited.');
// View the term and ensure that hook_taxonomy_term_view() and
// hook_entity_view() are invoked.
$term = taxonomy_term_load($term->tid);
$term_build = taxonomy_term_page($term);
$this->assertFalse(empty($term_build['term_heading']['term']['taxonomy_test_term_view_check']), 'hook_taxonomy_term_view() was invoked when viewing the term.');
$this->assertFalse(empty($term_build['term_heading']['term']['taxonomy_test_entity_view_check']), 'hook_entity_view() was invoked when viewing the term.');
// Delete the term.
taxonomy_term_delete($term->tid);
$antonym = db_query('SELECT tid FROM {taxonomy_term_antonym} WHERE tid = :tid', array(
':tid' => $term->tid,
))
->fetchField();
$this->assertFalse($antonym, 'The antonym were deleted from the database.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.