Commit c7fd064c authored by alexpott's avatar alexpott
Browse files

Issue #2455131 by andypost, larowlan: Field comment_field_data.field_name...

Issue #2455131 by andypost, larowlan: Field comment_field_data.field_name should be using Field API formatter
parent 17d2e5cf
......@@ -158,23 +158,6 @@ public function getViewsData() {
unset($data['comment_field_data']['thread']['filter']);
unset($data['comment_field_data']['thread']['argument']);
$data['comment_field_data']['field_name'] = array(
'title' => t('Comment field name'),
'help' => t('The Field name from which the comment originated.'),
'field' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
);
$entities_types = \Drupal::entityManager()->getDefinitions();
// Provide a relationship for each entity type except comment.
......
<?php
/**
* @file
* Contains \Drupal\comment\Tests\Views\CommentFieldNameTest.
*/
namespace Drupal\comment\Tests\Views;
use Drupal\comment\Entity\Comment;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\user\RoleInterface;
use Drupal\views\Views;
/**
* Tests the comment field name field.
*
* @group comment
*/
class CommentFieldNameTest extends CommentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_comment_field_name'];
/**
* The second comment entity used by this test.
*
* @var \Drupal\comment\CommentInterface
*/
protected $customComment;
/**
* The comment field name used by this test.
*
* @var string
*/
protected $fieldName = 'comment_custom';
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->addDefaultCommentField('node', 'page', $this->fieldName);
$this->customComment = Comment::create([
'entity_id' => $this->nodeUserCommented->id(),
'entity_type' => 'node',
'field_name' => $this->fieldName,
]);
$this->customComment->save();
}
/**
* Test comment field name.
*/
public function testCommentFieldName() {
$view = Views::getView('test_comment_field_name');
$this->executeView($view);
$expected_result = [
[
'cid' => $this->comment->id(),
'field_name' => $this->comment->getFieldName(),
],
[
'cid' => $this->customComment->id(),
'field_name' => $this->customComment->getFieldName(),
],
];
$column_map = [
'cid' => 'cid',
'comment_field_data_field_name' => 'field_name',
];
$this->assertIdenticalResultset($view, $expected_result, $column_map);
// Test that no data can be rendered.
$this->assertIdentical(FALSE, isset($view->field['field_name']));
// Grant permission to properly check view access on render.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']);
$this->container->get('account_switcher')->switchTo(new AnonymousUserSession());
$view = Views::getView('test_comment_field_name');
$this->executeView($view);
// Test that data rendered.
$this->assertIdentical($this->comment->getFieldName(), $view->field['field_name']->advancedRender($view->result[0]));
$this->assertIdentical($this->customComment->getFieldName(), $view->field['field_name']->advancedRender($view->result[1]));
}
}
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: none
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: full
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ' previous'
next: 'next ›'
first: '« first'
last: 'last »'
quantity: 9
style:
type: default
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment