3 namespace Drupal\Tests\taxonomy\Functional\Views;
5 use Drupal\taxonomy\Entity\Term;
6 use Drupal\taxonomy\Entity\Vocabulary;
7 use Drupal\views\Entity\View;
8 use Drupal\views\Tests\ViewTestData;
11 * Test the taxonomy term index filter.
13 * @see \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid
17 class TaxonomyIndexTidFilterTest extends TaxonomyTestBase {
22 public static $modules = ['taxonomy', 'taxonomy_test_views', 'views', 'node'];
27 public static $testViews = ['test_filter_taxonomy_index_tid__non_existing_dependency'];
30 * @var \Drupal\taxonomy\TermInterface[]
32 protected $terms = [];
37 protected function setUp($import_test_views = TRUE) {
40 // Setup vocabulary and terms so the initial import is valid.
46 // This will get a term ID of 3.
47 $term = Term::create([
52 // This will get a term ID of 4.
53 $this->terms[$term->id()] = $term;
54 $term = Term::create([
59 $this->terms[$term->id()] = $term;
61 ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
65 * Tests dependencies are not added for terms that do not exist.
67 public function testConfigDependency() {
68 /** @var \Drupal\views\Entity\View $view */
69 $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
71 // Dependencies are sorted.
72 $content_dependencies = [
73 $this->terms[3]->getConfigDependencyName(),
74 $this->terms[4]->getConfigDependencyName(),
76 sort($content_dependencies);
80 'taxonomy.vocabulary.tags',
82 'content' => $content_dependencies,
88 ], $view->calculateDependencies()->getDependencies());
90 $this->terms[3]->delete();
94 'taxonomy.vocabulary.tags',
97 $this->terms[4]->getConfigDependencyName(),
104 ], $view->calculateDependencies()->getDependencies());
108 * Tests post update function fixes dependencies.
110 * @see views_post_update_taxonomy_index_tid()
112 public function testPostUpdateFunction() {
113 /** @var \Drupal\views\Entity\View $view */
114 $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
116 // Dependencies are sorted.
117 $content_dependencies = [
118 $this->terms[3]->getConfigDependencyName(),
119 $this->terms[4]->getConfigDependencyName(),
121 sort($content_dependencies);
125 'taxonomy.vocabulary.tags',
127 'content' => $content_dependencies,
133 ], $view->calculateDependencies()->getDependencies());
135 $this->terms[3]->delete();
137 \Drupal::moduleHandler()->loadInclude('views', 'post_update.php');
138 views_post_update_taxonomy_index_tid();
140 $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
143 'taxonomy.vocabulary.tags',
146 $this->terms[4]->getConfigDependencyName(),
153 ], $view->getDependencies());