diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyRelationshipTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyRelationshipTest.php new file mode 100644 index 0000000..061fb9a --- /dev/null +++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyRelationshipTest.php @@ -0,0 +1,112 @@ +term1->set('parent', $this->term2->id()); + $this->term1->save(); + // Store terms in an array for testing. + $this->terms[] =$this->term1; + $this->terms[] =$this->term2; + // Only set term1 on node1 and term2 on node2 for testing. + unset($this->nodes[0]->field_views_testing_tags[1]); + $this->nodes[0]->save(); + unset($this->nodes[1]->field_views_testing_tags[0]); + $this->nodes[1]->save(); + + Views::viewsData()->clear(); + ViewTestData::createTestViews(get_class($this), array('test_taxonomy_term_relationship')); + + } + + /** + * Tests the taxonomy parent plugin UI. + */ + public function testTaxonomyRelationships() { + + // Check the generated views data of taxonomy_index. + $views_data = Views::viewsData()->get('taxonomy_index'); + // Check the table join data. + $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid'); + $this->assertEqual($views_data['table']['join']['node_field_data']['left_field'], 'nid'); + $this->assertEqual($views_data['table']['join']['node_field_data']['field'], 'nid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'tid'); + + // Check the generated views data of taxonomy_term_hierarchy. + $views_data = Views::viewsData()->get('taxonomy_term_hierarchy'); + // Check the table join data. + $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'parent'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid'); + // Check the parent relationship data. + $this->assertEqual($views_data['parent']['relationship']['base'], 'taxonomy_term_field_data'); + $this->assertEqual($views_data['parent']['relationship']['field'], 'parent'); + $this->assertEqual($views_data['parent']['relationship']['label'], t('Parent')); + $this->assertEqual($views_data['parent']['relationship']['id'], 'standard'); + // Check the parent filter and argument data. + $this->assertEqual($views_data['parent']['filter']['id'], 'numeric'); + $this->assertEqual($views_data['parent']['argument']['id'], 'taxonomy'); + + // Check an actual test view. + $view = Views::getView('test_taxonomy_term_relationship'); + $this->executeView($view); + /** @var \Drupal\views\ResultRow $row */ + foreach ($view->result as $index => $row) { + // Check that the actual ID of the entity is the expected one. + $this->assertEqual($row->tid, $this->terms[$index]->id()); + + // Also check that we have the correct result entity. + $this->assertEqual($row->_entity->id(), $this->terms[$index]->id()); + $this->assertTrue($row->_entity instanceof TermInterface); + + if (!$index) { + $this->assertTrue($row->_relationship_entities['parent'] instanceof TermInterface); + $this->assertEqual($row->_relationship_entities['parent']->id(), $this->term2->id()); + $this->assertEqual($row->taxonomy_term_field_data_taxonomy_term_hierarchy_tid, $this->term2->id()); + } + $this->assertTrue($row->_relationship_entities['nid'] instanceof NodeInterface); + $this->assertEqual($row->_relationship_entities['nid']->id(), $this->nodes[$index]->id()); + } + } + +} diff --git a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_term_relationship.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_term_relationship.yml new file mode 100644 index 0000000..eb561c6 --- /dev/null +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_term_relationship.yml @@ -0,0 +1,202 @@ +langcode: en +status: true +dependencies: + module: + - node + - taxonomy + - user +id: test_taxonomy_term_relationship +label: test_taxonomy_term_relationship +module: views +description: '' +tag: '' +base_table: taxonomy_term_field_data +base_field: tid +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: full + options: + items_per_page: 10 + offset: 0 + id: 0 + total_pages: null + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + tags: + previous: '‹ previous' + next: 'next ›' + first: '« first' + last: 'last »' + quantity: 9 + 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: + tid: + id: tid + table: taxonomy_term_field_data + field: tid + entity_type: taxonomy_term + entity_field: tid + plugin_id: field + tid_1: + id: tid_1 + table: taxonomy_term_field_data + field: tid + relationship: parent + 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 + click_sort_column: value + type: number_integer + settings: + thousand_separator: '' + prefix_suffix: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: taxonomy_term + entity_field: tid + plugin_id: field + nid: + id: nid + table: node + field: nid + entity_type: node + entity_field: nid + plugin_id: field + relationship: nid + filters: { } + sorts: + tid: + id: tid + table: taxonomy_term_field_data + field: tid + entity_type: taxonomy_term + entity_field: tid + plugin_id: standard + header: { } + footer: { } + empty: { } + relationships: + nid: + id: nid + table: taxonomy_index + field: nid + relationship: none + group_type: group + admin_label: node + required: false + plugin_id: standard + parent: + id: parent + table: taxonomy_term_hierarchy + field: parent + relationship: none + group_type: group + admin_label: Parent + required: false + plugin_id: standard + arguments: { } + display_extenders: { } + cache_metadata: + contexts: + - 'languages:language_content' + - 'languages:language_interface' + cacheable: false