updated core to 8.6.1 via composer
This commit is contained in:
+32
@@ -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();
|
||||
+250
@@ -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: { }
|
||||
+128
@@ -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: { }
|
||||
@@ -5,4 +5,4 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- taxonomy
|
||||
- drupal:taxonomy
|
||||
|
||||
+2
-2
@@ -5,5 +5,5 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- taxonomy
|
||||
- migrate
|
||||
- drupal:taxonomy
|
||||
- drupal:migrate
|
||||
|
||||
@@ -5,4 +5,4 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- taxonomy
|
||||
- drupal:taxonomy
|
||||
|
||||
+2
-2
@@ -5,5 +5,5 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- taxonomy
|
||||
- views
|
||||
- drupal:taxonomy
|
||||
- drupal:views
|
||||
|
||||
-1
@@ -171,4 +171,3 @@ display:
|
||||
- url
|
||||
- user.permissions
|
||||
tags: { }
|
||||
|
||||
|
||||
+2
-2
@@ -124,8 +124,8 @@ display:
|
||||
relationships:
|
||||
parent:
|
||||
id: parent
|
||||
table: taxonomy_term_hierarchy
|
||||
field: parent
|
||||
table: taxonomy_term__parent
|
||||
field: parent_target_id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: Parent
|
||||
|
||||
+2
-2
@@ -186,8 +186,8 @@ display:
|
||||
plugin_id: standard
|
||||
parent:
|
||||
id: parent
|
||||
table: taxonomy_term_hierarchy
|
||||
field: parent
|
||||
table: taxonomy_term__parent
|
||||
field: parent_target_id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: Parent
|
||||
|
||||
+163
@@ -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: { }
|
||||
+1
-1
@@ -4,4 +4,4 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- taxonomy
|
||||
- drupal:taxonomy
|
||||
|
||||
@@ -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',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
}
|
||||
@@ -50,12 +50,12 @@ class TaxonomyQueryAlterTest extends BrowserTestBase {
|
||||
$this->setupQueryTagTestHooks();
|
||||
$loaded_terms = $term_storage->loadParents($terms[2]->id());
|
||||
$this->assertEqual(count($loaded_terms), 1, 'All parent terms were loaded');
|
||||
$this->assertQueryTagTestResult(2, 1, 'TermStorage::loadParents()');
|
||||
$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(2, 1, 'TermStorage::loadChildren()');
|
||||
$this->assertQueryTagTestResult(3, 1, 'TermStorage::loadChildren()');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$query = db_select('taxonomy_term_data', 't');
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
@@ -20,7 +19,7 @@ trait TaxonomyTestTrait {
|
||||
$vocabulary = Vocabulary::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
'description' => $this->randomMachineName(),
|
||||
'vid' => Unicode::strtolower($this->randomMachineName()),
|
||||
'vid' => mb_strtolower($this->randomMachineName()),
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
'weight' => mt_rand(0, 10),
|
||||
]);
|
||||
|
||||
@@ -17,7 +17,7 @@ trait TaxonomyTranslationTestTrait {
|
||||
/**
|
||||
* The vocabulary.
|
||||
*
|
||||
* @var \Drupal\taxonomy\Entity\Vocabulary;
|
||||
* @var \Drupal\taxonomy\Entity\Vocabulary
|
||||
*/
|
||||
protected $vocabulary;
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
|
||||
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.
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
|
||||
/**
|
||||
@@ -49,7 +48,7 @@ class TermIndexTest extends TaxonomyTestBase {
|
||||
// Create a vocabulary and add two term reference fields to article nodes.
|
||||
$this->vocabulary = $this->createVocabulary();
|
||||
|
||||
$this->fieldName1 = Unicode::strtolower($this->randomMachineName());
|
||||
$this->fieldName1 = mb_strtolower($this->randomMachineName());
|
||||
$handler_settings = [
|
||||
'target_bundles' => [
|
||||
$this->vocabulary->id() => $this->vocabulary->id(),
|
||||
@@ -69,7 +68,7 @@ class TermIndexTest extends TaxonomyTestBase {
|
||||
])
|
||||
->save();
|
||||
|
||||
$this->fieldName2 = Unicode::strtolower($this->randomMachineName());
|
||||
$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')
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,11 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional\Views;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\views\Views;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
* Tests the representative node relationship for terms.
|
||||
*
|
||||
@@ -21,73 +16,6 @@ class TaxonomyDefaultArgumentTest extends TaxonomyTestBase {
|
||||
*/
|
||||
public static $testViews = ['taxonomy_default_argument_test'];
|
||||
|
||||
/**
|
||||
* Tests the relationship.
|
||||
*/
|
||||
public function testNodePath() {
|
||||
$view = Views::getView('taxonomy_default_argument_test');
|
||||
|
||||
$request = Request::create($this->nodes[0]->url());
|
||||
$request->server->set('SCRIPT_NAME', $GLOBALS['base_path'] . 'index.php');
|
||||
$request->server->set('SCRIPT_FILENAME', 'index.php');
|
||||
|
||||
$response = $this->container->get('http_kernel')
|
||||
->handle($request, HttpKernelInterface::SUB_REQUEST);
|
||||
$view->setRequest($request);
|
||||
$view->setResponse($response);
|
||||
|
||||
$view->initHandlers();
|
||||
$expected = implode(',', [$this->term1->id(), $this->term2->id()]);
|
||||
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
|
||||
$view->destroy();
|
||||
}
|
||||
|
||||
public function testNodePathWithViewSelection() {
|
||||
// Change the term entity reference field to use a view as selection plugin.
|
||||
\Drupal::service('module_installer')->install(['entity_reference_test']);
|
||||
|
||||
$field_name = 'field_' . $this->vocabulary->id();
|
||||
$field = FieldConfig::loadByName('node', 'article', $field_name);
|
||||
$field->setSetting('handler', 'views');
|
||||
$field->setSetting('handler_settings', [
|
||||
'view' => [
|
||||
'view_name' => 'test_entity_reference',
|
||||
'display_name' => 'entity_reference_1',
|
||||
],
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
$view = Views::getView('taxonomy_default_argument_test');
|
||||
|
||||
$request = Request::create($this->nodes[0]->url());
|
||||
$request->server->set('SCRIPT_NAME', $GLOBALS['base_path'] . 'index.php');
|
||||
$request->server->set('SCRIPT_FILENAME', 'index.php');
|
||||
|
||||
$response = $this->container->get('http_kernel')->handle($request, HttpKernelInterface::SUB_REQUEST);
|
||||
$view->setRequest($request);
|
||||
$view->setResponse($response);
|
||||
|
||||
$view->initHandlers();
|
||||
$expected = implode(',', [$this->term1->id(), $this->term2->id()]);
|
||||
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
|
||||
}
|
||||
|
||||
public function testTermPath() {
|
||||
$view = Views::getView('taxonomy_default_argument_test');
|
||||
|
||||
$request = Request::create($this->term1->url());
|
||||
$request->server->set('SCRIPT_NAME', $GLOBALS['base_path'] . 'index.php');
|
||||
$request->server->set('SCRIPT_FILENAME', 'index.php');
|
||||
|
||||
$response = $this->container->get('http_kernel')->handle($request, HttpKernelInterface::SUB_REQUEST);
|
||||
$view->setRequest($request);
|
||||
$view->setResponse($response);
|
||||
$view->initHandlers();
|
||||
|
||||
$expected = $this->term1->id();
|
||||
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests escaping of page title when the taxonomy plugin provides it.
|
||||
*/
|
||||
|
||||
@@ -199,7 +199,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
|
||||
// Select 'Term' and 'Vocabulary' as filters.
|
||||
$edit = [
|
||||
'name[taxonomy_term_field_data.tid]' => TRUE,
|
||||
'name[taxonomy_term_field_data.vid]' => 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.
|
||||
|
||||
@@ -61,24 +61,24 @@ class TaxonomyRelationshipTest extends TaxonomyTestBase {
|
||||
$this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid');
|
||||
$this->assertEqual($views_data['table']['join']['node_field_data']['left_field'], 'nid');
|
||||
$this->assertEqual($views_data['table']['join']['node_field_data']['field'], 'nid');
|
||||
$this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid');
|
||||
$this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'tid');
|
||||
$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_hierarchy.
|
||||
$views_data = Views::viewsData()->get('taxonomy_term_hierarchy');
|
||||
// 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_hierarchy']['left_field'], 'tid');
|
||||
$this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'parent');
|
||||
$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'], 'tid');
|
||||
$this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'entity_id');
|
||||
// Check the parent relationship data.
|
||||
$this->assertEqual($views_data['parent']['relationship']['base'], 'taxonomy_term_field_data');
|
||||
$this->assertEqual($views_data['parent']['relationship']['field'], 'parent');
|
||||
$this->assertEqual($views_data['parent']['relationship']['label'], t('Parent'));
|
||||
$this->assertEqual($views_data['parent']['relationship']['id'], 'standard');
|
||||
$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']['filter']['id'], 'numeric');
|
||||
$this->assertEqual($views_data['parent']['argument']['id'], 'taxonomy');
|
||||
$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');
|
||||
@@ -95,7 +95,7 @@ class TaxonomyRelationshipTest extends TaxonomyTestBase {
|
||||
if (!$index) {
|
||||
$this->assertTrue($row->_relationship_entities['parent'] instanceof TermInterface);
|
||||
$this->assertEqual($row->_relationship_entities['parent']->id(), $this->term2->id());
|
||||
$this->assertEqual($row->taxonomy_term_field_data_taxonomy_term_hierarchy_tid, $this->term2->id());
|
||||
$this->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());
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional\Views;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\node\Entity\Node;
|
||||
@@ -50,7 +49,7 @@ class TaxonomyTermViewTest extends TaxonomyTestBase {
|
||||
|
||||
// Create a vocabulary and add two term reference fields to article nodes.
|
||||
|
||||
$this->fieldName1 = Unicode::strtolower($this->randomMachineName());
|
||||
$this->fieldName1 = mb_strtolower($this->randomMachineName());
|
||||
|
||||
$handler_settings = [
|
||||
'target_bundles' => [
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
@@ -144,12 +143,12 @@ class VocabularyCrudTest extends TaxonomyTestBase {
|
||||
public function testUninstallReinstall() {
|
||||
// Field storages and fields attached to taxonomy term bundles should be
|
||||
// removed when the module is uninstalled.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name');
|
||||
$field_name = mb_strtolower($this->randomMachineName() . '_field_name');
|
||||
$storage_definition = [
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'type' => 'text',
|
||||
'cardinality' => 4
|
||||
'cardinality' => 4,
|
||||
];
|
||||
FieldStorageConfig::create($storage_definition)->save();
|
||||
$field_definition = [
|
||||
@@ -165,7 +164,7 @@ class VocabularyCrudTest extends TaxonomyTestBase {
|
||||
// installed for testing below.
|
||||
$this->vocabulary->unsetThirdPartySetting('taxonomy_crud', 'foo');
|
||||
|
||||
require_once \Drupal::root() . '/core/includes/install.inc';
|
||||
require_once $this->root . '/core/includes/install.inc';
|
||||
$this->container->get('module_installer')->uninstall(['taxonomy']);
|
||||
$this->container->get('module_installer')->install(['taxonomy']);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
|
||||
@@ -43,7 +42,7 @@ class VocabularyLanguageTest extends TaxonomyTestBase {
|
||||
$this->assertField('edit-langcode', 'The language selector field was found on the page.');
|
||||
|
||||
// Create the vocabulary.
|
||||
$vid = Unicode::strtolower($this->randomMachineName());
|
||||
$vid = mb_strtolower($this->randomMachineName());
|
||||
$edit['name'] = $this->randomMachineName();
|
||||
$edit['description'] = $this->randomMachineName();
|
||||
$edit['langcode'] = 'aa';
|
||||
@@ -72,7 +71,7 @@ class VocabularyLanguageTest extends TaxonomyTestBase {
|
||||
// the terms are saved.
|
||||
$edit = [
|
||||
'name' => $this->randomMachineName(),
|
||||
'vid' => Unicode::strtolower($this->randomMachineName()),
|
||||
'vid' => mb_strtolower($this->randomMachineName()),
|
||||
'default_language[langcode]' => 'bb',
|
||||
'default_language[language_alterable]' => TRUE,
|
||||
];
|
||||
|
||||
@@ -83,6 +83,7 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
$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.
|
||||
@@ -108,7 +109,8 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
$assert_session->linkNotExists('Edit');
|
||||
$assert_session->linkNotExists('Delete');
|
||||
$assert_session->buttonNotExists('Save');
|
||||
$assert_session->pageTextNotContains('Weight');
|
||||
$assert_session->pageTextContains('Weight');
|
||||
$assert_session->fieldNotExists('Weight');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
$assert_session->pageTextContains($no_edit_help_text);
|
||||
|
||||
@@ -132,6 +134,7 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
$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);
|
||||
|
||||
@@ -154,7 +157,8 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
$assert_session->linkExists('Delete');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
$assert_session->buttonNotExists('Save');
|
||||
$assert_session->pageTextNotContains('Weight');
|
||||
$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.
|
||||
@@ -179,6 +183,7 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
$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.
|
||||
@@ -201,7 +206,8 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
$assert_session->linkNotExists('Delete');
|
||||
$assert_session->linkExists('Add term');
|
||||
$assert_session->buttonNotExists('Save');
|
||||
$assert_session->pageTextNotContains('Weight');
|
||||
$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.
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* Tests content translation for vocabularies.
|
||||
*
|
||||
@@ -39,7 +37,7 @@ class VocabularyTranslationTest extends TaxonomyTestBase {
|
||||
$this->assertField('edit-default-language-content-translation', 'The content translation checkbox is present on the page.');
|
||||
|
||||
// Create the vocabulary.
|
||||
$vid = Unicode::strtolower($this->randomMachineName());
|
||||
$vid = mb_strtolower($this->randomMachineName());
|
||||
$edit['name'] = $this->randomMachineName();
|
||||
$edit['description'] = $this->randomMachineName();
|
||||
$edit['langcode'] = 'en';
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
|
||||
@@ -39,7 +37,7 @@ class VocabularyUiTest extends TaxonomyTestBase {
|
||||
// Create a new vocabulary.
|
||||
$this->clickLink(t('Add vocabulary'));
|
||||
$edit = [];
|
||||
$vid = Unicode::strtolower($this->randomMachineName());
|
||||
$vid = mb_strtolower($this->randomMachineName());
|
||||
$edit['name'] = $this->randomMachineName();
|
||||
$edit['description'] = $this->randomMachineName();
|
||||
$edit['vid'] = $vid;
|
||||
@@ -131,7 +129,7 @@ class VocabularyUiTest extends TaxonomyTestBase {
|
||||
*/
|
||||
public function testTaxonomyAdminDeletingVocabulary() {
|
||||
// Create a vocabulary.
|
||||
$vid = Unicode::strtolower($this->randomMachineName());
|
||||
$vid = mb_strtolower($this->randomMachineName());
|
||||
$edit = [
|
||||
'name' => $this->randomMachineName(),
|
||||
'vid' => $vid,
|
||||
|
||||
@@ -92,7 +92,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
|
||||
$this->assertSame($values['vid'], $term->vid->target_id);
|
||||
$this->assertSame((string) $values['weight'], $term->weight->value);
|
||||
if ($values['parent'] === [0]) {
|
||||
$this->assertNull($term->parent->target_id);
|
||||
$this->assertSame(0, (int) $term->parent->target_id);
|
||||
}
|
||||
else {
|
||||
$parents = [];
|
||||
|
||||
@@ -32,7 +32,7 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupal6TestBase {
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$j = $i + 1;
|
||||
$vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_");
|
||||
$this->assertSame($this->getMigration('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID([$j]), [$vocabulary->id()]);
|
||||
$this->assertSame($this->getMigration('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationId([$j]), [$vocabulary->id()]);
|
||||
$this->assertSame("vocabulary $j (i=$i)", $vocabulary->label());
|
||||
$this->assertSame("description of vocabulary $j (i=$i)", $vocabulary->getDescription());
|
||||
$this->assertSame($i, $vocabulary->getHierarchy());
|
||||
|
||||
+7
-1
@@ -14,7 +14,13 @@ class MigrateTaxonomyVocabularyTranslationTest extends MigrateDrupal6TestBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language', 'taxonomy'];
|
||||
public static $modules = [
|
||||
'config_translation',
|
||||
'language',
|
||||
'taxonomy',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
||||
@@ -31,7 +31,7 @@ class MigrateTermNodeRevisionTest extends MigrateDrupal6TestBase {
|
||||
* Tests the Drupal 6 term-node revision association to Drupal 8 migration.
|
||||
*/
|
||||
public function testTermRevisionNode() {
|
||||
$node = \Drupal::entityManager()->getStorage('node')->loadRevision(2);
|
||||
$node = \Drupal::entityManager()->getStorage('node')->loadRevision(2001);
|
||||
$this->assertSame(2, count($node->field_vocabulary_3_i_2_));
|
||||
$this->assertSame('4', $node->field_vocabulary_3_i_2_[0]->target_id);
|
||||
$this->assertSame('5', $node->field_vocabulary_3_i_2_[1]->target_id);
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class MigrateVocabularyEntityDisplayTest extends MigrateDrupal6TestBase {
|
||||
$this->assertSame('entity_reference_label', $component['type']);
|
||||
$this->assertSame(20, $component['weight']);
|
||||
// Test the Id map.
|
||||
$this->assertSame(['node', 'article', 'default', 'field_tags'], $this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID([4, 'article']));
|
||||
$this->assertSame(['node', 'article', 'default', 'field_tags'], $this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationId([4, 'article']));
|
||||
|
||||
// Tests that a vocabulary named like a D8 base field will be migrated and
|
||||
// prefixed with 'field_' to avoid conflicts.
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class MigrateVocabularyEntityFormDisplayTest extends MigrateDrupal6TestBase {
|
||||
$this->assertSame('options_select', $component['type']);
|
||||
$this->assertSame(20, $component['weight']);
|
||||
// Test the Id map.
|
||||
$this->assertSame(['node', 'article', 'default', 'field_tags'], $this->getMigration('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID([4, 'article']));
|
||||
$this->assertSame(['node', 'article', 'default', 'field_tags'], $this->getMigration('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationId([4, 'article']));
|
||||
|
||||
// Test the term widget tags setting.
|
||||
$entity_form_display = EntityFormDisplay::load('node.story.default');
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
|
||||
$this->assertSame(['field_tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
|
||||
$this->assertSame(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
|
||||
|
||||
$this->assertSame(['node', 'article', 'field_tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID([4, 'article']));
|
||||
$this->assertSame(['node', 'article', 'field_tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationId([4, 'article']));
|
||||
|
||||
// Test the the field vocabulary_1_i_0_.
|
||||
$field_id = 'node.story.field_vocabulary_1_i_0_';
|
||||
|
||||
@@ -39,7 +39,7 @@ class MigrateVocabularyFieldTest extends MigrateDrupal6TestBase {
|
||||
$this->assertSame('taxonomy_term', $settings['target_type'], "Target type is correct.");
|
||||
$this->assertSame(1, $field_storage->getCardinality(), "Field cardinality in 1.");
|
||||
|
||||
$this->assertSame(['node', 'field_tags'], $this->getMigration('d6_vocabulary_field')->getIdMap()->lookupDestinationID([4]), "Test IdMap");
|
||||
$this->assertSame(['node', 'field_tags'], $this->getMigration('d6_vocabulary_field')->getIdMap()->lookupDestinationId([4]), "Test IdMap");
|
||||
|
||||
// Tests that a vocabulary named like a D8 base field will be migrated and
|
||||
// prefixed with 'field_' to avoid conflicts.
|
||||
|
||||
@@ -47,7 +47,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
|
||||
'd7_field',
|
||||
'd7_taxonomy_vocabulary',
|
||||
'd7_field_instance',
|
||||
'd7_taxonomy_term'
|
||||
'd7_taxonomy_term',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,11 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
|
||||
*/
|
||||
public function testTaxonomyTerms() {
|
||||
$this->assertEntity(1, 'General discussion', 'forums', '', NULL, 2);
|
||||
$this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.', 'filtered_html', 0, [], NULL, 3);
|
||||
|
||||
// Tests that terms that used the Drupal 7 Title module and that have their
|
||||
// name and description replaced by real fields are correctly migrated.
|
||||
$this->assertEntity(2, 'Term1 (This is a real field!)', 'test_vocabulary', 'The first term. (This is a real field!)', 'filtered_html', 0, [], NULL, 3);
|
||||
|
||||
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.', 'filtered_html');
|
||||
$this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 'full_html', 0, [3], 6);
|
||||
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', NULL, 3);
|
||||
|
||||
+4
-4
@@ -27,16 +27,16 @@ class TermSourceWithVocabularyFilterTest extends TermTest {
|
||||
[
|
||||
'tid' => 1,
|
||||
'vid' => 5,
|
||||
'name' => 'name value 1',
|
||||
'description' => 'description value 1',
|
||||
'name' => 'name value 1 (name_field)',
|
||||
'description' => 'description value 1 (description_field)',
|
||||
'weight' => 0,
|
||||
'parent' => [0],
|
||||
],
|
||||
[
|
||||
'tid' => 4,
|
||||
'vid' => 5,
|
||||
'name' => 'name value 4',
|
||||
'description' => 'description value 4',
|
||||
'name' => 'name value 4 (name_field)',
|
||||
'description' => 'description value 4 (description_field)',
|
||||
'weight' => 1,
|
||||
'parent' => [1],
|
||||
],
|
||||
|
||||
@@ -126,19 +126,57 @@ class TermTest extends MigrateSqlSourceTestBase {
|
||||
'machine_name' => 'categories',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_config'] = [
|
||||
[
|
||||
'id' => '3',
|
||||
'translatable' => '0',
|
||||
],
|
||||
[
|
||||
'id' => '4',
|
||||
'translatable' => '1',
|
||||
],
|
||||
[
|
||||
'id' => '5',
|
||||
'translatable' => '1',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_config_instance'] = [
|
||||
[
|
||||
'id' => '2',
|
||||
'field_id' => 3,
|
||||
'field_name' => 'field_term_field',
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'tags',
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => 0,
|
||||
],
|
||||
[
|
||||
'id' => '3',
|
||||
'field_id' => 3,
|
||||
'field_name' => 'field_term_field',
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'categories',
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => 0,
|
||||
],
|
||||
[
|
||||
'id' => '4',
|
||||
'field_id' => '4',
|
||||
'field_name' => 'name_field',
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'tags',
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => '0',
|
||||
],
|
||||
[
|
||||
'id' => '5',
|
||||
'field_id' => '5',
|
||||
'field_name' => 'description_field',
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'tags',
|
||||
'data' => 'a:0:{}',
|
||||
'deleted' => '0',
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_data_field_term_field'] = [
|
||||
[
|
||||
@@ -156,6 +194,61 @@ class TermTest extends MigrateSqlSourceTestBase {
|
||||
'delta' => 0,
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_data_name_field'] = [
|
||||
[
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'tags',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'und',
|
||||
'delta' => '0',
|
||||
'name_field_value' => 'name value 1 (name_field)',
|
||||
'name_field_format' => NULL,
|
||||
],
|
||||
[
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'tags',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '4',
|
||||
'revision_id' => '4',
|
||||
'language' => 'und',
|
||||
'delta' => '0',
|
||||
'name_field_value' => 'name value 4 (name_field)',
|
||||
'name_field_format' => NULL,
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['field_data_description_field'] = [
|
||||
[
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'tags',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'language' => 'und',
|
||||
'delta' => '0',
|
||||
'description_field_value' => 'description value 1 (description_field)',
|
||||
'description_field_format' => NULL,
|
||||
],
|
||||
[
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'tags',
|
||||
'deleted' => '0',
|
||||
'entity_id' => '4',
|
||||
'revision_id' => '4',
|
||||
'language' => 'und',
|
||||
'delta' => '0',
|
||||
'description_field_value' => 'description value 4 (description_field)',
|
||||
'description_field_format' => NULL,
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['system'] = [
|
||||
[
|
||||
'name' => 'title',
|
||||
'type' => 'module',
|
||||
'status' => 1,
|
||||
],
|
||||
];
|
||||
$tests[0]['source_data']['variable'] = [
|
||||
[
|
||||
'name' => 'forum_containers',
|
||||
@@ -168,8 +261,8 @@ class TermTest extends MigrateSqlSourceTestBase {
|
||||
[
|
||||
'tid' => 1,
|
||||
'vid' => 5,
|
||||
'name' => 'name value 1',
|
||||
'description' => 'description value 1',
|
||||
'name' => 'name value 1 (name_field)',
|
||||
'description' => 'description value 1 (description_field)',
|
||||
'weight' => 0,
|
||||
'parent' => [0],
|
||||
],
|
||||
@@ -192,8 +285,8 @@ class TermTest extends MigrateSqlSourceTestBase {
|
||||
[
|
||||
'tid' => 4,
|
||||
'vid' => 5,
|
||||
'name' => 'name value 4',
|
||||
'description' => 'description value 4',
|
||||
'name' => 'name value 4 (name_field)',
|
||||
'description' => 'description value 4 (description_field)',
|
||||
'weight' => 1,
|
||||
'parent' => [1],
|
||||
],
|
||||
@@ -233,16 +326,16 @@ class TermTest extends MigrateSqlSourceTestBase {
|
||||
[
|
||||
'tid' => 1,
|
||||
'vid' => 5,
|
||||
'name' => 'name value 1',
|
||||
'description' => 'description value 1',
|
||||
'name' => 'name value 1 (name_field)',
|
||||
'description' => 'description value 1 (description_field)',
|
||||
'weight' => 0,
|
||||
'parent' => [0],
|
||||
],
|
||||
[
|
||||
'tid' => 4,
|
||||
'vid' => 5,
|
||||
'name' => 'name value 4',
|
||||
'description' => 'description value 4',
|
||||
'name' => 'name value 4 (name_field)',
|
||||
'description' => 'description value 4 (description_field)',
|
||||
'weight' => 1,
|
||||
'parent' => [1],
|
||||
],
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Kernel\Views;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\views\Views;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
|
||||
/**
|
||||
* Init view with a request by provided url.
|
||||
*
|
||||
* @param string $request_url
|
||||
* The requested url.
|
||||
* @param string $view_name
|
||||
* The name of the view.
|
||||
*
|
||||
* @return \Drupal\views\ViewExecutable
|
||||
* The initiated view.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function initViewWithRequest($request_url, $view_name = 'taxonomy_default_argument_test') {
|
||||
$view = Views::getView($view_name);
|
||||
|
||||
$request = Request::create($request_url);
|
||||
$request->server->set('SCRIPT_NAME', $GLOBALS['base_path'] . 'index.php');
|
||||
$request->server->set('SCRIPT_FILENAME', 'index.php');
|
||||
|
||||
$response = $this->container->get('http_kernel')
|
||||
->handle($request, HttpKernelInterface::SUB_REQUEST);
|
||||
|
||||
$view->setRequest($request);
|
||||
$view->setResponse($response);
|
||||
$view->initHandlers();
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the relationship.
|
||||
*/
|
||||
public function testNodePath() {
|
||||
$view = $this->initViewWithRequest($this->nodes[0]->url());
|
||||
|
||||
$expected = implode(',', [$this->term1->id(), $this->term2->id()]);
|
||||
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
|
||||
$view->destroy();
|
||||
}
|
||||
|
||||
public function testNodePathWithViewSelection() {
|
||||
// Change the term entity reference field to use a view as selection plugin.
|
||||
\Drupal::service('module_installer')->install(['entity_reference_test']);
|
||||
|
||||
$field_name = 'field_' . $this->vocabulary->id();
|
||||
$field = FieldConfig::loadByName('node', 'article', $field_name);
|
||||
$field->setSetting('handler', 'views');
|
||||
$field->setSetting('handler_settings', [
|
||||
'view' => [
|
||||
'view_name' => 'test_entity_reference',
|
||||
'display_name' => 'entity_reference_1',
|
||||
],
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
$view = $this->initViewWithRequest($this->nodes[0]->url());
|
||||
|
||||
$expected = implode(',', [$this->term1->id(), $this->term2->id()]);
|
||||
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
|
||||
}
|
||||
|
||||
public function testTermPath() {
|
||||
$view = $this->initViewWithRequest($this->term1->url());
|
||||
|
||||
$expected = $this->term1->id();
|
||||
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Kernel\Views;
|
||||
|
||||
use Drupal\Core\Render\RenderContext;
|
||||
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
|
||||
/**
|
||||
* Tests the taxonomy term VID field handler.
|
||||
*
|
||||
* @group taxonomy
|
||||
*/
|
||||
class TaxonomyFieldVidTest extends ViewsKernelTestBase {
|
||||
|
||||
use TaxonomyTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['taxonomy', 'taxonomy_test_views', 'text', 'filter'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_taxonomy_vid_field'];
|
||||
|
||||
/**
|
||||
* A taxonomy term to use in this test.
|
||||
*
|
||||
* @var \Drupal\taxonomy\Entity\Term
|
||||
*/
|
||||
protected $term1;
|
||||
|
||||
/**
|
||||
* An admin user.
|
||||
*
|
||||
* @var \Drupal\user\Entity\User;
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installEntitySchema('user');
|
||||
$this->installConfig(['filter']);
|
||||
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
|
||||
$vocabulary = $this->createVocabulary();
|
||||
$this->term1 = $this->createTerm($vocabulary);
|
||||
|
||||
// Create user 1 and set is as the logged in user, so that the logged in
|
||||
// user has the correct permissions to view the vocabulary name.
|
||||
$this->adminUser = User::create(['name' => $this->randomString()]);
|
||||
$this->adminUser->save();
|
||||
$this->container->get('current_user')->setAccount($this->adminUser);
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the field handling for the Vocabulary ID.
|
||||
*/
|
||||
public function testViewsHandlerVidField() {
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = \Drupal::service('renderer');
|
||||
|
||||
$view = Views::getView('test_taxonomy_vid_field');
|
||||
$this->executeView($view);
|
||||
|
||||
$actual = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
|
||||
return $view->field['vid']->advancedRender($view->result[0]);
|
||||
});
|
||||
$vocabulary = Vocabulary::load($this->term1->bundle());
|
||||
$expected = $vocabulary->get('name');
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Kernel\Views;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
|
||||
/**
|
||||
* Base class for views kernel taxonomy tests.
|
||||
*/
|
||||
abstract class TaxonomyTestBase extends ViewsKernelTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
|
||||
use NodeCreationTrait {
|
||||
createNode as drupalCreateNode;
|
||||
}
|
||||
|
||||
use ContentTypeCreationTrait {
|
||||
createContentType as drupalCreateContentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = [
|
||||
'taxonomy',
|
||||
'taxonomy_test_views',
|
||||
'text',
|
||||
'node',
|
||||
'field',
|
||||
'filter',
|
||||
];
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
// Install node config to create body field.
|
||||
$this->installConfig(['node', 'filter']);
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$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->installEntitySchema('node');
|
||||
$this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
|
||||
$entity_type_manager = $this->container->get('entity_type.manager');
|
||||
$entity_type_manager
|
||||
->getStorage('entity_form_display')
|
||||
->load('node.article.default')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'entity_reference_autocomplete_tags',
|
||||
'weight' => -4,
|
||||
])
|
||||
->save();
|
||||
|
||||
$view_modes = [
|
||||
'default',
|
||||
'teaser',
|
||||
];
|
||||
foreach ($view_modes as $view_mode) {
|
||||
$entity_type_manager
|
||||
->getStorage('entity_view_display')
|
||||
->load("node.article.{$view_mode}")
|
||||
->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;
|
||||
}
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Unit\Plugin\migrate\cckfield;
|
||||
|
||||
/**
|
||||
* @group taxonomy
|
||||
* @group legacy
|
||||
*/
|
||||
class TaxonomyTermReferenceCckLegacyTest extends TaxonomyTermReferenceCckTest {
|
||||
|
||||
/**
|
||||
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
|
||||
*/
|
||||
public function testDefineValueProcessPipeline($method = 'processFieldValues') {
|
||||
parent::testDefineValueProcessPipeline($method);
|
||||
}
|
||||
|
||||
}
|
||||
+8
-4
@@ -44,11 +44,15 @@ class TaxonomyTermReferenceCckTest extends UnitTestCase {
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessCckFieldValues() {
|
||||
$this->plugin->processFieldValues($this->migration, 'somefieldname', []);
|
||||
$this->testDefineValueProcessPipeline('processCckFieldValues');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::defineValueProcessPipeline
|
||||
*/
|
||||
public function testDefineValueProcessPipeline($method = 'defineValueProcessPipeline') {
|
||||
$this->plugin->$method($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'sub_process',
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Unit\Plugin\migrate\field;
|
||||
|
||||
/**
|
||||
* @group taxonomy
|
||||
* @group legacy
|
||||
*/
|
||||
class TaxonomyTermReferenceFieldLegacyTest extends TaxonomyTermReferenceFieldTest {
|
||||
|
||||
/**
|
||||
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
|
||||
*/
|
||||
public function testDefineValueProcessPipeline($method = 'processFieldValues') {
|
||||
parent::testDefineValueProcessPipeline($method);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -31,7 +31,7 @@ class TaxonomyTermReferenceFieldTest extends UnitTestCase {
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processFieldValues() method will call
|
||||
// The plugin's defineValueProcessPipeline() method will call
|
||||
// setProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to setProcessOfProperty().
|
||||
@@ -44,10 +44,10 @@ class TaxonomyTermReferenceFieldTest extends UnitTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
* @covers ::defineValueProcessPipeline
|
||||
*/
|
||||
public function testProcessFieldValues() {
|
||||
$this->plugin->processFieldValues($this->migration, 'somefieldname', []);
|
||||
public function testDefineValueProcessPipeline($method = 'defineValueProcessPipeline') {
|
||||
$this->plugin->$method($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'sub_process',
|
||||
|
||||
Reference in New Issue
Block a user