.../modules/node/src/Tests/Views/FrontPageTest.php | 14 +++++++ .../src/Plugin/views/filter/TaxonomyIndexTid.php | 8 +++- .../src/Plugin/views/relationship/NodeTermData.php | 14 ++++++- .../Tests/Views/RelationshipNodeTermDataTest.php | 15 ++++++- .../src/Tests/Views/TaxonomyIndexTidUiTest.php | 48 ++++++++++++++++------ .../views.view.test_taxonomy_node_term_data.yml | 6 +-- .../user/src/Tests/Views/AccessRoleTest.php | 13 ++++++ .../src/Tests/Entity/FilterEntityBundleTest.php | 13 ++++++ .../views/src/Tests/Handler/AreaViewTest.php | 3 ++ .../views/src/Tests/Plugin/DisplayPageTest.php | 24 +++++++++++ 10 files changed, 137 insertions(+), 21 deletions(-) diff --git a/core/modules/node/src/Tests/Views/FrontPageTest.php b/core/modules/node/src/Tests/Views/FrontPageTest.php index 0760231..ac93dd3 100644 --- a/core/modules/node/src/Tests/Views/FrontPageTest.php +++ b/core/modules/node/src/Tests/Views/FrontPageTest.php @@ -49,6 +49,20 @@ public function testFrontPage() { ->save(); $view = Views::getView('frontpage'); + + // Tests \Drupal\node\Plugin\views\row\RssPluginBase::calculateDependencies(). + $expected = [ + 'config' => [ + 'core.entity_view_mode.node.rss', + 'core.entity_view_mode.node.teaser', + ], + 'module' => [ + 'node', + 'user', + ], + ]; + $this->assertIdentical($expected, $view->calculateDependencies()); + $view->setDisplay('page_1'); $this->executeView($view); $view->preview(); diff --git a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php index bb991fb..78954f0 100644 --- a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php @@ -2,7 +2,7 @@ /** * @file - * Definition of views_handler_filter_term_node_tid. + * Contains \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid. */ namespace Drupal\taxonomy\Plugin\views\filter; @@ -384,6 +384,12 @@ public function calculateDependencies() { ->load($this->options['vid']); $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName(); + $term_storage = \Drupal::entityManager()->getStorage('taxonomy_term'); + foreach (array_keys($this->options['value']) as $tid) { + $term = $term_storage->load($tid); + $dependencies[$term->getConfigDependencyKey()][] = $term->getConfigDependencyName(); + } + return $dependencies; } diff --git a/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php b/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php index 333d773..b363cdd 100644 --- a/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php +++ b/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\taxonomy\Plugin\views\relationship\NodeTermData. + * Contains \Drupal\taxonomy\Plugin\views\relationship\NodeTermData. */ namespace Drupal\taxonomy\Plugin\views\relationship; @@ -63,6 +63,16 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { } /** + * {@inheritdoc} + */ + public function submitOptionsForm(&$form, FormStateInterface $form_state) { + // Transform the #type = checkboxes value to a numerically indexed array, + // because the config schema expects a sequence, not a mapping. + $vids = $form_state->getValue(['options', 'vids']); + $form_state->setValue(['options', 'vids'], array_values(array_filter($vids))); + } + + /** * Called to implement a relationship in a query. */ public function query() { @@ -110,7 +120,7 @@ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); $vocabulary_storage = \Drupal::entityManager()->getStorage('taxonomy_vocabulary'); - foreach (array_keys($this->options['vids']) as $vocabulary_id) { + foreach ($this->options['vids'] as $vocabulary_id) { if ($vocabulary = $vocabulary_storage->load($vocabulary_id)) { $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName(); } diff --git a/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php b/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php index 930990f..9208a28 100644 --- a/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php +++ b/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php @@ -25,6 +25,16 @@ class RelationshipNodeTermDataTest extends TaxonomyTestBase { function testViewsHandlerRelationshipNodeTermData() { $view = Views::getView('test_taxonomy_node_term_data'); + // Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies(). + $expected = [ + 'config' => ['core.entity_view_mode.node.teaser'], + 'module' => [ + 'node', + 'taxonomy', + 'user', + ], + ]; + $this->assertIdentical($expected, $view->calculateDependencies()); $this->executeView($view, array($this->term1->id(), $this->term2->id())); $expected_result = array( array( @@ -39,10 +49,13 @@ function testViewsHandlerRelationshipNodeTermData() { // Change the view to test relation limited by vocabulary. \Drupal::config('views.view.test_taxonomy_node_term_data') - ->set('display.default.display_options.relationships.term_node_tid.vids.tags', 'views_testing_tags') + ->set('display.default.display_options.relationships.term_node_tid.vids', ['views_testing_tags']) ->save(); $view = Views::getView('test_taxonomy_node_term_data'); + // Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies(). + $expected['config'][] = 'taxonomy.vocabulary.views_testing_tags'; + $this->assertIdentical($expected, $view->calculateDependencies()); $this->executeView($view, array($this->term1->id(), $this->term2->id())); $this->assertIdenticalResultset($view, $expected_result, $column_map); } diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php index 831ff09..cccc6f9 100644 --- a/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php +++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests\Views; +use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Vocabulary; use Drupal\views\Tests\ViewTestData; use Drupal\views_ui\Tests\UITestBase; @@ -34,6 +35,13 @@ class TaxonomyIndexTidUiTest extends UITestBase { public static $modules = array('node', 'taxonomy', 'taxonomy_test_views'); /** + * A nested array of \Drupal\taxonomy\TermInterface objects. + * + * @var \Drupal\taxonomy\TermInterface[][] + */ + protected $terms = []; + + /** * {@inheritdoc} */ protected function setUp() { @@ -44,14 +52,6 @@ protected function setUp() { 'name' => 'Tags', ])->save(); - ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views')); - } - - /** - * Tests the filter UI. - */ - public function testFilterUI() { - $terms = array(); // Setup a hierarchy which looks like this: // term 0.0 // term 1.0 @@ -61,15 +61,21 @@ public function testFilterUI() { // - term 2.2 for ($i = 0; $i < 3; $i++) { for ($j = 0; $j <= $i; $j++) { - $terms[$i][$j] = $term = entity_create('taxonomy_term', array( + $this->terms[$i][$j] = $term = Term::create([ 'vid' => 'tags', 'name' => "Term $i.$j", 'parent' => isset($terms[$i][0]) ? $terms[$i][0]->id() : 0, - )); + ]); $term->save(); } } + ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views')); + } + /** + * Tests the filter UI. + */ + public function testFilterUI() { $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid'); $result = $this->xpath('//select[@id="edit-options-value"]/option'); @@ -79,12 +85,12 @@ public function testFilterUI() { for ($i = 0; $i < 3; $i++) { for ($j = 0; $j <= $i; $j++) { $option = $result[$counter++]; - $prefix = $terms[$i][$j]->parent->target_id ? '-' : ''; + $prefix = $this->terms[$i][$j]->parent->target_id ? '-' : ''; $attributes = $option->attributes(); $tid = (string) $attributes->value; - $this->assertEqual($prefix . $terms[$i][$j]->getName(), (string) $option); - $this->assertEqual($terms[$i][$j]->id(), $tid); + $this->assertEqual($prefix . $this->terms[$i][$j]->getName(), (string) $option); + $this->assertEqual($this->terms[$i][$j]->id(), $tid); } } @@ -97,6 +103,22 @@ public function testFilterUI() { $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid'); $result = $this->xpath('//input[@id="edit-options-value"]/@data-autocomplete-path'); $this->assertEqual((string) $result[0], \Drupal::url('taxonomy.autocomplete_vid', ['taxonomy_vocabulary' => 'tags'])); + + // Tests \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::calculateDependencies(). + $expected = [ + 'config' => [ + 'taxonomy.vocabulary.tags', + ], + 'content' => [ + 'taxonomy_term:tags:' . Term::load(2)->uuid(), + ], + 'module' => [ + 'node', + 'taxonomy', + 'user', + ] + ]; + $this->assertIdentical($expected, $view->calculateDependencies()); } } diff --git a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_node_term_data.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_node_term_data.yml index 2afdfb1..38f4907 100644 --- a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_node_term_data.yml +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_node_term_data.yml @@ -57,16 +57,14 @@ display: id: term_node_tid admin_label: 'Term #1' table: node - vids: - tags: '' + vids: {} plugin_id: node_term_data term_node_tid_1: field: term_node_tid id: term_node_tid_1 admin_label: 'Term #2' table: node - vids: - tags: '' + vids: {} plugin_id: node_term_data sorts: nid: diff --git a/core/modules/user/src/Tests/Views/AccessRoleTest.php b/core/modules/user/src/Tests/Views/AccessRoleTest.php index b4086bd..f01f412 100644 --- a/core/modules/user/src/Tests/Views/AccessRoleTest.php +++ b/core/modules/user/src/Tests/Views/AccessRoleTest.php @@ -38,6 +38,11 @@ function testAccessRole() { $this->normalRole => $this->normalRole, ); $view->save(); + $expected = [ + 'config' => ['user.role.' . $this->normalRole], + 'module' => ['user'], + ]; + $this->assertIdentical($expected, $view->calculateDependencies()); $executable = Views::executableFactory()->get($view); $executable->setDisplay('page_1'); @@ -65,6 +70,14 @@ function testAccessRole() { 'anonymous' => 'anonymous', ); $view->save(); + $expected = [ + 'config' => [ + 'user.role.anonymous', + 'user.role.' . $this->normalRole, + ], + 'module' => ['user'], + ]; + $this->assertIdentical($expected, $view->calculateDependencies()); $this->drupalLogin($this->webUser); $this->drupalGet('test-role'); $this->assertResponse(403); diff --git a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php b/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php index f5f2d7a..c806109 100644 --- a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php +++ b/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php @@ -73,6 +73,19 @@ protected function setUp() { */ public function testFilterEntity() { $view = Views::getView('test_entity_type_filter'); + + // Tests \Drupal\views\Plugin\views\filter\Bundle::calculateDependencies(). + $expected = [ + 'config' => [ + 'node.type.test_bundle', + 'node.type.test_bundle_2', + ], + 'module' => [ + 'node' + ] + ]; + $this->assertIdentical($expected, $view->calculateDependencies()); + $this->executeView($view); // Test we have all the results, with all types selected. diff --git a/core/modules/views/src/Tests/Handler/AreaViewTest.php b/core/modules/views/src/Tests/Handler/AreaViewTest.php index 7f93855..ef7498b 100644 --- a/core/modules/views/src/Tests/Handler/AreaViewTest.php +++ b/core/modules/views/src/Tests/Handler/AreaViewTest.php @@ -38,6 +38,9 @@ class AreaViewTest extends ViewUnitTestBase { public function testViewArea() { $view = Views::getView('test_area_view'); + // Tests \Drupal\views\Plugin\views\area\View::calculateDependencies(). + $this->assertIdentical(['config' => ['views.view.test_simple_argument']], $view->calculateDependencies()); + $this->executeView($view); $output = $view->render(); $output = drupal_render($output); diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php index 085e9fe..4222f17 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php @@ -140,4 +140,28 @@ public function testMenuLinks() { $this->assertEqual($menu_link->getTitle(), 'Test child (with parent)'); } + /** + * Tests the calculated dependencies for various views using Page displays. + */ + public function testDependencies() { + $view = Views::getView('test_page_display'); + $this->assertIdentical([], $view->calculateDependencies()); + + $view = Views::getView('test_page_display_route'); + $expected = [ + 'content' => ['StaticTest'], + 'module' => ['views_test_data'], + ]; + $this->assertIdentical($expected, $view->calculateDependencies()); + + $view = Views::getView('test_page_display_menu'); + $expected = [ + 'config' => [ + 'system.menu.admin', + 'system.menu.tools', + ], + ]; + $this->assertIdentical($expected, $view->calculateDependencies()); + } + }