Backup of db before drupal security update
[yaffs-website] / web / core / modules / taxonomy / tests / src / Functional / Views / TaxonomyIndexTidFilterTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Functional\Views;
4
5 use Drupal\taxonomy\Entity\Term;
6 use Drupal\taxonomy\Entity\Vocabulary;
7 use Drupal\views\Entity\View;
8 use Drupal\views\Tests\ViewTestData;
9
10 /**
11  * Test the taxonomy term index filter.
12  *
13  * @see \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid
14  *
15  * @group taxonomy
16  */
17 class TaxonomyIndexTidFilterTest extends TaxonomyTestBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = ['taxonomy', 'taxonomy_test_views', 'views', 'node'];
23
24   /**
25    * {@inheritdoc}
26    */
27   public static $testViews = ['test_filter_taxonomy_index_tid__non_existing_dependency'];
28
29   /**
30    * @var \Drupal\taxonomy\TermInterface[]
31    */
32   protected $terms = [];
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function setUp($import_test_views = TRUE) {
38     parent::setUp(FALSE);
39
40     // Setup vocabulary and terms so the initial import is valid.
41     Vocabulary::create([
42       'vid' => 'tags',
43       'name' => 'Tags',
44     ])->save();
45
46     // This will get a term ID of 3.
47     $term = Term::create([
48       'vid' => 'tags',
49       'name' => 'muh',
50     ]);
51     $term->save();
52     // This will get a term ID of 4.
53     $this->terms[$term->id()] = $term;
54     $term = Term::create([
55       'vid' => 'tags',
56       'name' => 'muh',
57     ]);
58     $term->save();
59     $this->terms[$term->id()] = $term;
60
61     ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
62   }
63
64   /**
65    * Tests dependencies are not added for terms that do not exist.
66    */
67   public function testConfigDependency() {
68     /** @var \Drupal\views\Entity\View $view */
69     $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
70
71     // Dependencies are sorted.
72     $content_dependencies = [
73       $this->terms[3]->getConfigDependencyName(),
74       $this->terms[4]->getConfigDependencyName(),
75     ];
76     sort($content_dependencies);
77
78     $this->assertEqual([
79       'config' => [
80         'taxonomy.vocabulary.tags',
81       ],
82       'content' => $content_dependencies,
83       'module' => [
84         'node',
85         'taxonomy',
86         'user',
87       ],
88     ], $view->calculateDependencies()->getDependencies());
89
90     $this->terms[3]->delete();
91
92     $this->assertEqual([
93       'config' => [
94         'taxonomy.vocabulary.tags',
95       ],
96       'content' => [
97         $this->terms[4]->getConfigDependencyName(),
98       ],
99       'module' => [
100         'node',
101         'taxonomy',
102         'user',
103       ],
104     ], $view->calculateDependencies()->getDependencies());
105   }
106
107   /**
108    * Tests post update function fixes dependencies.
109    *
110    * @see views_post_update_taxonomy_index_tid()
111    */
112   public function testPostUpdateFunction() {
113     /** @var \Drupal\views\Entity\View $view */
114     $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
115
116     // Dependencies are sorted.
117     $content_dependencies = [
118       $this->terms[3]->getConfigDependencyName(),
119       $this->terms[4]->getConfigDependencyName(),
120     ];
121     sort($content_dependencies);
122
123     $this->assertEqual([
124       'config' => [
125         'taxonomy.vocabulary.tags',
126       ],
127       'content' => $content_dependencies,
128       'module' => [
129         'node',
130         'taxonomy',
131         'user',
132       ],
133     ], $view->calculateDependencies()->getDependencies());
134
135     $this->terms[3]->delete();
136
137     \Drupal::moduleHandler()->loadInclude('views', 'post_update.php');
138     views_post_update_taxonomy_index_tid();
139
140     $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
141     $this->assertEqual([
142       'config' => [
143         'taxonomy.vocabulary.tags',
144       ],
145       'content' => [
146         $this->terms[4]->getConfigDependencyName(),
147       ],
148       'module' => [
149         'node',
150         'taxonomy',
151         'user',
152       ],
153     ], $view->getDependencies());
154   }
155
156 }