You are here

protected function TaxonomyTermFilterDepthTest::setUp in Drupal 9

Same name in this branch
  1. 9 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermFilterDepthTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTermFilterDepthTest::setUp()
  2. 9 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTermFilterDepthTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTermFilterDepthTest::setUp()
Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermFilterDepthTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTermFilterDepthTest::setUp()
  2. 10 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermFilterDepthTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTermFilterDepthTest::setUp()

Overrides TaxonomyTestBase::setUp

File

core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermFilterDepthTest.php, line 47

Class

TaxonomyTermFilterDepthTest
Test the taxonomy term with depth filter.

Namespace

Drupal\Tests\taxonomy\Functional\Views

Code

protected function setUp($import_test_views = TRUE) : void {
  parent::setUp($import_test_views);

  // Create a hierarchy 3 deep. Note the parent setup function creates two
  // top-level terms w/o children.
  $first = $this
    ->createTerm([
    'name' => 'First',
  ]);
  $second = $this
    ->createTerm([
    'name' => 'Second',
    'parent' => $first
      ->id(),
  ]);
  $third = $this
    ->createTerm([
    'name' => 'Third',
    'parent' => $second
      ->id(),
  ]);

  // Create a node w/o any terms.
  $settings = [
    'type' => 'article',
  ];
  $this->nodes[] = $this
    ->drupalCreateNode($settings);

  // Create a node with only the top level term.
  $settings['field_views_testing_tags'][0]['target_id'] = $first
    ->id();
  $this->nodes[] = $this
    ->drupalCreateNode($settings);

  // Create a node with only the third level term.
  $settings['field_views_testing_tags'][0]['target_id'] = $third
    ->id();
  $this->nodes[] = $this
    ->drupalCreateNode($settings);
  $this->terms[0] = $first;
  $this->terms[1] = $second;
  $this->terms[2] = $third;
  $this->view = Views::getView('test_filter_taxonomy_index_tid_depth');

  // Fix the created date to match the expectations of the order by in the
  // view. Node 1 should be the most recent node and node 6 should be the
  // oldest.
  $request_time = \Drupal::time()
    ->getRequestTime();
  foreach ($this->nodes as $i => $node) {
    $node
      ->setCreatedTime($request_time - $i)
      ->save();
  }
}