You are here

public function TaxonomyMenuUnitTest::testTaxonomyMenuCRUD in Taxonomy menu 7.2

Same name and namespace in other branches
  1. 7 taxonomy_menu.test \TaxonomyMenuUnitTest::testTaxonomyMenuCRUD()

Tests CRUD functions.

File

tests/taxonomy_menu.test, line 318
Defines abstract base test class for the Taxonomy menu module tests.

Class

TaxonomyMenuUnitTest
Tests for taxonomy vocabulary functions.

Code

public function testTaxonomyMenuCRUD() {
  $menu_name = 'main-menu';
  $vocabulary = $this->vocabulary;
  $terms = $this->terms_hierarchy;
  $hierarchy_term = $this->terms_hierarchy[3];

  // Arbitrary term for hierarchy.
  $vid = $this->vocabulary->vid;

  // Ensure that the taxonomy vocabulary form is successfully submitted.
  $edit['taxonomy_menu[vocab_parent]'] = $menu_name . ':0';
  $vocab = $this->vocabulary->machine_name;
  $this
    ->drupalPost('admin/structure/taxonomy/' . $vocab . '/edit', $edit, t('Save'));
  $this
    ->assertResponse(200);

  // Ensure that the same number of menu links are created from the taxonomy
  // terms of the vocabulary.
  $this
    ->assertEqualNumberTermsMenuLinks(count($terms), $vocabulary, $menu_name);

  // Ensure that the menu link is updated when the taxonomy term is updated.
  $new_name = $this
    ->randomName();
  $hierarchy_term->name = $new_name;
  taxonomy_term_save($hierarchy_term);
  $this
    ->drupalGet('admin/structure/menu/manage/' . $menu_name);
  $this
    ->assertLink($new_name);

  // Ensure that the menu link is deleted when the taxonomy term is deleted.
  // Hierarchy term [3] has 1 children, if we delete it, 2 taxonomy terms
  // should be deleted.
  $orig_mlid = _taxonomy_menu_get_mlid($hierarchy_term->tid, $vid);
  taxonomy_term_delete($hierarchy_term->tid);
  $this
    ->assertEqualNumberTermsMenuLinks(count($terms) - 2, $vocabulary, $menu_name);
  $menu_link = menu_link_load($orig_mlid);
  $message = 'The menu link ' . $orig_mlid . ' associated to the term ' . $hierarchy_term->tid . ' could not be found.';
  $this
    ->assertFalse($menu_link, $message);
  $mlid = _taxonomy_menu_get_mlid($hierarchy_term->tid, $vid);
  $message = 'The ( mlid = ' . $orig_mlid . ' / tid = ' . $hierarchy_term->tid . ') association could not be found in {taxonomy_menu} table.';
  $this
    ->assertFalse($mlid, $message);

  // Ensure that all menu links and all associations in {taxonomy_menu} table
  // are deleted when a vocabulary is deleted.
  $mlids = _taxonomy_menu_get_menu_items($vid);
  taxonomy_vocabulary_delete($vid);
  $this
    ->assertEqualNumberTermsMenuLinks(0, $vocabulary, $menu_name);
}