diff --git a/core/modules/views/src/Tests/NodeAccessTest.php b/core/modules/views/src/Tests/NodeAccessTest.php new file mode 100644 index 0000000..dc5296a --- /dev/null +++ b/core/modules/views/src/Tests/NodeAccessTest.php @@ -0,0 +1,167 @@ +adminUser = $this->drupalCreateUser(['access administration pages']); + // User to check non-admin access. + $this->regularUser = $this->drupalCreateUser(); + + // Create Basic page and Article node types. + //$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); + + $field_names = $this->setUpFieldStorages(1); + + // Attach the field to nodes only. + $field = [ + 'field_name' => $field_names[0], + 'entity_type' => 'node', + 'bundle' => 'page', + ]; + entity_create('field_config', $field)->save(); + + // Create Entity Reference field. + $this->fieldStorages[] = entity_create('field_storage_config', [ + 'field_name' => 'field_related_pages', + 'entity_type' => 'node', + 'type' => 'entity_reference', + 'settings' => ['target_type' => 'node'], + ]); + end($this->fieldStorages)->save(); + + // Attach the entity_reference field to articles only. + $field = entity_create('field_config', [ + 'field_storage' => end($this->fieldStorages), + 'bundle' => 'article', + 'settings' => [ + 'handler' => 'default', + 'handler_settings' => [ + 'target_bundles' => ['article'], + 'sort' => ['field' => '_none'], + ], + ], + ]); + $field->save(); + + // Now create some example nodes/users for the view result. + for ($i = 0; $i < 2; $i++) { + $edit = [ + $field_names[0] => [ + ['value' => $this->randomMachineName()], + ], + ]; + if ($i > 1) { + // Set the entity reference field values. + $edit['field_related_pages'][0]['target_id'] = 1; + } + $nodes[] = $this->drupalCreateNode($edit); + } + + $this->container->get('views.views_data')->clear(); + self::$testViews = ['test_articles']; + ViewTestData::createTestViews(get_class($this), ['views_test_config']); + } + + /** + * Unit testing the view. + * + */ + function testViewsData() { + $view = Views::getView('test_articles'); + $view->setDisplay(); + + // Execute the view as anonymous user. + $view->execute(); + + // Assert the row count of the view. + $count = count($view->result); + debug($count); + $this->assertEqual(2, $count, 'The number of returned rows match.'); + + $this->drupalLogin($this->adminUser); + $view->execute(); + + // Assert the row count of the view. + $count = count($view->result); + debug($count); + $this->assertEqual(2, $count, 'The number of returned rows match.'); + + // Enable the mynodeaccess module. + \Drupal::service('module_installer')->install(['views_test_mynodeaccess']); + + + // Rebuild permissions. + /*$this->drupalGet('admin/reports/status/rebuild'); + $this->drupalPostForm(NULL, array(), t('Rebuild permissions')); + $this->assertText(t('The content access permissions have been rebuilt.'));*/ + node_access_rebuild(); + + // Execute the view: admin and anonymous users will again see the same thing. + $this->drupalLogin($this->adminUser); + $view->execute(); + + // Assert the row count of the view. + $count = count($view->result); + debug($count); + $this->assertEqual(2, $count, 'The number of returned rows match.'); + // Execute the view as anonymous user. + + $this->drupalLogout(); + $view->execute(); + + // Assert the row count of the view. + $count = count($view->result); + debug($count); + $this->assertEqual(2, $count, 'The number of returned rows match.'); + + } + +} diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_articles.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_articles.yml new file mode 100644 index 0000000..aa7feb3 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_articles.yml @@ -0,0 +1,179 @@ +langcode: en +status: true +dependencies: + module: + - node + - user +id: test_articles +label: test_articles +module: views +description: '' +tag: '' +base_table: node +base_field: nid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: perm + options: + perm: 'access content' + cache: + type: none + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: none + options: + offset: 0 + style: + type: default + options: + grouping: { } + row_class: '' + default_row_class: true + uses_fields: false + row: + type: fields + options: + inline: { } + separator: '' + hide_empty: false + default_field_elements: true + fields: + title: + id: title + table: node_field_data + field: title + entity_type: node + entity_field: title + label: '' + alter: + alter_text: false + make_link: false + absolute: false + trim: false + word_boundary: false + ellipsis: false + strip_tags: false + html: false + hide_empty: false + empty_zero: false + link_to_node: true + plugin_id: node + relationship: none + group_type: group + admin_label: '' + exclude: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_alter_empty: true + title_1: + id: title_1 + table: node_field_data + field: title + relationship: field_related_pages + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + link_to_node: true + entity_type: node + entity_field: title + plugin_id: node + filters: { } + sorts: { } + header: { } + footer: { } + empty: { } + relationships: + field_related_pages: + id: field_related_pages + table: node__field_related_pages + field: field_related_pages + relationship: none + group_type: group + admin_label: 'field_related_pages: Content' + required: false + plugin_id: standard + arguments: { } + display_extenders: { } + filter_groups: + operator: AND + groups: { } + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: 1 + display_options: + display_extenders: { } + path: articles diff --git a/core/modules/views/tests/modules/views_test_mynodeaccess/views_test_mynodeaccess.info.yml b/core/modules/views/tests/modules/views_test_mynodeaccess/views_test_mynodeaccess.info.yml new file mode 100644 index 0000000..313025d --- /dev/null +++ b/core/modules/views/tests/modules/views_test_mynodeaccess/views_test_mynodeaccess.info.yml @@ -0,0 +1,8 @@ +name: My node access test module +description: Implement hook_node_grants and see what happens. +package: Aangstrom +type: module +version: 1.0 +core: 8.x +dependencies: + - node diff --git a/core/modules/views/tests/modules/views_test_mynodeaccess/views_test_mynodeaccess.module b/core/modules/views/tests/modules/views_test_mynodeaccess/views_test_mynodeaccess.module new file mode 100644 index 0000000..e7b219c --- /dev/null +++ b/core/modules/views/tests/modules/views_test_mynodeaccess/views_test_mynodeaccess.module @@ -0,0 +1,30 @@ + array(0), + ); +} diff --git a/core/modules/views/tests/modules/views_test_remove_inner_joins/views_test_remove_inner_joins.info.yml b/core/modules/views/tests/modules/views_test_remove_inner_joins/views_test_remove_inner_joins.info.yml new file mode 100644 index 0000000..24396332 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_remove_inner_joins/views_test_remove_inner_joins.info.yml @@ -0,0 +1,8 @@ +name: Views Test Remove inner joins +description: Heavy-handed fix for https://www.drupal.org/node/2273849. +package: Aangstrom +type: module +version: 1.0 +core: 8.x +dependencies: + - views diff --git a/core/modules/views/tests/modules/views_test_remove_inner_joins/views_test_remove_inner_joins.module b/core/modules/views/tests/modules/views_test_remove_inner_joins/views_test_remove_inner_joins.module new file mode 100644 index 0000000..44ce517 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_remove_inner_joins/views_test_remove_inner_joins.module @@ -0,0 +1,17 @@ +