Move all files to 2017/

This commit is contained in:
Oliver Davies 2025-09-29 22:25:17 +01:00
parent ac7370f67f
commit 2875863330
15717 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,32 @@
<?php
/**
* @file
* Contains database additions to drupal-8.filled.standard.php.gz for testing
* the upgrade path of https://www.drupal.org/project/drupal/issues/2981887.
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
$view_file = __DIR__ . '/views.view.test_taxonomy_term_view_with_content_translation_status.yml';
$view_with_cts_config = Yaml::decode(file_get_contents($view_file));
$view_file = __DIR__ . '/views.view.test_taxonomy_term_view_without_content_translation_status.yml';
$view_without_cts_config = Yaml::decode(file_get_contents($view_file));
$connection->insert('config')
->fields(['collection', 'name', 'data'])
->values([
'collection' => '',
'name' => 'views.view.test_taxonomy_term_view_with_content_translation_status',
'data' => serialize($view_with_cts_config),
])
->values([
'collection' => '',
'name' => 'views.view.test_taxonomy_term_view_without_content_translation_status',
'data' => serialize($view_without_cts_config),
])
->execute();

View file

@ -0,0 +1,250 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_taxonomy_term_view_with_content_translation_status
label: 'Test taxonomy term view with content translation status'
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: tag
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:
name:
id: name
table: taxonomy_term_field_data
field: name
entity_type: taxonomy_term
entity_field: name
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
type: string
settings:
link_to_entity: true
plugin_id: term_name
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
click_sort_column: value
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
convert_spaces: false
content_translation_status:
id: content_translation_status
table: taxonomy_term_field_data
field: content_translation_status
relationship: none
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: boolean
settings:
format: true-false
format_custom_true: ''
format_custom_false: ''
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: content_translation_status
plugin_id: field
filters:
content_translation_status:
id: content_translation_status
table: taxonomy_term_field_data
field: content_translation_status
relationship: none
group_type: group
admin_label: ''
operator: '='
value: All
group: 1
exposed: true
expose:
operator_id: ''
label: 'Translation status'
description: ''
use_operator: false
operator: content_translation_status_op
identifier: content_translation_status
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: taxonomy_term
entity_field: content_translation_status
plugin_id: boolean
sorts:
content_translation_status:
id: content_translation_status
table: taxonomy_term_field_data
field: content_translation_status
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
entity_type: taxonomy_term
entity_field: content_translation_status
plugin_id: standard
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- user.permissions
tags: { }

View file

@ -0,0 +1,128 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_taxonomy_term_view_without_content_translation_status
label: 'Test taxonomy term view without content translation status'
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: tag
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:
name:
id: name
table: taxonomy_term_field_data
field: name
entity_type: taxonomy_term
entity_field: name
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
type: string
settings:
link_to_entity: true
plugin_id: term_name
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
click_sort_column: value
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
convert_spaces: false
filters: { }
sorts: { }
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- user.permissions
tags: { }

View file

@ -0,0 +1,7 @@
taxonomy.vocabulary.*.third_party.taxonomy_crud:
type: mapping
label: 'Schema for taxonomy_crud module additions to vocabulary entity'
mapping:
foo:
type: string
label: 'Label for foo'

View file

@ -0,0 +1,8 @@
name: 'Taxonomy CRUD tests'
type: module
description: 'Provides 3rd party settings for vocabulary.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:taxonomy

View file

@ -0,0 +1,15 @@
<?php
/**
* @file
* Provides hook implementations for testing purposes.
*/
use Drupal\taxonomy\VocabularyInterface;
/**
* Implements hook_ENTITY_TYPE_presave() for taxonomy_vocabulary entities.
*/
function taxonomy_crud_taxonomy_vocabulary_presave(VocabularyInterface $vocabulary) {
$vocabulary->setThirdPartySetting('taxonomy_crud', 'foo', 'bar');
}

View file

@ -0,0 +1,32 @@
id: taxonomy_term_stub_test
label: Taxonomy term stub
migration_tags:
- Import and rollback test
source:
plugin: embedded_data
data_rows:
-
id: 1
vocab: 1
name: music
parent: 2
ids:
id:
type: integer
process:
tid: id
vid: vocab
name: name
weight: weight
parent:
plugin: migration_lookup
migration: taxonomy_term_stub_test
source: parent
destination:
plugin: entity:taxonomy_term
migration_dependencies:
required:
- vocabularies
provider:
- migrate_drupal
- taxonomy

View file

@ -0,0 +1,9 @@
name: 'Taxonomy Migrate stub test'
type: module
description: 'Provides a migration plugin for stub testing.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:taxonomy
- drupal:migrate

View file

@ -0,0 +1,8 @@
name: 'Taxonomy test'
type: module
description: 'Provides test hook implementations for taxonomy tests'
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:taxonomy

View file

@ -0,0 +1,38 @@
<?php
/**
* @file
* Provides test hook implementations for taxonomy tests.
*/
use Drupal\Core\Database\Query\AlterableInterface;
/**
* Implements hook_query_alter().
*/
function taxonomy_test_query_alter(AlterableInterface $query) {
$value = \Drupal::state()->get(__FUNCTION__);
if (isset($value)) {
\Drupal::state()->set(__FUNCTION__, ++$value);
}
}
/**
* Implements hook_query_TAG_alter().
*/
function taxonomy_test_query_term_access_alter(AlterableInterface $query) {
$value = \Drupal::state()->get(__FUNCTION__);
if (isset($value)) {
\Drupal::state()->set(__FUNCTION__, ++$value);
}
}
/**
* Implements hook_query_TAG_alter().
*/
function taxonomy_test_query_taxonomy_term_access_alter(AlterableInterface $query) {
$value = \Drupal::state()->get(__FUNCTION__);
if (isset($value)) {
\Drupal::state()->set(__FUNCTION__, ++$value);
}
}

View file

@ -0,0 +1,9 @@
name: 'Taxonomy test views'
type: module
description: 'Provides default views for views taxonomy tests.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:taxonomy
- drupal:views

View file

@ -0,0 +1,258 @@
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: taxonomy_all_terms_test
label: taxonomy_all_terms_test
module: views
description: ''
tag: ''
base_table: node_field_data
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: tag
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:
term_node_tid:
id: term_node_tid
table: node_field_data
field: term_node_tid
relationship: none
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
type: separator
separator: ', '
link_to_taxonomy: true
limit: false
vids:
tags: '0'
entity_type: node
plugin_id: taxonomy_index_tid
filters: { }
sorts:
nid:
id: nid
table: node
field: nid
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
entity_type: node
entity_field: nid
plugin_id: standard
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
- user.permissions
max-age: 0
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: taxonomy_all_terms_test
cache_metadata:
contexts:
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
- user.permissions
cacheable: false
page_2:
display_plugin: page
id: page_2
display_title: 'Token tests'
position: 2
display_options:
display_extenders: { }
display_description: ''
fields:
term_node_tid:
id: term_node_tid
table: node_field_data
field: term_node_tid
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: true
text: "Term: {{ term_node_tid }}<br />\nThe taxonomy term ID for the term: {{ term_node_tid__tid }}<br />\nThe taxonomy term name for the term: {{ term_node_tid__name }}<br />\nThe machine name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary_vid }}<br />\nThe name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary }}<br />"
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
type: separator
separator: '<br />'
link_to_taxonomy: false
limit: false
vids:
tags: '0'
entity_type: node
plugin_id: taxonomy_index_tid
defaults:
fields: false
path: taxonomy_all_terms_token_test
cache_metadata:
contexts:
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
- user.permissions
max-age: 0

View file

@ -0,0 +1,172 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: taxonomy_default_argument_test
label: taxonomy_default_argument_test
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: tag
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, 20, 40, 60'
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: 'entity:taxonomy_term'
options:
relationship: none
view_mode: default
fields:
name:
id: name
table: taxonomy_term_field_data
field: name
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
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
plugin_id: field
type: string
settings:
link_to_entity: true
entity_type: taxonomy_term
entity_field: name
filters: { }
sorts: { }
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
tid:
id: tid
table: taxonomy_term_field_data
field: tid
relationship: none
group_type: group
admin_label: ''
default_action: default
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: taxonomy_tid
default_argument_options:
term_page: '1'
node: true
anyall: ','
limit: false
vids: { }
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
not: false
plugin_id: taxonomy
entity_type: taxonomy_term
entity_field: tid
rendering_language: '***LANGUAGE_entity_translation***'
page_1:
display_plugin: page
id: page_1
display_title: Page
position: null
display_options:
path: taxonomy_default_argument_test

View file

@ -0,0 +1,227 @@
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: test_argument_taxonomy_index_tid_depth
label: test_argument_taxonomy_index_tid_depth
module: views
description: ''
tag: ''
base_table: node_field_data
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: tag
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:
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
settings:
link_to_entity: true
plugin_id: field
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
click_sort_column: value
type: string
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
filters:
status:
value: '1'
table: node_field_data
field: status
plugin_id: boolean
entity_type: node
entity_field: status
id: status
expose:
operator: ''
group: 1
sorts:
created:
id: created
table: node_field_data
field: created
order: DESC
entity_type: node
entity_field: created
plugin_id: date
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
granularity: second
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
term_node_tid_depth:
id: term_node_tid_depth
table: node_field_data
field: term_node_tid_depth
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: true
title: '{{ arguments.term_node_tid_depth }}'
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
depth: 0
break_phrase: false
use_taxonomy_term_path: false
entity_type: node
plugin_id: taxonomy_index_tid_depth
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- 'user.node_grants:view'
- user.permissions
cacheable: false
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: test_argument_taxonomy_index_tid_depth
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- 'user.node_grants:view'
- user.permissions
cacheable: false

View file

@ -0,0 +1,173 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_argument_taxonomy_vocabulary
label: test_argument_taxonomy_vocabulary
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: tag
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
row:
type: 'entity:taxonomy_term'
fields:
name:
id: name
table: taxonomy_term_field_data
field: name
entity_type: taxonomy_term
entity_field: name
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
type: string
settings:
link_to_entity: true
plugin_id: term_name
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
click_sort_column: value
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
convert_spaces: false
filters: { }
sorts: { }
title: ''
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
vid:
id: vid
table: taxonomy_term_field_data
field: vid
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
not: false
entity_type: taxonomy_term
entity_field: vid
plugin_id: vocabulary_vid
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- user.permissions
tags: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: test_argument_taxonomy_vocabulary
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- user.permissions
tags: { }

View file

@ -0,0 +1,424 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_field_filters
label: 'Test field filters'
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: tag
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:
items_per_page: 0
offset: 0
style:
type: default
row:
type: 'entity:taxonomy_term'
fields:
name:
id: name
table: taxonomy_term_field_data
field: name
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
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
plugin_id: field
type: string
settings:
link_to_entity: true
entity_type: taxonomy_term
entity_field: name
filters:
name:
id: name
table: taxonomy_term_field_data
field: name
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Comida
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: taxonomy_term
entity_field: name
sorts: { }
title: 'Name filter page'
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
page_dc:
display_plugin: page
id: page_dc
display_title: 'Description Comida'
position: 3
display_options:
display_description: ''
path: test-desc-filter
filters:
description__value:
id: description__value
table: taxonomy_term_field_data
field: description__value
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Comida
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: taxonomy_term
entity_field: description
defaults:
filters: false
filter_groups: false
title: false
filter_groups:
operator: AND
groups:
1: AND
title: 'Description filter page'
page_dp:
display_plugin: page
id: page_dp
display_title: 'Description Comida'
position: 3
display_options:
display_description: ''
path: test-desc-paris
filters:
description__value:
id: description__value
table: taxonomy_term_field_data
field: description__value
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Paris
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: taxonomy_term
entity_field: description
defaults:
filters: false
filter_groups: false
title: false
filter_groups:
operator: AND
groups:
1: AND
title: 'Description filter page'
page_fc:
display_plugin: page
id: page_fc
display_title: 'Field Comida'
position: 3
display_options:
display_description: ''
path: test-field-filter
filters:
field_foo_value:
id: field_foo_value
table: taxonomy_term__field_foo
field: field_foo_value
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Comida
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: taxonomy_term
entity_field: field_foo
defaults:
filters: false
filter_groups: false
title: false
filter_groups:
operator: AND
groups:
1: AND
title: 'Field filter page'
page_fp:
display_plugin: page
id: page_fp
display_title: 'Field Paris'
position: 3
display_options:
display_description: ''
path: test-field-paris
filters:
field_foo_value:
id: field_foo_value
table: taxonomy_term__field_foo
field: field_foo_value
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Paris
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: taxonomy_term
entity_field: field_foo
defaults:
filters: false
filter_groups: false
title: false
filter_groups:
operator: AND
groups:
1: AND
title: 'Field filter page'
page_nc:
display_plugin: page
id: page_nc
display_title: 'Name Comida'
position: 1
display_options:
path: test-name-filter
display_description: ''
page_np:
display_plugin: page
id: page_np
display_title: 'Name Paris'
position: 1
display_options:
path: test-name-paris
display_description: ''
filters:
name:
id: name
table: taxonomy_term_field_data
field: name
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Paris
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: taxonomy_term
entity_field: name
defaults:
filters: false
filter_groups: false
filter_groups:
operator: AND
groups:
1: AND

View file

@ -0,0 +1,186 @@
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: test_filter_taxonomy_index_tid
label: test_filter_taxonomy_index_tid
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 1
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
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:
title:
id: title
table: node_field_data
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
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
plugin_id: field
entity_type: node
entity_field: title
filters:
status:
value: '1'
table: node_field_data
field: status
id: status
expose:
operator: '0'
group: 1
plugin_id: boolean
entity_type: node
entity_field: status
tid:
id: tid
table: taxonomy_index
field: tid
relationship: none
group_type: group
admin_label: ''
operator: or
value:
- 2
group: 1
exposed: false
expose:
operator_id: '0'
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
reduce_duplicates: false
type: select
limit: true
vid: tags
hierarchy: true
error_message: true
plugin_id: taxonomy_index_tid
sorts: { }
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 2
display_options:
display_extenders: { }
path: test-filter-taxonomy-index-tid

View file

@ -0,0 +1,187 @@
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: test_filter_taxonomy_index_tid__non_existing_dependency
label: test_filter_taxonomy_index_tid__non_existing_dependency
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 1
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
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:
title:
id: title
table: node_field_data
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
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
plugin_id: field
entity_type: node
entity_field: title
filters:
status:
value: '1'
table: node_field_data
field: status
id: status
expose:
operator: '0'
group: 1
plugin_id: boolean
entity_type: node
entity_field: status
tid:
id: tid
table: taxonomy_index
field: tid
relationship: none
group_type: group
admin_label: ''
operator: or
value:
- 3
- 4
group: 1
exposed: false
expose:
operator_id: '0'
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
reduce_duplicates: false
type: select
limit: true
vid: tags
hierarchy: true
error_message: true
plugin_id: taxonomy_index_tid
sorts: { }
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 2
display_options:
display_extenders: { }
path: test-filter-taxonomy-index-tid

View file

@ -0,0 +1,178 @@
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: test_filter_taxonomy_index_tid_depth
label: test_filter_taxonomy_index_tid_depth
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 1
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
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:
title:
id: title
table: node_field_data
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
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
plugin_id: field
entity_type: node
entity_field: title
filters:
status:
value: '1'
table: node_field_data
field: status
id: status
expose:
operator: '0'
group: 1
plugin_id: boolean
entity_type: node
entity_field: status
tid_depth:
id: tid_depth
table: node_field_data
field: term_node_tid_depth
relationship: none
group_type: group
admin_label: ''
operator: or
value: { }
group: 1
exposed: false
expose:
operator_id: '0'
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
reduce_duplicates: false
type: select
limit: true
vid: views_testing_tags
hierarchy: true
depth: -2
error_message: true
plugin_id: taxonomy_index_tid_depth
sorts: { }
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }

View file

@ -0,0 +1,83 @@
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: test_groupwise_term
label: test_groupwise
module: views
description: ''
tag: default
base_table: taxonomy_term_field_data
base_field: tid
core: 8.0-dev
display:
default:
display_options:
access:
type: perm
cache:
type: tag
exposed_form:
type: basic
fields:
name:
field: name
id: name
table: taxonomy_term_field_data
plugin_id: term_name
type: string
settings:
link_to_entity: true
convert_spaces: false
entity_type: taxonomy_term
entity_field: name
nid:
field: nid
id: nid
relationship: tid_representative
table: node_field_data
plugin_id: node
entity_type: node
entity_field: nid
pager:
options:
items_per_page: 10
type: full
query:
type: views_query
relationships:
tid_representative:
admin_label: 'Representative node'
field: tid_representative
group_type: group
id: tid_representative
relationship: none
required: false
subquery_namespace: ''
subquery_order: DESC
subquery_regenerate: true
subquery_sort: node_field_data.nid
subquery_view: ''
table: taxonomy_term_field_data
plugin_id: groupwise_max
row:
type: fields
sorts:
tid:
field: tid
id: tid
order: DESC
table: taxonomy_term_field_data
plugin_id: standard
entity_type: taxonomy_term
entity_field: tid
style:
type: default
title: test_groupwise
display_plugin: default
display_title: Master
id: default
position: 0

View file

@ -0,0 +1,89 @@
langcode: en
status: true
dependencies:
module:
- node
- taxonomy
- user
id: test_taxonomy_node_term_data
label: test_taxonomy_node_term_data
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: '8'
display:
default:
display_options:
access:
type: perm
arguments:
tid:
default_argument_type: fixed
field: tid
id: tid
relationship: term_node_tid
summary:
format: default_summary
number_of_records: 0
summary_options:
items_per_page: 25
table: taxonomy_term_field_data
plugin_id: taxonomy
entity_type: taxonomy_term
entity_field: tid
tid_1:
default_argument_type: fixed
field: tid
id: tid_1
relationship: term_node_tid_1
summary:
format: default_summary
number_of_records: 0
summary_options:
items_per_page: 25
table: taxonomy_term_field_data
plugin_id: taxonomy
entity_type: taxonomy_term
entity_field: tid
cache:
type: tag
exposed_form:
type: basic
pager:
type: full
query:
type: views_query
relationships:
term_node_tid:
field: term_node_tid
id: term_node_tid
admin_label: 'Term #1'
table: node_field_data
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_field_data
vids: {}
plugin_id: node_term_data
sorts:
nid:
field: nid
id: nid
order: DESC
table: node_field_data
plugin_id: standard
entity_type: node
entity_field: nid
style:
type: default
row:
type: 'entity:node'
display_plugin: default
display_title: Master
id: default
position: 0

View file

@ -0,0 +1,134 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_taxonomy_parent
label: test_taxonomy_parent
module: views
description: ''
tag: ''
base_table: taxonomy_term_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: tag
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:
name:
id: name
table: taxonomy_term_data
field: name
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
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
plugin_id: field
type: string
settings:
link_to_entity: true
entity_type: taxonomy_term
entity_field: name
filters: { }
sorts: { }
header: { }
footer: { }
empty: { }
relationships:
parent:
id: parent
table: taxonomy_term__parent
field: parent_target_id
relationship: none
group_type: group
admin_label: Parent
required: true
plugin_id: standard
arguments: { }

View file

@ -0,0 +1,158 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_taxonomy_term_name
label: test_taxonomy_term_name
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: tag
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, 20, 40, 60'
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:
name:
id: name
table: taxonomy_term_field_data
field: name
relationship: none
group_type: group
admin_label: ''
label: Name
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: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
plugin_id: term_name
type: string
settings:
link_to_entity: false
convert_spaces: false
entity_type: taxonomy_term
entity_field: name
filters: { }
sorts:
tid:
id: tid
table: taxonomy_term_field_data
field: tid
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
plugin_id: standard
entity_type: taxonomy_term
entity_field: tid
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }

View file

@ -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: tag
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_data
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__parent
field: parent_target_id
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'
max-age: 0

View file

@ -0,0 +1,157 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_taxonomy_tid_field
label: test_taxonomy_tid_field
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: tag
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, 20, 40, 60'
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:
name:
id: name
table: taxonomy_term_field_data
field: name
relationship: none
group_type: group
admin_label: ''
label: Name
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: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
plugin_id: field
type: string
settings:
link_to_entity: true
entity_type: taxonomy_term
entity_field: name
filters: { }
sorts:
tid:
id: tid
table: taxonomy_term_field_data
field: tid
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
plugin_id: standard
entity_type: taxonomy_term
entity_field: tid
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }

View file

@ -0,0 +1,163 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_taxonomy_vid_field
label: test_taxonomy_vid_field
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: tag
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:
vid:
id: vid
table: taxonomy_term_field_data
field: vid
relationship: none
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: target_id
type: entity_reference_label
settings:
link: false
group_column: target_id
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: vid
plugin_id: field
filters: { }
sorts: { }
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- user.permissions
tags: { }

View file

@ -0,0 +1,19 @@
<?php
namespace Drupal\vocabulary_serialization_test;
use Drupal\Core\Cache\CacheableResponse;
use Drupal\taxonomy\VocabularyInterface;
class VocabularyResponse extends CacheableResponse {
/**
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
public function setVocabulary(VocabularyInterface $vocabulary) {
$this->vocabulary = $vocabulary;
}
}

View file

@ -0,0 +1,15 @@
<?php
namespace Drupal\vocabulary_serialization_test;
use Drupal\taxonomy\VocabularyInterface;
class VocabularySerializationTestController {
public function vocabularyResponse(VocabularyInterface $taxonomy_vocabulary) {
$response = new VocabularyResponse('this is the output');
$response->setVocabulary($taxonomy_vocabulary);
return $response;
}
}

View file

@ -0,0 +1,7 @@
name: 'Vocabulary serialization test'
type: module
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:taxonomy

View file

@ -0,0 +1,6 @@
vocabulary_serialization_test:
path: '/vocabulary_serialization_test/{taxonomy_vocabulary}'
defaults:
_controller: 'Drupal\vocabulary_serialization_test\VocabularySerializationTestController::vocabularyResponse'
requirements:
_access: 'TRUE'

View file

@ -0,0 +1,69 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Posts an article with a taxonomy term and a date prior to 1970.
*
* @group taxonomy
*/
class EarlyDateTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'datetime'];
protected function setUp() {
parent::setUp();
// Create a tags vocabulary for the 'article' content type.
$vocabulary = Vocabulary::create([
'name' => 'Tags',
'vid' => 'tags',
]);
$vocabulary->save();
$field_name = 'field_' . $vocabulary->id();
$handler_settings = [
'target_bundles' => [
$vocabulary->id() => $vocabulary->id(),
],
'auto_create' => TRUE,
];
$this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($field_name, [
'type' => 'entity_reference_autocomplete_tags',
])
->save();
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'administer nodes', 'bypass node access']));
}
/**
* Test taxonomy functionality with nodes prior to 1970.
*/
public function testTaxonomyEarlyDateNode() {
// Posts an article with a taxonomy term and a date prior to 1970.
$date = new DrupalDateTime('1969-01-01 00:00:00');
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['created[0][value][date]'] = $date->format('Y-m-d');
$edit['created[0][value][time]'] = $date->format('H:i:s');
$edit['body[0][value]'] = $this->randomMachineName();
$edit['field_tags[target_id]'] = $this->randomMachineName();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
// Checks that the node has been saved.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertEqual($node->getCreatedTime(), $date->getTimestamp(), 'Legacy node was saved with the right date.');
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
/**
* Verifies operation of a taxonomy-based Entity Query.
*
* @group taxonomy
*/
class EfqTest extends TaxonomyTestBase {
/**
* Vocabulary for testing.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
$this->vocabulary = $this->createVocabulary();
}
/**
* Tests that a basic taxonomy entity query works.
*/
public function testTaxonomyEfq() {
$terms = [];
for ($i = 0; $i < 5; $i++) {
$term = $this->createTerm($this->vocabulary);
$terms[$term->id()] = $term;
}
$result = \Drupal::entityQuery('taxonomy_term')->execute();
sort($result);
$this->assertEqual(array_keys($terms), $result, 'Taxonomy terms were retrieved by entity query.');
$tid = reset($result);
$ids = (object) [
'entity_type' => 'taxonomy_term',
'entity_id' => $tid,
'bundle' => $this->vocabulary->id(),
];
$term = _field_create_entity_from_ids($ids);
$this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
// Create a second vocabulary and five more terms.
$vocabulary2 = $this->createVocabulary();
$terms2 = [];
for ($i = 0; $i < 5; $i++) {
$term = $this->createTerm($vocabulary2);
$terms2[$term->id()] = $term;
}
$result = \Drupal::entityQuery('taxonomy_term')
->condition('vid', $vocabulary2->id())
->execute();
sort($result);
$this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', ['%name' => $vocabulary2->label()]));
$tid = reset($result);
$ids = (object) [
'entity_type' => 'taxonomy_term',
'entity_id' => $tid,
'bundle' => $vocabulary2->id(),
];
$term = _field_create_entity_from_ids($ids);
$this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
}
}

View file

@ -0,0 +1,178 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Hal;
use Drupal\taxonomy\Entity\Term;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase;
/**
* @group hal
*/
class TermHalJsonAnonTest extends TermResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
// We test with multiple parent terms, and combinations thereof.
// @see ::createEntity()
// @see ::testGet()
// @see ::testGetTermWithParent()
// @see ::providerTestGetTermWithParent()
// @see ::testGetTermWithParent()
$parent_term_ids = [];
for ($i = 0; $i < $this->entity->get('parent')->count(); $i++) {
$parent_term_ids[$i] = (int) $this->entity->get('parent')[$i]->target_id;
}
$expected_parent_normalization_links = FALSE;
$expected_parent_normalization_embedded = FALSE;
switch ($parent_term_ids) {
case [0]:
$expected_parent_normalization_links = [
NULL,
];
$expected_parent_normalization_embedded = [
NULL,
];
break;
case [2]:
$expected_parent_normalization_links = [
[
'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
],
];
$expected_parent_normalization_embedded = [
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
],
],
'uuid' => [
['value' => Term::load(2)->uuid()],
],
],
];
break;
case [0, 2]:
$expected_parent_normalization_links = [
NULL,
[
'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
],
];
$expected_parent_normalization_embedded = [
NULL,
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
],
],
'uuid' => [
['value' => Term::load(2)->uuid()],
],
],
];
break;
case [3, 2]:
$expected_parent_normalization_links = [
[
'href' => $this->baseUrl . '/taxonomy/term/3?_format=hal_json',
],
[
'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
],
];
$expected_parent_normalization_embedded = [
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/taxonomy/term/3?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
],
],
'uuid' => [
['value' => Term::load(3)->uuid()],
],
],
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/taxonomy/term/2?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
],
],
'uuid' => [
['value' => Term::load(2)->uuid()],
],
],
];
break;
}
return $normalization + [
'_links' => [
'self' => [
'href' => $this->baseUrl . '/llama?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
],
$this->baseUrl . '/rest/relation/taxonomy_term/camelids/parent' => $expected_parent_normalization_links,
],
'_embedded' => [
$this->baseUrl . '/rest/relation/taxonomy_term/camelids/parent' => $expected_parent_normalization_embedded,
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/taxonomy_term/camelids',
],
],
];
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class TermHalJsonBasicAuthTest extends TermHalJsonAnonTest {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,18 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class TermHalJsonCookieTest extends TermHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,37 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Hal;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\taxonomy\Functional\Rest\VocabularyResourceTestBase;
/**
* @group hal
*/
class VocabularyHalJsonAnonTest extends VocabularyResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* @todo Remove this override in https://www.drupal.org/node/2805281.
*/
public function testGet() {
$this->markTestSkipped();
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\taxonomy\Functional\Rest\VocabularyResourceTestBase;
/**
* @group hal
*/
class VocabularyHalJsonBasicAuthTest extends VocabularyResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal', 'basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\taxonomy\Functional\Rest\VocabularyResourceTestBase;
/**
* @group hal
*/
class VocabularyHalJsonCookieTest extends VocabularyResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,62 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\taxonomy\Entity\Term;
/**
* Tests the loading of multiple taxonomy terms at once.
*
* @group taxonomy
*/
class LoadMultipleTest extends TaxonomyTestBase {
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
}
/**
* Create a vocabulary and some taxonomy terms, ensuring they're loaded
* correctly using entity_load_multiple().
*/
public function testTaxonomyTermMultipleLoad() {
// Create a vocabulary.
$vocabulary = $this->createVocabulary();
// Create five terms in the vocabulary.
$i = 0;
while ($i < 5) {
$i++;
$this->createTerm($vocabulary);
}
// Load the terms from the vocabulary.
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]);
$count = count($terms);
$this->assertEqual($count, 5, format_string('Correct number of terms were loaded. @count terms.', ['@count' => $count]));
// Load the same terms again by tid.
$terms2 = Term::loadMultiple(array_keys($terms));
$this->assertEqual($count, count($terms2), 'Five terms were loaded by tid.');
$this->assertEqual($terms, $terms2, 'Both arrays contain the same terms.');
// Remove one term from the array, then delete it.
$deleted = array_shift($terms2);
$deleted->delete();
$deleted_term = Term::load($deleted->id());
$this->assertFalse($deleted_term);
// Load terms from the vocabulary by vid.
$terms3 = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]);
$this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.');
$this->assertFalse(isset($terms3[$deleted->id()]));
// Create a single term and load it by name.
$term = $this->createTerm($vocabulary);
$loaded_terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $term->getName()]);
$this->assertEqual(count($loaded_terms), 1, 'One term was loaded.');
$loaded_term = reset($loaded_terms);
$this->assertEqual($term->id(), $loaded_term->id(), 'Term loaded by name successfully.');
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class TermJsonAnonTest extends TermResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class TermJsonBasicAuthTest extends TermResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class TermJsonCookieTest extends TermResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,365 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Core\Cache\Cache;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use GuzzleHttp\RequestOptions;
abstract class TermResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'path'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'taxonomy_term';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [
'changed' => NULL,
];
/**
* @var \Drupal\taxonomy\TermInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['access content']);
break;
case 'POST':
$this->grantPermissionsToTestedRole(['create terms in camelids']);
break;
case 'PATCH':
// Grant the 'create url aliases' permission to test the case when
// the path field is accessible, see
// \Drupal\Tests\rest\Functional\EntityResource\Node\NodeResourceTestBase
// for a negative test.
$this->grantPermissionsToTestedRole(['edit terms in camelids', 'create url aliases']);
break;
case 'DELETE':
$this->grantPermissionsToTestedRole(['delete terms in camelids']);
break;
}
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
$vocabulary = Vocabulary::load('camelids');
if (!$vocabulary) {
// Create a "Camelids" vocabulary.
$vocabulary = Vocabulary::create([
'name' => 'Camelids',
'vid' => 'camelids',
]);
$vocabulary->save();
}
// Create a "Llama" taxonomy term.
$term = Term::create(['vid' => $vocabulary->id()])
->setName('Llama')
->setDescription("It is a little known fact that llamas cannot count higher than seven.")
->setChangedTime(123456789)
->set('path', '/llama');
$term->save();
return $term;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
// We test with multiple parent terms, and combinations thereof.
// @see ::createEntity()
// @see ::testGet()
// @see ::testGetTermWithParent()
// @see ::providerTestGetTermWithParent()
$parent_term_ids = [];
for ($i = 0; $i < $this->entity->get('parent')->count(); $i++) {
$parent_term_ids[$i] = (int) $this->entity->get('parent')[$i]->target_id;
}
$expected_parent_normalization = FALSE;
switch ($parent_term_ids) {
case [0]:
$expected_parent_normalization = [
[
'target_id' => NULL,
],
];
break;
case [2]:
$expected_parent_normalization = [
[
'target_id' => 2,
'target_type' => 'taxonomy_term',
'target_uuid' => Term::load(2)->uuid(),
'url' => base_path() . 'taxonomy/term/2',
],
];
break;
case [0, 2]:
$expected_parent_normalization = [
[
'target_id' => NULL,
],
[
'target_id' => 2,
'target_type' => 'taxonomy_term',
'target_uuid' => Term::load(2)->uuid(),
'url' => base_path() . 'taxonomy/term/2',
],
];
break;
case [3, 2]:
$expected_parent_normalization = [
[
'target_id' => 3,
'target_type' => 'taxonomy_term',
'target_uuid' => Term::load(3)->uuid(),
'url' => base_path() . 'taxonomy/term/3',
],
[
'target_id' => 2,
'target_type' => 'taxonomy_term',
'target_uuid' => Term::load(2)->uuid(),
'url' => base_path() . 'taxonomy/term/2',
],
];
break;
}
return [
'tid' => [
['value' => 1],
],
'uuid' => [
['value' => $this->entity->uuid()],
],
'vid' => [
[
'target_id' => 'camelids',
'target_type' => 'taxonomy_vocabulary',
'target_uuid' => Vocabulary::load('camelids')->uuid(),
],
],
'name' => [
['value' => 'Llama'],
],
'description' => [
[
'value' => 'It is a little known fact that llamas cannot count higher than seven.',
'format' => NULL,
'processed' => "<p>It is a little known fact that llamas cannot count higher than seven.</p>\n",
],
],
'parent' => $expected_parent_normalization,
'weight' => [
['value' => 0],
],
'langcode' => [
[
'value' => 'en',
],
],
'changed' => [
$this->formatExpectedTimestampItemValues($this->entity->getChangedTime()),
],
'default_langcode' => [
[
'value' => TRUE,
],
],
'path' => [
[
'alias' => '/llama',
'pid' => 1,
'langcode' => 'en',
],
],
'status' => [
[
'value' => TRUE,
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return [
'vid' => [
[
'target_id' => 'camelids',
],
],
'name' => [
[
'value' => 'Dramallama',
],
],
'description' => [
[
'value' => 'Dramallamas are the coolest camelids.',
'format' => NULL,
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
switch ($method) {
case 'GET':
return "The 'access content' permission is required and the taxonomy term must be published.";
case 'POST':
return "The following permissions are required: 'create terms in camelids' OR 'administer taxonomy'.";
case 'PATCH':
return "The following permissions are required: 'edit terms in camelids' OR 'administer taxonomy'.";
case 'DELETE':
return "The following permissions are required: 'delete terms in camelids' OR 'administer taxonomy'.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
/**
* Tests PATCHing a term's path.
*
* For a negative test, see the similar test coverage for Node.
*
* @see \Drupal\Tests\rest\Functional\EntityResource\Node\NodeResourceTestBase::testPatchPath()
*/
public function testPatchPath() {
$this->initAuthentication();
$this->provisionEntityResource();
$this->setUpAuthorization('GET');
$this->setUpAuthorization('PATCH');
$url = $this->getEntityResourceUrl()->setOption('query', ['_format' => static::$format]);
// GET term's current normalization.
$response = $this->request('GET', $url, $this->getAuthenticationRequestOptions('GET'));
$normalization = $this->serializer->decode((string) $response->getBody(), static::$format);
// Change term's path alias.
$normalization['path'][0]['alias'] .= 's-rule-the-world';
// Create term PATCH request.
$request_options = [];
$request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
$request_options = array_merge_recursive($request_options, $this->getAuthenticationRequestOptions('PATCH'));
$request_options[RequestOptions::BODY] = $this->serializer->encode($normalization, static::$format);
// PATCH request: 200.
$response = $this->request('PATCH', $url, $request_options);
$this->assertResourceResponse(200, FALSE, $response);
$updated_normalization = $this->serializer->decode((string) $response->getBody(), static::$format);
$this->assertSame($normalization['path'], $updated_normalization['path']);
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheTags() {
return Cache::mergeTags(parent::getExpectedCacheTags(), ['config:filter.format.plain_text', 'config:filter.settings']);
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return Cache::mergeContexts(['url.site'], $this->container->getParameter('renderer.config')['required_cache_contexts']);
}
/**
* Tests GETting a term with a parent term other than the default <root> (0).
*
* @see ::getExpectedNormalizedEntity()
*
* @dataProvider providerTestGetTermWithParent
*/
public function testGetTermWithParent(array $parent_term_ids) {
// Create all possible parent terms.
Term::create(['vid' => Vocabulary::load('camelids')->id()])
->setName('Lamoids')
->save();
Term::create(['vid' => Vocabulary::load('camelids')->id()])
->setName('Wimoids')
->save();
// Modify the entity under test to use the provided parent terms.
$this->entity->set('parent', $parent_term_ids)->save();
$this->initAuthentication();
$url = $this->getEntityResourceUrl();
$url->setOption('query', ['_format' => static::$format]);
$request_options = $this->getAuthenticationRequestOptions('GET');
$this->provisionEntityResource();
$this->setUpAuthorization('GET');
$response = $this->request('GET', $url, $request_options);
$expected = $this->getExpectedNormalizedEntity();
static::recursiveKSort($expected);
$actual = $this->serializer->decode((string) $response->getBody(), static::$format);
static::recursiveKSort($actual);
$this->assertSame($expected, $actual);
}
public function providerTestGetTermWithParent() {
return [
'root parent: [0] (= no parent)' => [
[0],
],
'non-root parent: [2]' => [
[2],
],
'multiple parents: [0,2] (root + non-root parent)' => [
[0, 2],
],
'multiple parents: [3,2] (both non-root parents)' => [
[3, 2],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessCacheability() {
// @see \Drupal\taxonomy\TermAccessControlHandler::checkAccess()
return parent::getExpectedUnauthorizedAccessCacheability()
->addCacheTags(['taxonomy_term:1']);
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class TermXmlAnonTest extends TermResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
public function testPatchPath() {
// Deserialization of the XML format is not supported.
$this->markTestSkipped();
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class TermXmlBasicAuthTest extends TermResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
/**
* {@inheritdoc}
*/
public function testPatchPath() {
// Deserialization of the XML format is not supported.
$this->markTestSkipped();
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class TermXmlCookieTest extends TermResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
/**
* {@inheritdoc}
*/
public function testPatchPath() {
// Deserialization of the XML format is not supported.
$this->markTestSkipped();
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class VocabularyJsonAnonTest extends VocabularyResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* Disable the GET test coverage due to bug in taxonomy module.
* @todo Fix in https://www.drupal.org/node/2805281: remove this override.
*/
public function testGet() {
$this->markTestSkipped();
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class VocabularyJsonBasicAuthTest extends VocabularyResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class VocabularyJsonCookieTest extends VocabularyResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,83 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class VocabularyResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'taxonomy_vocabulary';
/**
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer taxonomy']);
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
$vocabulary = Vocabulary::create([
'name' => 'Llama',
'vid' => 'llama',
]);
$vocabulary->save();
return $vocabulary;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'uuid' => $this->entity->uuid(),
'vid' => 'llama',
'langcode' => 'en',
'status' => TRUE,
'dependencies' => [],
'name' => 'Llama',
'description' => NULL,
'hierarchy' => 0,
'weight' => 0,
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update in https://www.drupal.org/node/2300677.
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
if ($method === 'GET') {
return "The following permissions are required: 'access taxonomy overview' OR 'administer taxonomy'.";
}
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class VocabularyXmlAnonTest extends VocabularyResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class VocabularyXmlBasicAuthTest extends VocabularyResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}

View file

@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class VocabularyXmlCookieTest extends VocabularyResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}

View file

@ -0,0 +1,135 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\views\Views;
/**
* Ensure that data added as terms appears in RSS feeds if "RSS Category" format
* is selected.
*
* @group taxonomy
*/
class RssTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'field_ui', 'views'];
/**
* Vocabulary for testing.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
/**
* Name of the taxonomy term reference field.
*
* @var string
*/
protected $fieldName;
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access', 'administer content types', 'administer node display']));
$this->vocabulary = $this->createVocabulary();
$this->fieldName = 'taxonomy_' . $this->vocabulary->id();
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
'auto_create' => TRUE,
];
$this->createEntityReferenceField('node', 'article', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName, [
'type' => 'options_select',
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName, [
'type' => 'entity_reference_label',
])
->save();
}
/**
* Tests that terms added to nodes are displayed in core RSS feed.
*
* Create a node and assert that taxonomy terms appear in rss.xml.
*/
public function testTaxonomyRss() {
// Create two taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
// RSS display must be added manually.
$this->drupalGet("admin/structure/types/manage/article/display");
$edit = [
"display_modes_custom[rss]" => '1',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
// Change the format to 'RSS category'.
$this->drupalGet("admin/structure/types/manage/article/display/rss");
$edit = [
"fields[taxonomy_" . $this->vocabulary->id() . "][type]" => 'entity_reference_rss_category',
"fields[taxonomy_" . $this->vocabulary->id() . "][region]" => 'content',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
// Post an article.
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit[$this->fieldName . '[]'] = $term1->id();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
// Check that the term is displayed when the RSS feed is viewed.
$this->drupalGet('rss.xml');
$test_element = sprintf(
'<category %s>%s</category>',
'domain="' . $term1->url('canonical', ['absolute' => TRUE]) . '"',
$term1->getName()
);
$this->assertRaw($test_element, 'Term is displayed when viewing the rss feed.');
// Test that the feed icon exists for the term.
$this->drupalGet("taxonomy/term/{$term1->id()}");
$this->assertLinkByHref("taxonomy/term/{$term1->id()}/feed");
// Test that the feed page exists for the term.
$this->drupalGet("taxonomy/term/{$term1->id()}/feed");
$assert = $this->assertSession();
$assert->responseHeaderContains('Content-Type', 'application/rss+xml');
// Ensure the RSS version is 2.0.
$rss_array = $this->getSession()->getDriver()->find('rss');
$this->assertEquals('2.0', reset($rss_array)->getAttribute('version'));
// Check that the "Exception value" is disabled by default.
$this->drupalGet('taxonomy/term/all/feed');
$this->assertResponse(404);
// Set the exception value to 'all'.
$view = Views::getView('taxonomy_term');
$arguments = $view->getDisplay()->getOption('arguments');
$arguments['tid']['exception']['value'] = 'all';
$view->getDisplay()->overrideOption('arguments', $arguments);
$view->storage->save();
// Check the article is shown in the feed.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$raw_xml = '<title>' . $node->label() . '</title>';
$this->drupalGet('taxonomy/term/all/feed');
$this->assertRaw($raw_xml, "Raw text '$raw_xml' is found.");
// Unpublish the article and check that it is not shown in the feed.
$node->setUnpublished()->save();
$this->drupalGet('taxonomy/term/all/feed');
$this->assertNoRaw($raw_xml);
}
}

View file

@ -0,0 +1,103 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\TestFileCreationTrait;
use Drupal\user\RoleInterface;
use Drupal\file\Entity\File;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests access checks of private image fields.
*
* @group taxonomy
*/
class TaxonomyImageTest extends TaxonomyTestBase {
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
compareFiles as drupalCompareFiles;
}
/**
* Used taxonomy vocabulary.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['image'];
protected function setUp() {
parent::setUp();
// Remove access content permission from registered users.
user_role_revoke_permissions(RoleInterface::AUTHENTICATED_ID, ['access content']);
$this->vocabulary = $this->createVocabulary();
// Add a field to the vocabulary.
$entity_type = 'taxonomy_term';
$name = 'field_test';
FieldStorageConfig::create([
'field_name' => $name,
'entity_type' => $entity_type,
'type' => 'image',
'settings' => [
'uri_scheme' => 'private',
],
])->save();
FieldConfig::create([
'field_name' => $name,
'entity_type' => $entity_type,
'bundle' => $this->vocabulary->id(),
'settings' => [],
])->save();
entity_get_display($entity_type, $this->vocabulary->id(), 'default')
->setComponent($name, [
'type' => 'image',
'settings' => [],
])
->save();
entity_get_form_display($entity_type, $this->vocabulary->id(), 'default')
->setComponent($name, [
'type' => 'image_image',
'settings' => [],
])
->save();
}
public function testTaxonomyImageAccess() {
$user = $this->drupalCreateUser(['administer site configuration', 'administer taxonomy', 'access user profiles']);
$this->drupalLogin($user);
// Create a term and upload the image.
$files = $this->drupalGetTestFiles('image');
$image = array_pop($files);
$edit['name[0][value]'] = $this->randomMachineName();
$edit['files[field_test_0]'] = \Drupal::service('file_system')->realpath($image->uri);
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
$this->drupalPostForm(NULL, ['field_test[0][alt]' => $this->randomMachineName()], t('Save'));
$terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $edit['name[0][value]']]);
$term = reset($terms);
$this->assertText(t('Created new term @name.', ['@name' => $term->getName()]));
// Create a user that should have access to the file and one that doesn't.
$access_user = $this->drupalCreateUser(['access content']);
$no_access_user = $this->drupalCreateUser();
$image = File::load($term->field_test->target_id);
$this->drupalLogin($access_user);
$this->drupalGet(file_create_url($image->getFileUri()));
$this->assertResponse(200, 'Private image on term is accessible with right permission');
$this->drupalLogin($no_access_user);
$this->drupalGet(file_create_url($image->getFileUri()));
$this->assertResponse(403, 'Private image on term not accessible without right permission');
}
}

View file

@ -0,0 +1,119 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests that appropriate query tags are added.
*
* @group taxonomy
*/
class TaxonomyQueryAlterTest extends BrowserTestBase {
use TaxonomyTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy', 'taxonomy_test'];
/**
* Tests that appropriate tags are added when querying the database.
*/
public function testTaxonomyQueryAlter() {
// Create a new vocabulary and add a few terms to it.
$vocabulary = $this->createVocabulary();
$terms = [];
for ($i = 0; $i < 5; $i++) {
$terms[$i] = $this->createTerm($vocabulary);
}
// Set up hierarchy. Term 2 is a child of 1.
$terms[2]->parent = $terms[1]->id();
$terms[2]->save();
$term_storage = \Drupal::entityManager()->getStorage('taxonomy_term');
$this->setupQueryTagTestHooks();
$loaded_term = $term_storage->load($terms[0]->id());
$this->assertEqual($loaded_term->id(), $terms[0]->id(), 'First term was loaded');
$this->assertQueryTagTestResult(1, 0, 'TermStorage::load()');
$this->setupQueryTagTestHooks();
$loaded_terms = $term_storage->loadTree($vocabulary->id());
$this->assertEqual(count($loaded_terms), count($terms), 'All terms were loaded');
$this->assertQueryTagTestResult(1, 1, 'TermStorage::loadTree()');
$this->setupQueryTagTestHooks();
$loaded_terms = $term_storage->loadParents($terms[2]->id());
$this->assertEqual(count($loaded_terms), 1, 'All parent terms were loaded');
$this->assertQueryTagTestResult(3, 1, 'TermStorage::loadParents()');
$this->setupQueryTagTestHooks();
$loaded_terms = $term_storage->loadChildren($terms[1]->id());
$this->assertEqual(count($loaded_terms), 1, 'All child terms were loaded');
$this->assertQueryTagTestResult(3, 1, 'TermStorage::loadChildren()');
$this->setupQueryTagTestHooks();
$query = db_select('taxonomy_term_data', 't');
$query->addField('t', 'tid');
$query->addTag('taxonomy_term_access');
$tids = $query->execute()->fetchCol();
$this->assertEqual(count($tids), count($terms), 'All term IDs were retrieved');
$this->assertQueryTagTestResult(1, 1, 'custom db_select() with taxonomy_term_access tag (preferred)');
$this->setupQueryTagTestHooks();
$query = db_select('taxonomy_term_data', 't');
$query->addField('t', 'tid');
$query->addTag('term_access');
$tids = $query->execute()->fetchCol();
$this->assertEqual(count($tids), count($terms), 'All term IDs were retrieved');
$this->assertQueryTagTestResult(1, 1, 'custom db_select() with term_access tag (deprecated)');
$this->setupQueryTagTestHooks();
$query = \Drupal::entityQuery('taxonomy_term');
$query->addTag('taxonomy_term_access');
$result = $query->execute();
$this->assertEqual(count($result), count($terms), 'All term IDs were retrieved');
$this->assertQueryTagTestResult(1, 1, 'custom EntityFieldQuery with taxonomy_term_access tag (preferred)');
$this->setupQueryTagTestHooks();
$query = \Drupal::entityQuery('taxonomy_term');
$query->addTag('term_access');
$result = $query->execute();
$this->assertEqual(count($result), count($terms), 'All term IDs were retrieved');
$this->assertQueryTagTestResult(1, 1, 'custom EntityFieldQuery with term_access tag (deprecated)');
}
/**
* Sets up the hooks in the test module.
*/
protected function setupQueryTagTestHooks() {
taxonomy_terms_static_reset();
\Drupal::state()->set('taxonomy_test_query_alter', 0);
\Drupal::state()->set('taxonomy_test_query_term_access_alter', 0);
\Drupal::state()->set('taxonomy_test_query_taxonomy_term_access_alter', 0);
}
/**
* Verifies invocation of the hooks in the test module.
*
* @param int $expected_generic_invocations
* The number of times the generic query_alter hook is expected to have
* been invoked.
* @param int $expected_specific_invocations
* The number of times the tag-specific query_alter hooks are expected to
* have been invoked.
* @param string $method
* A string describing the invoked function which generated the query.
*/
protected function assertQueryTagTestResult($expected_generic_invocations, $expected_specific_invocations, $method) {
$this->assertIdentical($expected_generic_invocations, \Drupal::state()->get('taxonomy_test_query_alter'), 'hook_query_alter() invoked when executing ' . $method);
$this->assertIdentical($expected_specific_invocations, \Drupal::state()->get('taxonomy_test_query_term_access_alter'), 'Deprecated hook_query_term_access_alter() invoked when executing ' . $method);
$this->assertIdentical($expected_specific_invocations, \Drupal::state()->get('taxonomy_test_query_taxonomy_term_access_alter'), 'Preferred hook_query_taxonomy_term_access_alter() invoked when executing ' . $method);
}
}

View file

@ -0,0 +1,95 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
/**
* Ensure that the term indentation works properly.
*
* @group taxonomy
*/
class TaxonomyTermIndentationTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy'];
/**
* Vocabulary for testing.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
$this->vocabulary = $this->createVocabulary();
}
/**
* Tests term indentation.
*/
public function testTermIndentation() {
$assert = $this->assertSession();
// Create three taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
$term3 = $this->createTerm($this->vocabulary);
// Get the taxonomy storage.
$taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
// Indent the second term under the first one.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview');
$hidden_edit = [
'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
'terms[tid:' . $term2->id() . ':0][term][parent]' => 1,
'terms[tid:' . $term2->id() . ':0][term][depth]' => 1,
];
// Because we can't post hidden form elements, we have to change them in
// code here, and then submit.
foreach ($hidden_edit as $field => $value) {
$node = $assert->hiddenFieldExists($field);
$node->setValue($value);
}
$edit = [
'terms[tid:' . $term2->id() . ':0][weight]' => 1,
];
// Submit the edited form and check for HTML indentation element presence.
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertPattern('|<div class="js-indentation indentation">&nbsp;</div>|');
// Check explicitly that term 2's parent is term 1.
$parents = $taxonomy_storage->loadParents($term2->id());
$this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent');
// Move the second term back out to the root level.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview');
$hidden_edit = [
'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
];
// Because we can't post hidden form elements, we have to change them in
// code here, and then submit.
foreach ($hidden_edit as $field => $value) {
$node = $assert->hiddenFieldExists($field);
$node->setValue($value);
}
$edit = [
'terms[tid:' . $term2->id() . ':0][weight]' => 1,
];
$this->drupalPostForm(NULL, $edit, t('Save'));
// All terms back at the root level, no indentation should be present.
$this->assertSession()->responseNotMatches('|<div class="js-indentation indentation">&nbsp;</div>|');
// Check explicitly that term 2 has no parents.
\Drupal::entityManager()->getStorage('taxonomy_term')->resetCache();
$parents = $taxonomy_storage->loadParents($term2->id());
$this->assertTrue(empty($parents), 'Term 2 has no parents now');
}
}

View file

@ -0,0 +1,67 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
/**
* Ensures that the term pager works properly.
*
* @group taxonomy
*/
class TaxonomyTermPagerTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy'];
/**
* Vocabulary for testing.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
$this->vocabulary = $this->createVocabulary();
}
/**
* Tests that the pager is displayed properly on the term overview page.
*/
public function testTaxonomyTermOverviewPager() {
// Set limit to 3 terms per page.
$this->config('taxonomy.settings')
->set('terms_per_page_admin', '3')
->save();
// Create 3 terms.
for ($x = 1; $x <= 3; $x++) {
$this->createTerm($this->vocabulary);
}
// Get Page 1.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertNoPattern('|<nav class="pager" [^>]*>|', 'Pager is not visible on page 1');
// Create 3 more terms to show pager.
for ($x = 1; $x <= 3; $x++) {
$this->createTerm($this->vocabulary);
}
// Get Page 1.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertPattern('|<nav class="pager" [^>]*>|', 'Pager is visible on page 1');
// Get Page 2.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 1]]);
$this->assertPattern('|<nav class="pager" [^>]*>|', 'Pager is visible on page 2');
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Provides common helper methods for Taxonomy module tests.
*/
abstract class TaxonomyTestBase extends BrowserTestBase {
use TaxonomyTestTrait;
use EntityReferenceTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy', 'block'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('system_breadcrumb_block');
// Create Basic page and Article node types.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
}
}
}

View file

@ -0,0 +1,59 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Provides common helper methods for Taxonomy module tests.
*/
trait TaxonomyTestTrait {
/**
* Returns a new vocabulary with random properties.
*/
public function createVocabulary() {
// Create a vocabulary.
$vocabulary = Vocabulary::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'vid' => mb_strtolower($this->randomMachineName()),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'weight' => mt_rand(0, 10),
]);
$vocabulary->save();
return $vocabulary;
}
/**
* Returns a new term with random properties in vocabulary $vid.
*
* @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary
* The vocabulary object.
* @param array $values
* (optional) An array of values to set, keyed by property name. If the
* entity type has bundles, the bundle key has to be specified.
*
* @return \Drupal\taxonomy\Entity\Term
* The new taxonomy term object.
*/
public function createTerm(Vocabulary $vocabulary, $values = []) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = Term::create($values + [
'name' => $this->randomMachineName(),
'description' => [
'value' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->id(),
],
'vid' => $vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
]);
$term->save();
return $term;
}
}

View file

@ -0,0 +1,101 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
/**
* Provides common testing base for translated taxonomy terms.
*/
trait TaxonomyTranslationTestTrait {
use EntityReferenceTestTrait;
/**
* The vocabulary.
*
* @var \Drupal\taxonomy\Entity\Vocabulary
*/
protected $vocabulary;
/**
* The field name for our taxonomy term field.
*
* @var string
*/
protected $termFieldName = 'field_tag';
/**
* The langcode of the source language.
*
* @var string
*/
protected $baseLangcode = 'en';
/**
* Target langcode for translation.
*
* @var string
*/
protected $translateToLangcode = 'hu';
/**
* The node to check the translated value on.
*
* @var \Drupal\node\Entity\Node
*/
protected $node;
/**
* Adds additional languages.
*/
protected function setupLanguages() {
ConfigurableLanguage::createFromLangcode($this->translateToLangcode)->save();
$this->rebuildContainer();
}
/**
* Enables translations where it needed.
*/
protected function enableTranslation() {
// Enable translation for the current entity type and ensure the change is
// picked up.
\Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
\Drupal::service('content_translation.manager')->setEnabled('taxonomy_term', $this->vocabulary->id(), TRUE);
drupal_static_reset();
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::service('router.builder')->rebuild();
\Drupal::service('entity.definition_update_manager')->applyUpdates();
}
/**
* Adds term reference field for the article content type.
*/
protected function setUpTermReferenceField() {
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
'auto_create' => TRUE,
];
$this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
$field_storage->setTranslatable(FALSE);
$field_storage->save();
entity_get_form_display('node', 'article', 'default')
->setComponent($this->termFieldName, [
'type' => 'entity_reference_autocomplete_tags',
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->termFieldName, [
'type' => 'entity_reference_label',
])
->save();
}
}

View file

@ -0,0 +1,124 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\TermInterface;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
/**
* Tests the taxonomy term access permissions.
*
* @group taxonomy
*/
class TermAccessTest extends TaxonomyTestBase {
use AssertPageCacheContextsAndTagsTrait;
/**
* Test access control functionality for taxonomy terms.
*/
public function testTermAccess() {
$assert_session = $this->assertSession();
$vocabulary = $this->createVocabulary();
// Create two terms.
$published_term = Term::create([
'vid' => $vocabulary->id(),
'name' => 'Published term',
'status' => 1,
]);
$published_term->save();
$unpublished_term = Term::create([
'vid' => $vocabulary->id(),
'name' => 'Unpublished term',
'status' => 0,
]);
$unpublished_term->save();
// Start off logged in as admin.
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
// Test the 'administer taxonomy' permission.
$this->drupalGet('taxonomy/term/' . $published_term->id());
$assert_session->statusCodeEquals(200);
$this->assertTermAccess($published_term, 'view', TRUE);
$this->drupalGet('taxonomy/term/' . $unpublished_term->id());
$assert_session->statusCodeEquals(200);
$this->assertTermAccess($unpublished_term, 'view', TRUE);
$this->drupalGet('taxonomy/term/' . $published_term->id() . '/edit');
$assert_session->statusCodeEquals(200);
$this->assertTermAccess($published_term, 'update', TRUE);
$this->drupalGet('taxonomy/term/' . $unpublished_term->id() . '/edit');
$assert_session->statusCodeEquals(200);
$this->assertTermAccess($unpublished_term, 'update', TRUE);
$this->drupalGet('taxonomy/term/' . $published_term->id() . '/delete');
$assert_session->statusCodeEquals(200);
$this->assertTermAccess($published_term, 'delete', TRUE);
$this->drupalGet('taxonomy/term/' . $unpublished_term->id() . '/delete');
$assert_session->statusCodeEquals(200);
$this->assertTermAccess($unpublished_term, 'delete', TRUE);
// Test the 'access content' permission.
$this->drupalLogin($this->drupalCreateUser(['access content']));
$this->drupalGet('taxonomy/term/' . $published_term->id());
$assert_session->statusCodeEquals(200);
$this->assertTermAccess($published_term, 'view', TRUE);
$this->drupalGet('taxonomy/term/' . $unpublished_term->id());
$assert_session->statusCodeEquals(403);
$this->assertTermAccess($unpublished_term, 'view', FALSE, "The 'access content' permission is required and the taxonomy term must be published.");
$this->drupalGet('taxonomy/term/' . $published_term->id() . '/edit');
$assert_session->statusCodeEquals(403);
$this->assertTermAccess($published_term, 'update', FALSE, "The following permissions are required: 'edit terms in {$vocabulary->id()}' OR 'administer taxonomy'.");
$this->drupalGet('taxonomy/term/' . $unpublished_term->id() . '/edit');
$assert_session->statusCodeEquals(403);
$this->assertTermAccess($unpublished_term, 'update', FALSE, "The following permissions are required: 'edit terms in {$vocabulary->id()}' OR 'administer taxonomy'.");
$this->drupalGet('taxonomy/term/' . $published_term->id() . '/delete');
$assert_session->statusCodeEquals(403);
$this->assertTermAccess($published_term, 'delete', FALSE, "The following permissions are required: 'delete terms in {$vocabulary->id()}' OR 'administer taxonomy'.");
$this->drupalGet('taxonomy/term/' . $unpublished_term->id() . '/delete');
$assert_session->statusCodeEquals(403);
$this->assertTermAccess($unpublished_term, 'delete', FALSE, "The following permissions are required: 'delete terms in {$vocabulary->id()}' OR 'administer taxonomy'.");
// Install the Views module and repeat the checks for the 'view' permission.
\Drupal::service('module_installer')->install(['views'], TRUE);
$this->rebuildContainer();
$this->drupalGet('taxonomy/term/' . $published_term->id());
$assert_session->statusCodeEquals(200);
// @todo Change this assertion to expect a 403 status code when
// https://www.drupal.org/project/drupal/issues/2983070 is fixed.
$this->drupalGet('taxonomy/term/' . $unpublished_term->id());
$assert_session->statusCodeEquals(404);
}
/**
* Checks access on taxonomy term.
*
* @param \Drupal\taxonomy\TermInterface $term
* A taxonomy term entity.
* @param $access_operation
* The entity operation, e.g. 'view', 'edit', 'delete', etc.
* @param bool $access_allowed
* Whether the current use has access to the given operation or not.
* @param string $access_reason
* (optional) The reason of the access result.
*/
protected function assertTermAccess(TermInterface $term, $access_operation, $access_allowed, $access_reason = '') {
$access_result = $term->access($access_operation, NULL, TRUE);
$this->assertSame($access_allowed, $access_result->isAllowed());
if ($access_reason) {
$this->assertSame($access_reason, $access_result->getReason());
}
}
}

View file

@ -0,0 +1,229 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the autocomplete implementation of the taxonomy class.
*
* @group taxonomy
*/
class TermAutocompleteTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node'];
/**
* The vocabulary.
*
* @var \Drupal\taxonomy\Entity\Vocabulary
*/
protected $vocabulary;
/**
* The field to add to the content type for the taxonomy terms.
*
* @var string
*/
protected $fieldName;
/**
* The admin user.
*
* @var \Drupal\user\Entity\User
*/
protected $adminUser;
/**
* The autocomplete URL to call.
*
* @var string
*/
protected $autocompleteUrl;
/**
* The term IDs indexed by term names.
*
* @var array
*/
protected $termIds;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create a vocabulary.
$this->vocabulary = $this->createVocabulary();
// Create 11 terms, which have some sub-string in common, in a
// non-alphabetical order, so that we will have more than 10 matches later
// when we test the correct number of results is returned, and we can test
// the order of the results. The location of the sub-string to match varies
// also, since it should not be necessary to start with the sub-string to
// match it. Save term IDs to reuse later.
$termNames = [
'aaa 20 bbb',
'aaa 70 bbb',
'aaa 10 bbb',
'aaa 12 bbb',
'aaa 40 bbb',
'aaa 11 bbb',
'aaa 30 bbb',
'aaa 50 bbb',
'aaa 80',
'aaa 90',
'bbb 60 aaa',
];
foreach ($termNames as $termName) {
$term = $this->createTerm($this->vocabulary, ['name' => $termName]);
$this->termIds[$termName] = $term->id();
}
// Create a taxonomy_term_reference field on the article Content Type that
// uses a taxonomy_autocomplete widget.
$this->fieldName = mb_strtolower($this->randomMachineName());
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'target_type' => 'taxonomy_term',
],
])->save();
FieldConfig::create([
'field_name' => $this->fieldName,
'bundle' => 'article',
'entity_type' => 'node',
'settings' => [
'handler' => 'default',
'handler_settings' => [
// Restrict selection of terms to a single vocabulary.
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
],
],
])->save();
EntityFormDisplay::load('node.article.default')
->setComponent($this->fieldName, [
'type' => 'entity_reference_autocomplete',
])
->save();
EntityViewDisplay::load('node.article.default')
->setComponent($this->fieldName, [
'type' => 'entity_reference_label',
])
->save();
// Create a user and then login.
$this->adminUser = $this->drupalCreateUser(['create article content']);
$this->drupalLogin($this->adminUser);
// Retrieve the autocomplete url.
$this->drupalGet('node/add/article');
$result = $this->xpath('//input[@name="' . $this->fieldName . '[0][target_id]"]');
$this->autocompleteUrl = $this->getAbsoluteUrl($result[0]->getAttribute('data-autocomplete-path'));
}
/**
* Helper function for JSON formatted requests.
*
* @param string|\Drupal\Core\Url $path
* Drupal path or URL to load into Mink controlled browser.
* @param array $options
* (optional) Options to be forwarded to the url generator.
* @param string[] $headers
* (optional) An array containing additional HTTP request headers.
*
* @return string[]
* Array representing decoded JSON response.
*/
protected function drupalGetJson($path, array $options = [], array $headers = []) {
$options = array_merge_recursive(['query' => ['_format' => 'json']], $options);
return Json::decode($this->drupalGet($path, $options, $headers));
}
/**
* Tests that the autocomplete method returns the good number of results.
*
* @see \Drupal\taxonomy\Controller\TermAutocompleteController::autocomplete()
*/
public function testAutocompleteCountResults() {
// Test that no matching term found.
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'zzz']]
);
$this->assertTrue(empty($data), 'Autocomplete returned no results');
// Test that only one matching term found, when only one matches.
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'aaa 10']]
);
$this->assertEqual(1, count($data), 'Autocomplete returned 1 result');
// Test the correct number of matches when multiple are partial matches.
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'aaa 1']]
);
$this->assertEqual(3, count($data), 'Autocomplete returned 3 results');
// Tests that only 10 results are returned, even if there are more than 10
// matches.
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'aaa']]
);
$this->assertEqual(10, count($data), 'Autocomplete returned only 10 results (for over 10 matches)');
}
/**
* Tests that the autocomplete method returns properly ordered results.
*
* @see \Drupal\taxonomy\Controller\TermAutocompleteController::autocomplete()
*/
public function testAutocompleteOrderedResults() {
$expectedResults = [
'aaa 10 bbb',
'aaa 11 bbb',
'aaa 12 bbb',
'aaa 20 bbb',
'aaa 30 bbb',
'aaa 40 bbb',
'aaa 50 bbb',
'aaa 70 bbb',
'bbb 60 aaa',
];
// Build $expected to match the autocomplete results.
$expected = [];
foreach ($expectedResults as $termName) {
$expected[] = [
'value' => $termName . ' (' . $this->termIds[$termName] . ')',
'label' => $termName,
];
}
$data = $this->drupalGetJson(
$this->autocompleteUrl,
['query' => ['q' => 'bbb']]
);
$this->assertIdentical($expected, $data);
}
}

View file

@ -0,0 +1,42 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
use Drupal\Tests\system\Functional\Entity\EntityWithUriCacheTagsTestBase;
/**
* Tests the Taxonomy term entity's cache tags.
*
* @group taxonomy
*/
class TermCacheTagsTest extends EntityWithUriCacheTagsTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Create a "Camelids" vocabulary.
$vocabulary = Vocabulary::create([
'name' => 'Camelids',
'vid' => 'camelids',
]);
$vocabulary->save();
// Create a "Llama" taxonomy term.
$term = Term::create([
'name' => 'Llama',
'vid' => $vocabulary->id(),
]);
$term->save();
return $term;
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
/**
* Tests views contextual links on terms.
*
* @group taxonomy
*/
class TermContextualLinksTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'contextual',
];
/**
* Tests contextual links.
*/
public function testTermContextualLinks() {
$vocabulary = $this->createVocabulary();
$term = $this->createTerm($vocabulary);
$user = $this->drupalCreateUser([
'administer taxonomy',
'access contextual links',
]);
$this->drupalLogin($user);
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertSession()->elementAttributeContains('css', 'div[data-contextual-id]', 'data-contextual-id', 'taxonomy_term:taxonomy_term=' . $term->id() . ':');
}
}

View file

@ -0,0 +1,79 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
/**
* Tests the settings of restricting term selection to a single vocabulary.
*
* @group taxonomy
*/
class TermEntityReferenceTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['entity_reference_test', 'entity_test'];
/**
* Tests an entity reference field restricted to a single vocabulary.
*
* Creates two vocabularies with a term, then set up the entity reference
* field to limit the target vocabulary to one of them, ensuring that
* the restriction applies.
*/
public function testSelectionTestVocabularyRestriction() {
// Create two vocabularies.
$vocabulary = $this->createVocabulary();
$vocabulary2 = $this->createVocabulary();
$term = $this->createTerm($vocabulary);
$term2 = $this->createTerm($vocabulary2);
// Create an entity reference field.
$field_name = 'taxonomy_' . $vocabulary->id();
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'translatable' => FALSE,
'settings' => [
'target_type' => 'taxonomy_term',
],
'type' => 'entity_reference',
'cardinality' => 1,
]);
$field_storage->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'entity_type' => 'entity_test',
'bundle' => 'test_bundle',
'settings' => [
'handler' => 'default',
'handler_settings' => [
// Restrict selection of terms to a single vocabulary.
'target_bundles' => [
$vocabulary->id() => $vocabulary->id(),
],
],
],
]);
$field->save();
$handler = $this->container->get('plugin.manager.entity_reference_selection')->getSelectionHandler($field);
$result = $handler->getReferenceableEntities();
$expected_result = [
$vocabulary->id() => [
$term->id() => $term->getName(),
],
];
$this->assertIdentical($result, $expected_result, 'Terms selection restricted to a single vocabulary.');
}
}

View file

@ -0,0 +1,213 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests the hook implementations that maintain the taxonomy index.
*
* @group taxonomy
*/
class TermIndexTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['views'];
/**
* Vocabulary for testing.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
/**
* Name of the taxonomy term reference field.
*
* @var string
*/
protected $fieldName1;
/**
* Name of the taxonomy term reference field.
*
* @var string
*/
protected $fieldName2;
protected function setUp() {
parent::setUp();
// Create an administrative user.
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
// Create a vocabulary and add two term reference fields to article nodes.
$this->vocabulary = $this->createVocabulary();
$this->fieldName1 = mb_strtolower($this->randomMachineName());
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
'auto_create' => TRUE,
];
$this->createEntityReferenceField('node', 'article', $this->fieldName1, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName1, [
'type' => 'options_select',
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName1, [
'type' => 'entity_reference_label',
])
->save();
$this->fieldName2 = mb_strtolower($this->randomMachineName());
$this->createEntityReferenceField('node', 'article', $this->fieldName2, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName2, [
'type' => 'options_select',
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName2, [
'type' => 'entity_reference_label',
])
->save();
}
/**
* Tests that the taxonomy index is maintained properly.
*/
public function testTaxonomyIndex() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Create terms in the vocabulary.
$term_1 = $this->createTerm($this->vocabulary);
$term_2 = $this->createTerm($this->vocabulary);
// Post an article.
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomMachineName();
$edit["{$this->fieldName1}[]"] = $term_1->id();
$edit["{$this->fieldName2}[]"] = $term_1->id();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
// Check that the term is indexed, and only once.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed once.');
// Update the article to change one term.
$edit["{$this->fieldName1}[]"] = $term_2->id();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
// Check that both terms are indexed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed.');
// Update the article to change another term.
$edit["{$this->fieldName2}[]"] = $term_2->id();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
// Check that only one term is indexed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$this->assertEqual(0, $index_count, 'Term 1 is not indexed.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed once.');
// Redo the above tests without interface.
$node_storage->resetCache([$node->id()]);
$node = $node_storage->load($node->id());
$node->title = $this->randomMachineName();
// Update the article with no term changed.
$node->save();
// Check that the index was not changed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$this->assertEqual(0, $index_count, 'Term 1 is not indexed.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed once.');
// Update the article to change one term.
$node->{$this->fieldName1} = [['target_id' => $term_1->id()]];
$node->save();
// Check that both terms are indexed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed.');
// Update the article to change another term.
$node->{$this->fieldName2} = [['target_id' => $term_1->id()]];
$node->save();
// Check that only one term is indexed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed once.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$this->assertEqual(0, $index_count, 'Term 2 is not indexed.');
}
/**
* Tests that there is a link to the parent term on the child term page.
*/
public function testTaxonomyTermHierarchyBreadcrumbs() {
// Create two taxonomy terms and set term2 as the parent of term1.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
$term1->parent = [$term2->id()];
$term1->save();
// Verify that the page breadcrumbs include a link to the parent term.
$this->drupalGet('taxonomy/term/' . $term1->id());
// Breadcrumbs are not rendered with a language, prevent the term
// language from being added to the options.
$this->assertRaw(\Drupal::l($term2->getName(), $term2->urlInfo('canonical', ['language' => NULL])), 'Parent term link is displayed when viewing the node.');
}
}

View file

@ -0,0 +1,143 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
/**
* Tests the language functionality for the taxonomy terms.
*
* @group taxonomy
*/
class TermLanguageTest extends TaxonomyTestBase {
public static $modules = ['language'];
/**
* Vocabulary for testing.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
protected function setUp() {
parent::setUp();
// Create an administrative user.
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
// Create a vocabulary to which the terms will be assigned.
$this->vocabulary = $this->createVocabulary();
// Add some custom languages.
foreach (['aa', 'bb', 'cc'] as $language_code) {
ConfigurableLanguage::create([
'id' => $language_code,
'label' => $this->randomMachineName(),
])->save();
}
}
public function testTermLanguage() {
// Configure the vocabulary to not hide the language selector.
$edit = [
'default_language[language_alterable]' => TRUE,
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
// Add a term.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
// Check that we have the language selector.
$this->assertField('edit-langcode-0-value', t('The language selector field was found on the page.'));
// Submit the term.
$edit = [
'name[0][value]' => $this->randomMachineName(),
'langcode[0][value]' => 'aa',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
$this->assertEqual($term->language()->getId(), $edit['langcode[0][value]'], 'The term contains the correct langcode.');
// Check if on the edit page the language is correct.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->assertOptionSelected('edit-langcode-0-value', $edit['langcode[0][value]'], 'The term language was correctly selected.');
// Change the language of the term.
$edit['langcode[0][value]'] = 'bb';
$this->drupalPostForm('taxonomy/term/' . $term->id() . '/edit', $edit, t('Save'));
// Check again that on the edit page the language is correct.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->assertOptionSelected('edit-langcode-0-value', $edit['langcode[0][value]'], 'The term language was correctly selected.');
}
public function testDefaultTermLanguage() {
// Configure the vocabulary to not hide the language selector, and make the
// default language of the terms fixed.
$edit = [
'default_language[langcode]' => 'bb',
'default_language[language_alterable]' => TRUE,
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode-0-value', 'bb', 'The expected langcode was selected.');
// Make the default language of the terms to be the current interface.
$edit = [
'default_language[langcode]' => 'current_interface',
'default_language[language_alterable]' => TRUE,
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
$this->drupalGet('aa/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode-0-value', 'aa', "The expected langcode, 'aa', was selected.");
$this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode-0-value', 'bb', "The expected langcode, 'bb', was selected.");
// Change the default language of the site and check if the default terms
// language is still correctly selected.
$this->config('system.site')->set('default_langcode', 'cc')->save();
$edit = [
'default_language[langcode]' => LanguageInterface::LANGCODE_SITE_DEFAULT,
'default_language[language_alterable]' => TRUE,
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode-0-value', 'cc', "The expected langcode, 'cc', was selected.");
}
/**
* Tests that translated terms are displayed correctly on the term overview.
*/
public function testTermTranslatedOnOverviewPage() {
// Configure the vocabulary to not hide the language selector.
$edit = [
'default_language[language_alterable]' => TRUE,
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
// Add a term.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
// Submit the term.
$edit = [
'name[0][value]' => $this->randomMachineName(),
'langcode[0][value]' => 'aa',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
// Add a translation for that term.
$translated_title = $this->randomMachineName();
$term->addTranslation('bb', [
'name' => $translated_title,
]);
$term->save();
// Overview page in the other language shows the translated term
$this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertPattern('|<a[^>]*>' . $translated_title . '</a>|', 'The term language is correct');
}
}

View file

@ -0,0 +1,606 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Utility\Tags;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests load, save and delete for taxonomy terms.
*
* @group taxonomy
*/
class TermTest extends TaxonomyTestBase {
/**
* Vocabulary for testing.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
/**
* Taxonomy term reference field for testing.
*
* @var \Drupal\field\FieldConfigInterface
*/
protected $field;
/**
* Modules to enable.
*
* @var string[]
*/
public static $modules = ['block'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('local_actions_block');
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('page_title_block');
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
$this->vocabulary = $this->createVocabulary();
$field_name = 'taxonomy_' . $this->vocabulary->id();
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
'auto_create' => TRUE,
];
$this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$this->field = FieldConfig::loadByName('node', 'article', $field_name);
entity_get_form_display('node', 'article', 'default')
->setComponent($field_name, [
'type' => 'options_select',
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($field_name, [
'type' => 'entity_reference_label',
])
->save();
}
/**
* The "parent" field must restrict references to the same vocabulary.
*/
public function testParentHandlerSettings() {
$vocabulary_fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('taxonomy_term', $this->vocabulary->id());
$parent_target_bundles = $vocabulary_fields['parent']->getSetting('handler_settings')['target_bundles'];
$this->assertIdentical([$this->vocabulary->id() => $this->vocabulary->id()], $parent_target_bundles);
}
/**
* Test terms in a single and multiple hierarchy.
*/
public function testTaxonomyTermHierarchy() {
// Create two taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
// Get the taxonomy storage.
$taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
// Check that hierarchy is flat.
$vocabulary = Vocabulary::load($this->vocabulary->id());
$this->assertEqual(0, $vocabulary->getHierarchy(), 'Vocabulary is flat.');
// Edit $term2, setting $term1 as parent.
$edit = [];
$edit['parent[]'] = [$term1->id()];
$this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));
// Check the hierarchy.
$children = $taxonomy_storage->loadChildren($term1->id());
$parents = $taxonomy_storage->loadParents($term2->id());
$this->assertTrue(isset($children[$term2->id()]), 'Child found correctly.');
$this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.');
// Load and save a term, confirming that parents are still set.
$term = Term::load($term2->id());
$term->save();
$parents = $taxonomy_storage->loadParents($term2->id());
$this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.');
// Create a third term and save this as a parent of term2.
$term3 = $this->createTerm($this->vocabulary);
$term2->parent = [$term1->id(), $term3->id()];
$term2->save();
$parents = $taxonomy_storage->loadParents($term2->id());
$this->assertTrue(isset($parents[$term1->id()]) && isset($parents[$term3->id()]), 'Both parents found successfully.');
}
/**
* Tests that many terms with parents show on each page
*/
public function testTaxonomyTermChildTerms() {
// Set limit to 10 terms per page. Set variable to 9 so 10 terms appear.
$this->config('taxonomy.settings')->set('terms_per_page_admin', '9')->save();
$term1 = $this->createTerm($this->vocabulary);
$terms_array = [];
$taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
// Create 40 terms. Terms 1-12 get parent of $term1. All others are
// individual terms.
for ($x = 1; $x <= 40; $x++) {
$edit = [];
// Set terms in order so we know which terms will be on which pages.
$edit['weight'] = $x;
// Set terms 1-20 to be children of first term created.
if ($x <= 12) {
$edit['parent'] = $term1->id();
}
$term = $this->createTerm($this->vocabulary, $edit);
$children = $taxonomy_storage->loadChildren($term1->id());
$parents = $taxonomy_storage->loadParents($term->id());
$terms_array[$x] = Term::load($term->id());
}
// Get Page 1.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertText($term1->getName(), 'Parent Term is displayed on Page 1');
for ($x = 1; $x <= 13; $x++) {
$this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 1');
}
// Get Page 2.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 1]]);
$this->assertText($term1->getName(), 'Parent Term is displayed on Page 2');
for ($x = 1; $x <= 18; $x++) {
$this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 2');
}
// Get Page 3.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 2]]);
$this->assertNoText($term1->getName(), 'Parent Term is not displayed on Page 3');
for ($x = 1; $x <= 17; $x++) {
$this->assertNoText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' not found on Page 3');
}
for ($x = 18; $x <= 25; $x++) {
$this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 3');
}
}
/**
* Test that hook_node_$op implementations work correctly.
*
* Save & edit a node and assert that taxonomy terms are saved/loaded properly.
*/
public function testTaxonomyNode() {
// Create two taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
// Post an article.
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomMachineName();
$edit[$this->field->getName() . '[]'] = $term1->id();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
// Check that the term is displayed when the node is viewed.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->drupalGet('node/' . $node->id());
$this->assertText($term1->getName(), 'Term is displayed when viewing the node.');
$this->clickLink(t('Edit'));
$this->assertText($term1->getName(), 'Term is displayed when editing the node.');
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertText($term1->getName(), 'Term is displayed after saving the node with no changes.');
// Edit the node with a different term.
$edit[$this->field->getName() . '[]'] = $term2->id();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->drupalGet('node/' . $node->id());
$this->assertText($term2->getName(), 'Term is displayed when viewing the node.');
// Preview the node.
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Preview'));
$this->assertUniqueText($term2->getName(), 'Term is displayed when previewing the node.');
$this->drupalPostForm('node/' . $node->id() . '/edit', NULL, t('Preview'));
$this->assertUniqueText($term2->getName(), 'Term is displayed when previewing the node again.');
}
/**
* Test term creation with a free-tagging vocabulary from the node form.
*/
public function testNodeTermCreationAndDeletion() {
// Enable tags in the vocabulary.
$field = $this->field;
entity_get_form_display($field->getTargetEntityTypeId(), $field->getTargetBundle(), 'default')
->setComponent($field->getName(), [
'type' => 'entity_reference_autocomplete_tags',
'settings' => [
'placeholder' => 'Start typing here.',
],
])
->save();
// Prefix the terms with a letter to ensure there is no clash in the first
// three letters.
// @see https://www.drupal.org/node/2397691
$terms = [
'term1' => 'a' . $this->randomMachineName(),
'term2' => 'b' . $this->randomMachineName(),
'term3' => 'c' . $this->randomMachineName() . ', ' . $this->randomMachineName(),
'term4' => 'd' . $this->randomMachineName(),
];
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomMachineName();
// Insert the terms in a comma separated list. Vocabulary 1 is a
// free-tagging field created by the default profile.
$edit[$field->getName() . '[target_id]'] = Tags::implode($terms);
// Verify the placeholder is there.
$this->drupalGet('node/add/article');
$this->assertRaw('placeholder="Start typing here."', 'Placeholder is present.');
// Preview and verify the terms appear but are not created.
$this->drupalPostForm(NULL, $edit, t('Preview'));
foreach ($terms as $term) {
$this->assertText($term, 'The term appears on the node preview.');
}
$tree = $this->container->get('entity.manager')->getStorage('taxonomy_term')->loadTree($this->vocabulary->id());
$this->assertTrue(empty($tree), 'The terms are not created on preview.');
// taxonomy.module does not maintain its static caches.
taxonomy_terms_static_reset();
// Save, creating the terms.
$this->drupalPostForm('node/add/article', $edit, t('Save'));
$this->assertText(t('@type @title has been created.', ['@type' => t('Article'), '@title' => $edit['title[0][value]']]), 'The node was created successfully.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
$this->assert(isset($view_link), 'The message area contains a link to a node');
foreach ($terms as $term) {
$this->assertText($term, 'The term was saved and appears on the node page.');
}
// Get the created terms.
$term_objects = [];
foreach ($terms as $key => $term) {
$term_objects[$key] = taxonomy_term_load_multiple_by_name($term);
$term_objects[$key] = reset($term_objects[$key]);
}
// Get the node.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
// Test editing the node.
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
foreach ($terms as $term) {
$this->assertText($term, 'The term was retained after edit and still appears on the node page.');
}
// Delete term 1 from the term edit page.
$this->drupalGet('taxonomy/term/' . $term_objects['term1']->id() . '/edit');
$this->clickLink(t('Delete'));
$this->drupalPostForm(NULL, NULL, t('Delete'));
// Delete term 2 from the term delete page.
$this->drupalGet('taxonomy/term/' . $term_objects['term2']->id() . '/delete');
$this->drupalPostForm(NULL, [], t('Delete'));
$term_names = [$term_objects['term3']->getName(), $term_objects['term4']->getName()];
$this->drupalGet('node/' . $node->id());
foreach ($term_names as $term_name) {
$this->assertText($term_name, format_string('The term %name appears on the node page after two terms, %deleted1 and %deleted2, were deleted.', ['%name' => $term_name, '%deleted1' => $term_objects['term1']->getName(), '%deleted2' => $term_objects['term2']->getName()]));
}
$this->assertNoText($term_objects['term1']->getName(), format_string('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term1']->getName()]));
$this->assertNoText($term_objects['term2']->getName(), format_string('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term2']->getName()]));
}
/**
* Save, edit and delete a term using the user interface.
*/
public function testTermInterface() {
\Drupal::service('module_installer')->install(['views']);
$edit = [
'name[0][value]' => $this->randomMachineName(12),
'description[0][value]' => $this->randomMachineName(100),
];
// Explicitly set the parents field to 'root', to ensure that
// TermForm::save() handles the invalid term ID correctly.
$edit['parent[]'] = [0];
// Create the term to edit.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
$this->assertNotNull($term, 'Term found in database.');
// Submitting a term takes us to the add page; we need the List page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->clickLink(t('Edit'));
$this->assertRaw($edit['name[0][value]'], 'The randomly generated term name is present.');
$this->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
$edit = [
'name[0][value]' => $this->randomMachineName(14),
'description[0][value]' => $this->randomMachineName(102),
];
// Edit the term.
$this->drupalPostForm('taxonomy/term/' . $term->id() . '/edit', $edit, t('Save'));
// Check that the term is still present at admin UI after edit.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertText($edit['name[0][value]'], 'The randomly generated term name is present.');
$this->assertLink(t('Edit'));
// Check the term link can be clicked through to the term page.
$this->clickLink($edit['name[0][value]']);
$this->assertResponse(200, 'Term page can be accessed via the listing link.');
// View the term and check that it is correct.
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertText($edit['name[0][value]'], 'The randomly generated term name is present.');
$this->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
// Did this page request display a 'term-listing-heading'?
$this->assertTrue($this->xpath('//div[contains(@class, "field--name-description")]'), 'Term page displayed the term description element.');
// Check that it does NOT show a description when description is blank.
$term->setDescription(NULL);
$term->save();
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertFalse($this->xpath('//div[contains(@class, "field--entity-taxonomy-term--description")]'), 'Term page did not display the term description when description was blank.');
// Check that the description value is processed.
$value = $this->randomMachineName();
$term->setDescription($value);
$term->save();
$this->assertEqual($term->description->processed, "<p>$value</p>\n");
// Check that the term feed page is working.
$this->drupalGet('taxonomy/term/' . $term->id() . '/feed');
// Delete the term.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->clickLink(t('Delete'));
$this->drupalPostForm(NULL, NULL, t('Delete'));
// Assert that the term no longer exists.
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertResponse(404, 'The taxonomy term page was not found.');
}
/**
* Save, edit and delete a term using the user interface.
*/
public function testTermReorder() {
$assert = $this->assertSession();
$this->createTerm($this->vocabulary);
$this->createTerm($this->vocabulary);
$this->createTerm($this->vocabulary);
$taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
// Fetch the created terms in the default alphabetical order, i.e. term1
// precedes term2 alphabetically, and term2 precedes term3.
$taxonomy_storage->resetCache();
list($term1, $term2, $term3) = $taxonomy_storage->loadTree($this->vocabulary->id(), 0, NULL, TRUE);
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
// Each term has four hidden fields, "tid:1:0[tid]", "tid:1:0[parent]",
// "tid:1:0[depth]", and "tid:1:0[weight]". Change the order to term2,
// term3, term1 by setting weight property, make term3 a child of term2 by
// setting the parent and depth properties, and update all hidden fields.
$hidden_edit = [
'terms[tid:' . $term2->id() . ':0][term][tid]' => $term2->id(),
'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
'terms[tid:' . $term3->id() . ':0][term][tid]' => $term3->id(),
'terms[tid:' . $term3->id() . ':0][term][parent]' => $term2->id(),
'terms[tid:' . $term3->id() . ':0][term][depth]' => 1,
'terms[tid:' . $term1->id() . ':0][term][tid]' => $term1->id(),
'terms[tid:' . $term1->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term1->id() . ':0][term][depth]' => 0,
];
// Because we can't post hidden form elements, we have to change them in
// code here, and then submit.
foreach ($hidden_edit as $field => $value) {
$node = $assert->hiddenFieldExists($field);
$node->setValue($value);
}
// Edit non-hidden elements within drupalPostForm().
$edit = [
'terms[tid:' . $term2->id() . ':0][weight]' => 0,
'terms[tid:' . $term3->id() . ':0][weight]' => 1,
'terms[tid:' . $term1->id() . ':0][weight]' => 2,
];
$this->drupalPostForm(NULL, $edit, 'Save');
$taxonomy_storage->resetCache();
$terms = $taxonomy_storage->loadTree($this->vocabulary->id());
$this->assertEqual($terms[0]->tid, $term2->id(), 'Term 2 was moved above term 1.');
$this->assertEqual($terms[1]->parents, [$term2->id()], 'Term 3 was made a child of term 2.');
$this->assertEqual($terms[2]->tid, $term1->id(), 'Term 1 was moved below term 2.');
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', [], t('Reset to alphabetical'));
// Submit confirmation form.
$this->drupalPostForm(NULL, [], t('Reset to alphabetical'));
// Ensure form redirected back to overview.
$this->assertUrl('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$taxonomy_storage->resetCache();
$terms = $taxonomy_storage->loadTree($this->vocabulary->id(), 0, NULL, TRUE);
$this->assertEqual($terms[0]->id(), $term1->id(), 'Term 1 was moved to back above term 2.');
$this->assertEqual($terms[1]->id(), $term2->id(), 'Term 2 was moved to back below term 1.');
$this->assertEqual($terms[2]->id(), $term3->id(), 'Term 3 is still below term 2.');
$this->assertEqual($terms[2]->parents, [$term2->id()], 'Term 3 is still a child of term 2.');
}
/**
* Test saving a term with multiple parents through the UI.
*/
public function testTermMultipleParentsInterface() {
// Add a new term to the vocabulary so that we can have multiple parents.
$parent = $this->createTerm($this->vocabulary);
// Add a new term with multiple parents.
$edit = [
'name[0][value]' => $this->randomMachineName(12),
'description[0][value]' => $this->randomMachineName(100),
'parent[]' => [0, $parent->id()],
];
// Save the new term.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
// Check that the term was successfully created.
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
$this->assertNotNull($term, 'Term found in database.');
$this->assertEqual($edit['name[0][value]'], $term->getName(), 'Term name was successfully saved.');
$this->assertEqual($edit['description[0][value]'], $term->getDescription(), 'Term description was successfully saved.');
// Check that the parent tid is still there. The other parent (<root>) is
// not added by \Drupal\taxonomy\TermStorageInterface::loadParents().
$parents = $this->container->get('entity.manager')->getStorage('taxonomy_term')->loadParents($term->id());
$parent = reset($parents);
$this->assertEqual($edit['parent[]'][1], $parent->id(), 'Term parents were successfully saved.');
}
/**
* Test taxonomy_term_load_multiple_by_name().
*/
public function testTaxonomyGetTermByName() {
$term = $this->createTerm($this->vocabulary);
// Load the term with the exact name.
$terms = taxonomy_term_load_multiple_by_name($term->getName());
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name.');
// Load the term with space concatenated.
$terms = taxonomy_term_load_multiple_by_name(' ' . $term->getName() . ' ');
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded with extra whitespace.');
// Load the term with name uppercased.
$terms = taxonomy_term_load_multiple_by_name(strtoupper($term->getName()));
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded with uppercased name.');
// Load the term with name lowercased.
$terms = taxonomy_term_load_multiple_by_name(strtolower($term->getName()));
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded with lowercased name.');
// Try to load an invalid term name.
$terms = taxonomy_term_load_multiple_by_name('Banana');
$this->assertFalse($terms, 'No term loaded with an invalid name.');
// Try to load the term using a substring of the name.
$terms = taxonomy_term_load_multiple_by_name(mb_substr($term->getName(), 2), 'No term loaded with a substring of the name.');
$this->assertFalse($terms);
// Create a new term in a different vocabulary with the same name.
$new_vocabulary = $this->createVocabulary();
$new_term = Term::create([
'name' => $term->getName(),
'vid' => $new_vocabulary->id(),
]);
$new_term->save();
// Load multiple terms with the same name.
$terms = taxonomy_term_load_multiple_by_name($term->getName());
$this->assertEqual(count($terms), 2, 'Two terms loaded with the same name.');
// Load single term when restricted to one vocabulary.
$terms = taxonomy_term_load_multiple_by_name($term->getName(), $this->vocabulary->id());
$this->assertEqual(count($terms), 1, 'One term loaded when restricted by vocabulary.');
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name and vocabulary machine name.');
// Create a new term with another name.
$term2 = $this->createTerm($this->vocabulary);
// Try to load a term by name that doesn't exist in this vocabulary but
// exists in another vocabulary.
$terms = taxonomy_term_load_multiple_by_name($term2->getName(), $new_vocabulary->id());
$this->assertFalse($terms, 'Invalid term name restricted by vocabulary machine name not loaded.');
// Try to load terms filtering by a non-existing vocabulary.
$terms = taxonomy_term_load_multiple_by_name($term2->getName(), 'non_existing_vocabulary');
$this->assertEqual(count($terms), 0, 'No terms loaded when restricted by a non-existing vocabulary.');
}
/**
* Tests that editing and saving a node with no changes works correctly.
*/
public function testReSavingTags() {
// Enable tags in the vocabulary.
$field = $this->field;
entity_get_form_display($field->getTargetEntityTypeId(), $field->getTargetBundle(), 'default')
->setComponent($field->getName(), [
'type' => 'entity_reference_autocomplete_tags',
])
->save();
// Create a term and a node using it.
$term = $this->createTerm($this->vocabulary);
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName(8);
$edit['body[0][value]'] = $this->randomMachineName(16);
$edit[$this->field->getName() . '[target_id]'] = $term->getName();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
// Check that the term is displayed when editing and saving the node with no
// changes.
$this->clickLink(t('Edit'));
$this->assertRaw($term->getName(), 'Term is displayed when editing the node.');
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertRaw($term->getName(), 'Term is displayed after saving the node with no changes.');
}
/**
* Check the breadcrumb on edit and delete a term page.
*/
public function testTermBreadcrumbs() {
$edit = [
'name[0][value]' => $this->randomMachineName(14),
'description[0][value]' => $this->randomMachineName(100),
'parent[]' => [0],
];
// Create the term.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, 'Save');
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
$this->assertNotNull($term, 'Term found in database.');
// Check the breadcrumb on the term edit page.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$breadcrumbs = $this->getSession()->getPage()->findAll('css', 'nav.breadcrumb ol li a');
$this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.');
$this->assertIdentical($breadcrumbs[0]->getText(), 'Home', 'First breadcrumb text is Home');
$this->assertIdentical($breadcrumbs[1]->getText(), $term->label(), 'Second breadcrumb text is term name on term edit page.');
$this->assertEscaped($breadcrumbs[1]->getText(), 'breadcrumbs displayed and escaped.');
// Check the breadcrumb on the term delete page.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$breadcrumbs = $this->getSession()->getPage()->findAll('css', 'nav.breadcrumb ol li a');
$this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.');
$this->assertIdentical($breadcrumbs[0]->getText(), 'Home', 'First breadcrumb text is Home');
$this->assertIdentical($breadcrumbs[1]->getText(), $term->label(), 'Second breadcrumb text is term name on term delete page.');
$this->assertEscaped($breadcrumbs[1]->getText(), 'breadcrumbs displayed and escaped.');
}
}

View file

@ -0,0 +1,107 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\node\Entity\Node;
/**
* Tests the translation of taxonomy terms field on nodes.
*
* @group taxonomy
*/
class TermTranslationFieldViewTest extends TaxonomyTestBase {
use TaxonomyTranslationTestTrait;
/**
* The term that should be translated.
*
* @var \Drupal\taxonomy\Entity\Term
*/
protected $term;
/**
* The tag in the source language.
*
* @var string
*/
protected $baseTagName = 'OriginalTagName';
/**
* The translated value for the tag.
*
* @var string
*/
protected $translatedTagName = 'TranslatedTagName';
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['language', 'content_translation', 'taxonomy'];
protected function setUp() {
parent::setUp();
$this->setupLanguages();
$this->vocabulary = $this->createVocabulary();
$this->enableTranslation();
$this->setUpTerm();
$this->setUpTermReferenceField();
$this->setUpNode();
}
/**
* Tests if the translated taxonomy term is displayed.
*/
public function testTranslatedTaxonomyTermReferenceDisplay() {
$path = 'node/' . $this->node->id();
$translation_path = $this->translateToLangcode . '/' . $path;
$this->drupalGet($path);
$this->assertNoText($this->translatedTagName);
$this->assertText($this->baseTagName);
$this->drupalGet($translation_path);
$this->assertText($this->translatedTagName);
$this->assertNoText($this->baseTagName);
}
/**
* Creates a test subject node, with translation.
*/
protected function setUpNode() {
/** @var \Drupal\node\Entity\Node $node */
$node = Node::create([
'title' => $this->randomMachineName(),
'type' => 'article',
'description' => [
[
'value' => $this->randomMachineName(),
'format' => 'basic_html',
],
],
$this->termFieldName => [['target_id' => $this->term->id()]],
'langcode' => $this->baseLangcode,
]);
$node->save();
$node->addTranslation($this->translateToLangcode, $node->toArray());
$node->save();
$this->node = $node;
}
/**
* Creates a test subject term, with translation.
*/
protected function setUpTerm() {
$this->term = $this->createTerm($this->vocabulary, [
'name' => $this->baseTagName,
'langcode' => $this->baseLangcode,
]);
$this->term->addTranslation($this->translateToLangcode, [
'name' => $this->translatedTagName,
]);
$this->term->save();
}
}

View file

@ -0,0 +1,149 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Url;
use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait;
/**
* Tests for proper breadcrumb translation.
*
* @group taxonomy
*/
class TermTranslationTest extends TaxonomyTestBase {
use AssertBreadcrumbTrait;
use TaxonomyTranslationTestTrait;
/**
* Term to translated term mapping.
*
* @var array
*/
protected $termTranslationMap = [
'one' => 'translatedOne',
'two' => 'translatedTwo',
'three' => 'translatedThree',
];
/**
* Created terms.
*
* @var \Drupal\taxonomy\Entity\Term[]
*/
protected $terms = [];
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'language', 'content_translation'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->setupLanguages();
$this->vocabulary = $this->createVocabulary();
$this->enableTranslation();
$this->setUpTerms();
$this->setUpTermReferenceField();
}
/**
* Test translated breadcrumbs.
*/
public function testTranslatedBreadcrumbs() {
// Ensure non-translated breadcrumb is correct.
$breadcrumb = [Url::fromRoute('<front>')->toString() => 'Home'];
foreach ($this->terms as $term) {
$breadcrumb[$term->url()] = $term->label();
}
// The last item will not be in the breadcrumb.
array_pop($breadcrumb);
// Check the breadcrumb on the leaf term page.
$term = $this->getLeafTerm();
$this->assertBreadcrumb($term->urlInfo(), $breadcrumb, $term->label());
$languages = \Drupal::languageManager()->getLanguages();
// Construct the expected translated breadcrumb.
$breadcrumb = [Url::fromRoute('<front>', [], ['language' => $languages[$this->translateToLangcode]])->toString() => 'Home'];
foreach ($this->terms as $term) {
$translated = $term->getTranslation($this->translateToLangcode);
$url = $translated->url('canonical', ['language' => $languages[$this->translateToLangcode]]);
$breadcrumb[$url] = $translated->label();
}
array_pop($breadcrumb);
// Check for the translated breadcrumb on the translated leaf term page.
$term = $this->getLeafTerm();
$translated = $term->getTranslation($this->translateToLangcode);
$this->assertBreadcrumb($translated->urlInfo('canonical', ['language' => $languages[$this->translateToLangcode]]), $breadcrumb, $translated->label());
}
/**
* Test translation of terms are showed in the node.
*/
public function testTermsTranslation() {
// Set the display of the term reference field on the article content type
// to "Check boxes/radio buttons".
entity_get_form_display('node', 'article', 'default')
->setComponent($this->termFieldName, [
'type' => 'options_buttons',
])
->save();
$this->drupalLogin($this->drupalCreateUser(['create article content']));
// Test terms are listed.
$this->drupalget('node/add/article');
$this->assertText('one');
$this->assertText('two');
$this->assertText('three');
// Test terms translated are listed.
$this->drupalget('hu/node/add/article');
$this->assertText('translatedOne');
$this->assertText('translatedTwo');
$this->assertText('translatedThree');
}
/**
* Setup translated terms in a hierarchy.
*/
protected function setUpTerms() {
$parent_vid = 0;
foreach ($this->termTranslationMap as $name => $translation) {
$term = $this->createTerm($this->vocabulary, [
'name' => $name,
'langcode' => $this->baseLangcode,
'parent' => $parent_vid,
]);
$term->addTranslation($this->translateToLangcode, [
'name' => $translation,
]);
$term->save();
// Each term is nested under the last.
$parent_vid = $term->id();
$this->terms[] = $term;
}
}
/**
* Get the final (leaf) term in the hierarchy.
*
* @return \Drupal\taxonomy\Entity\Term
* The final term in the hierarchy.
*/
protected function getLeafTerm() {
return $this->terms[count($this->termTranslationMap) - 1];
}
}

View file

@ -0,0 +1,164 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests the Term Translation UI.
*
* @group taxonomy
*/
class TermTranslationUITest extends ContentTranslationUITestBase {
/**
* The vocabulary used for creating terms.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['language', 'content_translation', 'taxonomy'];
protected function setUp() {
$this->entityTypeId = 'taxonomy_term';
$this->bundle = 'tags';
parent::setUp();
}
/**
* {@inheritdoc}
*/
protected function setupBundle() {
parent::setupBundle();
// Create a vocabulary.
$this->vocabulary = Vocabulary::create([
'name' => $this->bundle,
'description' => $this->randomMachineName(),
'vid' => $this->bundle,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'weight' => mt_rand(0, 10),
]);
$this->vocabulary->save();
}
/**
* {@inheritdoc}
*/
protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), ['administer taxonomy']);
}
/**
* {@inheritdoc}
*/
protected function getNewEntityValues($langcode) {
return ['name' => $this->randomMachineName()] + parent::getNewEntityValues($langcode);
}
/**
* Returns an edit array containing the values to be posted.
*/
protected function getEditValues($values, $langcode, $new = FALSE) {
$edit = parent::getEditValues($values, $langcode, $new);
// To be able to post values for the configurable base fields (name,
// description) have to be suffixed with [0][value].
foreach ($edit as $property => $value) {
foreach (['name', 'description'] as $key) {
if ($property == $key) {
$edit[$key . '[0][value]'] = $value;
unset($edit[$property]);
}
}
}
return $edit;
}
/**
* {@inheritdoc}
*/
public function testTranslationUI() {
parent::testTranslationUI();
// Make sure that no row was inserted for taxonomy vocabularies which do
// not have translations enabled.
$rows = db_query('SELECT tid, count(tid) AS count FROM {taxonomy_term_field_data} WHERE vid <> :vid GROUP BY tid', [':vid' => $this->bundle])->fetchAll();
foreach ($rows as $row) {
$this->assertTrue($row->count < 2, 'Term does not have translations.');
}
}
/**
* Tests translate link on vocabulary term list.
*/
public function testTranslateLinkVocabularyAdminPage() {
$this->drupalLogin($this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), ['access administration pages', 'administer taxonomy'])));
$values = [
'name' => $this->randomMachineName(),
];
$translatable_tid = $this->createEntity($values, $this->langcodes[0], $this->vocabulary->id());
// Create an untranslatable vocabulary.
$untranslatable_vocabulary = Vocabulary::create([
'name' => 'untranslatable_voc',
'description' => $this->randomMachineName(),
'vid' => 'untranslatable_voc',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'weight' => mt_rand(0, 10),
]);
$untranslatable_vocabulary->save();
$values = [
'name' => $this->randomMachineName(),
];
$untranslatable_tid = $this->createEntity($values, $this->langcodes[0], $untranslatable_vocabulary->id());
// Verify translation links.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertResponse(200, 'The translatable vocabulary page was found.');
$this->assertLinkByHref('term/' . $translatable_tid . '/translations', 0, 'The translations link exists for a translatable vocabulary.');
$this->assertLinkByHref('term/' . $translatable_tid . '/edit', 0, 'The edit link exists for a translatable vocabulary.');
$this->drupalGet('admin/structure/taxonomy/manage/' . $untranslatable_vocabulary->id() . '/overview');
$this->assertResponse(200);
$this->assertLinkByHref('term/' . $untranslatable_tid . '/edit');
$this->assertNoLinkByHref('term/' . $untranslatable_tid . '/translations');
}
/**
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {
// We only want to test the title for non-english translations.
if ($langcode != 'en') {
$options = ['language' => $languages[$langcode]];
$url = $entity->urlInfo('edit-form', $options);
$this->drupalGet($url);
$title = t('@title [%language translation]', [
'@title' => $entity->getTranslation($langcode)->label(),
'%language' => $languages[$langcode]->getName(),
]);
$this->assertRaw($title);
}
}
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
/**
* Verifies that various taxonomy pages use the expected theme.
*
* @group taxonomy
*/
class ThemeTest extends TaxonomyTestBase {
protected function setUp() {
parent::setUp();
// Make sure we are using distinct default and administrative themes for
// the duration of these tests.
\Drupal::service('theme_handler')->install(['bartik', 'seven']);
$this->config('system.theme')
->set('default', 'bartik')
->set('admin', 'seven')
->save();
// Create and log in as a user who has permission to add and edit taxonomy
// terms and view the administrative theme.
$admin_user = $this->drupalCreateUser(['administer taxonomy', 'view the administration theme']);
$this->drupalLogin($admin_user);
}
/**
* Test the theme used when adding, viewing and editing taxonomy terms.
*/
public function testTaxonomyTermThemes() {
// Adding a term to a vocabulary is considered an administrative action and
// should use the administrative theme.
$vocabulary = $this->createVocabulary();
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
$this->assertRaw('seven/css/base/elements.css', t("The administrative theme's CSS appears on the page for adding a taxonomy term."));
// Viewing a taxonomy term should use the default theme.
$term = $this->createTerm($vocabulary);
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertRaw('bartik/css/base/elements.css', t("The default theme's CSS appears on the page for viewing a taxonomy term."));
// Editing a taxonomy term should use the same theme as adding one.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->assertRaw('seven/css/base/elements.css', t("The administrative theme's CSS appears on the page for editing a taxonomy term."));
}
}

View file

@ -0,0 +1,147 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Render\BubbleableMetadata;
/**
* Generates text using placeholders for dummy content to check taxonomy token
* replacement.
*
* @group taxonomy
*/
class TokenReplaceTest extends TaxonomyTestBase {
/**
* The vocabulary used for creating terms.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
/**
* Name of the taxonomy term reference field.
*
* @var string
*/
protected $fieldName;
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
$this->vocabulary = $this->createVocabulary();
$this->fieldName = 'taxonomy_' . $this->vocabulary->id();
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
'auto_create' => TRUE,
];
$this->createEntityReferenceField('node', 'article', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName, [
'type' => 'options_select',
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName, [
'type' => 'entity_reference_label',
])
->save();
}
/**
* Creates some terms and a node, then tests the tokens generated from them.
*/
public function testTaxonomyTokenReplacement() {
$token_service = \Drupal::token();
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
// Create two taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
// Edit $term2, setting $term1 as parent.
$edit = [];
$edit['name[0][value]'] = '<blink>Blinking Text</blink>';
$edit['parent[]'] = [$term1->id()];
$this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));
// Create node with term2.
$edit = [];
$node = $this->drupalCreateNode(['type' => 'article']);
$edit[$this->fieldName . '[]'] = $term2->id();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
// Generate and test sanitized tokens for term1.
$tests = [];
$tests['[term:tid]'] = $term1->id();
$tests['[term:name]'] = $term1->getName();
$tests['[term:description]'] = $term1->description->processed;
$tests['[term:url]'] = $term1->url('canonical', ['absolute' => TRUE]);
$tests['[term:node-count]'] = 0;
$tests['[term:parent:name]'] = '[term:parent:name]';
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
$tests['[term:vocabulary]'] = $this->vocabulary->label();
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($term1);
$metadata_tests = [];
$metadata_tests['[term:tid]'] = $base_bubbleable_metadata;
$metadata_tests['[term:name]'] = $base_bubbleable_metadata;
$metadata_tests['[term:description]'] = $base_bubbleable_metadata;
$metadata_tests['[term:url]'] = $base_bubbleable_metadata;
$metadata_tests['[term:node-count]'] = $base_bubbleable_metadata;
$metadata_tests['[term:parent:name]'] = $base_bubbleable_metadata;
$bubbleable_metadata = clone $base_bubbleable_metadata;
$metadata_tests['[term:vocabulary:name]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags());
$metadata_tests['[term:vocabulary]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags());
foreach ($tests as $input => $expected) {
$bubbleable_metadata = new BubbleableMetadata();
$output = $token_service->replace($input, ['term' => $term1], ['langcode' => $language_interface->getId()], $bubbleable_metadata);
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', ['%token' => $input]));
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
}
// Generate and test sanitized tokens for term2.
$tests = [];
$tests['[term:tid]'] = $term2->id();
$tests['[term:name]'] = $term2->getName();
$tests['[term:description]'] = $term2->description->processed;
$tests['[term:url]'] = $term2->url('canonical', ['absolute' => TRUE]);
$tests['[term:node-count]'] = 1;
$tests['[term:parent:name]'] = $term1->getName();
$tests['[term:parent:url]'] = $term1->url('canonical', ['absolute' => TRUE]);
$tests['[term:parent:parent:name]'] = '[term:parent:parent:name]';
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, ['term' => $term2], ['langcode' => $language_interface->getId()]);
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', ['%token' => $input]));
}
// Generate and test sanitized tokens.
$tests = [];
$tests['[vocabulary:vid]'] = $this->vocabulary->id();
$tests['[vocabulary:name]'] = $this->vocabulary->label();
$tests['[vocabulary:description]'] = $this->vocabulary->getDescription();
$tests['[vocabulary:node-count]'] = 1;
$tests['[vocabulary:term-count]'] = 2;
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, ['vocabulary' => $this->vocabulary], ['langcode' => $language_interface->getId()]);
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', ['%token' => $input]));
}
}
}

View file

@ -0,0 +1,101 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\taxonomy\Entity\Term;
/**
* Ensure that the taxonomy updates are running as expected.
*
* @group taxonomy
* @group Update
* @group legacy
*/
class TaxonomyParentUpdateTest extends UpdatePathTestBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $db;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->db = $this->container->get('database');
}
/**
* {@inheritdoc}
*/
public function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz',
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.php',
];
}
/**
* Tests taxonomy term parents update.
*
* @see taxonomy_update_8501()
* @see taxonomy_update_8502()
* @see taxonomy_update_8503()
*/
public function testTaxonomyUpdateParents() {
// Force the update hook to only run one term per batch.
drupal_rewrite_settings([
'settings' => [
'entity_update_batch_size' => (object) [
'value' => 1,
'required' => TRUE,
],
],
]);
// Run updates.
$this->runUpdates();
/** @var \Drupal\taxonomy\TermInterface $term */
$term = Term::load(1);
$parents = [2, 3];
$this->assertCount(2, $term->parent);
$this->assertTrue(in_array($term->parent[0]->entity->id(), $parents));
$this->assertTrue(in_array($term->parent[1]->entity->id(), $parents));
$term = Term::load(2);
$parents = [0, 3];
$this->assertCount(2, $term->parent);
$this->assertTrue(in_array($term->parent[0]->target_id, $parents));
$this->assertTrue(in_array($term->parent[1]->target_id, $parents));
$term = Term::load(3);
$this->assertCount(1, $term->parent);
// Target ID is returned as string.
$this->assertSame(0, (int) $term->get('parent')[0]->target_id);
// Test if the view has been converted to use the {taxonomy_term__parent}
// table instead of the {taxonomy_term_hierarchy} table.
$view = $this->config("views.view.test_taxonomy_parent");
$relationship_base_path = 'display.default.display_options.relationships.parent';
$this->assertSame('taxonomy_term__parent', $view->get("$relationship_base_path.table"));
$this->assertSame('parent_target_id', $view->get("$relationship_base_path.field"));
$filters_base_path_1 = 'display.default.display_options.filters.parent';
$this->assertSame('taxonomy_term__parent', $view->get("$filters_base_path_1.table"));
$this->assertSame('parent_target_id', $view->get("$filters_base_path_1.field"));
$filters_base_path_2 = 'display.default.display_options.filters.parent';
$this->assertSame('taxonomy_term__parent', $view->get("$filters_base_path_2.table"));
$this->assertSame('parent_target_id', $view->get("$filters_base_path_2.field"));
// The {taxonomy_term_hierarchy} table has been removed.
$this->assertFalse($this->db->schema()->tableExists('taxonomy_term_hierarchy'));
}
}

View file

@ -0,0 +1,139 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\user\Entity\User;
use Drupal\views\Entity\View;
/**
* Tests the upgrade path for taxonomy terms.
*
* @group taxonomy
* @group Update
* @group legacy
*/
class TaxonomyTermUpdatePathTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz',
__DIR__ . '/../../../fixtures/update/drupal-8.views-taxonomy-term-publishing-status-2981887.php',
];
}
/**
* Tests the conversion of taxonomy terms to be publishable.
*
* @see taxonomy_update_8601()
*/
public function testPublishable() {
$this->runUpdates();
// Log in as user 1.
$account = User::load(1);
$account->passRaw = 'drupal';
$this->drupalLogin($account);
// Make sure our vocabulary exists.
$this->drupalGet('admin/structure/taxonomy/manage/test_vocabulary/overview');
// Make sure our terms exist.
$assert_session = $this->assertSession();
$assert_session->pageTextContains('Test root term');
$assert_session->pageTextContains('Test child term');
$this->drupalGet('taxonomy/term/3');
$assert_session->statusCodeEquals('200');
// Make sure the terms are still translated.
$this->drupalGet('taxonomy/term/2/translations');
$assert_session->linkExists('Test root term - Spanish');
$storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
// Check that the 'content_translation_status' field has been updated
// correctly.
/** @var \Drupal\taxonomy\TermInterface $term */
$term = $storage->load(2);
$translation = $term->getTranslation('es');
$this->assertTrue($translation->isPublished());
// Check that taxonomy terms can be created, saved and then loaded.
$term = $storage->create([
'name' => 'Test term',
'vid' => 'tags',
]);
$term->save();
$term = $storage->loadUnchanged($term->id());
$this->assertEquals('Test term', $term->label());
$this->assertEquals('tags', $term->bundle());
$this->assertTrue($term->isPublished());
// Check that the term can be unpublished.
$term->setUnpublished();
$term->save();
$term = $storage->loadUnchanged($term->id());
$this->assertFalse($term->isPublished());
// Test the update does not run when a status field already exists.
module_load_install('taxonomy');
$this->assertEquals('The publishing status field has <strong>not</strong> been added to taxonomy terms. See <a href="https://www.drupal.org/node/2985366">this page</a> for more information on how to install it.', (string) taxonomy_update_8601());
// Test the message can be overridden.
\Drupal::state()->set('taxonomy_update_8601_skip_message', 'Another message');
$this->assertEquals('Another message', (string) taxonomy_update_8601());
}
/**
* Tests handling of the publishing status in taxonomy term views updates.
*
* @see taxonomy_post_update_handle_publishing_status_addition_in_views()
*/
public function testPublishingStatusUpdateForTaxonomyTermViews() {
// Check that the test view was previously using the
// 'content_translation_status' field.
$config = \Drupal::config('views.view.test_taxonomy_term_view_with_content_translation_status');
$display_options = $config->get('display.default.display_options');
$this->assertEquals('content_translation_status', $display_options['fields']['content_translation_status']['field']);
$this->assertEquals('content_translation_status', $display_options['filters']['content_translation_status']['field']);
$this->assertEquals('content_translation_status', $display_options['sorts']['content_translation_status']['field']);
// Check a test view without any filter.
$config = \Drupal::config('views.view.test_taxonomy_term_view_without_content_translation_status');
$display_options = $config->get('display.default.display_options');
$this->assertEmpty($display_options['filters']);
$this->runUpdates();
// Check that a view which had a field, filter and a sort on the
// 'content_translation_status' field has been updated to use the new
// 'status' field.
$view = View::load('test_taxonomy_term_view_with_content_translation_status');
foreach ($view->get('display') as $display) {
$this->assertEquals('status', $display['display_options']['fields']['content_translation_status']['field']);
$this->assertEquals('status', $display['display_options']['sorts']['content_translation_status']['field']);
$this->assertEquals('status', $display['display_options']['filters']['content_translation_status']['field']);
}
// Check that a view without any filters has been updated to include a
// filter for the 'status' field.
$view = View::load('test_taxonomy_term_view_without_content_translation_status');
foreach ($view->get('display') as $display) {
$this->assertNotEmpty($display['display_options']['filters']);
$this->assertEquals('status', $display['display_options']['filters']['status']['field']);
}
}
/**
* {@inheritdoc}
*/
protected function replaceUser1() {
// Do not replace the user from our dump.
}
}

View file

@ -0,0 +1,120 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
/**
* Tests the plugin of the taxonomy: term argument validator.
*
* @group taxonomy
* @see Views\taxonomy\Plugin\views\argument_validator\Term
*/
class ArgumentValidatorTermTest extends TaxonomyTestBase {
/**
* Stores the taxonomy term used by this test.
*
* @var array
*/
protected $terms = [];
/**
* Stores the taxonomy names used by this test.
*
* @var array
*/
protected $names = [];
/**
* Stores the taxonomy IDs used by this test.
*
* @var array
*/
protected $ids = [];
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views_test_config'];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_argument_validator_term'];
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Add three terms to the 'tags' vocabulary.
for ($i = 0; $i < 3; $i++) {
$this->terms[] = $term = $this->createTerm();
$this->names[] = $term->label();
$this->ids[] = $term->id();
}
}
/**
* Tests the term argument validator plugin.
*/
public function testArgumentValidatorTerm() {
$view = Views::getView('test_argument_validator_term');
$view->initHandlers();
// Test the single validator for term IDs.
$view->argument['tid']->validator->options['type'] = 'tid';
// Pass in a single valid term.
foreach ($this->terms as $term) {
$this->assertTrue($view->argument['tid']->setArgument($term->id()));
$this->assertEqual($view->argument['tid']->getTitle(), $term->label());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
}
// Pass in a invalid term.
$this->assertFalse($view->argument['tid']->setArgument(rand(1000, 10000)));
$this->assertEqual('', $view->argument['tid']->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Test the multiple validator for term IDs.
$view->argument['tid']->validator->options['type'] = 'tids';
$view->argument['tid']->options['break_phrase'] = TRUE;
// Pass in a single term.
$this->assertTrue($view->argument['tid']->setArgument($this->terms[0]->id()));
$this->assertEqual($view->argument['tid']->getTitle(), $this->terms[0]->label());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Check for multiple valid terms separated by commas.
$this->assertTrue($view->argument['tid']->setArgument(implode(',', $this->ids)));
$this->assertEqual($view->argument['tid']->getTitle(), implode(', ', $this->names));
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Check for multiple valid terms separated by plus signs.
$this->assertTrue($view->argument['tid']->setArgument(implode('+', $this->ids)));
$this->assertEqual($view->argument['tid']->getTitle(), implode(' + ', $this->names));
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Check for a single invalid term.
$this->assertFalse($view->argument['tid']->setArgument(rand(1000, 10000)));
$this->assertEqual('', $view->argument['tid']->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
// Check for multiple invalid terms.
$this->assertFalse($view->argument['tid']->setArgument(implode(',', [rand(1000, 10000), rand(1000, 10000)])));
$this->assertEqual('', $view->argument['tid']->getTitle());
$view->argument['tid']->validated_title = NULL;
$view->argument['tid']->argument_validated = NULL;
}
}

View file

@ -0,0 +1,58 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
/**
* Tests the taxonomy term on node relationship handler.
*
* @group taxonomy
*/
class RelationshipNodeTermDataTest extends TaxonomyTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_taxonomy_node_term_data'];
public 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->getDependencies());
$this->executeView($view, [$this->term1->id(), $this->term2->id()]);
$expected_result = [
[
'nid' => $this->nodes[1]->id(),
],
[
'nid' => $this->nodes[0]->id(),
],
];
$column_map = ['nid' => 'nid'];
$this->assertIdenticalResultset($view, $expected_result, $column_map);
// Change the view to test relation limited by vocabulary.
$this->config('views.view.test_taxonomy_node_term_data')
->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->getDependencies());
$this->executeView($view, [$this->term1->id(), $this->term2->id()]);
$this->assertIdenticalResultset($view, $expected_result, $column_map);
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
/**
* Tests the representative node relationship for terms.
*
* @group taxonomy
*/
class RelationshipRepresentativeNodeTest extends TaxonomyTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_groupwise_term'];
/**
* Tests the relationship.
*/
public function testRelationship() {
$view = Views::getView('test_groupwise_term');
$this->executeView($view);
$map = ['node_field_data_taxonomy_term_field_data_nid' => 'nid', 'tid' => 'tid'];
$expected_result = [
[
'nid' => $this->nodes[1]->id(),
'tid' => $this->term2->id(),
],
[
'nid' => $this->nodes[1]->id(),
'tid' => $this->term1->id(),
],
];
$this->assertIdenticalResultset($view, $expected_result, $map);
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
/**
* Tests the representative node relationship for terms.
*
* @group taxonomy
*/
class TaxonomyDefaultArgumentTest extends TaxonomyTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['taxonomy_default_argument_test'];
/**
* Tests escaping of page title when the taxonomy plugin provides it.
*/
public function testTermTitleEscaping() {
$this->term1->setName('<em>Markup</em>')->save();
$this->drupalGet('taxonomy_default_argument_test/' . $this->term1->id());
$this->assertEscaped($this->term1->label());
}
}

View file

@ -0,0 +1,67 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests the "All terms" taxonomy term field handler.
*
* @group taxonomy
*/
class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['taxonomy_all_terms_test'];
/**
* Tests the "all terms" field handler.
*/
public function testViewsHandlerAllTermsField() {
$this->term1->setName('<em>Markup</em>')->save();
$view = Views::getView('taxonomy_all_terms_test');
$this->executeView($view);
$this->drupalGet('taxonomy_all_terms_test');
$actual = $this->xpath('//a[@href="' . $this->term1->url() . '"]');
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term1 links');
$this->assertEqual($actual[0]->getText(), $this->term1->label());
$this->assertEqual($actual[1]->getText(), $this->term1->label());
$this->assertEscaped($this->term1->label());
$actual = $this->xpath('//a[@href="' . $this->term2->url() . '"]');
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term2 links');
$this->assertEqual($actual[0]->getText(), $this->term2->label());
$this->assertEqual($actual[1]->getText(), $this->term2->label());
}
/**
* Tests token replacement in the "all terms" field handler.
*/
public function testViewsHandlerAllTermsWithTokens() {
$view = Views::getView('taxonomy_all_terms_test');
$this->drupalGet('taxonomy_all_terms_token_test');
// Term itself: {{ term_node_tid }}
$this->assertText('Term: ' . $this->term1->getName());
// The taxonomy term ID for the term: {{ term_node_tid__tid }}
$this->assertText('The taxonomy term ID for the term: ' . $this->term1->id());
// The taxonomy term name for the term: {{ term_node_tid__name }}
$this->assertText('The taxonomy term name for the term: ' . $this->term1->getName());
// The machine name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary_vid }}
$this->assertText('The machine name for the vocabulary the term belongs to: ' . $this->term1->bundle());
// The name for the vocabulary the term belongs to: {{ term_node_tid__vocabulary }}
$vocabulary = Vocabulary::load($this->term1->bundle());
$this->assertText('The name for the vocabulary the term belongs to: ' . $vocabulary->label());
}
}

View file

@ -0,0 +1,185 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Tests taxonomy field filters with translations.
*
* @group taxonomy
*/
class TaxonomyFieldFilterTest extends ViewTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['language', 'taxonomy', 'taxonomy_test_views', 'text', 'views', 'node'];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_field_filters'];
/**
* The vocabulary used for creating terms.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
/**
* List of taxonomy term names by language.
*
* @var array
*/
public $termNames = [];
public function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Set up term names.
$this->termNames = [
'en' => 'Food in Paris',
'es' => 'Comida en Paris',
'fr' => 'Nouriture en Paris',
];
// Create a vocabulary.
$this->vocabulary = Vocabulary::create([
'name' => 'Views testing tags',
'vid' => 'views_testing_tags',
]);
$this->vocabulary->save();
// Add a translatable field to the vocabulary.
$field = FieldStorageConfig::create([
'field_name' => 'field_foo',
'entity_type' => 'taxonomy_term',
'type' => 'text',
]);
$field->save();
FieldConfig::create([
'field_name' => 'field_foo',
'entity_type' => 'taxonomy_term',
'label' => 'Foo',
'bundle' => 'views_testing_tags',
])->save();
// Create term with translations.
$taxonomy = $this->createTermWithProperties(['name' => $this->termNames['en'], 'langcode' => 'en', 'description' => $this->termNames['en'], 'field_foo' => $this->termNames['en']]);
foreach (['es', 'fr'] as $langcode) {
$translation = $taxonomy->addTranslation($langcode, ['name' => $this->termNames[$langcode]]);
$translation->description->value = $this->termNames[$langcode];
$translation->field_foo->value = $this->termNames[$langcode];
}
$taxonomy->save();
Views::viewsData()->clear();
ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
$this->container->get('router.builder')->rebuild();
}
/**
* Tests description and term name filters.
*/
public function testFilters() {
// Test the name filter page, which filters for name contains 'Comida'.
// Should show just the Spanish translation, once.
$this->assertPageCounts('test-name-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida name filter');
// Test the description filter page, which filters for description contains
// 'Comida'. Should show just the Spanish translation, once.
$this->assertPageCounts('test-desc-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida description filter');
// Test the field filter page, which filters for field_foo contains
// 'Comida'. Should show just the Spanish translation, once.
$this->assertPageCounts('test-field-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida field filter');
// Test the name Paris filter page, which filters for name contains
// 'Paris'. Should show each translation once.
$this->assertPageCounts('test-name-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris name filter');
// Test the description Paris page, which filters for description contains
// 'Paris'. Should show each translation, once.
$this->assertPageCounts('test-desc-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris description filter');
// Test the field Paris filter page, which filters for field_foo contains
// 'Paris'. Should show each translation once.
$this->assertPageCounts('test-field-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris field filter');
}
/**
* Asserts that the given taxonomy translation counts are correct.
*
* @param string $path
* Path of the page to test.
* @param array $counts
* Array whose keys are languages, and values are the number of times
* that translation should be shown on the given page.
* @param string $message
* Message suffix to display.
*/
protected function assertPageCounts($path, $counts, $message) {
// Get the text of the page.
$this->drupalGet($path);
$text = $this->getTextContent();
// Check the counts. Note that the title and body are both shown on the
// page, and they are the same. So the title/body string should appear on
// the page twice as many times as the input count.
foreach ($counts as $langcode => $count) {
$this->assertEqual(substr_count($text, $this->termNames[$langcode]), 2 * $count, 'Translation ' . $langcode . ' has count ' . $count . ' with ' . $message);
}
}
/**
* Creates a taxonomy term with specified name and other properties.
*
* @param array $properties
* Array of properties and field values to set.
*
* @return \Drupal\taxonomy\TermInterface
* The created taxonomy term.
*/
protected function createTermWithProperties($properties) {
// Use the first available text format.
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$properties += [
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'field_foo' => $this->randomMachineName(),
];
$term = Term::create([
'name' => $properties['name'],
'description' => $properties['description'],
'format' => $format->id(),
'vid' => $this->vocabulary->id(),
'langcode' => $properties['langcode'],
]);
$term->field_foo->value = $properties['field_foo'];
$term->save();
return $term;
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Core\Render\RenderContext;
use Drupal\views\Views;
/**
* Tests the taxonomy term TID field handler.
*
* @group taxonomy
*/
class TaxonomyFieldTidTest extends TaxonomyTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_taxonomy_tid_field'];
public function testViewsHandlerTidField() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$view = Views::getView('test_taxonomy_tid_field');
$this->executeView($view);
$actual = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$expected = \Drupal::l($this->term1->label(), $this->term1->urlInfo());
$this->assertEqual($expected, $actual);
}
}

View file

@ -0,0 +1,156 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\views\Entity\View;
use Drupal\views\Tests\ViewTestData;
/**
* Test the taxonomy term index filter.
*
* @see \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid
*
* @group taxonomy
*/
class TaxonomyIndexTidFilterTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views', 'node'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_filter_taxonomy_index_tid__non_existing_dependency'];
/**
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = [];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp(FALSE);
// Setup vocabulary and terms so the initial import is valid.
Vocabulary::create([
'vid' => 'tags',
'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',
'name' => 'muh',
]);
$term->save();
$this->terms[$term->id()] = $term;
ViewTestData::createTestViews(get_class($this), ['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');
// 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[4]->getConfigDependencyName(),
],
'module' => [
'node',
'taxonomy',
'user',
],
], $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();
\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',
'user',
],
], $view->getDependencies());
}
}

View file

@ -0,0 +1,220 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\views_ui\Functional\UITestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Entity\View;
/**
* Tests the taxonomy index filter handler UI.
*
* @group taxonomy
* @see \Drupal\taxonomy\Plugin\views\field\TaxonomyIndexTid
*/
class TaxonomyIndexTidUiTest extends UITestBase {
use EntityReferenceTestTrait;
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_filter_taxonomy_index_tid', 'test_taxonomy_term_name'];
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'taxonomy', 'views', 'views_ui', 'taxonomy_test_views'];
/**
* A nested array of \Drupal\taxonomy\TermInterface objects.
*
* @var \Drupal\taxonomy\TermInterface[][]
*/
protected $terms = [];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->adminUser = $this->drupalCreateUser(['administer taxonomy', 'administer views']);
$this->drupalLogin($this->adminUser);
Vocabulary::create([
'vid' => 'tags',
'name' => 'Tags',
])->save();
// Setup a hierarchy which looks like this:
// term 0.0
// term 1.0
// - term 1.1
// term 2.0
// - term 2.1
// - term 2.2
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j <= $i; $j++) {
$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), ['taxonomy_test_views']);
Vocabulary::create([
'vid' => 'empty_vocabulary',
'name' => 'Empty Vocabulary',
])->save();
}
/**
* 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');
// Ensure that the expected hierarchy is available in the UI.
$counter = 0;
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j <= $i; $j++) {
$option = $result[$counter++];
$prefix = $this->terms[$i][$j]->parent->target_id ? '-' : '';
$tid = $option->getAttribute('value');
$this->assertEqual($prefix . $this->terms[$i][$j]->getName(), $option->getText());
$this->assertEqual($this->terms[$i][$j]->id(), $tid);
}
}
// Ensure the autocomplete input element appears when using the 'textfield'
// type.
$view = View::load('test_filter_taxonomy_index_tid');
$display =& $view->getDisplay('default');
$display['display_options']['filters']['tid']['type'] = 'textfield';
$view->save();
$this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid');
$this->assertFieldById('edit-options-value', NULL);
// 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()->getDependencies());
}
/**
* Tests exposed taxonomy filters.
*/
public function testExposedFilter() {
$node_type = $this->drupalCreateContentType(['type' => 'page']);
// Create the tag field itself.
$field_name = 'taxonomy_tags';
$this->createEntityReferenceField('node', $node_type->id(), $field_name, NULL, 'taxonomy_term');
// Create 4 nodes: 1 without a term, 2 with the same term, and 1 with a
// different term.
$node1 = $this->drupalCreateNode();
$node2 = $this->drupalCreateNode([
$field_name => [['target_id' => $this->terms[1][0]->id()]],
]);
$node3 = $this->drupalCreateNode([
$field_name => [['target_id' => $this->terms[1][0]->id()]],
]);
$node4 = $this->drupalCreateNode([
$field_name => [['target_id' => $this->terms[2][0]->id()]],
]);
// Only the nodes with the selected term should be shown.
$this->drupalGet('test-filter-taxonomy-index-tid');
$xpath = $this->xpath('//div[@class="view-content"]//a');
$this->assertIdentical(2, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node2->url()]);
$this->assertIdentical(1, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node3->url()]);
$this->assertIdentical(1, count($xpath));
// Expose the filter.
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid', [], 'Expose filter');
// Set the operator to 'empty' and remove the default term ID.
$this->drupalPostForm(NULL, [
'options[operator]' => 'empty',
'options[value][]' => [],
], 'Apply');
// Save the view.
$this->drupalPostForm(NULL, [], 'Save');
// After switching to 'empty' operator, the node without a term should be
// shown.
$this->drupalGet('test-filter-taxonomy-index-tid');
$xpath = $this->xpath('//div[@class="view-content"]//a');
$this->assertIdentical(1, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node1->url()]);
$this->assertIdentical(1, count($xpath));
// Set the operator to 'not empty'.
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid', ['options[operator]' => 'not empty'], 'Apply');
// Save the view.
$this->drupalPostForm(NULL, [], 'Save');
// After switching to 'not empty' operator, all nodes with terms should be
// shown.
$this->drupalGet('test-filter-taxonomy-index-tid');
$xpath = $this->xpath('//div[@class="view-content"]//a');
$this->assertIdentical(3, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node2->url()]);
$this->assertIdentical(1, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node3->url()]);
$this->assertIdentical(1, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node4->url()]);
$this->assertIdentical(1, count($xpath));
// Select 'Term ID' as the field to be displayed.
$edit = ['name[taxonomy_term_field_data.tid]' => TRUE];
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_taxonomy_term_name/default/field', $edit, 'Add and configure fields');
// Select 'Term' and 'Vocabulary' as filters.
$edit = [
'name[taxonomy_term_field_data.tid]' => TRUE,
'name[taxonomy_term_field_data.vid]' => TRUE,
];
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_taxonomy_term_name/default/filter', $edit, 'Add and configure filter criteria');
// Select 'Empty Vocabulary' and 'Autocomplete' from the list of options.
$this->drupalPostForm('admin/structure/views/nojs/handler-extra/test_taxonomy_term_name/default/filter/tid', [], 'Apply and continue');
// Expose the filter.
$edit = ['options[expose_button][checkbox][checkbox]' => TRUE];
$this->drupalPostForm('admin/structure/views/nojs/handler/test_taxonomy_term_name/default/filter/tid', $edit, 'Expose filter');
$this->drupalPostForm('admin/structure/views/nojs/handler/test_taxonomy_term_name/default/filter/tid', $edit, 'Apply');
// Filter 'Taxonomy terms' belonging to 'Empty Vocabulary'.
$edit = ['options[value][empty_vocabulary]' => TRUE];
$this->drupalPostForm('admin/structure/views/nojs/handler/test_taxonomy_term_name/default/filter/vid', $edit, 'Apply');
$this->drupalPostForm('admin/structure/views/view/test_taxonomy_term_name/edit/default', [], 'Save');
$this->drupalPostForm(NULL, [], t('Update preview'));
$preview = $this->xpath("//div[@class='view-content']");
$this->assertTrue(empty($preview), 'No results.');
}
}

View file

@ -0,0 +1,47 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Tests\ViewTestData;
use Drupal\Tests\views_ui\Functional\UITestBase;
/**
* Tests views taxonomy parent plugin UI.
*
* @group taxonomy
* @see Drupal\taxonomy\Plugin\views\access\Role
*/
class TaxonomyParentUITest extends UITestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_taxonomy_parent'];
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy', 'taxonomy_test_views'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
}
/**
* Tests the taxonomy parent plugin UI.
*/
public function testTaxonomyParentUI() {
$this->drupalGet('admin/structure/views/nojs/handler/test_taxonomy_parent/default/relationship/parent');
$this->assertNoText('The handler for this item is broken or missing.');
}
}

View file

@ -0,0 +1,105 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\TermInterface;
use Drupal\views\Views;
/**
* Tests taxonomy relationships with parent term and node.
*
* @group taxonomy
*/
class TaxonomyRelationshipTest extends TaxonomyTestBase {
/**
* Stores the terms used in the tests.
*
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = [];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_taxonomy_term_relationship'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Make term2 parent of term1.
$this->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();
}
/**
* 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__parent']['left_field'], 'entity_id');
$this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['field'], 'tid');
// Check the generated views data of taxonomy_term__parent.
$views_data = Views::viewsData()->get('taxonomy_term__parent');
// Check the table join data.
$this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['left_field'], 'entity_id');
$this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['field'], 'parent_target_id');
$this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid');
$this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'entity_id');
// Check the parent relationship data.
$this->assertEqual($views_data['parent_target_id']['relationship']['base'], 'taxonomy_term_field_data');
$this->assertEqual($views_data['parent_target_id']['relationship']['base field'], 'tid');
$this->assertEqual($views_data['parent_target_id']['relationship']['label'], t('Parent'));
$this->assertEqual($views_data['parent_target_id']['relationship']['id'], 'standard');
// Check the parent filter and argument data.
$this->assertEqual($views_data['parent_target_id']['filter']['id'], 'numeric');
$this->assertEqual($views_data['parent_target_id']['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__parent_tid, $this->term2->id());
}
$this->assertTrue($row->_relationship_entities['nid'] instanceof NodeInterface);
$this->assertEqual($row->_relationship_entities['nid']->id(), $this->nodes[$index]->id());
}
}
}

View file

@ -0,0 +1,59 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
/**
* Tests the taxonomy term with depth argument.
*
* @group taxonomy
*/
class TaxonomyTermArgumentDepthTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views', 'node'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_argument_taxonomy_index_tid_depth'];
/**
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = [];
/**
* @var \Drupal\views\ViewExecutable
*/
protected $view;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create a term with markup in the label.
$first = $this->createTerm(['name' => '<em>First</em>']);
// Create a node w/o any terms.
$settings = ['type' => 'article'];
// Create a node with linked to the term.
$settings['field_views_testing_tags'][0]['target_id'] = $first->id();
$this->nodes[] = $this->drupalCreateNode($settings);
$this->terms[0] = $first;
}
/**
* Tests title escaping.
*/
public function testTermWithDepthArgumentTitleEscaping() {
$this->drupalGet('test_argument_taxonomy_index_tid_depth/' . $this->terms[0]->id());
$this->assertEscaped($this->terms[0]->label());
}
}

View file

@ -0,0 +1,136 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
/**
* Test the taxonomy term with depth filter.
*
* @group taxonomy
*/
class TaxonomyTermFilterDepthTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views', 'node'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_filter_taxonomy_index_tid_depth'];
/**
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = [];
/**
* @var \Drupal\views\ViewExecutable
*/
protected $view;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create a hierarchy 3 deep. Note the parent setup function creates two
// top-level terms w/o children.
$first = $this->createTerm(['name' => 'First']);
$second = $this->createTerm(['name' => 'Second', 'parent' => $first->id()]);
$third = $this->createTerm(['name' => 'Third', 'parent' => $second->id()]);
// Create a node w/o any terms.
$settings = ['type' => 'article'];
$this->nodes[] = $this->drupalCreateNode($settings);
// Create a node with only the top level term.
$settings['field_views_testing_tags'][0]['target_id'] = $first->id();
$this->nodes[] = $this->drupalCreateNode($settings);
// Create a node with only the third level term.
$settings['field_views_testing_tags'][0]['target_id'] = $third->id();
$this->nodes[] = $this->drupalCreateNode($settings);
$this->terms[0] = $first;
$this->terms[1] = $second;
$this->terms[2] = $third;
$this->view = Views::getView('test_filter_taxonomy_index_tid_depth');
}
/**
* Tests the terms with depth filter.
*/
public function testTermWithDepthFilter() {
$column_map = ['nid' => 'nid'];
$assert_method = 'assertIdentical';
// Default view has an empty value for this filter, so all nodes should be
// returned.
$expected = [
['nid' => 1],
['nid' => 2],
['nid' => 3],
['nid' => 4],
['nid' => 5],
];
$this->executeView($this->view);
$this->assertIdenticalResultsetHelper($this->view, $expected, $column_map, $assert_method);
// Set filter to search on top-level term, with depth 0.
$expected = [['nid' => 4]];
$this->assertTermWithDepthResult($this->terms[0]->id(), 0, $expected);
// Top-level term, depth 1.
$expected = [['nid' => 4]];
$this->assertTermWithDepthResult($this->terms[0]->id(), 0, $expected);
// Top-level term, depth 2.
$expected = [['nid' => 4], ['nid' => 5]];
$this->assertTermWithDepthResult($this->terms[0]->id(), 2, $expected);
// Second-level term, depth 1.
$expected = [['nid' => 5]];
$this->assertTermWithDepthResult($this->terms[1]->id(), 1, $expected);
// Third-level term, depth 0.
$expected = [['nid' => 5]];
$this->assertTermWithDepthResult($this->terms[2]->id(), 0, $expected);
// Third-level term, depth 1.
$expected = [['nid' => 5]];
$this->assertTermWithDepthResult($this->terms[2]->id(), 1, $expected);
// Third-level term, depth -2.
$expected = [['nid' => 4], ['nid' => 5]];
$this->assertTermWithDepthResult($this->terms[2]->id(), -2, $expected);
}
/**
* Changes the tid filter to given term and depth.
*
* @param int $tid
* The term ID to filter on.
* @param int $depth
* The depth to search.
* @param array $expected
* The expected views result.
*/
protected function assertTermWithDepthResult($tid, $depth, array $expected) {
$this->view->destroy();
$this->view->initDisplay();
$filters = $this->view->displayHandlers->get('default')
->getOption('filters');
$filters['tid_depth']['depth'] = $depth;
$filters['tid_depth']['value'] = [$tid];
$this->view->displayHandlers->get('default')
->setOption('filters', $filters);
$this->executeView($this->view);
$this->assertIdenticalResultsetHelper($this->view, $expected, ['nid' => 'nid'], 'assertIdentical');
}
}

View file

@ -0,0 +1,161 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
use Drupal\views\Views;
/**
* Tests the taxonomy term view page and its translation.
*
* @group taxonomy
*/
class TaxonomyTermViewTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy', 'views'];
/**
* An user with permissions to administer taxonomy.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Name of the taxonomy term reference field.
*
* @var string
*/
protected $fieldName1;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create an administrative user.
$this->adminUser = $this->drupalCreateUser(['administer taxonomy', 'bypass node access']);
$this->drupalLogin($this->adminUser);
// Create a vocabulary and add two term reference fields to article nodes.
$this->fieldName1 = mb_strtolower($this->randomMachineName());
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
'auto_create' => TRUE,
];
$this->createEntityReferenceField('node', 'article', $this->fieldName1, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName1, [
'type' => 'options_select',
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName1, [
'type' => 'entity_reference_label',
])
->save();
}
/**
* Tests that the taxonomy term view is working properly.
*/
public function testTaxonomyTermView() {
// Create terms in the vocabulary.
$term = $this->createTerm();
// Post an article.
$edit = [];
$edit['title[0][value]'] = $original_title = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomMachineName();
$edit["{$this->fieldName1}[]"] = $term->id();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertText($term->label());
$this->assertText($node->label());
\Drupal::service('module_installer')->install(['language', 'content_translation']);
ConfigurableLanguage::createFromLangcode('ur')->save();
// Enable translation for the article content type and ensure the change is
// picked up.
\Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
$roles = $this->adminUser->getRoles(TRUE);
Role::load(reset($roles))
->grantPermission('create content translations')
->grantPermission('translate any entity')
->save();
drupal_static_reset();
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::service('router.builder')->rebuild();
\Drupal::service('entity.definition_update_manager')->applyUpdates();
$edit['title[0][value]'] = $translated_title = $this->randomMachineName();
$this->drupalPostForm('node/' . $node->id() . '/translations/add/en/ur', $edit, t('Save (this translation)'));
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertText($term->label());
$this->assertText($original_title);
$this->assertNoText($translated_title);
$this->drupalGet('ur/taxonomy/term/' . $term->id());
$this->assertText($term->label());
$this->assertNoText($original_title);
$this->assertText($translated_title);
// Uninstall language module and ensure that the language is not part of the
// query anymore.
// @see \Drupal\views\Plugin\views\filter\LanguageFilter::query()
$node->delete();
// We also have to remove the nodes created by the parent ::setUp() method
// if we want to be able to uninstall the Content Translation module.
foreach (Node::loadMultiple() as $node) {
$node->delete();
}
\Drupal::service('module_installer')->uninstall(['content_translation', 'language']);
$view = Views::getView('taxonomy_term');
$view->initDisplay();
$view->setArguments([$term->id()]);
$view->build();
/** @var \Drupal\Core\Database\Query\Select $query */
$query = $view->build_info['query'];
$tables = $query->getTables();
// Ensure that the join to node_field_data is not added by default.
$this->assertEqual(['node_field_data', 'taxonomy_index'], array_keys($tables));
// Ensure that the filter to the language column is not there by default.
$condition = $query->conditions();
// We only want to check the no. of conditions in the query.
unset($condition['#conjunction']);
$this->assertEqual(1, count($condition));
// Clear permissions for anonymous users to check access for default views.
Role::load(RoleInterface::ANONYMOUS_ID)->revokePermission('access content')->save();
// Test the default views disclose no data by default.
$this->drupalLogout();
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertResponse(403);
$this->drupalGet('taxonomy/term/' . $term->id() . '/feed');
$this->assertResponse(403);
}
}

View file

@ -0,0 +1,155 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Base class for all taxonomy tests.
*/
abstract class TaxonomyTestBase extends ViewTestBase {
use EntityReferenceTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy', 'taxonomy_test_views'];
/**
* Stores the nodes used for the different tests.
*
* @var \Drupal\node\NodeInterface[]
*/
protected $nodes = [];
/**
* The vocabulary used for creating terms.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
/**
* Stores the first term used in the different tests.
*
* @var \Drupal\taxonomy\TermInterface
*/
protected $term1;
/**
* Stores the second term used in the different tests.
*
* @var \Drupal\taxonomy\TermInterface
*/
protected $term2;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->mockStandardInstall();
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
}
$this->term1 = $this->createTerm();
$this->term2 = $this->createTerm();
$node = [];
$node['type'] = 'article';
$node['field_views_testing_tags'][]['target_id'] = $this->term1->id();
$node['field_views_testing_tags'][]['target_id'] = $this->term2->id();
$this->nodes[] = $this->drupalCreateNode($node);
$this->nodes[] = $this->drupalCreateNode($node);
}
/**
* Provides a workaround for the inability to use the standard profile.
*
* @see https://www.drupal.org/node/1708692
*/
protected function mockStandardInstall() {
$this->drupalCreateContentType([
'type' => 'article',
]);
// Create the vocabulary for the tag field.
$this->vocabulary = Vocabulary::create([
'name' => 'Views testing tags',
'vid' => 'views_testing_tags',
]);
$this->vocabulary->save();
$field_name = 'field_' . $this->vocabulary->id();
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
'auto_create' => TRUE,
];
$this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($field_name, [
'type' => 'entity_reference_autocomplete_tags',
'weight' => -4,
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($field_name, [
'type' => 'entity_reference_label',
'weight' => 10,
])
->save();
entity_get_display('node', 'article', 'teaser')
->setComponent($field_name, [
'type' => 'entity_reference_label',
'weight' => 10,
])
->save();
}
/**
* Creates and returns a taxonomy term.
*
* @param array $settings
* (optional) An array of values to override the following default
* properties of the term:
* - name: A random string.
* - description: A random string.
* - format: First available text format.
* - vid: Vocabulary ID of self::$vocabulary object.
* - langcode: LANGCODE_NOT_SPECIFIED.
* Defaults to an empty array.
*
* @return \Drupal\taxonomy\Entity\Term
* The created taxonomy term.
*/
protected function createTerm(array $settings = []) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$settings += [
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->id(),
'vid' => $this->vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
];
$term = Term::create($settings);
$term->save();
return $term;
}
}

View file

@ -0,0 +1,76 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests the vocabulary argument.
*
* @group taxonomy
*/
class TaxonomyVocabularyArgumentTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_argument_taxonomy_vocabulary'];
/**
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = [];
/**
* Vocabularies used for creating terms.
*
* @var \Drupal\taxonomy\VocabularyInterface[]
*/
protected $vocabularies;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Add default vocabulary to list of vocabularies.
$this->vocabularies[] = $this->vocabulary;
// Create additional vocabulary.
$vocabulary = Vocabulary::create([
'name' => 'Views testing category',
'vid' => 'views_testing_category',
]);
$vocabulary->save();
$this->vocabularies[] = $vocabulary;
// Create some terms.
$this->terms[0] = $this->createTerm([
'name' => 'First',
'vid' => $this->vocabularies[0]->id(),
]);
$this->terms[1] = $this->createTerm([
'name' => 'Second',
'vid' => $this->vocabularies[1]->id(),
]);
}
/**
* Tests the vocabulary argument handler.
*
* @see Drupal\taxonomy\Plugin\views\argument\VocabularyVid
*/
public function testTermWithVocabularyArgument() {
$this->drupalGet('test_argument_taxonomy_vocabulary/' . $this->vocabularies[0]->id());
// First term should be present.
$this->assertText($this->terms[0]->label());
// Second term should not be present.
$this->assertNoText($this->terms[1]->label());
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
/**
* Tests the term_name field handler.
*
* @group taxonomy
*
* @see \Drupal\taxonomy\Plugin\views\field\TermName
*/
class TermNameFieldTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $testViews = ['test_taxonomy_term_name'];
/**
* Tests term name field plugin functionality.
*/
public function testTermNameField() {
$this->term1->name->value = $this->randomMachineName() . ' ' . $this->randomMachineName();
$this->term1->save();
$user = $this->drupalCreateUser(['access content']);
$this->drupalLogin($user);
$view = Views::getView('test_taxonomy_term_name');
$view->initDisplay();
$this->executeView($view);
$this->assertEqual($this->term1->getName(), $view->getStyle()->getField(0, 'name'));
$this->assertEqual($this->term2->getName(), $view->getStyle()->getField(1, 'name'));
$view = Views::getView('test_taxonomy_term_name');
$display =& $view->storage->getDisplay('default');
$display['display_options']['fields']['name']['convert_spaces'] = TRUE;
$view->storage->invalidateCaches();
$this->executeView($view);
$this->assertEqual(str_replace(' ', '-', $this->term1->getName()), $view->getStyle()->getField(0, 'name'));
$this->assertEqual($this->term2->getName(), $view->getStyle()->getField(1, 'name'));
}
}

View file

@ -0,0 +1,181 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests loading, saving and deleting vocabularies.
*
* @group taxonomy
*/
class VocabularyCrudTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['field_test', 'taxonomy_crud'];
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(['create article content', 'administer taxonomy']);
$this->drupalLogin($admin_user);
$this->vocabulary = $this->createVocabulary();
}
/**
* Test deleting a taxonomy that contains terms.
*/
public function testTaxonomyVocabularyDeleteWithTerms() {
// Delete any existing vocabularies.
foreach (Vocabulary::loadMultiple() as $vocabulary) {
$vocabulary->delete();
}
$query = \Drupal::entityQuery('taxonomy_term')->count();
// Assert that there are no terms left.
$this->assertEqual(0, $query->execute(), 'There are no terms remaining.');
$terms = [];
for ($i = 0; $i < 5; $i++) {
$terms[$i] = $this->createTerm($vocabulary);
}
// Set up hierarchy. term 2 is a child of 1 and 4 a child of 1 and 2.
$terms[2]->parent = [$terms[1]->id()];
$terms[2]->save();
$terms[4]->parent = [$terms[1]->id(), $terms[2]->id()];
$terms[4]->save();
// Assert that there are now 5 terms.
$this->assertEqual(5, $query->execute(), 'There are 5 terms found.');
$vocabulary->delete();
// Assert that there are no terms left.
$this->assertEqual(0, $query->execute(), 'All terms are deleted.');
}
/**
* Ensure that the vocabulary static reset works correctly.
*/
public function testTaxonomyVocabularyLoadStaticReset() {
$original_vocabulary = Vocabulary::load($this->vocabulary->id());
$this->assertTrue(is_object($original_vocabulary), 'Vocabulary loaded successfully.');
$this->assertEqual($this->vocabulary->label(), $original_vocabulary->label(), 'Vocabulary loaded successfully.');
// Change the name and description.
$vocabulary = $original_vocabulary;
$vocabulary->set('name', $this->randomMachineName());
$vocabulary->set('description', $this->randomMachineName());
$vocabulary->save();
// Load the vocabulary.
$new_vocabulary = Vocabulary::load($original_vocabulary->id());
$this->assertEqual($new_vocabulary->label(), $vocabulary->label(), 'The vocabulary was loaded.');
// Delete the vocabulary.
$this->vocabulary->delete();
$vocabularies = Vocabulary::loadMultiple();
$this->assertTrue(!isset($vocabularies[$this->vocabulary->id()]), 'The vocabulary was deleted.');
}
/**
* Tests for loading multiple vocabularies.
*/
public function testTaxonomyVocabularyLoadMultiple() {
// Delete any existing vocabularies.
foreach (Vocabulary::loadMultiple() as $vocabulary) {
$vocabulary->delete();
}
// Create some vocabularies and assign weights.
$vocabulary1 = $this->createVocabulary();
$vocabulary1->set('weight', 0);
$vocabulary1->save();
$vocabulary2 = $this->createVocabulary();
$vocabulary2->set('weight', 1);
$vocabulary2->save();
$vocabulary3 = $this->createVocabulary();
$vocabulary3->set('weight', 2);
$vocabulary3->save();
// Check if third party settings exist.
$this->assertEqual('bar', $vocabulary1->getThirdPartySetting('taxonomy_crud', 'foo'), 'Third party settings were added to the vocabulary.');
$this->assertEqual('bar', $vocabulary2->getThirdPartySetting('taxonomy_crud', 'foo'), 'Third party settings were added to the vocabulary.');
$this->assertEqual('bar', $vocabulary3->getThirdPartySetting('taxonomy_crud', 'foo'), 'Third party settings were added to the vocabulary.');
// Fetch the names for all vocabularies, confirm that they are keyed by
// machine name.
$names = taxonomy_vocabulary_get_names();
$this->assertEqual($names[$vocabulary1->id()], $vocabulary1->id(), 'Vocabulary 1 name found.');
// Fetch the vocabularies with entity_load_multiple(), specifying IDs.
// Ensure they are returned in the same order as the original array.
$vocabularies = Vocabulary::loadMultiple([$vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id()]);
$loaded_order = array_keys($vocabularies);
$expected_order = [$vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id()];
$this->assertIdentical($loaded_order, $expected_order);
// Test loading vocabularies by their properties.
$controller = $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary');
// Fetch vocabulary 1 by name.
$vocabulary = current($controller->loadByProperties(['name' => $vocabulary1->label()]));
$this->assertEqual($vocabulary->id(), $vocabulary1->id(), 'Vocabulary loaded successfully by name.');
// Fetch vocabulary 2 by name and ID.
$vocabulary = current($controller->loadByProperties([
'name' => $vocabulary2->label(),
'vid' => $vocabulary2->id(),
]));
$this->assertEqual($vocabulary->id(), $vocabulary2->id(), 'Vocabulary loaded successfully by name and ID.');
}
/**
* Test uninstall and reinstall of the taxonomy module.
*/
public function testUninstallReinstall() {
// Field storages and fields attached to taxonomy term bundles should be
// removed when the module is uninstalled.
$field_name = mb_strtolower($this->randomMachineName() . '_field_name');
$storage_definition = [
'field_name' => $field_name,
'entity_type' => 'taxonomy_term',
'type' => 'text',
'cardinality' => 4,
];
FieldStorageConfig::create($storage_definition)->save();
$field_definition = [
'field_name' => $field_name,
'entity_type' => 'taxonomy_term',
'bundle' => $this->vocabulary->id(),
'label' => $this->randomMachineName() . '_label',
];
FieldConfig::create($field_definition)->save();
// Remove the third party setting from the memory copy of the vocabulary.
// We keep this invalid copy around while the taxonomy module is not even
// installed for testing below.
$this->vocabulary->unsetThirdPartySetting('taxonomy_crud', 'foo');
require_once $this->root . '/core/includes/install.inc';
$this->container->get('module_installer')->uninstall(['taxonomy']);
$this->container->get('module_installer')->install(['taxonomy']);
// Now create a vocabulary with the same name. All fields
// connected to this vocabulary name should have been removed when the
// module was uninstalled. Creating a new field with the same name and
// an instance of this field on the same bundle name should be successful.
$this->vocabulary->enforceIsNew();
$this->vocabulary->save();
FieldStorageConfig::create($storage_definition)->save();
FieldConfig::create($field_definition)->save();
}
}

View file

@ -0,0 +1,124 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
/**
* Tests the language functionality for vocabularies.
*
* @group taxonomy
*/
class VocabularyLanguageTest extends TaxonomyTestBase {
public static $modules = ['language'];
protected function setUp() {
parent::setUp();
// Create an administrative user.
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
// Add some custom languages.
ConfigurableLanguage::create([
'id' => 'aa',
'label' => $this->randomMachineName(),
])->save();
ConfigurableLanguage::create([
'id' => 'bb',
'label' => $this->randomMachineName(),
])->save();
}
/**
* Tests language settings for vocabularies.
*/
public function testVocabularyLanguage() {
$this->drupalGet('admin/structure/taxonomy/add');
// Check that we have the language selector available.
$this->assertField('edit-langcode', 'The language selector field was found on the page.');
// Create the vocabulary.
$vid = mb_strtolower($this->randomMachineName());
$edit['name'] = $this->randomMachineName();
$edit['description'] = $this->randomMachineName();
$edit['langcode'] = 'aa';
$edit['vid'] = $vid;
$this->drupalPostForm(NULL, $edit, t('Save'));
// Check the language on the edit page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.');
// Change the language and save again.
$edit['langcode'] = 'bb';
unset($edit['vid']);
$this->drupalPostForm(NULL, $edit, t('Save'));
// Check again the language on the edit page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.');
}
/**
* Tests term language settings for vocabulary terms are saved and updated.
*/
public function testVocabularyDefaultLanguageForTerms() {
// Add a new vocabulary and check that the default language settings are for
// the terms are saved.
$edit = [
'name' => $this->randomMachineName(),
'vid' => mb_strtolower($this->randomMachineName()),
'default_language[langcode]' => 'bb',
'default_language[language_alterable]' => TRUE,
];
$vid = $edit['vid'];
$this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
// Check that the vocabulary was actually created.
$this->drupalGet('admin/structure/taxonomy/manage/' . $edit['vid']);
$this->assertResponse(200, 'The vocabulary has been created.');
// Check that the language settings were saved.
$language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']);
$this->assertEqual($language_settings->getDefaultLangcode(), 'bb', 'The langcode was saved.');
$this->assertTrue($language_settings->isLanguageAlterable(), 'The visibility setting was saved.');
// Check that the correct options are selected in the interface.
$this->assertOptionSelected('edit-default-language-langcode', 'bb', 'The correct default language for the terms of this vocabulary is selected.');
$this->assertFieldChecked('edit-default-language-language-alterable', 'Show language selection option is checked.');
// Edit the vocabulary and check that the new settings are updated.
$edit = [
'default_language[langcode]' => 'aa',
'default_language[language_alterable]' => FALSE,
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
// And check again the settings and also the interface.
$language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
$this->assertEqual($language_settings->getDefaultLangcode(), 'aa', 'The langcode was saved.');
$this->assertFalse($language_settings->isLanguageAlterable(), 'The visibility setting was saved.');
$this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.');
$this->assertNoFieldChecked('edit-default-language-language-alterable', 'Show language selection option is not checked.');
// Check that language settings are changed after editing vocabulary.
$edit = [
'name' => $this->randomMachineName(),
'default_language[langcode]' => 'authors_default',
'default_language[language_alterable]' => FALSE,
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
// Check that we have the new settings.
$new_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
$this->assertEqual($new_settings->getDefaultLangcode(), 'authors_default', 'The langcode was saved.');
$this->assertFalse($new_settings->isLanguageAlterable(), 'The new visibility setting was saved.');
}
}

View file

@ -0,0 +1,369 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Utility\Unicode;
/**
* Tests the taxonomy vocabulary permissions.
*
* @group taxonomy
*/
class VocabularyPermissionsTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['help'];
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('page_title_block');
$this->drupalPlaceBlock('local_actions_block');
$this->drupalPlaceBlock('help_block');
}
/**
* Create, edit and delete a vocabulary via the user interface.
*/
public function testVocabularyPermissionsVocabulary() {
// VocabularyTest.php already tests for user with "administer taxonomy"
// permission.
// Test as user without proper permissions.
$authenticated_user = $this->drupalCreateUser([]);
$this->drupalLogin($authenticated_user);
$assert_session = $this->assertSession();
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy');
$assert_session->statusCodeEquals(403);
// Test as user with "access taxonomy overview" permissions.
$proper_user = $this->drupalCreateUser(['access taxonomy overview']);
$this->drupalLogin($proper_user);
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy');
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('Vocabulary name');
$assert_session->linkNotExists('Add vocabulary');
}
/**
* Test the vocabulary overview permission.
*/
public function testTaxonomyVocabularyOverviewPermissions() {
// Create two vocabularies, one with two terms, the other without any term.
/** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary1 , $vocabulary2 */
$vocabulary1 = $this->createVocabulary();
$vocabulary2 = $this->createVocabulary();
$vocabulary1_id = $vocabulary1->id();
$vocabulary2_id = $vocabulary2->id();
$this->createTerm($vocabulary1);
$this->createTerm($vocabulary1);
// Assert expected help texts on first vocabulary.
$edit_help_text = t('You can reorganize the terms in @capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', ['@capital_name' => Unicode::ucfirst($vocabulary1->label())]);
$no_edit_help_text = t('@capital_name contains the following terms.', ['@capital_name' => Unicode::ucfirst($vocabulary1->label())]);
$assert_session = $this->assertSession();
// Logged in as admin user with 'administer taxonomy' permission.
$admin_user = $this->drupalCreateUser(['administer taxonomy']);
$this->drupalLogin($admin_user);
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->linkExists('Edit');
$assert_session->linkExists('Delete');
$assert_session->linkExists('Add term');
$assert_session->buttonExists('Save');
$assert_session->pageTextContains('Weight');
$assert_session->fieldExists('Weight');
$assert_session->pageTextContains($edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should be shown.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('No terms available');
$assert_session->linkExists('Add term');
// Login as a user without any of the required permissions.
$no_permission_user = $this->drupalCreateUser();
$this->drupalLogin($no_permission_user);
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
$assert_session->statusCodeEquals(403);
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
$assert_session->statusCodeEquals(403);
// Log in as a user with only the overview permission, neither edit nor
// delete operations must be available and no Save button.
$overview_only_user = $this->drupalCreateUser(['access taxonomy overview']);
$this->drupalLogin($overview_only_user);
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->linkNotExists('Edit');
$assert_session->linkNotExists('Delete');
$assert_session->buttonNotExists('Save');
$assert_session->pageTextContains('Weight');
$assert_session->fieldNotExists('Weight');
$assert_session->linkNotExists('Add term');
$assert_session->pageTextContains($no_edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should not be shown.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('No terms available');
$assert_session->linkNotExists('Add term');
// Login as a user with permission to edit terms, only edit link should be
// visible.
$edit_user = $this->createUser([
'access taxonomy overview',
'edit terms in ' . $vocabulary1_id,
'edit terms in ' . $vocabulary2_id,
]);
$this->drupalLogin($edit_user);
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->linkExists('Edit');
$assert_session->linkNotExists('Delete');
$assert_session->buttonExists('Save');
$assert_session->pageTextContains('Weight');
$assert_session->fieldExists('Weight');
$assert_session->linkNotExists('Add term');
$assert_session->pageTextContains($edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should not be shown.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('No terms available');
$assert_session->linkNotExists('Add term');
// Login as a user with permission only to delete terms.
$edit_delete_user = $this->createUser([
'access taxonomy overview',
'delete terms in ' . $vocabulary1_id,
'delete terms in ' . $vocabulary2_id,
]);
$this->drupalLogin($edit_delete_user);
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->linkNotExists('Edit');
$assert_session->linkExists('Delete');
$assert_session->linkNotExists('Add term');
$assert_session->buttonNotExists('Save');
$assert_session->pageTextContains('Weight');
$assert_session->fieldNotExists('Weight');
$assert_session->pageTextContains($no_edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should not be shown.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('No terms available');
$assert_session->linkNotExists('Add term');
// Login as a user with permission to edit and delete terms.
$edit_delete_user = $this->createUser([
'access taxonomy overview',
'edit terms in ' . $vocabulary1_id,
'delete terms in ' . $vocabulary1_id,
'edit terms in ' . $vocabulary2_id,
'delete terms in ' . $vocabulary2_id,
]);
$this->drupalLogin($edit_delete_user);
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->linkExists('Edit');
$assert_session->linkExists('Delete');
$assert_session->linkNotExists('Add term');
$assert_session->buttonExists('Save');
$assert_session->pageTextContains('Weight');
$assert_session->fieldExists('Weight');
$assert_session->pageTextContains($edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should not be shown.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('No terms available');
$assert_session->linkNotExists('Add term');
// Login as a user with permission to create new terms, only add new term
// link should be visible.
$edit_user = $this->createUser([
'access taxonomy overview',
'create terms in ' . $vocabulary1_id,
'create terms in ' . $vocabulary2_id,
]);
$this->drupalLogin($edit_user);
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->linkNotExists('Edit');
$assert_session->linkNotExists('Delete');
$assert_session->linkExists('Add term');
$assert_session->buttonNotExists('Save');
$assert_session->pageTextContains('Weight');
$assert_session->fieldNotExists('Weight');
$assert_session->pageTextContains($no_edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should not be shown.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('No terms available');
$assert_session->linkExists('Add term');
}
/**
* Create, edit and delete a taxonomy term via the user interface.
*/
public function testVocabularyPermissionsTaxonomyTerm() {
// Vocabulary used for creating, removing and editing terms.
$vocabulary = $this->createVocabulary();
// Test as admin user.
$user = $this->drupalCreateUser(['administer taxonomy']);
$this->drupalLogin($user);
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
$this->assertResponse(200);
$this->assertField('edit-name-0-value', 'Add taxonomy term form opened successfully.');
// Submit the term.
$edit = [];
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('Created new term @name.', ['@name' => $edit['name[0][value]']]), 'Term created successfully.');
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
$terms = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadByProperties(['name' => $edit['name[0][value]']]);
$term = reset($terms);
// Edit the term.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->assertResponse(200);
$this->assertText($edit['name[0][value]'], 'Edit taxonomy term form opened successfully.');
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('Updated term @name.', ['@name' => $edit['name[0][value]']]), 'Term updated successfully.');
// Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$this->assertRaw(t('Are you sure you want to delete the @entity-type %label?', ['@entity-type' => 'taxonomy term', '%label' => $edit['name[0][value]']]), 'Delete taxonomy term form opened successfully.');
// Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted term %name.', ['%name' => $edit['name[0][value]']]), 'Term deleted.');
// Test as user with "create" permissions.
$user = $this->drupalCreateUser(["create terms in {$vocabulary->id()}"]);
$this->drupalLogin($user);
$assert_session = $this->assertSession();
// Create a new term.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
$assert_session->statusCodeEquals(200);
$assert_session->fieldExists('name[0][value]');
// Submit the term.
$edit = [];
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$assert_session->pageTextContains(t('Created new term @name.', ['@name' => $edit['name[0][value]']]));
$terms = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadByProperties(['name' => $edit['name[0][value]']]);
$term = reset($terms);
// Ensure that edit and delete access is denied.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$assert_session->statusCodeEquals(403);
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$assert_session->statusCodeEquals(403);
// Test as user with "edit" permissions.
$user = $this->drupalCreateUser(["edit terms in {$vocabulary->id()}"]);
$this->drupalLogin($user);
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
$this->assertResponse(403, 'Add taxonomy term form open failed.');
// Create a test term.
$term = $this->createTerm($vocabulary);
// Edit the term.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->assertResponse(200);
$this->assertText($term->getName(), 'Edit taxonomy term form opened successfully.');
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('Updated term @name.', ['@name' => $edit['name[0][value]']]), 'Term updated successfully.');
// Verify that the update message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
// Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$this->assertResponse(403, 'Delete taxonomy term form open failed.');
// Test as user with "delete" permissions.
$user = $this->drupalCreateUser(["delete terms in {$vocabulary->id()}"]);
$this->drupalLogin($user);
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
$this->assertResponse(403, 'Add taxonomy term form open failed.');
// Create a test term.
$term = $this->createTerm($vocabulary);
// Edit the term.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->assertResponse(403, 'Edit taxonomy term form open failed.');
// Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$this->assertRaw(t('Are you sure you want to delete the @entity-type %label?', ['@entity-type' => 'taxonomy term', '%label' => $term->getName()]), 'Delete taxonomy term form opened successfully.');
// Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted term %name.', ['%name' => $term->getName()]), 'Term deleted.');
// Test as user without proper permissions.
$user = $this->drupalCreateUser();
$this->drupalLogin($user);
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
$this->assertResponse(403, 'Add taxonomy term form open failed.');
// Create a test term.
$term = $this->createTerm($vocabulary);
// Edit the term.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->assertResponse(403, 'Edit taxonomy term form open failed.');
// Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$this->assertResponse(403, 'Delete taxonomy term form open failed.');
}
}

View file

@ -0,0 +1,47 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\BrowserTestBase;
/**
* Regression test for https://www.drupal.org/node/2807263.
*
* When a Vocabulary entity is unserialized before the modules have been loaded
* (which happens in the KernelPreHandle Stack middleware), then the constants
* that the Vocabulary entity uses are not yet available because they are set in
* taxonomy.module. This means that for example the PageCache middleware cannot
* load any cached Vocabulary entity, because unserialization will fail.
*
* @group taxonomy
*/
class VocabularySerializationTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'vocabulary_serialization_test'];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
Vocabulary::create(['vid' => 'test'])->save();
}
public function testSerialization() {
$this->drupalGet('/vocabulary_serialization_test/test');
$this->assertSession()->statusCodeEquals(200);
$this->assertSame('this is the output', $this->getSession()->getPage()->getContent());
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');
$this->drupalGet('/vocabulary_serialization_test/test');
$this->assertSession()->statusCodeEquals(200);
$this->assertSame('this is the output', $this->getSession()->getPage()->getContent());
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'HIT');
}
}

View file

@ -0,0 +1,53 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
/**
* Tests content translation for vocabularies.
*
* @group taxonomy
*/
class VocabularyTranslationTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['content_translation', 'language'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create an administrative user.
$this->drupalLogin($this->drupalCreateUser([
'administer taxonomy',
'administer content translation',
]));
}
/**
* Tests language settings for vocabularies.
*/
public function testVocabularyLanguage() {
$this->drupalGet('admin/structure/taxonomy/add');
// Check that the field to enable content translation is available.
$this->assertField('edit-default-language-content-translation', 'The content translation checkbox is present on the page.');
// Create the vocabulary.
$vid = mb_strtolower($this->randomMachineName());
$edit['name'] = $this->randomMachineName();
$edit['description'] = $this->randomMachineName();
$edit['langcode'] = 'en';
$edit['vid'] = $vid;
$edit['default_language[content_translation]'] = TRUE;
$this->drupalPostForm(NULL, $edit, t('Save'));
// Check if content translation is enabled on the edit page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
$this->assertFieldChecked('edit-default-language-content-translation', 'The content translation was correctly selected.');
}
}

View file

@ -0,0 +1,158 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Url;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests the taxonomy vocabulary interface.
*
* @group taxonomy
*/
class VocabularyUiTest extends TaxonomyTestBase {
/**
* The vocabulary used for creating terms.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $vocabulary;
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
$this->vocabulary = $this->createVocabulary();
$this->drupalPlaceBlock('local_actions_block');
$this->drupalPlaceBlock('page_title_block');
}
/**
* Create, edit and delete a vocabulary via the user interface.
*/
public function testVocabularyInterface() {
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy');
// Create a new vocabulary.
$this->clickLink(t('Add vocabulary'));
$edit = [];
$vid = mb_strtolower($this->randomMachineName());
$edit['name'] = $this->randomMachineName();
$edit['description'] = $this->randomMachineName();
$edit['vid'] = $vid;
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Created new vocabulary %name.', ['%name' => $edit['name']]), 'Vocabulary created successfully.');
// Edit the vocabulary.
$this->drupalGet('admin/structure/taxonomy');
$this->assertText($edit['name'], 'Vocabulary name found in the vocabulary overview listing.');
$this->assertText($edit['description'], 'Vocabulary description found in the vocabulary overview listing.');
$this->assertLinkByHref(Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $edit['vid']])->toString());
$this->clickLink(t('Edit vocabulary'));
$edit = [];
$edit['name'] = $this->randomMachineName();
$edit['description'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalGet('admin/structure/taxonomy');
$this->assertText($edit['name'], 'Vocabulary name found in the vocabulary overview listing.');
$this->assertText($edit['description'], 'Vocabulary description found in the vocabulary overview listing.');
// Try to submit a vocabulary with a duplicate machine name.
$edit['vid'] = $vid;
$this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
$this->assertText(t('The machine-readable name is already in use. It must be unique.'));
// Try to submit an invalid machine name.
$edit['vid'] = '!&^%';
$this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
$this->assertText(t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
// Ensure that vocabulary titles are escaped properly.
$edit = [];
$edit['name'] = 'Don\'t Panic';
$edit['description'] = $this->randomMachineName();
$edit['vid'] = 'don_t_panic';
$this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
$site_name = $this->config('system.site')->get('name');
$this->assertTitle(t("Don't Panic | @site-name", ['@site-name' => $site_name]), 'The page title contains the escaped character.');
}
/**
* Changing weights on the vocabulary overview with two or more vocabularies.
*/
public function testTaxonomyAdminChangingWeights() {
// Create some vocabularies.
for ($i = 0; $i < 10; $i++) {
$this->createVocabulary();
}
// Get all vocabularies and change their weights.
$vocabularies = Vocabulary::loadMultiple();
$edit = [];
foreach ($vocabularies as $key => $vocabulary) {
$weight = -$vocabulary->get('weight');
$vocabularies[$key]->set('weight', $weight);
$edit['vocabularies[' . $key . '][weight]'] = $weight;
}
// Saving the new weights via the interface.
$this->drupalPostForm('admin/structure/taxonomy', $edit, t('Save'));
// Load the vocabularies from the database.
$this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache();
$new_vocabularies = Vocabulary::loadMultiple();
// Check that the weights are saved in the database correctly.
foreach ($vocabularies as $key => $vocabulary) {
$this->assertEqual($new_vocabularies[$key]->get('weight'), $vocabularies[$key]->get('weight'), 'The vocabulary weight was changed.');
}
}
/**
* Test the vocabulary overview with no vocabularies.
*/
public function testTaxonomyAdminNoVocabularies() {
// Delete all vocabularies.
$vocabularies = Vocabulary::loadMultiple();
foreach ($vocabularies as $key => $vocabulary) {
$vocabulary->delete();
}
// Confirm that no vocabularies are found in the database.
$this->assertFalse(Vocabulary::loadMultiple(), 'No vocabularies found.');
$this->drupalGet('admin/structure/taxonomy');
// Check the default message for no vocabularies.
$this->assertText(t('No vocabularies available.'));
}
/**
* Deleting a vocabulary.
*/
public function testTaxonomyAdminDeletingVocabulary() {
// Create a vocabulary.
$vid = mb_strtolower($this->randomMachineName());
$edit = [
'name' => $this->randomMachineName(),
'vid' => $vid,
];
$this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
$this->assertText(t('Created new vocabulary'), 'New vocabulary was created.');
// Check the created vocabulary.
$this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache();
$vocabulary = Vocabulary::load($vid);
$this->assertTrue($vocabulary, 'Vocabulary found.');
// Delete the vocabulary.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id());
$this->clickLink(t('Delete'));
$this->assertRaw(t('Are you sure you want to delete the vocabulary %name?', ['%name' => $vocabulary->label()]), '[confirm deletion] Asks for confirmation.');
$this->assertText(t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'), '[confirm deletion] Inform that all terms will be deleted.');
// Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted vocabulary %name.', ['%name' => $vocabulary->label()]), 'Vocabulary deleted.');
$this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache();
$this->assertFalse(Vocabulary::load($vid), 'Vocabulary not found.');
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Drupal\Tests\taxonomy\Kernel\Migrate;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to taxonomy.settings.yml.
*
* @group migrate_drupal_6
*/
class MigrateTaxonomyConfigsTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('taxonomy_settings');
}
/**
* Tests migration of taxonomy variables to taxonomy.settings.yml.
*/
public function testTaxonomySettings() {
$config = $this->config('taxonomy.settings');
$this->assertIdentical(100, $config->get('terms_per_page_admin'));
$this->assertIdentical(FALSE, $config->get('override_selector'));
$this->assertConfigSchema(\Drupal::service('config.typed'), 'taxonomy.settings', $config->get());
}
}

Some files were not shown because too many files have changed in this diff Show more