diff -u b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidFilterTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidFilterTest.php --- b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidFilterTest.php +++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidFilterTest.php @@ -43,11 +43,13 @@ 'name' => 'Tags', ])->save(); + // This will get a term ID of 3. $term = Term::create([ 'vid' => 'tags', 'name' => 'muh', ]); $term->save(); + // This will get a term ID of 4. $this->terms[$term->id()] = $term; $term = Term::create([ 'vid' => 'tags', @@ -59,33 +61,90 @@ ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views')); } + /** + * Tests dependencies are not added for terms that do not exist. + */ public function testConfigDependency() { /** @var \Drupal\views\Entity\View $view */ $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency'); - $view->calculateDependencies(); + // Dependencies are sorted. + $content_dependencies = [ + $this->terms[3]->getConfigDependencyName(), + $this->terms[4]->getConfigDependencyName(), + ]; + sort($content_dependencies); + + $this->assertEqual([ + 'config' => [ + 'taxonomy.vocabulary.tags', + ], + 'content' => $content_dependencies, + 'module' => [ + 'node', + 'taxonomy', + 'user', + ], + ], $view->calculateDependencies()->getDependencies()); + + $this->terms[3]->delete(); + $this->assertEqual([ 'config' => [ 'taxonomy.vocabulary.tags', ], 'content' => [ - $this->terms[3]->getConfigDependencyName(), + $this->terms[4]->getConfigDependencyName(), ], 'module' => [ 'node', 'taxonomy', 'user', ], - ], $view->getDependencies()); + ], $view->calculateDependencies()->getDependencies()); + } + + /** + * Tests post update function fixes dependencies. + * + * @see views_post_update_taxonomy_index_tid() + */ + public function testPostUpdateFunction() { + /** @var \Drupal\views\Entity\View $view */ + $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency'); + + // Dependencies are sorted. + $content_dependencies = [ + $this->terms[3]->getConfigDependencyName(), + $this->terms[4]->getConfigDependencyName(), + ]; + sort($content_dependencies); + + $this->assertEqual([ + 'config' => [ + 'taxonomy.vocabulary.tags', + ], + 'content' => $content_dependencies, + 'module' => [ + 'node', + 'taxonomy', + 'user', + ], + ], $view->calculateDependencies()->getDependencies()); $this->terms[3]->delete(); - $view->calculateDependencies(); + \Drupal::moduleHandler()->loadInclude('views', 'post_update.php'); + views_post_update_taxonomy_index_tid(); + $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency'); $this->assertEqual([ 'config' => [ 'taxonomy.vocabulary.tags', ], + 'content' => [ + $this->terms[4]->getConfigDependencyName(), + ], 'module' => [ 'node', 'taxonomy', diff -u b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_filter_taxonomy_index_tid__non_existing_dependency.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_filter_taxonomy_index_tid__non_existing_dependency.yml --- b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_filter_taxonomy_index_tid__non_existing_dependency.yml +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_filter_taxonomy_index_tid__non_existing_dependency.yml @@ -136,6 +136,7 @@ operator: or value: - 3 + - 4 group: 1 exposed: false expose: only in patch2: unchanged: --- a/core/modules/views/views.post_update.php +++ b/core/modules/views/views.post_update.php @@ -159,3 +159,22 @@ function views_post_update_field_formatter_dependencies() { /** * @} End of "addtogroup updates-8.0.x". */ + +/** + * @addtogroup updates-8.1.x + * @{ + */ + +/** + * Fix views with dependencies on taxonomy terms that don't exist. + */ +function views_post_update_taxonomy_index_tid() { + $views = View::loadMultiple(); + array_walk($views, function(View $view) { + $view->save(); + }); +} + +/** + * @} End of "addtogroup updates-8.1.x". + */