You are here

protected function HierarchicalFacetIntegrationTest::createHierarchialTermStructure in Facets 8

Same name in this branch
  1. 8 tests/src/Functional/HierarchicalFacetIntegrationTest.php \Drupal\Tests\facets\Functional\HierarchicalFacetIntegrationTest::createHierarchialTermStructure()
  2. 8 modules/facets_summary/tests/src/Functional/HierarchicalFacetIntegrationTest.php \Drupal\Tests\facets_summary\Functional\HierarchicalFacetIntegrationTest::createHierarchialTermStructure()

Setup a term structure for our test.

1 call to HierarchicalFacetIntegrationTest::createHierarchialTermStructure()
HierarchicalFacetIntegrationTest::setUp in tests/src/Functional/HierarchicalFacetIntegrationTest.php

File

tests/src/Functional/HierarchicalFacetIntegrationTest.php, line 341

Class

HierarchicalFacetIntegrationTest
Tests the hierarchical facets implementation.

Namespace

Drupal\Tests\facets\Functional

Code

protected function createHierarchialTermStructure() {

  // Generate 2 parent terms.
  foreach ([
    'Parent 1',
    'Parent 2',
  ] as $name) {
    $this->parents[$name] = Term::create([
      'name' => $name,
      'description' => '',
      'vid' => $this->vocabulary
        ->id(),
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]);
    $this->parents[$name]
      ->save();
  }

  // Generate 4 child terms.
  foreach (range(1, 4) as $i) {
    $this->terms[$i] = Term::create([
      'name' => sprintf('Child %d', $i),
      'description' => '',
      'vid' => $this->vocabulary
        ->id(),
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]);
    $this->terms[$i]
      ->save();
  }

  // Build up the hierarchy.
  $this->terms[1]->parent = [
    $this->parents['Parent 1']
      ->id(),
  ];
  $this->terms[1]
    ->save();
  $this->terms[2]->parent = [
    $this->parents['Parent 1']
      ->id(),
  ];
  $this->terms[2]
    ->save();
  $this->terms[3]->parent = [
    $this->parents['Parent 2']
      ->id(),
  ];
  $this->terms[3]
    ->save();
  $this->terms[4]->parent = [
    $this->parents['Parent 2']
      ->id(),
  ];
  $this->terms[4]
    ->save();
}