You are here

public function TaxonomyEntityIndexTermFilterDepthTest::testTermWithDepthFilter in Taxonomy Entity Index 8

Tests the terms with depth filter.

File

tests/src/Functional/Views/TaxonomyEntityIndexTermFilterDepthTest.php, line 84

Class

TaxonomyEntityIndexTermFilterDepthTest
Test the taxonomy term with depth filter.

Namespace

Drupal\Tests\taxonomy_entity_index\Functional\Views

Code

public function testTermWithDepthFilter() {
  $column_map = [
    'nid' => 'nid',
  ];
  $assert_method = 'assertIdentical';

  // Default view has an empty value for this filter, so all nodes should be
  // returned.
  $expected = array_map(function (NodeInterface $node) {
    return [
      'nid' => $node
        ->id(),
    ];
  }, $this->nodes);
  $this
    ->executeView($this->view);
  $this
    ->assertIdenticalResultsetHelper($this->view, $expected, $column_map, $assert_method);

  // Set filter to search on top-level term, with depth 0.
  $expected = [
    [
      'nid' => 4,
    ],
  ];
  $this
    ->assertTermWithDepthResult($this->terms[0]
    ->id(), 0, $expected);

  // Top-level term, depth 1.
  $expected = [
    [
      'nid' => 4,
    ],
  ];
  $this
    ->assertTermWithDepthResult($this->terms[0]
    ->id(), 1, $expected);

  // Top-level term, depth 2.
  $expected = [
    [
      'nid' => 4,
    ],
    [
      'nid' => 5,
    ],
  ];
  $this
    ->assertTermWithDepthResult($this->terms[0]
    ->id(), 2, $expected);

  // Second-level term, depth 1.
  $expected = [
    [
      'nid' => 5,
    ],
  ];
  $this
    ->assertTermWithDepthResult($this->terms[1]
    ->id(), 1, $expected);

  // Third-level term, depth 0.
  $expected = [
    [
      'nid' => 5,
    ],
  ];
  $this
    ->assertTermWithDepthResult($this->terms[2]
    ->id(), 0, $expected);

  // Third-level term, depth 1.
  $expected = [
    [
      'nid' => 5,
    ],
  ];
  $this
    ->assertTermWithDepthResult($this->terms[2]
    ->id(), 1, $expected);

  // Third-level term, depth -2.
  $expected = [
    [
      'nid' => 4,
    ],
    [
      'nid' => 5,
    ],
  ];
  $this
    ->assertTermWithDepthResult($this->terms[2]
    ->id(), -2, $expected);
}