You are here

public function HierarchicalTaxonomyMenuDynamicTest::testDynamicBehaviourWhenCollapsed in Hierarchical Taxonomy Menu 8

Tests dynamic behaviour when menu items are collapsed.

File

tests/src/FunctionalJavascript/HierarchicalTaxonomyMenuDynamicTest.php, line 149

Class

HierarchicalTaxonomyMenuDynamicTest
Tests the Hierarchical Taxonomy Menu dynamic behaviour.

Namespace

Drupal\Tests\hierarchical_taxonomy_menu\FunctionalJavascript

Code

public function testDynamicBehaviourWhenCollapsed() {
  $this->block
    ->set('settings', [
    'label' => 'Hierarchical Taxonomy Menu',
    'label_display' => 'visible',
    'vocabulary' => $this->vocabulary
      ->id() . '|',
    'collapsible' => TRUE,
  ]);
  $this->block
    ->save();
  $this
    ->drupalGet('<front>');

  // We should see just parents. All descendants must be hidden.
  for ($i = 1; $i < 4; $i++) {
    $this
      ->assertSession()
      ->pageTextContains('Parent term ' . $i);
    for ($n = 1; $n < 12; $n++) {
      $this
        ->assertSession()
        ->pageTextNotContains('Child term ' . $i . '-' . $n);
    }
  }
  $this
    ->clickLink('Parent term 1');

  // We should see just parents and first descendant of Parent term 1.
  for ($i = 1; $i < 4; $i++) {
    $this
      ->assertSession()
      ->pageTextContains('Parent term ' . $i);
    for ($n = 1; $n < 12; $n++) {
      if ($i == 1 && $n == 1) {
        $this
          ->assertSession()
          ->pageTextContains('Child term ' . $i . '-' . $n);
      }
      else {
        $this
          ->assertSession()
          ->pageTextNotContains('Child term ' . $i . '-' . $n);
      }
    }
  }
  $this
    ->clickLink('Child term 1-1');

  // We should see just parents and first descendant of Child term 1-1.
  for ($i = 1; $i < 4; $i++) {
    $this
      ->assertSession()
      ->pageTextContains('Parent term ' . $i);
    for ($n = 1; $n < 12; $n++) {
      if ($i == 1 && ($n == 1 || $n == 2)) {
        $this
          ->assertSession()
          ->pageTextContains('Child term ' . $i . '-' . $n);
      }
      else {
        $this
          ->assertSession()
          ->pageTextNotContains('Child term ' . $i . '-' . $n);
      }
    }
  }
}