Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 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,16 @@
<?php
/**
* @file
* Dummy module emptying comment titles to test for appropriate and accessible
* markup in edge case scenarios where comments have empty titles.
*/
use Drupal\comment\CommentInterface;
/**
* 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,25 @@
<?php
/**
* @file
* Contains \Drupal\comment_test\Controller\CommentTestController.
*/
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,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
cacheable: false

View file

@ -0,0 +1,400 @@
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
date_format: long
custom_date_format: ''
timezone: ''
plugin_id: date
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: 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: true
table: comment_field_data
field: status
id: status
expose:
operator: ''
group: 1
plugin_id: boolean
entity_type: comment
entity_field: status
status_node:
value: true
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,335 @@
<?php
/**
* @file
* Contains \Drupal\Tests\comment\Unit\CommentLinkBuilderTest.
*/
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 {
if (!function_exists('history_read')) {
function history_read() {
return 0;
}
}
}

View file

@ -0,0 +1,64 @@
<?php
/**
* @file
* Contains \Drupal\Tests\comment\Unit\CommentManagerTest.
*/
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,128 @@
<?php
/**
* @file
* Contains \Drupal\Tests\comment\Unit\CommentStatisticsUnitTest.
*/
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';
break;
case 2:
return 'something-else';
break;
default:
return FALSE;
break;
}
}
}

View file

@ -0,0 +1,89 @@
<?php
/**
* @file
* Contains \Drupal\Tests\comment\Unit\Entity\CommentLockTest.
*/
namespace Drupal\Tests\comment\Unit\Entity;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityType;
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);
\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(''));
$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);
}
}