You are here

function TaxonomyMenuHierarchyTest::testTaxonomyMenuHierarchy in Taxonomy menu 7

File

./taxonomy_menu.test, line 180
Tests for taxonomy_menu.module.

Class

TaxonomyMenuHierarchyTest
Tests for features requiring a taxonomy hierarchy.

Code

function testTaxonomyMenuHierarchy() {
  $edit = array();
  $edit['taxonomy_menu[vocab_parent]'] = 'navigation:0';
  $this
    ->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/edit', $edit, 'Save');
  $this
    ->assertResponse(200);

  // By default, auto expand is on : we must find the whole hierarchy.
  foreach ($this->terms as $term) {
    $this
      ->assertLink($term->name);

    // 1st level
    foreach ($term->children as $child) {
      $this
        ->assertLink($child->name);

      // 2nd level
      foreach ($child->children as $granchild) {
        $this
          ->assertLink($granchild->name);

        // 3 level
        // No sub level.
      }
    }
  }

  // Set auto expand to off.
  $edit = array();
  $edit['taxonomy_menu[options][expanded]'] = FALSE;

  // $edit['taxonomy_menu[options][rebuild]'] = '1'; // Rebuild menu on submit.
  $this
    ->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/edit', $edit, 'Save');
  $this
    ->assertResponse(200);

  // $this->drupalGet('admin/structure/taxonomy/'.  $this->vocabulary->machine_name . '/edit');
  // We should have links to the first level of the hierarchy only.
  $this
    ->drupalGet('<front>');
  foreach ($this->terms as $term) {
    $this
      ->assertLink($term->name);
    foreach ($term->children as $child) {
      $this
        ->assertNoLink($child->name);
    }
  }

  // Move to term1_2 : we should have links to
  // - 1st level
  // - siblings of term1_2
  // - children of term1_2
  $this
    ->clickLink("term1");
  $this
    ->clickLink("term1_2");
  foreach ($this->terms as $term) {
    $this
      ->assertLink($term->name);

    // 1st level
    foreach ($term->children as $child) {

      // second level
      if ($term->name != "term1") {
        $this
          ->assertNoLink($child->name);
      }
      else {

        // We must have a link AND the children.
        $this
          ->assertLink($child->name);
        if ($child->name == "term1_2") {
          foreach ($child->children as $grandchild) {
            $this
              ->assertLink($grandchild->name);
          }
        }
      }
    }
  }
}