Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,8 @@
name: 'Comment empty titles test'
type: module
description: 'Support module for testing empty title accessibility with Comment module.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- comment

View file

@ -0,0 +1,14 @@
<?php
/**
* @file
* Dummy module emptying comment titles to test for appropriate and accessible
* markup in edge case scenarios where comments have empty titles.
*/
/**
* Implements hook_preprocess_comment().
*/
function comment_empty_titles_test_preprocess_comment(&$variables) {
$variables['title'] = '';
}

View file

@ -0,0 +1,8 @@
name: 'Comment test'
type: module
description: 'Support module for Comment module testing.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- comment

View file

@ -0,0 +1,44 @@
<?php
/**
* @file
* Dummy module implementing comment related hooks to test API interaction with
* the Comment module.
*/
use Drupal\comment\CommentInterface;
use Drupal\Core\Url;
/**
* Implements hook_entity_type_alter().
*/
function comment_test_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
if (\Drupal::languageManager()->isMultilingual()) {
// Enable language handling for comment fields.
$translation = $entity_types['comment']->get('translation');
$translation['comment_test'] = TRUE;
$entity_types['comment']->set('translation', $translation);
}
}
/**
* Implements hook_comment_links_alter().
*/
function comment_test_comment_links_alter(array &$links, CommentInterface &$entity, array &$context) {
// Allow tests to enable or disable this alter hook.
if (!\Drupal::state()->get('comment_test_links_alter_enabled', FALSE)) {
return;
}
$links['comment_test'] = array(
'#theme' => 'links__comment__comment_test',
'#attributes' => array('class' => array('links', 'inline')),
'#links' => array(
'comment-report' => array(
'title' => t('Report'),
'url' => Url::fromRoute('comment_test.report', ['comment' => $entity->id()], ['query' => ['token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")]]),
),
),
);
}

View file

@ -0,0 +1,8 @@
comment_test.report:
path: '/comment/{comment}/report'
defaults:
_title: 'Report'
_controller: '\Drupal\comment_test\Controller\CommentTestController::commentReport'
requirements:
_access: 'TRUE'
_csrf_token: 'TRUE'

View file

@ -0,0 +1,20 @@
<?php
namespace Drupal\comment_test\Controller;
use Drupal\comment\CommentInterface;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller for the comment_test.module.
*/
class CommentTestController extends ControllerBase {
/**
* Provides a comment report.
*/
public function commentReport(CommentInterface $comment) {
return ['#markup' => $this->t('Report for a comment')];
}
}

View file

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

View file

@ -0,0 +1,43 @@
langcode: en
status: true
dependencies:
module:
- comment
- entity_test
- user
id: test_comment
label: test_comment
module: views
description: ''
tag: ''
base_table: comment_field_data
base_field: cid
core: 8.x
display:
default:
display_plugin: default
display_title: Master
id: default
position: 0
display_options:
defaults:
fields: false
pager: false
sorts: false
row:
type: fields
fields:
subject:
id: subject
table: comment_field_data
field: subject
label: ''
type: string
plugin_id: field
entity_type: comment
entity_field: subject
pager:
options:
offset: 0
type: none
sorts: { }

View file

@ -0,0 +1,203 @@
langcode: en
status: true
dependencies:
module:
- comment
- user
id: test_comment_field_name
label: 'Comment field name test'
module: views
description: ''
tag: ''
base_table: comment_field_data
base_field: cid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access comments'
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
row:
type: fields
relationships: { }
fields:
field_name:
id: field_name
table: comment_field_data
field: field_name
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: string
settings:
link_to_entity: 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: comment
entity_field: field_name
plugin_id: field
filters:
field_name:
id: field_name
table: comment_field_data
field: field_name
relationship: none
group_type: group
admin_label: ''
operator: starts
value: comment
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: comment
entity_field: field_name
plugin_id: string
sorts:
field_name:
id: field_name
table: comment_field_data
field: field_name
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
entity_type: comment
entity_field: field_name
plugin_id: standard
title: 'Comment Field Name test'
header: { }
footer: { }
empty: { }
arguments: { }
display_extenders: { }
cache_metadata:
contexts:
- languages
- user
max-age: 0

View file

@ -0,0 +1,254 @@
langcode: en
status: true
dependencies:
module:
- comment
- user
id: test_comment_operations
label: test_comment_operations
module: views
description: ''
tag: ''
base_table: comment_field_data
base_field: cid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'administer comments'
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: table
options:
grouping: { }
row_class: ''
default_row_class: true
override: true
sticky: false
caption: ''
summary: ''
description: ''
columns:
subject: subject
operations: operations
info:
subject:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
operations:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
default: '-1'
empty_table: false
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
relationships: { }
fields:
subject:
id: subject
table: comment_field_data
field: subject
relationship: none
group_type: group
admin_label: ''
label: Subject
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: false
ellipsis: false
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: string
settings:
link_to_entity: true
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: comment
entity_field: subject
plugin_id: field
operations:
id: operations
table: comment
field: operations
relationship: none
group_type: group
admin_label: ''
label: Operations
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
destination: true
entity_type: comment
plugin_id: entity_operations
filters: { }
sorts: { }
header: { }
footer: { }
empty: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: 0
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- user.permissions
tags: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: test-comment-operations
cache_metadata:
max-age: 0
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- user.permissions
tags: { }

View file

@ -0,0 +1,402 @@
langcode: en
status: true
dependencies:
config:
- field.storage.comment.comment_body
module:
- comment
- node
- rest
- text
- user
id: test_comment_rest
label: 'Comments by node'
module: views
description: ''
tag: ''
base_table: comment_field_data
base_field: cid
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: serializer
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
relationships:
node:
id: node
table: comment_field_data
field: node
required: true
plugin_id: standard
relationship: none
group_type: group
admin_label: Content
fields:
subject:
id: subject
table: comment_field_data
field: subject
relationship: none
group_type: group
entity_type: comment
entity_field: subject
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
type: string
settings:
link_to_entity: false
plugin_id: field
name:
id: name
table: comment_field_data
field: name
entity_type: comment
entity_field: name
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
plugin_id: field
type: comment_username
created:
id: created
table: comment_field_data
field: created
entity_type: comment
entity_field: created
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
type: timestamp
settings:
date_format: long
custom_date_format: ''
timezone: ''
plugin_id: field
comment_body:
id: comment_body
table: comment__comment_body
field: comment_body
relationship: none
entity_type: comment
entity_field: comment_body
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: text_default
settings: { }
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
plugin_id: field
filters: { }
sorts:
cid:
id: cid
table: comment_field_data
field: cid
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
entity_type: comment
entity_field: cid
plugin_id: standard
header: { }
footer: { }
empty: { }
arguments:
nid:
id: nid
table: node_field_data
field: nid
relationship: node
group_type: group
admin_label: ''
default_action: default
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: node
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
not: false
plugin_id: numeric
display_extenders: { }
rest_export_1:
display_plugin: rest_export
id: rest_export_1
display_title: 'REST export'
position: 1
display_options:
path: node/%node/comments
pager:
type: some
options:
items_per_page: 10
offset: 0
style:
type: serializer
options:
uses_fields: false
formats:
json: json
hal_json: hal_json
row:
type: data_field
options:
field_options:
subject:
alias: ''
raw_output: true
name:
alias: ''
raw_output: true
display_extenders: { }

View file

@ -0,0 +1,157 @@
langcode: en
status: true
dependencies:
module:
- comment
- node
- user
id: test_comment_row
label: test_comment_row
module: views
description: ''
tag: ''
base_table: comment_field_data
base_field: cid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 1
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: full
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ' Previous'
next: 'Next '
first: '« First'
last: 'Last »'
quantity: 9
style:
type: default
row:
type: 'entity:comment'
options:
view_mode: full
relationships:
node:
field: node
id: node
required: true
table: comment_field_data
relationship: none
group_type: group
admin_label: Content
fields:
subject:
id: subject
table: comment_field_data
field: subject
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
type: string
settings:
link_to_entity: true
plugin_id: field
entity_type: comment
entity_field: subject
filters:
status:
value: '1'
table: comment_field_data
field: status
id: status
expose:
operator: ''
group: 1
plugin_id: boolean
entity_type: comment
entity_field: status
status_node:
value: '1'
table: node_field_data
field: status
relationship: node
id: status_node
expose:
operator: ''
group: 1
plugin_id: boolean
entity_type: node
entity_field: status
sorts: { }
title: test_comment_row
header: { }
footer: { }
empty: { }
arguments: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
path: test-comment-row

View file

@ -0,0 +1,79 @@
langcode: en
status: true
dependencies:
module:
- comment
- node
- user
id: test_comment_rss
label: test_comment_rss
module: views
description: ''
tag: ''
base_table: comment_field_data
base_field: cid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: null
display_options:
access:
type: perm
cache:
type: tag
query:
type: views_query
exposed_form:
type: basic
pager:
type: full
style:
type: default
row:
type: fields
relationships:
node:
field: node
id: node
required: true
table: comment_field_data
fields:
subject:
id: subject
table: comment_field_data
field: subject
plugin_id: field
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
entity_type: comment
entity_field: subject
filters: { }
sorts: { }
feed_1:
display_plugin: feed
id: feed_1
display_title: Feed
position: null
display_options:
path: test-comment-rss
defaults:
row: false
row:
type: comment_rss
options: {}

View file

@ -0,0 +1,61 @@
langcode: en
status: true
dependencies:
module:
- comment
- comment_test_views
- node
- user
id: test_comment_user_uid
label: test_comment_user_uid
module: comment_test_views
description: ''
tag: default
base_table: node_field_data
base_field: nid
core: '8'
display:
default:
display_options:
access:
type: perm
arguments:
uid_touch:
default_argument_skip_url: false
default_argument_type: fixed
field: uid_touch
id: uid_touch
summary:
format: default_summary
number_of_records: 0
summary_options:
items_per_page: 25
table: node_field_data
plugin_id: argument_comment_user_uid
entity_type: node
cache:
type: tag
exposed_form:
type: basic
fields:
nid:
field: nid
id: nid
table: node_field_data
plugin_id: node
entity_type: node
entity_field: nid
pager:
type: full
query:
options:
query_comment: ''
type: views_query
style:
type: default
row:
type: 'entity:node'
display_plugin: default
display_title: Master
id: default
position: 0

View file

@ -0,0 +1,325 @@
langcode: en
status: true
dependencies:
module:
- comment
- node
- user
id: test_field_filters
label: 'Test field filters'
module: views
description: ''
tag: ''
base_table: comment_field_data
base_field: cid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: none
options:
items_per_page: 0
offset: 0
style:
type: default
row:
type: 'entity:comment'
options:
view_mode: default
relationships:
node:
id: node
table: comment_field_data
field: node
required: true
plugin_id: standard
relationship: none
group_type: group
admin_label: Content
fields:
subject:
id: subject
table: comment_field_data
field: subject
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
type: string
settings:
link_to_entity: false
plugin_id: field
entity_type: comment
entity_field: subject
filters:
subject:
id: subject
table: comment_field_data
field: subject
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Comida
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: comment
entity_field: subject
sorts: { }
title: 'Title filter page'
header: { }
footer: { }
empty: { }
arguments: { }
rendering_language: '***LANGUAGE_entity_translation***'
page_bf:
display_plugin: page
id: page_bf
display_title: 'Body Comida'
position: 1
display_options:
path: test-body-filter
display_description: ''
filters:
comment_body_value:
id: comment_body_value
table: comment__comment_body
field: comment_body_value
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Comida
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: comment
entity_field: comment_body
defaults:
filters: false
filter_groups: false
title: false
filter_groups:
operator: AND
groups:
1: AND
title: 'Body filter page'
page_bp:
display_plugin: page
id: page_bp
display_title: 'Body Paris'
position: 1
display_options:
path: test-body-paris
display_description: ''
filters:
comment_body_value:
id: comment_body_value
table: comment__comment_body
field: comment_body_value
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Paris
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: comment
entity_field: comment_body
defaults:
filters: false
filter_groups: false
title: false
filter_groups:
operator: AND
groups:
1: AND
title: 'Body filter page'
page_tc:
display_plugin: page
id: page_tc
display_title: 'Title Comida'
position: 1
display_options:
path: test-title-filter
display_description: ''
page_tp:
display_plugin: page
id: page_tp
display_title: 'Title Paris'
position: 1
display_options:
path: test-title-paris
display_description: ''
filters:
subject:
id: subject
table: comment_field_data
field: subject
relationship: none
group_type: group
admin_label: ''
operator: contains
value: Paris
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: string
entity_type: comment
entity_field: subject
defaults:
filters: false
filter_groups: false
filter_groups:
operator: AND
groups:
1: AND

View file

@ -0,0 +1,163 @@
langcode: en
status: true
dependencies:
module:
- comment
- node
- user
id: '2505879'
label: '2505879'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
pager:
type: full
style:
type: table
row:
type: fields
fields:
title:
id: title
table: node_field_data
field: title
entity_type: node
entity_field: title
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
settings:
link_to_entity: true
plugin_id: field
relationship: none
group_type: group
admin_label: ''
label: Title
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
click_sort_column: value
type: string
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
new_comments:
id: new_comments
table: node
field: new_comments
relationship: none
group_type: group
admin_label: ''
label: 'New comments'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
set_precision: false
precision: 0
decimal: .
prefix: ''
suffix: ''
link_to_comment: true
entity_type: node
plugin_id: node_new_comments
filters: { }
sorts: { }
title: ''
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
path: 'test-new-comments'

View file

@ -0,0 +1,100 @@
<?php
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
/**
* Tests comment status field access.
*
* @group comment
*/
class CommentStatusFieldAccessTest extends BrowserTestBase {
use CommentTestTrait;
/**
* {@inheritdoc}
*/
public $profile = 'testing';
/**
* Comment admin.
*
* @var \Drupal\user\UserInterface
*/
protected $commentAdmin;
/**
* Node author.
*
* @var \Drupal\user\UserInterface
*/
protected $nodeAuthor;
/**
* {@inheritdoc}
*/
public static $modules = [
'node',
'comment',
'user',
'system',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$node_type = NodeType::create([
'type' => 'article',
'name' => t('Article'),
]);
$node_type->save();
$this->nodeAuthor = $this->drupalCreateUser([
'create article content',
'skip comment approval',
'post comments',
'edit own comments',
'access comments',
'administer nodes',
]);
$this->commentAdmin = $this->drupalCreateUser([
'administer comments',
'create article content',
'edit own comments',
'skip comment approval',
'post comments',
'access comments',
'administer nodes',
]);
$this->addDefaultCommentField('node', 'article');
}
/**
* Tests comment status field access.
*/
public function testCommentStatusFieldAccessStatus() {
$this->drupalLogin($this->nodeAuthor);
$this->drupalGet('node/add/article');
$assert = $this->assertSession();
$assert->fieldNotExists('comment[0][status]');
$this->submitForm([
'title[0][value]' => 'Node 1',
], t('Save and publish'));
$assert->fieldExists('subject[0][value]');
$this->drupalLogin($this->commentAdmin);
$this->drupalGet('node/add/article');
$assert->fieldExists('comment[0][status]');
$this->submitForm([
'title[0][value]' => 'Node 2',
], t('Save and publish'));
$assert->fieldExists('subject[0][value]');
}
}

View file

@ -0,0 +1,160 @@
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\Cache\Cache;
use Drupal\comment\CommentInterface;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Drupal\comment\Entity\Comment;
use Drupal\entity_test\Entity\EntityTest;
/**
* Tests the bubbling up of comment cache tags when using the Comment list
* formatter on an entity.
*
* @group comment
*/
class CommentDefaultFormatterCacheTagsTest extends EntityKernelTestBase {
use CommentTestTrait;
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('entity_test', 'comment');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$session = new Session();
$request = Request::create('/');
$request->setSession($session);
/** @var \Symfony\Component\HttpFoundation\RequestStack $stack */
$stack = $this->container->get('request_stack');
$stack->pop();
$stack->push($request);
// Set the current user to one that can access comments. Specifically, this
// user does not have access to the 'administer comments' permission, to
// ensure only published comments are visible to the end user.
$current_user = $this->container->get('current_user');
$current_user->setAccount($this->createUser(array(), array('access comments')));
// Install tables and config needed to render comments.
$this->installSchema('comment', array('comment_entity_statistics'));
$this->installConfig(array('system', 'filter', 'comment'));
// Comment rendering generates links, so build the router.
$this->container->get('router.builder')->rebuild();
// Set up a field, so that the entity that'll be referenced bubbles up a
// cache tag when rendering it entirely.
$this->addDefaultCommentField('entity_test', 'entity_test');
}
/**
* Tests the bubbling of cache tags.
*/
public function testCacheTags() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
// Create the entity that will be commented upon.
$commented_entity = EntityTest::create(array('name' => $this->randomMachineName()));
$commented_entity->save();
// Verify cache tags on the rendered entity before it has comments.
$build = \Drupal::entityManager()
->getViewBuilder('entity_test')
->view($commented_entity);
$renderer->renderRoot($build);
$expected_cache_tags = [
'entity_test_view',
'entity_test:' . $commented_entity->id(),
'config:core.entity_form_display.comment.comment.default',
'config:field.field.comment.comment.comment_body',
'config:field.field.entity_test.entity_test.comment',
'config:field.storage.comment.comment_body',
'config:user.settings',
];
sort($expected_cache_tags);
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags);
// Create a comment on that entity. Comment loading requires that the uid
// also exists in the {users} table.
$user = $this->createUser();
$user->save();
$comment = Comment::create(array(
'subject' => 'Llama',
'comment_body' => array(
'value' => 'Llamas are cool!',
'format' => 'plain_text',
),
'entity_id' => $commented_entity->id(),
'entity_type' => 'entity_test',
'field_name' => 'comment',
'comment_type' => 'comment',
'status' => CommentInterface::PUBLISHED,
'uid' => $user->id(),
));
$comment->save();
// Load commented entity so comment_count gets computed.
// @todo Remove the $reset = TRUE parameter after
// https://www.drupal.org/node/597236 lands. It's a temporary work-around.
$storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
$storage->resetCache([$commented_entity->id()]);
$commented_entity = $storage->load($commented_entity->id());
// Verify cache tags on the rendered entity when it has comments.
$build = \Drupal::entityManager()
->getViewBuilder('entity_test')
->view($commented_entity);
$renderer->renderRoot($build);
$expected_cache_tags = [
'entity_test_view',
'entity_test:' . $commented_entity->id(),
'comment_view',
'comment:' . $comment->id(),
'config:filter.format.plain_text',
'user_view',
'user:2',
'config:core.entity_form_display.comment.comment.default',
'config:field.field.comment.comment.comment_body',
'config:field.field.entity_test.entity_test.comment',
'config:field.storage.comment.comment_body',
'config:user.settings',
];
sort($expected_cache_tags);
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags);
// Build a render array with the entity in a sub-element so that lazy
// builder elements bubble up outside of the entity and we can check that
// it got the correct cache max age.
$build = ['#type' => 'container'];
$build['entity'] = \Drupal::entityManager()
->getViewBuilder('entity_test')
->view($commented_entity);
$renderer->renderRoot($build);
// The entity itself was cached but the top-level element is max-age 0 due
// to the bubbled up max age due to the lazy-built comment form.
$this->assertIdentical(Cache::PERMANENT, $build['entity']['#cache']['max-age']);
$this->assertIdentical(0, $build['#cache']['max-age'], 'Top level render array has max-age 0');
// The children (fields) of the entity render array are only built in case
// of a cache miss.
$this->assertFalse(isset($build['entity']['comment']), 'Cache hit');
}
}

View file

@ -0,0 +1,315 @@
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\simpletest\TestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests comment field level access.
*
* @group comment
* @group Access
*/
class CommentFieldAccessTest extends EntityKernelTestBase {
use CommentTestTrait;
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('comment', 'entity_test', 'user');
/**
* Fields that only users with administer comments permissions can change.
*
* @var array
*/
protected $administrativeFields = array(
'uid',
'status',
'created',
);
/**
* These fields are automatically managed and can not be changed by any user.
*
* @var array
*/
protected $readOnlyFields = array(
'changed',
'hostname',
'cid',
'thread',
);
/**
* These fields can be edited on create only.
*
* @var array
*/
protected $createOnlyFields = [
'uuid',
'pid',
'comment_type',
'entity_id',
'entity_type',
'field_name',
];
/**
* These fields can only be edited by the admin or anonymous users if allowed.
*
* @var array
*/
protected $contactFields = array(
'name',
'mail',
'homepage',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(array('user', 'comment'));
$this->installSchema('comment', array('comment_entity_statistics'));
}
/**
* Test permissions on comment fields.
*/
public function testAccessToAdministrativeFields() {
// Create a comment type.
$comment_type = CommentType::create([
'id' => 'comment',
'label' => 'Default comments',
'description' => 'Default comment field',
'target_entity_type_id' => 'entity_test',
]);
$comment_type->save();
// Create a comment against a test entity.
$host = EntityTest::create();
$host->save();
// An administrator user. No user exists yet, ensure that the first user
// does not have UID 1.
$comment_admin_user = $this->createUser(['uid' => 2, 'name' => 'admin'], [
'administer comments',
'access comments',
]);
// Two comment enabled users, one with edit access.
$comment_enabled_user = $this->createUser(['name' => 'enabled'], [
'post comments',
'skip comment approval',
'edit own comments',
'access comments',
]);
$comment_no_edit_user = $this->createUser(['name' => 'no edit'], [
'post comments',
'skip comment approval',
'access comments',
]);
// An unprivileged user.
$comment_disabled_user = $this->createUser(['name' => 'disabled'], ['access content']);
$role = Role::load(RoleInterface::ANONYMOUS_ID);
$role->grantPermission('post comments')
->save();
$anonymous_user = new AnonymousUserSession();
// Add two fields.
$this->addDefaultCommentField('entity_test', 'entity_test', 'comment');
$this->addDefaultCommentField('entity_test', 'entity_test', 'comment_other');
// Change the second field's anonymous contact setting.
$instance = FieldConfig::loadByName('entity_test', 'entity_test', 'comment_other');
// Default is 'May not contact', for this field - they may contact.
$instance->setSetting('anonymous', COMMENT_ANONYMOUS_MAY_CONTACT);
$instance->save();
// Create three "Comments". One is owned by our edit-enabled user.
$comment1 = Comment::create([
'entity_type' => 'entity_test',
'name' => 'Tony',
'hostname' => 'magic.example.com',
'mail' => 'tonythemagicalpony@example.com',
'subject' => 'Bruce the Mesopotamian moose',
'entity_id' => $host->id(),
'comment_type' => 'comment',
'field_name' => 'comment',
'pid' => 0,
'uid' => 0,
'status' => 1,
]);
$comment1->save();
$comment2 = Comment::create([
'entity_type' => 'entity_test',
'hostname' => 'magic.example.com',
'subject' => 'Brian the messed up lion',
'entity_id' => $host->id(),
'comment_type' => 'comment',
'field_name' => 'comment',
'status' => 1,
'pid' => 0,
'uid' => $comment_enabled_user->id(),
]);
$comment2->save();
$comment3 = Comment::create([
'entity_type' => 'entity_test',
'hostname' => 'magic.example.com',
// Unpublished.
'status' => 0,
'subject' => 'Gail the minky whale',
'entity_id' => $host->id(),
'comment_type' => 'comment',
'field_name' => 'comment_other',
'pid' => $comment2->id(),
'uid' => $comment_no_edit_user->id(),
]);
$comment3->save();
// Note we intentionally don't save this comment so it remains 'new'.
$comment4 = Comment::create([
'entity_type' => 'entity_test',
'hostname' => 'magic.example.com',
// Unpublished.
'status' => 0,
'subject' => 'Daniel the Cocker-Spaniel',
'entity_id' => $host->id(),
'comment_type' => 'comment',
'field_name' => 'comment_other',
'pid' => 0,
'uid' => $anonymous_user->id(),
]);
// Generate permutations.
$combinations = [
'comment' => [$comment1, $comment2, $comment3, $comment4],
'user' => [$comment_admin_user, $comment_enabled_user, $comment_no_edit_user, $comment_disabled_user, $anonymous_user]
];
$permutations = TestBase::generatePermutations($combinations);
// Check access to administrative fields.
foreach ($this->administrativeFields as $field) {
foreach ($permutations as $set) {
$may_view = $set['comment']->{$field}->access('view', $set['user']);
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
$this->assertTrue($may_view, SafeMarkup::format('User @user can view field @field on comment @comment', [
'@user' => $set['user']->getUsername(),
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
]));
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments'), SafeMarkup::format('User @user @state update field @field on comment @comment', [
'@user' => $set['user']->getUsername(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
]));
}
}
// Check access to normal field.
foreach ($permutations as $set) {
$may_update = $set['comment']->access('update', $set['user']) && $set['comment']->subject->access('edit', $set['user']);
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments') || ($set['user']->hasPermission('edit own comments') && $set['user']->id() == $set['comment']->getOwnerId()), SafeMarkup::format('User @user @state update field subject on comment @comment', [
'@user' => $set['user']->getUsername(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
]));
}
// Check read-only fields.
foreach ($this->readOnlyFields as $field) {
// Check view operation.
foreach ($permutations as $set) {
$may_view = $set['comment']->{$field}->access('view', $set['user']);
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
// Nobody has access to view the hostname field.
if ($field === 'hostname') {
$view_access = FALSE;
$state = 'cannot';
}
else {
$view_access = TRUE;
$state = 'can';
}
$this->assertEqual($may_view, $view_access, SafeMarkup::format('User @user @state view field @field on comment @comment', [
'@user' => $set['user']->getUsername(),
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
'@state' => $state,
]));
$this->assertFalse($may_update, SafeMarkup::format('User @user @state update field @field on comment @comment', [
'@user' => $set['user']->getUsername(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
]));
}
}
// Check create-only fields.
foreach ($this->createOnlyFields as $field) {
// Check view operation.
foreach ($permutations as $set) {
$may_view = $set['comment']->{$field}->access('view', $set['user']);
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
$this->assertEqual($may_view, TRUE, SafeMarkup::format('User @user can view field @field on comment @comment', [
'@user' => $set['user']->getUsername(),
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
]));
$this->assertEqual($may_update, $set['user']->hasPermission('post comments') && $set['comment']->isNew(), SafeMarkup::format('User @user @state update field @field on comment @comment', [
'@user' => $set['user']->getUsername(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
]));
}
}
// Check contact fields.
foreach ($this->contactFields as $field) {
// Check view operation.
foreach ($permutations as $set) {
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
// To edit the 'mail' or 'name' field, either the user has the
// "administer comments" permissions or the user is anonymous and
// adding a new comment using a field that allows contact details.
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments') || (
$set['user']->isAnonymous() &&
$set['comment']->isNew() &&
$set['user']->hasPermission('post comments') &&
$set['comment']->getFieldName() == 'comment_other'
), SafeMarkup::format('User @user @state update field @field on comment @comment', [
'@user' => $set['user']->getUsername(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
]));
}
}
foreach ($permutations as $set) {
// Check no view-access to mail field for other than admin.
$may_view = $set['comment']->mail->access('view', $set['user']);
$this->assertEqual($may_view, $set['user']->hasPermission('administer comments'));
}
}
}

View file

@ -0,0 +1,138 @@
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\Entity\CommentType;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests integration of comment with other components.
*
* @group comment
*/
class CommentIntegrationTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'field', 'entity_test', 'user', 'system', 'dblog'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$this->installEntitySchema('comment');
$this->installSchema('dblog', ['watchdog']);
// Create a new 'comment' comment-type.
CommentType::create([
'id' => 'comment',
'label' => $this->randomString(),
])->save();
}
/**
* Tests view mode setting integration.
*
* @see comment_entity_view_display_presave()
* @see CommentDefaultFormatter::calculateDependencies()
*/
public function testViewMode() {
$mode = Unicode::strtolower($this->randomMachineName());
// Create a new comment view mode and a view display entity.
EntityViewMode::create([
'id' => "comment.$mode",
'targetEntityType' => 'comment',
'settings' => ['comment_type' => 'comment'],
])->save();
EntityViewDisplay::create([
'targetEntityType' => 'comment',
'bundle' => 'comment',
'mode' => $mode,
])->setStatus(TRUE)->save();
// Create a comment field attached to a host 'entity_test' entity.
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'type' => 'comment',
'field_name' => $field_name = Unicode::strtolower($this->randomMachineName()),
'settings' => [
'comment_type' => 'comment',
],
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'field_name' => $field_name,
])->save();
$component = [
'type' => 'comment_default',
'settings' => ['view_mode' => $mode, 'pager_id' => 0],
];
// Create a new 'entity_test' view display on host entity that uses the
// custom comment display in field formatter to show the field.
EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
])->setComponent($field_name, $component)->setStatus(TRUE)->save();
$host_display_id = 'entity_test.entity_test.default';
$comment_display_id = "comment.comment.$mode";
// Disable the "comment.comment.$mode" display.
EntityViewDisplay::load($comment_display_id)->setStatus(FALSE)->save();
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $host_display */
$host_display = EntityViewDisplay::load($host_display_id);
// Check that the field formatter has been disabled on host view display.
$this->assertNull($host_display->getComponent($field_name));
$this->assertTrue($host_display->get('hidden')[$field_name]);
// Check that the proper warning has been logged.
$arguments = [
'@id' => $host_display_id,
'@name' => $field_name,
'@display' => EntityViewMode::load("comment.$mode")->label(),
'@mode' => $mode,
];
$logged = (bool) Database::getConnection()->select('watchdog')
->fields('watchdog', ['wid'])
->condition('type', 'system')
->condition('message', "View display '@id': Comment field formatter '@name' was disabled because it is using the comment view display '@display' (@mode) that was just disabled.")
->condition('variables', serialize($arguments))
->execute()
->fetchField();
$this->assertTrue($logged);
// Re-enable the comment view display.
EntityViewDisplay::load($comment_display_id)->setStatus(TRUE)->save();
// Re-enable the comment field formatter on host entity view display.
EntityViewDisplay::load($host_display_id)->setComponent($field_name, $component)->save();
// Delete the "comment.$mode" view mode.
EntityViewMode::load("comment.$mode")->delete();
// Check that the comment view display entity has been deleted too.
$this->assertNull(EntityViewDisplay::load($comment_display_id));
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
$host_display = EntityViewDisplay::load($host_display_id);
// Check that the field formatter has been disabled on host view display.
$this->assertNull($host_display->getComponent($field_name));
$this->assertTrue($host_display->get('hidden')[$field_name]);
}
}

View file

@ -0,0 +1,67 @@
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
/**
* Tests the new entity API for the comment field type.
*
* @group comment
*/
class CommentItemTest extends FieldKernelTestBase {
use CommentTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['comment', 'entity_test', 'user'];
protected function setUp() {
parent::setUp();
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installConfig(['comment']);
}
/**
* Tests using entity fields of the comment field type.
*/
public function testCommentItem() {
$this->addDefaultCommentField('entity_test', 'entity_test', 'comment');
// Verify entity creation.
$entity = EntityTest::create();
$entity->name->value = $this->randomMachineName();
$entity->save();
// Verify entity has been created properly.
$id = $entity->id();
$storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
$storage->resetCache([$id]);
$entity = $storage->load($id);
$this->assertTrue($entity->comment instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->comment[0] instanceof CommentItemInterface, 'Field item implements interface.');
// Test sample item generation.
/** @var \Drupal\entity_test\Entity\EntityTest $entity */
$entity = EntityTest::create();
$entity->comment->generateSampleItems();
$this->entityValidateAndSave($entity);
$this->assertTrue(in_array($entity->get('comment')->status, [
CommentItemInterface::HIDDEN,
CommentItemInterface::CLOSED,
CommentItemInterface::OPEN,
]), 'Comment status value in defined range');
$mainProperty = $entity->comment[0]->mainPropertyName();
$this->assertEqual('status', $mainProperty);
}
}

View file

@ -0,0 +1,66 @@
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\Entity\CommentType;
use Drupal\KernelTests\KernelTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests that comment fields cannot be added to entities with non-integer IDs.
*
* @group comment
*/
class CommentStringIdEntitiesTest extends KernelTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = array(
'comment',
'user',
'field',
'field_ui',
'entity_test',
'text',
);
protected function setUp() {
parent::setUp();
$this->installEntitySchema('comment');
$this->installSchema('comment', array('comment_entity_statistics'));
// Create the comment body field storage.
$this->installConfig(array('field'));
}
/**
* Tests that comment fields cannot be added entities with non-integer IDs.
*/
public function testCommentFieldNonStringId() {
try {
$bundle = CommentType::create(array(
'id' => 'foo',
'label' => 'foo',
'description' => '',
'target_entity_type_id' => 'entity_test_string_id',
));
$bundle->save();
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'foo',
'entity_type' => 'entity_test_string_id',
'settings' => array(
'comment_type' => 'entity_test_string_id',
),
'type' => 'comment',
));
$field_storage->save();
$this->fail('Did not throw an exception as expected.');
}
catch (\UnexpectedValueException $e) {
$this->pass('Exception thrown when trying to create comment field on Entity Type with string ID.');
}
}
}

View file

@ -0,0 +1,201 @@
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\CommentInterface;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\user\Entity\User;
/**
* Tests comment validation constraints.
*
* @group comment
*/
class CommentValidationTest extends EntityKernelTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('comment', 'node');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('comment', array('comment_entity_statistics'));
}
/**
* Tests the comment validation constraints.
*/
public function testValidation() {
// Add a user.
$user = User::create(array('name' => 'test', 'status' => TRUE));
$user->save();
// Add comment type.
$this->entityManager->getStorage('comment_type')->create(array(
'id' => 'comment',
'label' => 'comment',
'target_entity_type_id' => 'node',
))->save();
// Add comment field to content.
$this->entityManager->getStorage('field_storage_config')->create(array(
'entity_type' => 'node',
'field_name' => 'comment',
'type' => 'comment',
'settings' => array(
'comment_type' => 'comment',
)
))->save();
// Create a page node type.
$this->entityManager->getStorage('node_type')->create(array(
'type' => 'page',
'name' => 'page',
))->save();
// Add comment field to page content.
/** @var \Drupal\field\FieldConfigInterface $field */
$field = $this->entityManager->getStorage('field_config')->create(array(
'field_name' => 'comment',
'entity_type' => 'node',
'bundle' => 'page',
'label' => 'Comment settings',
));
$field->save();
$node = $this->entityManager->getStorage('node')->create(array(
'type' => 'page',
'title' => 'test',
));
$node->save();
$comment = $this->entityManager->getStorage('comment')->create(array(
'entity_id' => $node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'comment_body' => $this->randomMachineName(),
));
$violations = $comment->validate();
$this->assertEqual(count($violations), 0, 'No violations when validating a default comment.');
$comment->set('subject', $this->randomString(65));
$this->assertLengthViolation($comment, 'subject', 64);
// Make the subject valid.
$comment->set('subject', $this->randomString());
$comment->set('name', $this->randomString(61));
$this->assertLengthViolation($comment, 'name', 60);
// Validate a name collision between an anonymous comment author name and an
// existing user account name.
$comment->set('name', 'test');
$comment->set('uid', 0);
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, "Violation found on author name collision");
$this->assertEqual($violations[0]->getPropertyPath(), "name");
$this->assertEqual($violations[0]->getMessage(), t('The name you used (%name) belongs to a registered user.', array('%name' => 'test')));
// Make the name valid.
$comment->set('name', 'valid unused name');
$comment->set('mail', 'invalid');
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when email is invalid');
$this->assertEqual($violations[0]->getPropertyPath(), 'mail.0.value');
$this->assertEqual($violations[0]->getMessage(), t('This value is not a valid email address.'));
$comment->set('mail', NULL);
$comment->set('homepage', 'http://example.com/' . $this->randomMachineName(237));
$this->assertLengthViolation($comment, 'homepage', 255);
$comment->set('homepage', 'invalid');
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when homepage is invalid');
$this->assertEqual($violations[0]->getPropertyPath(), 'homepage.0.value');
// @todo This message should be improved in
// https://www.drupal.org/node/2012690.
$this->assertEqual($violations[0]->getMessage(), t('This value should be of the correct primitive type.'));
$comment->set('homepage', NULL);
$comment->set('hostname', $this->randomString(129));
$this->assertLengthViolation($comment, 'hostname', 128);
$comment->set('hostname', NULL);
$comment->set('thread', $this->randomString(256));
$this->assertLengthViolation($comment, 'thread', 255);
$comment->set('thread', NULL);
// Force anonymous users to enter contact details.
$field->setSetting('anonymous', COMMENT_ANONYMOUS_MUST_CONTACT);
$field->save();
// Reset the node entity.
\Drupal::entityManager()->getStorage('node')->resetCache([$node->id()]);
$node = Node::load($node->id());
// Create a new comment with the new field.
$comment = $this->entityManager->getStorage('comment')->create(array(
'entity_id' => $node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'comment_body' => $this->randomMachineName(),
'uid' => 0,
'name' => '',
));
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when name is required, but empty and UID is anonymous.');
$this->assertEqual($violations[0]->getPropertyPath(), 'name');
$this->assertEqual($violations[0]->getMessage(), t('You have to specify a valid author.'));
// Test creating a default comment with a given user id works.
$comment = $this->entityManager->getStorage('comment')->create(array(
'entity_id' => $node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'comment_body' => $this->randomMachineName(),
'uid' => $user->id(),
));
$violations = $comment->validate();
$this->assertEqual(count($violations), 0, 'No violations when validating a default comment with an author.');
// Test specifying a wrong author name does not work.
$comment = $this->entityManager->getStorage('comment')->create(array(
'entity_id' => $node->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'comment_body' => $this->randomMachineName(),
'uid' => $user->id(),
'name' => 'not-test',
));
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, 'Violation found when author name and comment author do not match.');
$this->assertEqual($violations[0]->getPropertyPath(), 'name');
$this->assertEqual($violations[0]->getMessage(), t('The specified author name does not match the comment author.'));
}
/**
* Verifies that a length violation exists for the given field.
*
* @param \Drupal\comment\CommentInterface $comment
* The comment object to validate.
* @param string $field_name
* The field that violates the maximum length.
* @param int $length
* Number of characters that was exceeded.
*/
protected function assertLengthViolation(CommentInterface $comment, $field_name, $length) {
$violations = $comment->validate();
$this->assertEqual(count($violations), 1, "Violation found when $field_name is too long.");
$this->assertEqual($violations[0]->getPropertyPath(), "$field_name.0.value");
$field_label = $comment->get($field_name)->getFieldDefinition()->getLabel();
$this->assertEqual($violations[0]->getMessage(), t('%name: may not be longer than @max characters.', array('%name' => $field_label, '@max' => $length)));
}
}

View file

@ -0,0 +1,73 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate;
use Drupal\comment\Entity\CommentType;
use Drupal\migrate\MigrateException;
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
use Drupal\migrate_drupal\Tests\StubTestTrait;
use Drupal\node\Entity\NodeType;
/**
* Test stub creation for comment entities.
*
* @group comment
*/
class MigrateCommentStubTest extends MigrateDrupalTestBase {
use StubTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('comment');
$this->installEntitySchema('node');
// Make sure uid 0 is created (default uid for comments is 0).
$storage = \Drupal::entityManager()->getStorage('user');
// Insert a row for the anonymous user.
$storage
->create(array(
'uid' => 0,
'status' => 0,
'name' => '',
))
->save();
// Need at least one node type and comment type present.
NodeType::create([
'type' => 'testnodetype',
'name' => 'Test node type',
])->save();
CommentType::create([
'id' => 'testcommenttype',
'label' => 'Test comment type',
'target_entity_type_id' => 'node',
])->save();
}
/**
* Tests creation of comment stubs.
*/
public function testStub() {
try {
// We expect an exception, because there's no node to reference.
$this->performStubTest('comment');
$this->fail('Expected exception has not been thrown.');
}
catch (MigrateException $e) {
$this->assertIdentical($e->getMessage(),
'Stubbing failed, unable to generate value for field entity_id');
}
// The stub should pass when there's a node to point to.
$this->createStub('node');
$this->performStubTest('comment');
}
}

View file

@ -0,0 +1,74 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Upgrade comments.
*
* @group migrate_drupal_6
*/
class MigrateCommentTest extends MigrateDrupal6TestBase {
use CommentTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installConfig(['comment']);
// The entity.node.canonical route must exist when the RDF hook is called.
$this->container->get('router.builder')->rebuild();
$this->migrateContent();
$this->executeMigrations([
'd6_node',
'd6_comment_type',
'd6_comment_field',
'd6_comment_field_instance',
'd6_comment_entity_display',
'd6_comment_entity_form_display',
'd6_comment',
]);
}
/**
* Tests the Drupal 6 to Drupal 8 comment migration.
*/
public function testComments() {
/** @var \Drupal\Core\Entity\EntityStorageInterface $comment_storage */
$comment_storage = $this->container->get('entity.manager')->getStorage('comment');
/** @var \Drupal\comment\CommentInterface $comment */
$comment = $comment_storage->load(1);
$this->assertIdentical('The first comment.', $comment->getSubject());
$this->assertIdentical('The first comment body.', $comment->comment_body->value);
$this->assertIdentical('filtered_html', $comment->comment_body->format);
$this->assertIdentical(NULL, $comment->pid->target_id);
$this->assertIdentical('1', $comment->getCommentedEntityId());
$this->assertIdentical('node', $comment->getCommentedEntityTypeId());
$this->assertIdentical('en', $comment->language()->getId());
$this->assertIdentical('comment_no_subject', $comment->getTypeId());
$comment = $comment_storage->load(2);
$this->assertIdentical('The response to the second comment.', $comment->subject->value);
$this->assertIdentical('3', $comment->pid->target_id);
$comment = $comment_storage->load(3);
$this->assertIdentical('The second comment.', $comment->subject->value);
$this->assertIdentical(NULL, $comment->pid->target_id);
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\comment\Entity\CommentType;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Upgrade comment type.
*
* @group migrate_drupal_6
*/
class MigrateCommentTypeTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installConfig(['node', 'comment']);
$this->executeMigration('d6_comment_type');
}
/**
* Tests the Drupal 6 to Drupal 8 comment type migration.
*/
public function testCommentType() {
$comment_type = CommentType::load('comment');
$this->assertIdentical('node', $comment_type->getTargetEntityTypeId());
$comment_type = CommentType::load('comment_no_subject');
$this->assertIdentical('node', $comment_type->getTargetEntityTypeId());
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Base class for Drupal 6 comment variables to Drupal 8 entity display tests.
*/
abstract class MigrateCommentVariableDisplayBase extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment']);
$this->migrateContentTypes();
$this->executeMigrations([
'd6_comment_type',
'd6_comment_field',
'd6_comment_field_instance',
]);
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
/**
* Upgrade comment variables to entity.display.node.*.default.yml.
*
* @group migrate_drupal_6
*/
class MigrateCommentVariableEntityDisplayTest extends MigrateCommentVariableDisplayBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_comment_entity_display');
}
/**
* Tests comment variables migrated into an entity display.
*/
public function testCommentEntityDisplay() {
foreach (['page', 'story', 'article'] as $type) {
$component = EntityViewDisplay::load('node.' . $type . '.default')->getComponent('comment');
$this->assertIdentical('hidden', $component['label']);
$this->assertIdentical('comment_default', $component['type']);
$this->assertIdentical(20, $component['weight']);
}
}
}

View file

@ -0,0 +1,45 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Upgrade comment subject variable to core.entity_form_display.comment.*.default.yml
*
* @group migrate_drupal_6
*/
class MigrateCommentVariableEntityFormDisplaySubjectTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment']);
$this->executeMigrations([
'd6_comment_type',
'd6_comment_entity_form_display_subject',
]);
}
/**
* Tests comment subject variable migrated into an entity display.
*/
public function testCommentEntityFormDisplay() {
$component = EntityFormDisplay::load('comment.comment.default')
->getComponent('subject');
$this->assertIdentical('string_textfield', $component['type']);
$this->assertIdentical(10, $component['weight']);
$component = EntityFormDisplay::load('comment.comment_no_subject.default')
->getComponent('subject');
$this->assertNull($component);
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
/**
* Upgrade comment variables to core.entity_form_display.node.*.default.yml.
*
* @group migrate_drupal_6
*/
class MigrateCommentVariableEntityFormDisplayTest extends MigrateCommentVariableDisplayBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_comment_entity_form_display');
}
/**
* Tests comment variables migrated into an entity display.
*/
public function testCommentEntityFormDisplay() {
foreach (['page', 'article', 'story'] as $type) {
$component = EntityFormDisplay::load('node.' . $type . '.default')
->getComponent('comment');
$this->assertIdentical('comment_default', $component['type']);
$this->assertIdentical(20, $component['weight']);
}
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Upgrade comment variables to field.storage.node.comment.yml.
*
* @group migrate_drupal_6
*/
class MigrateCommentVariableFieldTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment']);
$this->migrateContentTypes();
$this->executeMigrations(['d6_comment_type', 'd6_comment_field']);
}
/**
* Tests comment variables migrated into a field entity.
*/
public function testCommentField() {
$this->assertTrue(is_object(FieldStorageConfig::load('node.comment')));
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d6;
use Drupal\comment\CommentManagerInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
use Drupal\node\Entity\Node;
/**
* Upgrade comment variables to field.instance.node.*.comment.yml.
*
* @group migrate_drupal_6
*/
class MigrateCommentVariableInstanceTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment']);
$this->migrateContentTypes();
$this->executeMigrations([
'd6_comment_type',
'd6_comment_field',
'd6_comment_field_instance',
]);
}
/**
* Test the migrated field instance values.
*/
public function testCommentFieldInstance() {
$node = Node::create(['type' => 'page']);
$this->assertIdentical(0, $node->comment->status);
$this->assertIdentical('comment', $node->comment->getFieldDefinition()->getName());
$settings = $node->comment->getFieldDefinition()->getSettings();
$this->assertIdentical(CommentManagerInterface::COMMENT_MODE_THREADED, $settings['default_mode']);
$this->assertIdentical(50, $settings['per_page']);
$this->assertFalse($settings['anonymous']);
$this->assertFalse($settings['form_location']);
$this->assertTrue($settings['preview']);
$node = Node::create(['type' => 'story']);
$this->assertIdentical(2, $node->comment_no_subject->status);
$this->assertIdentical('comment_no_subject', $node->comment_no_subject->getFieldDefinition()->getName());
$settings = $node->comment_no_subject->getFieldDefinition()->getSettings();
$this->assertIdentical(CommentManagerInterface::COMMENT_MODE_FLAT, $settings['default_mode']);
$this->assertIdentical(70, $settings['per_page']);
$this->assertTrue($settings['anonymous']);
$this->assertFalse($settings['form_location']);
$this->assertFalse($settings['preview']);
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d7;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of comment display configuration.
*
* @group comment
*/
class MigrateCommentEntityDisplayTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
'd7_comment_entity_display',
]);
}
/**
* Asserts a display entity.
*
* @param string $id
* The entity ID.
* @param string $component_id
* The ID of the display component.
*/
protected function assertDisplay($id, $component_id) {
$component = EntityViewDisplay::load($id)->getComponent($component_id);
$this->assertTrue(is_array($component));
$this->assertIdentical('hidden', $component['label']);
$this->assertIdentical('comment_default', $component['type']);
$this->assertIdentical(20, $component['weight']);
}
/**
* Tests the migrated display configuration.
*/
public function testMigration() {
$this->assertDisplay('node.page.default', 'comment_node_page');
$this->assertDisplay('node.article.default', 'comment_node_article');
$this->assertDisplay('node.book.default', 'comment_node_book');
$this->assertDisplay('node.blog.default', 'comment_node_blog');
$this->assertDisplay('node.forum.default', 'comment_node_forum');
$this->assertDisplay('node.test_content_type.default', 'comment_node_test_content_type');
}
}

View file

@ -0,0 +1,55 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d7;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of comment form's subject display configuration.
*
* @group comment
*/
class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_comment_entity_form_display_subject',
]);
}
/**
* Asserts a display entity.
*
* @param string $id
* The entity ID.
*/
protected function assertDisplay($id) {
$component = EntityFormDisplay::load($id)->getComponent('subject');
$this->assertTrue(is_array($component));
$this->assertIdentical('string_textfield', $component['type']);
$this->assertIdentical(10, $component['weight']);
}
/**
* Tests the migrated display configuration.
*/
public function testMigration() {
$this->assertDisplay('comment.comment_node_page.default');
$this->assertDisplay('comment.comment_node_article.default');
$this->assertDisplay('comment.comment_node_book.default');
$this->assertDisplay('comment.comment_node_blog.default');
$this->assertDisplay('comment.comment_node_forum.default');
$this->assertDisplay('comment.comment_node_test_content_type.default');
}
}

View file

@ -0,0 +1,59 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d7;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of comment form display configuration.
*
* @group comment
*/
class MigrateCommentEntityFormDisplayTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
'd7_comment_entity_form_display',
]);
}
/**
* Asserts a display entity.
*
* @param string $id
* The entity ID.
* @param string $component
* The ID of the form component.
*/
protected function assertDisplay($id, $component_id) {
$component = EntityFormDisplay::load($id)->getComponent($component_id);
$this->assertTrue(is_array($component));
$this->assertIdentical('comment_default', $component['type']);
$this->assertIdentical(20, $component['weight']);
}
/**
* Tests the migrated display configuration.
*/
public function testMigration() {
$this->assertDisplay('node.page.default', 'comment');
$this->assertDisplay('node.article.default', 'comment');
$this->assertDisplay('node.book.default', 'comment');
$this->assertDisplay('node.blog.default', 'comment');
$this->assertDisplay('node.forum.default', 'comment');
$this->assertDisplay('node.test_content_type.default', 'comment');
}
}

View file

@ -0,0 +1,86 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d7;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Field\FieldConfigInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests creation of comment reference fields for each comment type defined
* in Drupal 7.
*
* @group comment
*/
class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
]);
}
/**
* Asserts a comment field entity.
*
* @param string $id
* The entity ID.
* @param string $field_name
* The field name.
* @param string $bundle
* The bundle ID.
* @param int $default_mode
* The field's default_mode setting.
* @param int $per_page
* The field's per_page setting.
* @param bool $anonymous
* The field's anonymous setting.
* @param int $form_location
* The field's form_location setting.
* @param bool $preview
* The field's preview setting.
*/
protected function assertEntity($id, $field_name, $bundle, $default_mode, $per_page, $anonymous, $form_location, $preview) {
$entity = FieldConfig::load($id);
$this->assertTrue($entity instanceof FieldConfigInterface);
/** @var \Drupal\field\FieldConfigInterface $entity */
$this->assertIdentical('node', $entity->getTargetEntityTypeId());
$this->assertIdentical('Comments', $entity->label());
$this->assertTrue($entity->isRequired());
$this->assertIdentical($field_name, $entity->getFieldStorageDefinition()->getName());
$this->assertIdentical($bundle, $entity->getTargetBundle());
$this->assertTrue($entity->get('default_value')[0]['status']);
$this->assertEqual($default_mode, $entity->getSetting('default_mode'));
$this->assertIdentical($per_page, $entity->getSetting('per_page'));
$this->assertEqual($anonymous, $entity->getSetting('anonymous'));
// This assertion fails because 1 !== TRUE. It's extremely strange that
// the form_location setting is returning a boolean, but this appears to
// be a problem with the entity, not with the migration.
// $this->asserIdentical($form_location, $entity->getSetting('form_location'));
$this->assertEqual($preview, $entity->getSetting('preview'));
}
/**
* Tests the migrated fields.
*/
public function testMigration() {
$this->assertEntity('node.page.comment_node_page', 'comment_node_page', 'page', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
$this->assertEntity('node.article.comment_node_article', 'comment_node_article', 'article', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
$this->assertEntity('node.blog.comment_node_blog', 'comment_node_blog', 'blog', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
$this->assertEntity('node.book.comment_node_book', 'comment_node_book', 'book', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
$this->assertEntity('node.forum.comment_node_forum', 'comment_node_forum', 'forum', TRUE, 50, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
$this->assertEntity('node.test_content_type.comment_node_test_content_type', 'comment_node_test_content_type', 'test_content_type', TRUE, 30, FALSE, CommentItemInterface::FORM_BELOW, TRUE);
}
}

View file

@ -0,0 +1,61 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d7;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests creation of comment reference fields for each comment type defined
* in Drupal 7.
*
* @group comment
*/
class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_comment_field',
]);
}
/**
* Asserts a comment field entity.
*
* @param string $id
* The entity ID.
* @param string $comment_type
* The comment type (bundle ID) the field references.
*/
protected function assertEntity($id, $comment_type) {
$entity = FieldStorageConfig::load($id);
$this->assertTrue($entity instanceof FieldStorageConfigInterface);
/** @var \Drupal\field\FieldStorageConfigInterface $entity */
$this->assertIdentical('node', $entity->getTargetEntityTypeId());
$this->assertIdentical('comment', $entity->getType());
$this->assertIdentical($comment_type, $entity->getSetting('comment_type'));
}
/**
* Tests the migrated fields.
*/
public function testMigration() {
$this->assertEntity('node.comment_node_page', 'comment_node_page');
$this->assertEntity('node.comment_node_article', 'comment_node_article');
$this->assertEntity('node.comment_node_blog', 'comment_node_blog');
$this->assertEntity('node.comment_node_book', 'comment_node_book');
$this->assertEntity('node.comment_node_forum', 'comment_node_forum');
$this->assertEntity('node.comment_node_test_content_type', 'comment_node_test_content_type');
}
}

View file

@ -0,0 +1,70 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d7;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
use Drupal\node\NodeInterface;
/**
* Tests migration of comments from Drupal 7.
*
* @group comment
*/
class MigrateCommentTest extends MigrateDrupal7TestBase {
public static $modules = ['filter', 'node', 'comment', 'text'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->executeMigrations([
'd7_filter_format',
'd7_user_role',
'd7_user',
]);
$this->executeMigration('d7_node_type');
// We only need the test_content_type node migration to run for real, so
// mock all the others.
$this->prepareMigrations(array(
'd7_node' => array(
array(array(0), array(0)),
),
));
$this->executeMigrations([
'd7_node',
'd7_comment_type',
'd7_comment',
]);
}
/**
* Tests migration of comments from Drupal 7.
*/
public function testCommentMigration() {
$comment = Comment::load(1);
$this->assertTrue($comment instanceof CommentInterface);
/** @var \Drupal\comment\CommentInterface $comment */
$this->assertIdentical('A comment', $comment->getSubject());
$this->assertIdentical('1421727536', $comment->getCreatedTime());
$this->assertIdentical('1421727536', $comment->getChangedTime());
$this->assertTrue($comment->getStatus());
$this->assertIdentical('admin', $comment->getAuthorName());
$this->assertIdentical('admin@local.host', $comment->getAuthorEmail());
$this->assertIdentical('This is a comment', $comment->comment_body->value);
$this->assertIdentical('filtered_html', $comment->comment_body->format);
$node = $comment->getCommentedEntity();
$this->assertTrue($node instanceof NodeInterface);
$this->assertIdentical('1', $node->id());
}
}

View file

@ -0,0 +1,62 @@
<?php
namespace Drupal\Tests\comment\Kernel\Migrate\d7;
use Drupal\comment\CommentTypeInterface;
use Drupal\comment\Entity\CommentType;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of comment types from Drupal 7.
*
* @group comment
*/
class MigrateCommentTypeTest extends MigrateDrupal7TestBase {
public static $modules = ['node', 'comment', 'text'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
]);
}
/**
* Asserts a comment type entity.
*
* @param string $id
* The entity ID.
* @param string $label
* The entity label.
*/
protected function assertEntity($id, $label) {
$entity = CommentType::load($id);
$this->assertTrue($entity instanceof CommentTypeInterface);
/** @var \Drupal\comment\CommentTypeInterface $entity */
$this->assertIdentical($label, $entity->label());
$this->assertIdentical('node', $entity->getTargetEntityTypeId());
}
/**
* Tests the migrated comment types.
*/
public function testMigration() {
$this->assertEntity('comment_node_page', 'Basic page comment');
$this->assertEntity('comment_node_article', 'Article comment');
$this->assertEntity('comment_node_blog', 'Blog entry comment');
$this->assertEntity('comment_node_book', 'Book page comment');
$this->assertEntity('comment_node_forum', 'Forum topic comment');
$this->assertEntity('comment_node_test_content_type', 'Test content type comment');
$migration = $this->getMigration('d7_comment_type');
// Validate that the source count and processed count match up.
$this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount());
}
}

View file

@ -0,0 +1,176 @@
<?php
namespace Drupal\Tests\comment\Kernel\Views;
use Drupal\comment\CommentInterface;
use Drupal\comment\CommentManagerInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\views\Views;
/**
* Tests the comment link field handlers.
*
* @group comment
*/
class CommentLinksTest extends CommentViewsKernelTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_comment'];
/**
* Test the comment approve link.
*/
public function testLinkApprove() {
// Create an unapproved comment.
$comment = $this->commentStorage->create([
'uid' => $this->adminUser->id(),
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
'status' => 0,
]);
$comment->save();
$view = Views::getView('test_comment');
$view->setDisplay();
$view->displayHandlers->get('default')->overrideOption('fields', [
'approve_comment' => [
'table' => 'comment',
'field' => 'approve_comment',
'id' => 'approve_comment',
'plugin_id' => 'comment_link_approve',
],
]);
$view->save();
/* @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
$account_switcher = \Drupal::service('account_switcher');
$account_switcher->switchTo($this->adminUser);
$view->preview();
// Check if I can see the comment approve link on an unapproved comment.
$approve_comment = $view->style_plugin->getField(0, 'approve_comment');
$options = ['query' => ['destination' => '/']];
$url = Url::fromRoute('comment.approve', ['comment' => $comment->id()], $options);
$this->assertEqual(\Drupal::l('Approve', $url), (string) $approve_comment, 'Found a comment approve link for an unapproved comment.');
// Approve the comment.
$comment->setPublished(CommentInterface::PUBLISHED);
$comment->save();
$view = Views::getView('test_comment');
$view->preview();
// Check if I can see the comment approve link on an approved comment.
$approve_comment = $view->style_plugin->getField(1, 'approve_comment');
$this->assertFalse((string) $approve_comment, "Didn't find a comment approve link for an already approved comment.");
// Check if I can see the comment approve link on an approved comment as an
// anonymous user.
$account_switcher->switchTo(new AnonymousUserSession());
// Set the comment as unpublished again.
$comment->setPublished(CommentInterface::NOT_PUBLISHED);
$comment->save();
$view = Views::getView('test_comment');
$view->preview();
$replyto_comment = $view->style_plugin->getField(0, 'approve_comment');
$this->assertFalse((string) $replyto_comment, "I can't approve the comment as an anonymous user.");
}
/**
* Test the comment reply link.
*/
public function testLinkReply() {
$this->enableModules(['field', 'entity_test']);
$this->installEntitySchema('entity_test');
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installConfig(['field']);
$field_storage_comment = FieldStorageConfig::create([
'field_name' => 'comment',
'type' => 'comment',
'entity_type' => 'entity_test',
]);
$field_storage_comment->save();
// Create a comment field which allows threading.
$field_comment = FieldConfig::create([
'field_name' => 'comment',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'settings' => [
'default_mode' => CommentManagerInterface::COMMENT_MODE_THREADED,
],
]);
$field_comment->save();
$host = EntityTest::create(['name' => $this->randomString()]);
$host->save();
// Attach an unapproved comment to the test entity.
$comment = $this->commentStorage->create([
'uid' => $this->adminUser->id(),
'entity_type' => 'entity_test',
'entity_id' => $host->id(),
'comment_type' => 'entity_test',
'field_name' => $field_storage_comment->getName(),
'status' => 0,
]);
$comment->save();
$view = Views::getView('test_comment');
$view->setDisplay();
$view->displayHandlers->get('default')->overrideOption('fields', [
'replyto_comment' => [
'table' => 'comment',
'field' => 'replyto_comment',
'id' => 'replyto_comment',
'plugin_id' => 'comment_link_reply',
'entity_type' => 'comment',
],
]);
$view->save();
/* @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
$account_switcher = \Drupal::service('account_switcher');
$account_switcher->switchTo($this->adminUser);
$view->preview();
// Check if I can see the reply link on an unapproved comment.
$replyto_comment = $view->style_plugin->getField(0, 'replyto_comment');
$this->assertFalse((string) $replyto_comment, "I can't reply to an unapproved comment.");
// Approve the comment.
$comment->setPublished(CommentInterface::PUBLISHED);
$comment->save();
$view = Views::getView('test_comment');
$view->preview();
// Check if I can see the reply link on an approved comment.
$replyto_comment = $view->style_plugin->getField(0, 'replyto_comment');
$url = Url::fromRoute('comment.reply', [
'entity_type' => 'entity_test',
'entity' => $host->id(),
'field_name' => 'comment',
'pid' => $comment->id(),
]);
$this->assertEqual(\Drupal::l('Reply', $url), (string) $replyto_comment, 'Found the comment reply link as an admin user.');
// Check if I can see the reply link as an anonymous user.
$account_switcher->switchTo(new AnonymousUserSession());
$view = Views::getView('test_comment');
$view->preview();
$replyto_comment = $view->style_plugin->getField(0, 'replyto_comment');
$this->assertFalse((string) $replyto_comment, "Didn't find the comment reply link as an anonymous user.");
}
}

View file

@ -0,0 +1,166 @@
<?php
namespace Drupal\Tests\comment\Kernel\Views;
use Drupal\comment\Entity\Comment;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
use Drupal\views\Entity\View;
use Drupal\views\Views;
/**
* Tests comment user name field
*
* @group comment
*/
class CommentUserNameTest extends ViewsKernelTestBase {
/**
* Admin user.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
public static $modules = ['user', 'comment', 'entity_test'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('user');
$this->installEntitySchema('comment');
// Create the anonymous role.
$this->installConfig(['user']);
// Create an anonymous user.
$storage = \Drupal::entityManager()->getStorage('user');
// Insert a row for the anonymous user.
$storage
->create(array(
'uid' => 0,
'name' => '',
'status' => 0,
))
->save();
$admin_role = Role::create([
'id' => 'admin',
'permissions' => ['administer comments', 'access user profiles'],
]);
$admin_role->save();
/* @var \Drupal\user\RoleInterface $anonymous_role */
$anonymous_role = Role::load(Role::ANONYMOUS_ID);
$anonymous_role->grantPermission('access comments');
$anonymous_role->save();
$this->adminUser = User::create([
'name' => $this->randomMachineName(),
'roles' => [$admin_role->id()],
]);
$this->adminUser->save();
// Create some comments.
$comment = Comment::create([
'subject' => 'My comment title',
'uid' => $this->adminUser->id(),
'name' => $this->adminUser->label(),
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
'status' => 1,
]);
$comment->save();
$comment_anonymous = Comment::create([
'subject' => 'Anonymous comment title',
'uid' => 0,
'name' => 'barry',
'mail' => 'test@example.com',
'homepage' => 'https://example.com',
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
'created' => 123456,
'status' => 1,
]);
$comment_anonymous->save();
}
/**
* Test the username formatter.
*/
public function testUsername() {
$view_id = $this->randomMachineName();
$view = View::create([
'id' => $view_id,
'base_table' => 'comment_field_data',
'display' => [
'default' => [
'display_plugin' => 'default',
'id' => 'default',
'display_options' => [
'fields' => [
'name' => [
'table' => 'comment_field_data',
'field' => 'name',
'id' => 'name',
'plugin_id' => 'field',
'type' => 'comment_username'
],
'subject' => [
'table' => 'comment_field_data',
'field' => 'subject',
'id' => 'subject',
'plugin_id' => 'field',
'type' => 'string',
'settings' => [
'link_to_entity' => TRUE,
],
],
],
],
],
],
]);
$view->save();
/* @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
$account_switcher = \Drupal::service('account_switcher');
/* @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$account_switcher->switchTo($this->adminUser);
$executable = Views::getView($view_id);
$build = $executable->preview();
$this->setRawContent($renderer->renderRoot($build));
$this->verbose($this->getRawContent());
$this->assertLink('My comment title');
$this->assertLink('Anonymous comment title');
$this->assertLink($this->adminUser->label());
$this->assertLink('barry (not verified)');
$account_switcher->switchTo(new AnonymousUserSession());
$executable = Views::getView($view_id);
$executable->storage->invalidateCaches();
$build = $executable->preview();
$this->setRawContent($renderer->renderRoot($build));
// No access to user-profiles, so shouldn't be able to see links.
$this->assertNoLink($this->adminUser->label());
// Note: External users aren't pointing to drupal user profiles.
$this->assertLink('barry (not verified)');
$this->verbose($this->getRawContent());
$this->assertLink('My comment title');
$this->assertLink('Anonymous comment title');
}
}

View file

@ -0,0 +1,76 @@
<?php
namespace Drupal\Tests\comment\Kernel\Views;
use Drupal\comment\Entity\Comment;
use Drupal\user\Entity\User;
use Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase;
/**
* Tests base field access in Views for the comment entity.
*
* @group comment
*/
class CommentViewsFieldAccessTest extends FieldFieldAccessTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'entity_test'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('comment');
}
/**
* Check access for comment fields.
*/
public function testCommentFields() {
$user = User::create([
'name' => 'test user',
]);
$user->save();
$comment = Comment::create([
'subject' => 'My comment title',
'uid' => $user->id(),
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
]);
$comment->save();
$comment_anonymous = Comment::create([
'subject' => 'Anonymous comment title',
'uid' => 0,
'name' => 'anonymous',
'mail' => 'test@example.com',
'homepage' => 'https://example.com',
'entity_type' => 'entity_test',
'comment_type' => 'entity_test',
'created' => 123456,
'status' => 1,
]);
$comment_anonymous->save();
// @todo Expand the test coverage in https://www.drupal.org/node/2464635
$this->assertFieldAccess('comment', 'cid', $comment->id());
$this->assertFieldAccess('comment', 'cid', $comment_anonymous->id());
$this->assertFieldAccess('comment', 'uuid', $comment->uuid());
$this->assertFieldAccess('comment', 'subject', 'My comment title');
$this->assertFieldAccess('comment', 'subject', 'Anonymous comment title');
$this->assertFieldAccess('comment', 'name', 'anonymous');
$this->assertFieldAccess('comment', 'mail', 'test@example.com');
$this->assertFieldAccess('comment', 'homepage', 'https://example.com');
$this->assertFieldAccess('comment', 'uid', $user->getUsername());
// $this->assertFieldAccess('comment', 'created', \Drupal::service('date.formatter')->format(123456));
// $this->assertFieldAccess('comment', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));
$this->assertFieldAccess('comment', 'status', 'On');
}
}

View file

@ -0,0 +1,78 @@
<?php
namespace Drupal\Tests\comment\Kernel\Views;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\views\Tests\ViewTestData;
/**
* Provides a common test base for comment views tests.
*/
abstract class CommentViewsKernelTestBase extends ViewsKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['comment_test_views', 'user', 'comment'];
/**
* Admin user.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* The entity storage for comments.
*
* @var \Drupal\comment\CommentStorageInterface
*/
protected $commentStorage;
/**
* The entity storage for users.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['comment_test_views']);
$this->installEntitySchema('user');
$this->installEntitySchema('comment');
$this->installConfig(['user']);
$entity_manager = $this->container->get('entity.manager');
$this->commentStorage = $entity_manager->getStorage('comment');
$this->userStorage = $entity_manager->getStorage('user');
// Insert a row for the anonymous user.
$this->userStorage
->create([
'uid' => 0,
'name' => '',
'status' => 0,
])
->save();
$admin_role = Role::create(['id' => 'admin']);
$admin_role->grantPermission('administer comments');
$admin_role->save();
/* @var \Drupal\user\RoleInterface $anonymous_role */
$anonymous_role = Role::load(Role::ANONYMOUS_ID);
$anonymous_role->grantPermission('access comments');
$anonymous_role->save();
$this->adminUser = $this->userStorage->create(['name' => $this->randomMachineName()]);
$this->adminUser->addRole('admin');
$this->adminUser->save();
}
}

View file

@ -0,0 +1,328 @@
<?php
namespace Drupal\Tests\comment\Unit;
use Drupal\comment\CommentLinkBuilder;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\simpletest\TestBase;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\comment\CommentLinkBuilder
* @group comment
*/
class CommentLinkBuilderTest extends UnitTestCase {
/**
* Comment manager mock.
*
* @var \Drupal\comment\CommentManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $commentManager;
/**
* String translation mock.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $stringTranslation;
/**
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Module handler mock.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $moduleHandler;
/**
* Current user proxy mock.
*
* @var \Drupal\Core\Session\AccountProxyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currentUser;
/**
* Timestamp used in test.
*
* @var int
*/
protected $timestamp;
/**
* @var \Drupal\comment\CommentLinkBuilderInterface;
*/
protected $commentLinkBuilder;
/**
* Prepares mocks for the test.
*/
protected function setUp() {
$this->commentManager = $this->getMock('\Drupal\comment\CommentManagerInterface');
$this->stringTranslation = $this->getStringTranslationStub();
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
$this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface');
$this->currentUser = $this->getMock('\Drupal\Core\Session\AccountProxyInterface');
$this->commentLinkBuilder = new CommentLinkBuilder($this->currentUser, $this->commentManager, $this->moduleHandler, $this->stringTranslation, $this->entityManager);
$this->commentManager->expects($this->any())
->method('getFields')
->with('node')
->willReturn(array(
'comment' => array(),
));
$this->commentManager->expects($this->any())
->method('forbiddenMessage')
->willReturn("Can't let you do that Dave.");
$this->stringTranslation->expects($this->any())
->method('formatPlural')
->willReturnArgument(1);
}
/**
* Test the buildCommentedEntityLinks method.
*
* @param \Drupal\node\NodeInterface|\PHPUnit_Framework_MockObject_MockObject $node
* Mock node.
* @param array $context
* Context for the links.
* @param bool $has_access_comments
* TRUE if the user has 'access comments' permission.
* @param bool $history_exists
* TRUE if the history module exists.
* @param bool $has_post_comments
* TRUE if the use has 'post comments' permission.
* @param bool $is_anonymous
* TRUE if the user is anonymous.
* @param array $expected
* Array of expected links keyed by link ID. Can be either string (link
* title) or array of link properties.
*
* @dataProvider getLinkCombinations
*
* @covers ::buildCommentedEntityLinks
*/
public function testCommentLinkBuilder(NodeInterface $node, $context, $has_access_comments, $history_exists, $has_post_comments, $is_anonymous, $expected) {
$this->moduleHandler->expects($this->any())
->method('moduleExists')
->with('history')
->willReturn($history_exists);
$this->currentUser->expects($this->any())
->method('hasPermission')
->willReturnMap(array(
array('access comments', $has_access_comments),
array('post comments', $has_post_comments),
));
$this->currentUser->expects($this->any())
->method('isAuthenticated')
->willReturn(!$is_anonymous);
$this->currentUser->expects($this->any())
->method('isAnonymous')
->willReturn($is_anonymous);
$links = $this->commentLinkBuilder->buildCommentedEntityLinks($node, $context);
if (!empty($expected)) {
if (!empty($links)) {
foreach ($expected as $link => $detail) {
if (is_array($detail)) {
// Array of link attributes.
foreach ($detail as $key => $value) {
$this->assertEquals($value, $links['comment__comment']['#links'][$link][$key]);
}
}
else {
// Just the title.
$this->assertEquals($detail, $links['comment__comment']['#links'][$link]['title']);
}
}
}
else {
$this->fail('Expected links but found none.');
}
}
else {
$this->assertSame($links, $expected);
}
}
/**
* Data provider for ::testCommentLinkBuilder.
*/
public function getLinkCombinations() {
$cases = array();
// No links should be created if the entity doesn't have the field.
$cases[] = array(
$this->getMockNode(FALSE, CommentItemInterface::OPEN, CommentItemInterface::FORM_BELOW, 1),
array('view_mode' => 'teaser'),
TRUE,
TRUE,
TRUE,
TRUE,
array(),
);
foreach (array('search_result', 'search_index', 'print') as $view_mode) {
// Nothing should be output in these view modes.
$cases[] = array(
$this->getMockNode(TRUE, CommentItemInterface::OPEN, CommentItemInterface::FORM_BELOW, 1),
array('view_mode' => $view_mode),
TRUE,
TRUE,
TRUE,
TRUE,
array(),
);
}
// All other combinations.
$combinations = array(
'is_anonymous' => array(FALSE, TRUE),
'comment_count' => array(0, 1),
'has_access_comments' => array(0, 1),
'history_exists' => array(FALSE, TRUE),
'has_post_comments' => array(0, 1),
'form_location' => array(CommentItemInterface::FORM_BELOW, CommentItemInterface::FORM_SEPARATE_PAGE),
'comments' => array(
CommentItemInterface::OPEN,
CommentItemInterface::CLOSED,
CommentItemInterface::HIDDEN,
),
'view_mode' => array(
'teaser', 'rss', 'full',
),
);
$permutations = TestBase::generatePermutations($combinations);
foreach ($permutations as $combination) {
$case = array(
$this->getMockNode(TRUE, $combination['comments'], $combination['form_location'], $combination['comment_count']),
array('view_mode' => $combination['view_mode']),
$combination['has_access_comments'],
$combination['history_exists'],
$combination['has_post_comments'],
$combination['is_anonymous'],
);
$expected = array();
// When comments are enabled in teaser mode, and comments exist, and the
// user has access - we can output the comment count.
if ($combination['comments'] && $combination['view_mode'] == 'teaser' && $combination['comment_count'] && $combination['has_access_comments']) {
$expected['comment-comments'] = '1 comment';
// And if history module exists, we can show a 'new comments' link.
if ($combination['history_exists']) {
$expected['comment-new-comments'] = '';
}
}
// All view modes other than RSS.
if ($combination['view_mode'] != 'rss') {
// Where commenting is open.
if ($combination['comments'] == CommentItemInterface::OPEN) {
// And the user has post-comments permission.
if ($combination['has_post_comments']) {
// If the view mode is teaser, or the user can access comments and
// comments exist or the form is on a separate page.
if ($combination['view_mode'] == 'teaser' || ($combination['has_access_comments'] && $combination['comment_count']) || $combination['form_location'] == CommentItemInterface::FORM_SEPARATE_PAGE) {
// There should be a add comment link.
$expected['comment-add'] = array('title' => 'Add new comment');
if ($combination['form_location'] == CommentItemInterface::FORM_BELOW) {
// On the same page.
$expected['comment-add']['url'] = Url::fromRoute('node.view');
}
else {
// On a separate page.
$expected['comment-add']['url'] = Url::fromRoute('comment.reply', ['entity_type' => 'node', 'entity' => 1, 'field_name' => 'comment']);
}
}
}
elseif ($combination['is_anonymous']) {
// Anonymous users get the forbidden message if the can't post
// comments.
$expected['comment-forbidden'] = "Can't let you do that Dave.";
}
}
}
$case[] = $expected;
$cases[] = $case;
}
return $cases;
}
/**
* Builds a mock node based on given scenario.
*
* @param bool $has_field
* TRUE if the node has the 'comment' field.
* @param int $comment_status
* One of CommentItemInterface::OPEN|HIDDEN|CLOSED
* @param int $form_location
* One of CommentItemInterface::FORM_BELOW|FORM_SEPARATE_PAGE
* @param int $comment_count
* Number of comments against the field.
*
* @return \Drupal\node\NodeInterface|\PHPUnit_Framework_MockObject_MockObject
* Mock node for testing.
*/
protected function getMockNode($has_field, $comment_status, $form_location, $comment_count) {
$node = $this->getMock('\Drupal\node\NodeInterface');
$node->expects($this->once())
->method('hasField')
->willReturn($has_field);
if (empty($this->timestamp)) {
$this->timestamp = time();
}
$field_item = (object) array(
'status' => $comment_status,
'comment_count' => $comment_count,
'last_comment_timestamp' => $this->timestamp,
);
$node->expects($this->any())
->method('get')
->with('comment')
->willReturn($field_item);
$field_definition = $this->getMock('\Drupal\Core\Field\FieldDefinitionInterface');
$field_definition->expects($this->any())
->method('getSetting')
->with('form_location')
->willReturn($form_location);
$node->expects($this->any())
->method('getFieldDefinition')
->with('comment')
->willReturn($field_definition);
$node->expects($this->any())
->method('language')
->willReturn('und');
$node->expects($this->any())
->method('getEntityTypeId')
->willReturn('node');
$node->expects($this->any())
->method('id')
->willReturn(1);
$url = Url::fromRoute('node.view');
$node->expects($this->any())
->method('urlInfo')
->willReturn($url);
$node->expects($this->any())
->method('url')
->willReturn(array('route_name' => 'node.view'));
return $node;
}
}
namespace Drupal\comment;
if (!function_exists('history_read')) {
function history_read() {
return 0;
}
}

View file

@ -0,0 +1,59 @@
<?php
namespace Drupal\Tests\comment\Unit;
use Drupal\comment\CommentManager;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\comment\CommentManager
* @group comment
*/
class CommentManagerTest extends UnitTestCase {
/**
* Tests the getFields method.
*
* @covers ::getFields
*/
public function testGetFields() {
// Set up a content entity type.
$entity_type = $this->getMock('Drupal\Core\Entity\ContentEntityTypeInterface');
$entity_type->expects($this->any())
->method('getClass')
->will($this->returnValue('Node'));
$entity_type->expects($this->any())
->method('isSubclassOf')
->with('\Drupal\Core\Entity\FieldableEntityInterface')
->will($this->returnValue(TRUE));
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$entity_manager->expects($this->once())
->method('getFieldMapByFieldType')
->will($this->returnValue(array(
'node' => array(
'field_foobar' => array(
'type' => 'comment',
),
),
)));
$entity_manager->expects($this->any())
->method('getDefinition')
->will($this->returnValue($entity_type));
$comment_manager = new CommentManager(
$entity_manager,
$this->getMockBuilder('Drupal\Core\Entity\Query\QueryFactory')->disableOriginalConstructor()->getMock(),
$this->getMock('Drupal\Core\Config\ConfigFactoryInterface'),
$this->getMock('Drupal\Core\StringTranslation\TranslationInterface'),
$this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'),
$this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'),
$this->getMock('Drupal\Core\Session\AccountInterface')
);
$comment_fields = $comment_manager->getFields('node');
$this->assertArrayHasKey('field_foobar', $comment_fields);
}
}

View file

@ -0,0 +1,123 @@
<?php
namespace Drupal\Tests\comment\Unit;
use Drupal\comment\CommentStatistics;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\comment\CommentStatistics
* @group comment
*/
class CommentStatisticsUnitTest extends UnitTestCase {
/**
* Mock statement.
*
* @var \Drupal\Core\Database\Statement
*/
protected $statement;
/**
* Mock select interface.
*
* @var \Drupal\Core\Database\Query\SelectInterface
*/
protected $select;
/**
* Mock database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* CommentStatistics service under test.
*
* @var \Drupal\comment\CommentStatisticsInterface
*/
protected $commentStatistics;
/**
* Counts calls to fetchAssoc().
*
* @var int
*/
protected $calls_to_fetch;
/**
* Sets up required mocks and the CommentStatistics service under test.
*/
protected function setUp() {
$this->statement = $this->getMockBuilder('Drupal\Core\Database\Driver\sqlite\Statement')
->disableOriginalConstructor()
->getMock();
$this->statement->expects($this->any())
->method('fetchObject')
->will($this->returnCallback(array($this, 'fetchObjectCallback')));
$this->select = $this->getMockBuilder('Drupal\Core\Database\Query\Select')
->disableOriginalConstructor()
->getMock();
$this->select->expects($this->any())
->method('fields')
->will($this->returnSelf());
$this->select->expects($this->any())
->method('condition')
->will($this->returnSelf());
$this->select->expects($this->any())
->method('execute')
->will($this->returnValue($this->statement));
$this->database = $this->getMockBuilder('Drupal\Core\Database\Connection')
->disableOriginalConstructor()
->getMock();
$this->database->expects($this->once())
->method('select')
->will($this->returnValue($this->select));
$this->commentStatistics = new CommentStatistics($this->database, $this->getMock('Drupal\Core\Session\AccountInterface'), $this->getMock('Drupal\Core\Entity\EntityManagerInterface'), $this->getMock('Drupal\Core\State\StateInterface'));
}
/**
* Tests the read method.
*
* @see \Drupal\comment\CommentStatistics::read()
*
* @group Drupal
* @group Comment
*/
public function testRead() {
$this->calls_to_fetch = 0;
$results = $this->commentStatistics->read(array('1' => 'boo', '2' => 'foo'), 'snafoos');
$this->assertEquals($results, array('something', 'something-else'));
}
/**
* Return value callback for fetchObject() function on mocked object.
*
* @return bool|string
* 'Something' on first, 'something-else' on second and FALSE for the
* other calls to function.
*/
public function fetchObjectCallback() {
$this->calls_to_fetch++;
switch ($this->calls_to_fetch) {
case 1:
return 'something';
case 2:
return 'something-else';
default:
return FALSE;
}
}
}

View file

@ -0,0 +1,96 @@
<?php
namespace Drupal\Tests\comment\Unit\Entity;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Tests comment acquires and releases the right lock.
*
* @group comment
*/
class CommentLockTest extends UnitTestCase {
/**
* Test the lock behavior.
*/
public function testLocks() {
$container = new ContainerBuilder();
$container->set('module_handler', $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'));
$container->set('current_user', $this->getMock('Drupal\Core\Session\AccountInterface'));
$container->set('cache.test', $this->getMock('Drupal\Core\Cache\CacheBackendInterface'));
$container->set('comment.statistics', $this->getMock('Drupal\comment\CommentStatisticsInterface'));
$request_stack = new RequestStack();
$request_stack->push(Request::create('/'));
$container->set('request_stack', $request_stack);
$container->setParameter('cache_bins', array('cache.test' => 'test'));
$lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface');
$cid = 2;
$lock_name = "comment:$cid:.00/";
$lock->expects($this->at(0))
->method('acquire')
->with($lock_name, 30)
->will($this->returnValue(TRUE));
$lock->expects($this->at(1))
->method('release')
->with($lock_name);
$lock->expects($this->exactly(2))
->method($this->anything());
$container->set('lock', $lock);
$cache_tag_invalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidator');
$container->set('cache_tags.invalidator', $cache_tag_invalidator);
\Drupal::setContainer($container);
$methods = get_class_methods('Drupal\comment\Entity\Comment');
unset($methods[array_search('preSave', $methods)]);
unset($methods[array_search('postSave', $methods)]);
$methods[] = 'invalidateTagsOnSave';
$comment = $this->getMockBuilder('Drupal\comment\Entity\Comment')
->disableOriginalConstructor()
->setMethods($methods)
->getMock();
$comment->expects($this->once())
->method('isNew')
->will($this->returnValue(TRUE));
$comment->expects($this->once())
->method('hasParentComment')
->will($this->returnValue(TRUE));
$comment->expects($this->once())
->method('getParentComment')
->will($this->returnValue($comment));
$comment->expects($this->once())
->method('getCommentedEntityId')
->will($this->returnValue($cid));
$comment->expects($this->any())
->method('getThread')
->will($this->returnValue(''));
$parent_entity = $this->getMock('\Drupal\Core\Entity\ContentEntityInterface');
$parent_entity->expects($this->atLeastOnce())
->method('getCacheTagsToInvalidate')
->willReturn(['node:1']);
$comment->expects($this->once())
->method('getCommentedEntity')
->willReturn($parent_entity);
$entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$comment->expects($this->any())
->method('getEntityType')
->will($this->returnValue($entity_type));
$comment->expects($this->at(1))
->method('get')
->with('status')
->will($this->returnValue((object) array('value' => NULL)));
$storage = $this->getMock('Drupal\comment\CommentStorageInterface');
// preSave() should acquire the lock. (This is what's really being tested.)
$comment->preSave($storage);
// Release the acquired lock before exiting the test.
$comment->postSave($storage);
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
/**
* Tests the Drupal 6 comment source w/ high water handling.
*
* @group comment
*/
class CommentSourceWithHighWaterTest extends CommentTestBase {
const ORIGINAL_HIGH_WATER = 1382255613;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->migrationConfiguration['source']['high_water_property']['name'] = 'timestamp';
array_shift($this->expectedResults);
parent::setUp();
}
}

View file

@ -0,0 +1,12 @@
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
/**
* Tests D6 comment source plugin.
*
* @group comment
*/
class CommentTest extends CommentTestBase {
}

View file

@ -0,0 +1,80 @@
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Base class for comment source unit tests.
*/
abstract class CommentTestBase extends MigrateSqlSourceTestCase {
// The plugin system is not working during unit testing so the source plugin
// class needs to be manually specified.
const PLUGIN_CLASS = 'Drupal\comment\Plugin\migrate\source\d6\Comment';
// The fake Migration configuration entity.
protected $migrationConfiguration = array(
// The ID of the entity, can be any string.
'id' => 'test',
// This needs to be the identifier of the actual key: cid for comment, nid
// for node and so on.
'source' => array(
'plugin' => 'd6_comment',
),
);
// We need to set up the database contents; it's easier to do that below.
protected $expectedResults = array(
array(
'cid' => 1,
'pid' => 0,
'nid' => 2,
'uid' => 3,
'subject' => 'subject value 1',
'comment' => 'comment value 1',
'hostname' => 'hostname value 1',
'timestamp' => 1382255613,
'status' => 1,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat1',
'type' => 'story',
),
array(
'cid' => 2,
'pid' => 1,
'nid' => 3,
'uid' => 4,
'subject' => 'subject value 2',
'comment' => 'comment value 2',
'hostname' => 'hostname value 2',
'timestamp' => 1382255662,
'status' => 1,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as $k => $row) {
$this->databaseContents['comments'][$k] = $row;
$this->databaseContents['comments'][$k]['status'] = 1 - $this->databaseContents['comments'][$k]['status'];
}
// Add node table data.
$this->databaseContents['node'][] = array('nid' => 2, 'type' => 'story');
$this->databaseContents['node'][] = array('nid' => 3, 'type' => 'page');
parent::setUp();
}
}

View file

@ -0,0 +1,59 @@
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
use Drupal\comment\Plugin\migrate\source\d6\CommentVariablePerCommentType;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* @coversDefaultClass \Drupal\comment\Plugin\migrate\source\d6\CommentVariablePerCommentType
* @group comment
*/
class CommentVariablePerCommentTypeTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = CommentVariablePerCommentType::class;
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd6_comment_variable_per_comment_type',
),
);
protected $expectedResults = array(
// Each result will also include a label and description, but those are
// static values set by the source plugin and don't need to be asserted.
array(
'comment_type' => 'comment',
),
array(
'comment_type' => 'comment_no_subject',
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['node_type'] = array(
array(
'type' => 'page',
),
array(
'type' => 'story',
),
);
$this->databaseContents['variable'] = array(
array(
'name' => 'comment_subject_field_page',
'value' => serialize(1),
),
array(
'name' => 'comment_subject_field_story',
'value' => serialize(0),
),
);
parent::setUp();
}
}

View file

@ -0,0 +1,89 @@
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
use Drupal\comment\Plugin\migrate\source\d6\CommentVariable;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* @coversDefaultClass \Drupal\comment\Plugin\migrate\source\d6\CommentVariable
* @group comment
*/
class CommentVariableTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = CommentVariable::class;
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd6_comment_variable',
),
);
protected $expectedResults = array(
array(
'comment' => '1',
'comment_default_mode' => '1',
'comment_default_order' => '1',
'comment_default_per_page' => '50',
'comment_controls' => '1',
'comment_anonymous' => '1',
'comment_subject_field' => '1',
'comment_preview' => '1',
'comment_form_location' => '1',
'node_type' => 'page',
'comment_type' => 'comment',
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['node_type'] = array(
array(
'type' => 'page',
),
);
$this->databaseContents['variable'] = array(
array(
'name' => 'comment_page',
'value' => serialize(1),
),
array(
'name' => 'comment_default_mode_page',
'value' => serialize(1),
),
array(
'name' => 'comment_default_order_page',
'value' => serialize(1),
),
array(
'name' => 'comment_default_per_page_page',
'value' => serialize(50),
),
array(
'name' => 'comment_controls_page',
'value' => serialize(1),
),
array(
'name' => 'comment_anonymous_page',
'value' => serialize(1),
),
array(
'name' => 'comment_subject_field_page',
'value' => serialize(1),
),
array(
'name' => 'comment_preview_page',
'value' => serialize(1),
),
array(
'name' => 'comment_form_location_page',
'value' => serialize(1),
),
);
parent::setUp();
}
}

View file

@ -0,0 +1,100 @@
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D7 comment source plugin.
*
* @group comment
*/
class CommentTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\comment\Plugin\migrate\source\d7\Comment';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd7_comment',
),
);
protected $expectedResults = array(
array(
'cid' => '1',
'pid' => '0',
'nid' => '1',
'uid' => '1',
'subject' => 'A comment',
'hostname' => '::1',
'created' => '1421727536',
'changed' => '1421727536',
'status' => '1',
'thread' => '01/',
'name' => 'admin',
'mail' => '',
'homepage' => '',
'language' => 'und',
'comment_body' => array(
array(
'value' => 'This is a comment',
'format' => 'filtered_html',
),
),
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['comment'] = $this->expectedResults;
unset($this->databaseContents['comment'][0]['comment_body']);
$this->databaseContents['node'] = array(
array(
'nid' => '1',
'vid' => '1',
'type' => 'test_content_type',
'language' => 'en',
'title' => 'A Node',
'uid' => '1',
'status' => '1',
'created' => '1421727515',
'changed' => '1421727515',
'comment' => '2',
'promote' => '1',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
),
);
$this->databaseContents['field_config_instance'] = array(
array(
'id' => '14',
'field_id' => '1',
'field_name' => 'comment_body',
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'data' => 'a:0:{}',
'deleted' => '0',
),
);
$this->databaseContents['field_data_comment_body'] = array(
array(
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'delta' => '0',
'comment_body_value' => 'This is a comment',
'comment_body_format' => 'filtered_html',
),
);
parent::setUp();
}
}

View file

@ -0,0 +1,98 @@
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D7 comment type source plugin.
*
* @group comment
*/
class CommentTypeTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\comment\Plugin\migrate\source\d7\CommentType';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd7_comment_type',
),
);
protected $expectedResults = array(
array(
'bundle' => 'comment_node_article',
'node_type' => 'article',
'default_mode' => '1',
'per_page' => '50',
'anonymous' => '0',
'form_location' => '1',
'preview' => '0',
'subject' => '1',
'label' => 'Article comment',
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['node_type'] = array(
array(
'type' => 'article',
'name' => 'Article',
'base' => 'node_content',
'module' => 'node',
'description' => 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.',
'help' => 'Help text for articles',
'has_title' => '1',
'title_label' => 'Title',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'disabled' => '0',
'orig_type' => 'article',
),
);
$this->databaseContents['field_config_instance'] = array(
array(
'id' => '14',
'field_id' => '1',
'field_name' => 'comment_body',
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'data' => 'a:0:{}',
'deleted' => '0',
),
);
$this->databaseContents['variable'] = array(
array(
'name' => 'comment_default_mode_article',
'value' => serialize(1),
),
array(
'name' => 'comment_per_page_article',
'value' => serialize(50),
),
array(
'name' => 'comment_anonymous_article',
'value' => serialize(0),
),
array(
'name' => 'comment_form_location_article',
'value' => serialize(1),
),
array(
'name' => 'comment_preview_article',
'value' => serialize(0),
),
array(
'name' => 'comment_subject_article',
'value' => serialize(1),
),
);
parent::setUp();
}
}