View source
<?php
namespace Drupal\Tests\taxonomy_entity_index\Functional\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\file\Entity\File;
use Drupal\media\Entity\Media;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
class TaxonomyEntityIndexTermArgumentDepthTest extends TaxonomyEntityIndexTestBase {
use MediaTypeCreationTrait;
public static $modules = [
'views',
'node',
'media',
];
protected $defaultTheme = 'stark';
public static $testViews = [
'test_argument_taxonomy_entity_index_index_tid_depth',
];
protected $terms = [];
protected $view;
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->config('taxonomy_entity_index.settings')
->set('types', [
'node' => 'node',
'media' => 'media',
])
->save();
$first = $this
->createTerm([
'name' => 'First',
]);
$settings = [
'type' => 'article',
'title' => 'Node with Term',
];
$settings['field_views_testing_tags'][0]['target_id'] = $first
->id();
$this->nodes[] = $this
->drupalCreateNode($settings);
$settings = [
'type' => 'article',
'title' => 'Node without Term',
];
$node = $this
->drupalCreateNode($settings);
$this->nodes[] = $node;
$media_type = $this
->setupMediaTypeWithTaxonomy();
$file = File::create([
'uri' => 'public://llama.txt',
]);
$file
->setPermanent();
$file
->save();
$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;
}
public function testTermWithDepthArgument() {
$this
->drupalGet('test_argument_taxonomy_entity_index_index_tid_depth/' . $this->terms[0]
->id());
$this
->assertText($this->nodes[2]
->getTitle());
$this
->assertNoText($this->nodes[3]
->getTitle());
}
protected function setupMediaTypeWithTaxonomy() {
$media_type = $this
->createMediaType('file', [
'id' => 'document',
'label' => 'Document',
]);
$handler_settings = [
'target_bundles' => [
$this->vocabulary
->id() => $this->vocabulary
->id(),
],
'auto_create' => TRUE,
];
$this
->createEntityReferenceField('media', 'document', 'field_views_testing_tags', 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
}
}