You are here

protected function TaxonomyEntityIndexTermArgumentDepthTest::setUp in Taxonomy Entity Index 8

Overrides TaxonomyEntityIndexTestBase::setUp

File

tests/src/Functional/Views/TaxonomyEntityIndexTermArgumentDepthTest.php, line 55

Class

TaxonomyEntityIndexTermArgumentDepthTest
Tests the taxonomy term with depth argument.

Namespace

Drupal\Tests\taxonomy_entity_index\Functional\Views

Code

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

  // Enable indexing for node and media.
  $this
    ->config('taxonomy_entity_index.settings')
    ->set('types', [
    'node' => 'node',
    'media' => 'media',
  ])
    ->save();

  // Create a term.
  $first = $this
    ->createTerm([
    'name' => 'First',
  ]);

  // Create a node called "Node with Term" that is linked to the term.
  $settings = [
    'type' => 'article',
    'title' => 'Node with Term',
  ];
  $settings['field_views_testing_tags'][0]['target_id'] = $first
    ->id();
  $this->nodes[] = $this
    ->drupalCreateNode($settings);

  // Create a node called "Node without Term" without any terms.
  $settings = [
    'type' => 'article',
    'title' => 'Node without Term',
  ];
  $node = $this
    ->drupalCreateNode($settings);
  $this->nodes[] = $node;

  // Setup the media type.
  $media_type = $this
    ->setupMediaTypeWithTaxonomy();

  // Create a file to upload to be used in the media item.
  $file = File::create([
    'uri' => 'public://llama.txt',
  ]);
  $file
    ->setPermanent();
  $file
    ->save();

  // Create a media item called "Media with Term" that has the same numeric
  // ID as "Node without Term" but is linked to the term.
  $media = Media::create([
    'bundle' => 'document',
    'name' => 'Media with Term',
    'mid' => $node
      ->id(),
    'field_media_file' => [
      'target_id' => $file
        ->id(),
    ],
    'field_views_testing_tags' => [
      'target_id' => $first
        ->id(),
    ],
  ]);
  $media
    ->save();
  $this->terms[0] = $first;
}