You are here

public function HierarchicalTaxonomyMenuAdvancedTest::testCountOfReferencingNodes in Hierarchical Taxonomy Menu 8

Test count of referencing nodes.

File

tests/src/FunctionalJavascript/HierarchicalTaxonomyMenuAdvancedTest.php, line 283

Class

HierarchicalTaxonomyMenuAdvancedTest
Tests the Hierarchical Taxonomy Menu advanced config options.

Namespace

Drupal\Tests\hierarchical_taxonomy_menu\FunctionalJavascript

Code

public function testCountOfReferencingNodes() {
  $this->block
    ->set('settings', [
    'label' => 'Hierarchical Taxonomy Menu',
    'label_display' => 'visible',
    'vocabulary' => $this->vocabulary
      ->id() . '|',
    'show_count' => TRUE,
  ]);
  $this->block
    ->save();
  $this
    ->drupalGet('<front>');
  for ($i = 1; $i < 4; $i++) {
    $this
      ->assertSession()
      ->pageTextContains('Parent term ' . $i . ' [0]');
    for ($n = 1; $n < 12; $n++) {
      $this
        ->assertSession()
        ->pageTextContains('Child term ' . $i . '-' . $n . ' [0]');
    }
  }
  $term = Term::load(1);
  $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'Article 1',
    'field_tags' => $term,
  ]);
  $term = Term::load(2);
  $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'Article 2',
    'field_tags' => $term,
  ]);
  $term = Term::load(34);
  $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'Article 3',
    'field_tags' => $term,
  ]);
  $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'Article 4',
    'field_tags' => $term,
  ]);
  $this
    ->drupalGet('<front>');
  for ($i = 1; $i < 4; $i++) {
    if ($i == 1) {
      $this
        ->assertSession()
        ->pageTextContains('Parent term ' . $i . ' [1]');
    }
    else {
      $this
        ->assertSession()
        ->pageTextContains('Parent term ' . $i . ' [0]');
    }
    for ($n = 1; $n < 12; $n++) {
      if ($i == 1 && $n == 1) {
        $this
          ->assertSession()
          ->pageTextContains('Child term ' . $i . '-' . $n . ' [1]');
      }
      elseif ($i == 3 && $n == 9) {
        $this
          ->assertSession()
          ->pageTextContains('Child term ' . $i . '-' . $n . ' [2]');
      }
      else {
        $this
          ->assertSession()
          ->pageTextContains('Child term ' . $i . '-' . $n . ' [0]');
      }
    }
  }
}