Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
|
@ -15,7 +15,7 @@
|
|||
attach: function (context) {
|
||||
var $context = $(context);
|
||||
$context.find('fieldset.comment-entity-settings-form').drupalSetSummary(function (context) {
|
||||
return Drupal.checkPlain($(context).find('.form-item-comment input:checked').next('label').text());
|
||||
return Drupal.checkPlain($(context).find('.js-form-item-comment input:checked').next('label').text());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -29,6 +29,8 @@ comment.admin_approval:
|
|||
class: Drupal\comment\Plugin\Menu\LocalTask\UnapprovedComments
|
||||
parent_id: comment.admin
|
||||
weight: 1
|
||||
cache_tags:
|
||||
- comment_list
|
||||
|
||||
# Default tab for comment type editing.
|
||||
entity.comment_type.edit_form:
|
||||
|
|
|
@ -16,7 +16,6 @@ use Drupal\comment\CommentManagerInterface;
|
|||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
@ -66,15 +65,19 @@ function comment_help($route_name, RouteMatchInterface $route_match) {
|
|||
switch ($route_name) {
|
||||
case 'help.page.comment':
|
||||
$output = '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the <a href="!comment">online documentation for the Comment module</a>.', array('!comment' => 'https://www.drupal.org/documentation/modules/comment')) . '</p>';
|
||||
$output .= '<p>' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the <a href=":comment">online documentation for the Comment module</a>.', array(':comment' => 'https://www.drupal.org/documentation/modules/comment')) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Enabling commenting and configuring defaults') . '</dt>';
|
||||
$output .= '<dd>' . t('Comment functionality can be enabled for any entity sub-type (for example, a <a href="!content-type">content type</a>). On the Manage fields page for each entity sub-type, you can enable commenting by adding a Comments field. The entity sub-types each have their own default comment settings configured as: <em>Open</em> to allow new comments, <em>Closed</em> to view existing comments, but prevent new comments, or <em>Hidden</em> to hide existing comments and prevent new comments. For background information about entities, see the <a href="!field">Field module help page</a>.', array('!content-type' => (\Drupal::moduleHandler()->moduleExists('node')) ? \Drupal::url('entity.node_type.collection') : '#', '!field' => \Drupal::url('help.page', array('name' => 'field')))) . '</dd>';
|
||||
$output .= '<dt>' . t('Enabling commenting') . '</dt>';
|
||||
$output .= '<dd>' . t('Comment functionality can be enabled for any entity sub-type (for example, a <a href=":content-type">content type</a>) by adding a <em>Comments</em> field on its <em>Manage fields page</em>. Adding or removing commenting for an entity through the user interface requires the <a href=":field_ui">Field UI</a> module to be enabled, even though the commenting functionality works without it. For more information on fields and entities, see the <a href=":field">Field module help page</a>.', array(':content-type' => (\Drupal::moduleHandler()->moduleExists('node')) ? \Drupal::url('entity.node_type.collection') : '#', ':field' => \Drupal::url('help.page', array('name' => 'field')), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#')) . '</dd>';
|
||||
$output .= '<dt>' . t('Configuring commenting settings') . '</dt>';
|
||||
$output .= '<dd>' . t('Commenting settings can be configured by editing the <em>Comments</em> field on the <em>Manage fields page</em> of an entity type if the <em>Field UI module</em> is enabled. Configuration includes the label of the comments field, the number of comments to be displayed, and whether they are shown in threaded list. Commenting can be be configured as: <em>Open</em> to allow new comments, <em>Closed</em> to view existing comments, but prevent new comments, or <em>Hidden</em> to hide existing comments and prevent new comments. Changing this configuration for an entity type will not change existing entity items.') . '</dd>';
|
||||
$output .= '<dt>' . t('Overriding default settings') . '</dt>';
|
||||
$output .= '<dd>' . t('When you create an entity item, you can override the default comment settings. Changing the entity sub-type defaults will not affect existing entity items, whether they used the default settings or had overrides.') . '</dd>';
|
||||
$output .= '<dd>' . t('Users with the appropriate permissions can override the default commenting settings of an entity type when they create an item of that type.') . '</dd>';
|
||||
$output .= '<dt>' . t('Adding comment types') . '</dt>';
|
||||
$output .= '<dd>' . t('Additional <em>comment types</em> can be created per entity sub-type and added on the <a href=":field">Comment types page</a>. If there are multiple comment types available you can select the appropriate one after adding a <em>Comments field</em>.', array(':field' => \Drupal::url('entity.comment_type.collection'))) . '</dd>';
|
||||
$output .= '<dt>' . t('Approving and managing comments') . '</dt>';
|
||||
$output .= '<dd>' . t('Comments from users who have the <em>Skip comment approval</em> permission are published immediately. All other comments are placed in the <a href="!comment-approval">Unapproved comments</a> queue, until a user who has permission to <em>Administer comments and comment settings</em> publishes or deletes them. Published comments can be bulk managed on the <a href="!admin-comment">Published comments</a> administration page. When a comment has no replies, it remains editable by its author, as long as the author has <em>Edit own comments</em> permission.', array('!comment-approval' => \Drupal::url('comment.admin_approval'), '!admin-comment' => \Drupal::url('comment.admin'))) . '</dd>';
|
||||
$output .= '<dd>' . t('Comments from users who have the <em>Skip comment approval</em> permission are published immediately. All other comments are placed in the <a href=":comment-approval">Unapproved comments</a> queue, until a user who has permission to <em>Administer comments and comment settings</em> publishes or deletes them. Published comments can be bulk managed on the <a href=":admin-comment">Published comments</a> administration page. When a comment has no replies, it remains editable by its author, as long as the author has <em>Edit own comments</em> permission.', array(':comment-approval' => \Drupal::url('comment.admin_approval'), ':admin-comment' => \Drupal::url('comment.admin'))) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
|
||||
|
@ -143,11 +146,9 @@ function comment_theme() {
|
|||
function comment_field_config_create(FieldConfigInterface $field) {
|
||||
if ($field->getType() == 'comment' && !$field->isSyncing()) {
|
||||
// Assign default values for the field.
|
||||
if (!isset($field->default_value)) {
|
||||
$field->setDefaultValue(array());
|
||||
}
|
||||
$field->default_value += array(array());
|
||||
$field->default_value[0] += array(
|
||||
$default_value = $field->getDefaultValueLiteral();
|
||||
$default_value += array(array());
|
||||
$default_value[0] += array(
|
||||
'status' => CommentItemInterface::OPEN,
|
||||
'cid' => 0,
|
||||
'last_comment_timestamp' => 0,
|
||||
|
@ -155,6 +156,7 @@ function comment_field_config_create(FieldConfigInterface $field) {
|
|||
'last_comment_uid' => 0,
|
||||
'comment_count' => 0,
|
||||
);
|
||||
$field->setDefaultValue($default_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,7 +215,7 @@ function comment_node_links_alter(array &$node_links, NodeInterface $node, array
|
|||
/**
|
||||
* Implements hook_entity_view().
|
||||
*/
|
||||
function comment_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode) {
|
||||
function comment_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
|
||||
if ($entity instanceof FieldableEntityInterface && $view_mode == 'rss' && $display->getComponent('links')) {
|
||||
/** @var \Drupal\comment\CommentManagerInterface $comment_manager */
|
||||
$comment_manager = \Drupal::service('comment.manager');
|
||||
|
@ -298,8 +300,9 @@ function comment_form_field_ui_field_storage_add_form_alter(&$form, FormStateInt
|
|||
$form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($route_match->getParameter('commented_entity_type'), $route_match->getParameter('field_name'));
|
||||
}
|
||||
if (!_comment_entity_uses_integer_id($form_state->get('entity_type_id'))) {
|
||||
$optgroup = (string) t('General');
|
||||
// You cannot use comment fields on entity types with non-integer IDs.
|
||||
unset($form['add']['new_storage_type']['#options'][t('General')]['comment']);
|
||||
unset($form['add']['new_storage_type']['#options'][$optgroup]['comment']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -423,7 +426,7 @@ function _comment_entity_uses_integer_id($entity_type_id) {
|
|||
/**
|
||||
* Implements hook_node_update_index().
|
||||
*/
|
||||
function comment_node_update_index(EntityInterface $node, $langcode) {
|
||||
function comment_node_update_index(EntityInterface $node) {
|
||||
$index_comments = &drupal_static(__FUNCTION__);
|
||||
|
||||
if ($index_comments === NULL) {
|
||||
|
@ -564,26 +567,6 @@ function comment_preview(CommentInterface $comment, FormStateInterface $form_sta
|
|||
$entity = $comment->getCommentedEntity();
|
||||
|
||||
if (!$form_state->getErrors()) {
|
||||
// Attach the user and time information.
|
||||
$author_name = $comment->getAuthorName();
|
||||
if (!empty($author_name)) {
|
||||
$account = user_load_by_name($author_name);
|
||||
}
|
||||
elseif (\Drupal::currentUser()->isAuthenticated() && empty($comment->is_anonymous)) {
|
||||
$account = \Drupal::currentUser();
|
||||
}
|
||||
|
||||
if (!empty($account) && $account->isAuthenticated()) {
|
||||
$comment->setOwner($account);
|
||||
$comment->setAuthorName(SafeMarkup::checkPlain($account->getUsername()));
|
||||
}
|
||||
elseif (empty($author_name)) {
|
||||
$comment->setAuthorName(\Drupal::config('user.settings')->get('anonymous'));
|
||||
}
|
||||
|
||||
$created_time = !is_null($comment->getCreatedTime()) ? $comment->getCreatedTime() : REQUEST_TIME;
|
||||
$comment->setCreatedTime($created_time);
|
||||
$comment->changed->value = REQUEST_TIME;
|
||||
$comment->in_preview = TRUE;
|
||||
$comment_build = comment_view($comment);
|
||||
$comment_build['#weight'] = -100;
|
||||
|
@ -713,8 +696,8 @@ function template_preprocess_comment(&$variables) {
|
|||
$permalink_uri_parent->setOption('attributes', $attributes);
|
||||
$variables['parent_title'] = \Drupal::l($comment_parent->getSubject(), $permalink_uri_parent);
|
||||
$variables['parent_permalink'] = \Drupal::l(t('Parent permalink'), $permalink_uri_parent);
|
||||
$variables['parent'] = t('In reply to !parent_title by !parent_username',
|
||||
array('!parent_username' => $variables['parent_author'], '!parent_title' => $variables['parent_title']));
|
||||
$variables['parent'] = t('In reply to @parent_title by @parent_username',
|
||||
array('@parent_username' => $variables['parent_author'], '@parent_title' => $variables['parent_title']));
|
||||
}
|
||||
else {
|
||||
$variables['parent_comment'] = '';
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
* Builds placeholder replacement tokens for comment-related data.
|
||||
*/
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\Datetime\Entity\DateFormat;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
|
||||
|
@ -119,8 +117,6 @@ function comment_tokens($type, $tokens, array $data, array $options, BubbleableM
|
|||
else {
|
||||
$langcode = NULL;
|
||||
}
|
||||
$sanitize = !empty($options['sanitize']);
|
||||
|
||||
$replacements = array();
|
||||
|
||||
if ($type == 'comment' && !empty($data['comment'])) {
|
||||
|
@ -136,7 +132,7 @@ function comment_tokens($type, $tokens, array $data, array $options, BubbleableM
|
|||
|
||||
// Poster identity information for comments.
|
||||
case 'hostname':
|
||||
$replacements[$original] = $sanitize ? Html::escape($comment->getHostname()) : $comment->getHostname();
|
||||
$replacements[$original] = $comment->getHostname();
|
||||
break;
|
||||
|
||||
case 'mail':
|
||||
|
@ -146,23 +142,25 @@ function comment_tokens($type, $tokens, array $data, array $options, BubbleableM
|
|||
if ($comment->getOwnerId()) {
|
||||
$bubbleable_metadata->addCacheableDependency($comment->getOwner());
|
||||
}
|
||||
$replacements[$original] = $sanitize ? Html::escape($mail) : $mail;
|
||||
$replacements[$original] = $mail;
|
||||
break;
|
||||
|
||||
case 'homepage':
|
||||
$replacements[$original] = $sanitize ? UrlHelper::filterBadProtocol($comment->getHomepage()) : $comment->getHomepage();
|
||||
$replacements[$original] = UrlHelper::stripDangerousProtocols($comment->getHomepage());
|
||||
break;
|
||||
|
||||
case 'title':
|
||||
$replacements[$original] = $sanitize ? Xss::filter($comment->getSubject()) : $comment->getSubject();
|
||||
$replacements[$original] = $comment->getSubject();
|
||||
break;
|
||||
|
||||
case 'body':
|
||||
$replacements[$original] = $sanitize ? $comment->comment_body->processed : $comment->comment_body->value;
|
||||
// "processed" returns a \Drupal\Component\Render\MarkupInterface via
|
||||
// check_markup().
|
||||
$replacements[$original] = $comment->comment_body->processed;
|
||||
break;
|
||||
|
||||
case 'langcode':
|
||||
$replacements[$original] = $sanitize ? Html::escape($comment->language()->getId()) : $comment->language()->getId();
|
||||
$replacements[$original] = $comment->language()->getId();
|
||||
break;
|
||||
|
||||
// Comment related URLs.
|
||||
|
@ -183,14 +181,14 @@ function comment_tokens($type, $tokens, array $data, array $options, BubbleableM
|
|||
if ($comment->getOwnerId()) {
|
||||
$bubbleable_metadata->addCacheableDependency($comment->getOwner());
|
||||
}
|
||||
$replacements[$original] = $sanitize ? Xss::filter($name) : $name;
|
||||
$replacements[$original] = $name;
|
||||
break;
|
||||
|
||||
case 'parent':
|
||||
if ($comment->hasParentComment()) {
|
||||
$parent = $comment->getParentComment();
|
||||
$bubbleable_metadata->addCacheableDependency($parent);
|
||||
$replacements[$original] = $sanitize ? Xss::filter($parent->getSubject()) : $parent->getSubject();
|
||||
$replacements[$original] = $parent->getSubject();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -210,7 +208,7 @@ function comment_tokens($type, $tokens, array $data, array $options, BubbleableM
|
|||
$entity = $comment->getCommentedEntity();
|
||||
$bubbleable_metadata->addCacheableDependency($entity);
|
||||
$title = $entity->label();
|
||||
$replacements[$original] = $sanitize ? Xss::filter($title) : $title;
|
||||
$replacements[$original] = $title;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
id: comment.full
|
||||
label: 'Full comment'
|
||||
langcode: en
|
||||
status: false
|
||||
cache: true
|
||||
targetEntityType: comment
|
||||
dependencies:
|
||||
module:
|
||||
- comment
|
||||
id: comment.full
|
||||
label: 'Full comment'
|
||||
targetEntityType: comment
|
||||
cache: true
|
||||
|
|
|
@ -15,3 +15,4 @@ cardinality: 1
|
|||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: true
|
||||
custom_storage: false
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
id: comment_publish_action
|
||||
label: 'Publish comment'
|
||||
status: true
|
||||
langcode: en
|
||||
type: comment
|
||||
plugin: comment_publish_action
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- comment
|
||||
id: comment_publish_action
|
||||
label: 'Publish comment'
|
||||
type: comment
|
||||
plugin: comment_publish_action
|
||||
configuration: { }
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
id: comment_save_action
|
||||
label: 'Save comment'
|
||||
status: true
|
||||
langcode: en
|
||||
type: comment
|
||||
plugin: comment_save_action
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- comment
|
||||
id: comment_save_action
|
||||
label: 'Save comment'
|
||||
type: comment
|
||||
plugin: comment_save_action
|
||||
configuration: { }
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
id: comment_unpublish_action
|
||||
label: 'Unpublish comment'
|
||||
status: true
|
||||
langcode: en
|
||||
type: comment
|
||||
plugin: comment_unpublish_action
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- comment
|
||||
id: comment_unpublish_action
|
||||
label: 'Unpublish comment'
|
||||
type: comment
|
||||
plugin: comment_unpublish_action
|
||||
configuration: { }
|
||||
|
|
|
@ -3,6 +3,7 @@ status: true
|
|||
dependencies:
|
||||
module:
|
||||
- comment
|
||||
- node
|
||||
- user
|
||||
id: comments_recent
|
||||
label: 'Recent comments'
|
||||
|
@ -235,6 +236,14 @@ display:
|
|||
content: 'No comments available.'
|
||||
tokenize: false
|
||||
plugin_id: text_custom
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- user.permissions
|
||||
max-age: -1
|
||||
tags: { }
|
||||
block_1:
|
||||
display_plugin: block
|
||||
id: block_1
|
||||
|
@ -245,3 +254,11 @@ display:
|
|||
block_category: 'Lists (Views)'
|
||||
allow:
|
||||
items_per_page: true
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- user.permissions
|
||||
max-age: -1
|
||||
tags: { }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d6_comment
|
||||
label: Drupal 6 comments
|
||||
label: Comments
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d6_comment_entity_display
|
||||
label: Drupal 6 comment display configuration
|
||||
label: Comment display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d6_comment_entity_form_display
|
||||
label: Drupal 6 comment field form display configuration
|
||||
label: Comment field form display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d6_comment_entity_form_display_subject
|
||||
label: Drupal 6 comment subject form display configuration
|
||||
label: Comment subject form display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d6_comment_field
|
||||
label: Drupal 6 comment field configuration
|
||||
label: Comment field configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d6_comment_field_instance
|
||||
label: Drupal 6 comment field instance configuration
|
||||
label: Comment field instance configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d6_comment_type
|
||||
label: Drupal 6 comment type
|
||||
label: Comment type
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d7_comment
|
||||
label: Drupal 7 comments
|
||||
label: Comments
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d7_comment_entity_display
|
||||
label: Drupal 7 comment display configuration
|
||||
label: Comment display configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d7_comment_entity_form_display
|
||||
label: Drupal 7 comment field form display configuration
|
||||
label: Comment field form display configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d7_comment_entity_form_display_subject
|
||||
label: Drupal 7 comment subject form display configuration
|
||||
label: Comment subject form display configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d7_comment_field
|
||||
label: Drupal 7 comment field configuration
|
||||
label: Comment field configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d7_comment_field_instance
|
||||
label: Drupal 7 comment field instance configuration
|
||||
label: Comment field instance configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
id: d7_comment_type
|
||||
label: Drupal 7 comment type
|
||||
label: Comment type
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
|
|
|
@ -24,7 +24,7 @@ class CommentAccessControlHandler extends EntityAccessControlHandler {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\comment\CommentInterface|\Drupal\user\EntityOwnerInterface $entity */
|
||||
|
||||
$comment_admin = $account->hasPermission('administer comments');
|
||||
|
@ -130,18 +130,14 @@ class CommentAccessControlHandler extends EntityAccessControlHandler {
|
|||
}
|
||||
|
||||
if ($operation == 'view') {
|
||||
$entity = $items ? $items->getEntity() : NULL;
|
||||
// Admins can view any fields except hostname, other users need both the
|
||||
// "access comments" permission and for the comment to be published. The
|
||||
// mail field is hidden from non-admins.
|
||||
$admin_access = AccessResult::allowedIf($account->hasPermission('administer comments') && $field_definition->getName() != 'hostname')
|
||||
->cachePerPermissions();
|
||||
$anonymous_access = AccessResult::allowedIf($account->hasPermission('access comments') && (!$entity || $entity->isPublished()) && !in_array($field_definition->getName(), array('mail', 'hostname'), TRUE))
|
||||
->cachePerPermissions();
|
||||
if ($entity) {
|
||||
$anonymous_access->cacheUntilEntityChanges($entity);
|
||||
// Nobody has access to the hostname.
|
||||
if ($field_definition->getName() == 'hostname') {
|
||||
return AccessResult::forbidden();
|
||||
}
|
||||
// The mail field is hidden from non-admins.
|
||||
if ($field_definition->getName() == 'mail') {
|
||||
return AccessResult::allowedIfHasPermission($account, 'administer comments');
|
||||
}
|
||||
return $admin_access->orIf($anonymous_access);
|
||||
}
|
||||
return parent::checkFieldAccess($operation, $field_definition, $account, $items);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class CommentBreadcrumbBuilder implements BreadcrumbBuilderInterface {
|
|||
*/
|
||||
public function build(RouteMatchInterface $route_match) {
|
||||
$breadcrumb = new Breadcrumb();
|
||||
$breadcrumb->setCacheContexts(['route']);
|
||||
$breadcrumb->addCacheContexts(['route']);
|
||||
$breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
|
||||
|
||||
$entity = $route_match->getParameter('entity');
|
||||
|
|
|
@ -121,8 +121,11 @@ class CommentForm extends ContentEntityForm {
|
|||
}
|
||||
|
||||
// Prepare default values for form elements.
|
||||
$author = '';
|
||||
if ($is_admin) {
|
||||
$author = $comment->getAuthorName();
|
||||
if (!$comment->getOwnerId()) {
|
||||
$author = $comment->getAuthorName();
|
||||
}
|
||||
$status = $comment->getStatus();
|
||||
if (empty($comment_preview)) {
|
||||
$form['#title'] = $this->t('Edit comment %title', array(
|
||||
|
@ -131,12 +134,6 @@ class CommentForm extends ContentEntityForm {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if ($this->currentUser->isAuthenticated()) {
|
||||
$author = $this->currentUser->getUsername();
|
||||
}
|
||||
else {
|
||||
$author = ($comment->getAuthorName() ? $comment->getAuthorName() : '');
|
||||
}
|
||||
$status = ($this->currentUser->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED);
|
||||
}
|
||||
|
||||
|
@ -145,35 +142,46 @@ class CommentForm extends ContentEntityForm {
|
|||
$date = !empty($comment->date) ? $comment->date : DrupalDateTime::createFromTimestamp($comment->getCreatedTime());
|
||||
}
|
||||
|
||||
// Add the author name field depending on the current user.
|
||||
// The uid field is only displayed when a user with the permission
|
||||
// 'administer comments' is editing an existing comment from an
|
||||
// authenticated user.
|
||||
$owner = $comment->getOwner();
|
||||
$form['author']['uid'] = [
|
||||
'#type' => 'entity_autocomplete',
|
||||
'#target_type' => 'user',
|
||||
'#default_value' => $owner->isAnonymous() ? NULL : $owner,
|
||||
// A comment can be made anonymous by leaving this field empty therefore
|
||||
// there is no need to list them in the autocomplete.
|
||||
'#selection_settings' => ['include_anonymous' => FALSE],
|
||||
'#title' => $this->t('Authored by'),
|
||||
'#description' => $this->t('Leave blank for %anonymous.', ['%anonymous' => $config->get('anonymous')]),
|
||||
'#access' => $is_admin,
|
||||
];
|
||||
|
||||
// The name field is displayed when an anonymous user is adding a comment or
|
||||
// when a user with the permission 'administer comments' is editing an
|
||||
// existing comment from an anonymous user.
|
||||
$form['author']['name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Your name'),
|
||||
'#title' => $is_admin ? $this->t('Name for @anonymous', ['@anonymous' => $config->get('anonymous')]) : $this->t('Your name'),
|
||||
'#default_value' => $author,
|
||||
'#required' => ($this->currentUser->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
|
||||
'#maxlength' => 60,
|
||||
'#access' => $this->currentUser->isAnonymous() || $is_admin,
|
||||
'#size' => 30,
|
||||
'#attributes'=> [
|
||||
'data-drupal-default-value' => $config->get('anonymous'),
|
||||
],
|
||||
);
|
||||
|
||||
if ($is_admin) {
|
||||
$form['author']['name']['#type'] = 'entity_autocomplete';
|
||||
$form['author']['name']['#target_type'] = 'user';
|
||||
$form['author']['name']['#selection_settings'] = ['include_anonymous' => FALSE];
|
||||
$form['author']['name']['#process_default_value'] = FALSE;
|
||||
// The user name is validated and processed in static::buildEntity() and
|
||||
// static::validate().
|
||||
$form['author']['name']['#element_validate'] = array();
|
||||
$form['author']['name']['#title'] = $this->t('Authored by');
|
||||
$form['author']['name']['#description'] = $this->t('Leave blank for %anonymous.', array('%anonymous' => $config->get('anonymous')));
|
||||
}
|
||||
elseif ($this->currentUser->isAuthenticated()) {
|
||||
$form['author']['name']['#type'] = 'item';
|
||||
$form['author']['name']['#value'] = $form['author']['name']['#default_value'];
|
||||
$form['author']['name']['#theme'] = 'username';
|
||||
$form['author']['name']['#account'] = $this->currentUser;
|
||||
$form['author']['name']['#cache']['contexts'][] = 'user';
|
||||
}
|
||||
elseif($this->currentUser->isAnonymous()) {
|
||||
$form['author']['name']['#attributes']['data-drupal-default-value'] = $config->get('anonymous');
|
||||
// When editing a comment only display the name textfield if the uid field
|
||||
// is empty.
|
||||
$form['author']['name']['#states'] = [
|
||||
'visible' => [
|
||||
':input[name="uid"]' => array('empty' => TRUE),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Add author email and homepage fields depending on the current user.
|
||||
|
@ -263,22 +271,27 @@ class CommentForm extends ContentEntityForm {
|
|||
else {
|
||||
$comment->setCreatedTime(REQUEST_TIME);
|
||||
}
|
||||
$author_name = $form_state->getValue('name');
|
||||
|
||||
if (!$this->currentUser->isAnonymous()) {
|
||||
// Assign the owner based on the given user name - none means anonymous.
|
||||
$accounts = $this->entityManager->getStorage('user')
|
||||
->loadByProperties(array('name' => $author_name));
|
||||
$account = reset($accounts);
|
||||
$uid = $account ? $account->id() : 0;
|
||||
$comment->setOwnerId($uid);
|
||||
// Empty author ID should revert to anonymous.
|
||||
$author_id = $form_state->getValue('uid');
|
||||
if ($comment->id() && $this->currentUser->hasPermission('administer comments')) {
|
||||
// Admin can leave the author ID blank to revert to anonymous.
|
||||
$author_id = $author_id ?: 0;
|
||||
}
|
||||
|
||||
// If the comment was posted by an anonymous user and no author name was
|
||||
// required, use "Anonymous" by default.
|
||||
if ($comment->getOwnerId() === 0 && (!isset($author_name) || $author_name === '')) {
|
||||
$comment->setAuthorName($this->config('user.settings')->get('anonymous'));
|
||||
if (!is_null($author_id)) {
|
||||
if ($author_id === 0 && $form['author']['name']['#access']) {
|
||||
// Use the author name value when the form has access to the element and
|
||||
// the author ID is anonymous.
|
||||
$comment->setAuthorName($form_state->getValue('name'));
|
||||
}
|
||||
else {
|
||||
// Ensure the author name is not set.
|
||||
$comment->setAuthorName(NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$author_id = $this->currentUser->id();
|
||||
}
|
||||
$comment->setOwnerId($author_id);
|
||||
|
||||
// Validate the comment's subject. If not specified, extract from comment
|
||||
// body.
|
||||
|
|
|
@ -175,15 +175,15 @@ class CommentManager implements CommentManagerInterface {
|
|||
|
||||
if ($this->userConfig->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
|
||||
// Users can register themselves.
|
||||
return $this->t('<a href="@login">Log in</a> or <a href="@register">register</a> to post comments', array(
|
||||
'@login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination)),
|
||||
'@register' => $this->urlGenerator->generateFromRoute('user.register', array(), array('query' => $destination)),
|
||||
return $this->t('<a href=":login">Log in</a> or <a href=":register">register</a> to post comments', array(
|
||||
':login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination)),
|
||||
':register' => $this->urlGenerator->generateFromRoute('user.register', array(), array('query' => $destination)),
|
||||
));
|
||||
}
|
||||
else {
|
||||
// Only admins can add new users, no public registration.
|
||||
return $this->t('<a href="@login">Log in</a> to post comments', array(
|
||||
'@login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination)),
|
||||
return $this->t('<a href=":login">Log in</a> to post comments', array(
|
||||
':login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,8 +62,8 @@ class CommentViewBuilder extends EntityViewBuilder {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) {
|
||||
$build = parent::getBuildDefaults($entity, $view_mode, $langcode);
|
||||
protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
|
||||
$build = parent::getBuildDefaults($entity, $view_mode);
|
||||
|
||||
/** @var \Drupal\comment\CommentInterface $entity */
|
||||
// Store a threading field setting to use later in self::buildComponents().
|
||||
|
@ -88,7 +88,7 @@ class CommentViewBuilder extends EntityViewBuilder {
|
|||
* @throws \InvalidArgumentException
|
||||
* Thrown when a comment is attached to an entity that no longer exists.
|
||||
*/
|
||||
public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) {
|
||||
public function buildComponents(array &$build, array $entities, array $displays, $view_mode) {
|
||||
/** @var \Drupal\comment\CommentInterface[] $entities */
|
||||
if (empty($entities)) {
|
||||
return;
|
||||
|
@ -101,7 +101,7 @@ class CommentViewBuilder extends EntityViewBuilder {
|
|||
}
|
||||
$this->entityManager->getStorage('user')->loadMultiple(array_unique($uids));
|
||||
|
||||
parent::buildComponents($build, $entities, $displays, $view_mode, $langcode);
|
||||
parent::buildComponents($build, $entities, $displays, $view_mode);
|
||||
|
||||
// A counter to track the indentation level.
|
||||
$current_indent = 0;
|
||||
|
@ -136,7 +136,7 @@ class CommentViewBuilder extends EntityViewBuilder {
|
|||
'#lazy_builder' => ['comment.lazy_builders:renderLinks', [
|
||||
$entity->id(),
|
||||
$view_mode,
|
||||
$langcode,
|
||||
$entity->language()->getId(),
|
||||
!empty($entity->in_preview),
|
||||
]],
|
||||
'#create_placeholder' => TRUE,
|
||||
|
@ -166,8 +166,8 @@ class CommentViewBuilder extends EntityViewBuilder {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function alterBuild(array &$build, EntityInterface $comment, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL) {
|
||||
parent::alterBuild($build, $comment, $display, $view_mode, $langcode);
|
||||
protected function alterBuild(array &$build, EntityInterface $comment, EntityViewDisplayInterface $display, $view_mode) {
|
||||
parent::alterBuild($build, $comment, $display, $view_mode);
|
||||
if (empty($comment->in_preview)) {
|
||||
$prefix = '';
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ class CommentController extends ControllerBase {
|
|||
$query = $page_number ? array('page' => $page_number) : NULL;
|
||||
$links[$nid] = array(
|
||||
'new_comment_count' => (int) $new,
|
||||
'first_new_comment_link' => $this->getUrlGenerator()->generateFromPath('node/' . $node->id(), array('query' => $query, 'fragment' => 'new')),
|
||||
'first_new_comment_link' => $this->getUrlGenerator()->generateFromRoute('entity.node.canonical', array('node' => $node->id()), array('query' => $query, 'fragment' => 'new')),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -527,13 +527,6 @@ class Comment extends ContentEntityBase implements CommentInterface {
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChangedTime() {
|
||||
return $this->get('changed')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Drupal\comment\Form;
|
|||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\CommentStorageInterface;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Datetime\DateFormatter;
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
|
@ -39,7 +39,7 @@ class CommentAdminOverview extends FormBase {
|
|||
/**
|
||||
* The date formatter service.
|
||||
*
|
||||
* @var \Drupal\Core\Datetime\DateFormatter
|
||||
* @var \Drupal\Core\Datetime\DateFormatterInterface
|
||||
*/
|
||||
protected $dateFormatter;
|
||||
|
||||
|
@ -57,12 +57,12 @@ class CommentAdminOverview extends FormBase {
|
|||
* The entity manager service.
|
||||
* @param \Drupal\comment\CommentStorageInterface $comment_storage
|
||||
* The comment storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatter $date_formatter
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, CommentStorageInterface $comment_storage, DateFormatter $date_formatter, ModuleHandlerInterface $module_handler) {
|
||||
public function __construct(EntityManagerInterface $entity_manager, CommentStorageInterface $comment_storage, DateFormatterInterface $date_formatter, ModuleHandlerInterface $module_handler) {
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->commentStorage = $comment_storage;
|
||||
$this->dateFormatter = $date_formatter;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace Drupal\comment\Plugin\EntityReferenceSelection;
|
||||
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase;
|
||||
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
|
||||
use Drupal\comment\CommentInterface;
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,7 @@ use Drupal\comment\CommentInterface;
|
|||
* weight = 1
|
||||
* )
|
||||
*/
|
||||
class CommentSelection extends SelectionBase {
|
||||
class CommentSelection extends DefaultSelection {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -28,7 +28,7 @@ class AuthorNameFormatter extends FormatterBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items) {
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$elements = array();
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
|
|
|
@ -137,7 +137,7 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items) {
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$elements = array();
|
||||
$output = array();
|
||||
|
||||
|
@ -189,17 +189,8 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP
|
|||
$field_name,
|
||||
$this->getFieldSetting('comment_type'),
|
||||
]],
|
||||
'#create_placeholder' => TRUE,
|
||||
];
|
||||
|
||||
// @todo Remove this in https://www.drupal.org/node/2543334. Until
|
||||
// then, \Drupal\Core\Render\Renderer::hasPoorCacheability() isn't
|
||||
// integrated with cache context bubbling, so this duplicates the
|
||||
// contexts added by \Drupal\comment\CommentForm::form().
|
||||
$output['comment_form']['#cache']['contexts'][] = 'user.permissions';
|
||||
$output['comment_form']['#cache']['contexts'][] = 'user.roles:authenticated';
|
||||
if ($this->currentUser->isAuthenticated()) {
|
||||
$output['comment_form']['#cache']['contexts'][] = 'user';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -156,6 +156,13 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
|
|||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function mainPropertyName() {
|
||||
return 'status';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -187,7 +194,7 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
|
|||
'#title' => t('Comment type'),
|
||||
'#options' => $options,
|
||||
'#required' => TRUE,
|
||||
'#description' => $this->t('Select the Comment type to use for this comment field. Manage the comment types from the <a href="@url">administration overview page</a>.', array('@url' => $this->url('entity.comment_type.collection'))),
|
||||
'#description' => $this->t('Select the Comment type to use for this comment field. Manage the comment types from the <a href=":url">administration overview page</a>.', array(':url' => $this->url('entity.comment_type.collection'))),
|
||||
'#default_value' => $this->getSetting('comment_type'),
|
||||
'#disabled' => $has_data,
|
||||
);
|
||||
|
|
|
@ -9,8 +9,10 @@ namespace Drupal\comment\Plugin\migrate\destination;
|
|||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\migrate\Row;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -29,6 +31,20 @@ class EntityComment extends EntityContentBase {
|
|||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The entity query object.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
/**
|
||||
* An array of entity IDs for the 'commented entity' keyed by entity type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $stubCommentedEntityIds;
|
||||
|
||||
/**
|
||||
* Builds an comment entity destination.
|
||||
*
|
||||
|
@ -48,10 +64,13 @@ class EntityComment extends EntityContentBase {
|
|||
* The entity manager service.
|
||||
* @param \Drupal\Core\State\StateInterface $state
|
||||
* The state storage object.
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
|
||||
* The query object that can query the given entity type.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, StateInterface $state) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, StateInterface $state, QueryFactory $entity_query) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager);
|
||||
$this->state = $state;
|
||||
$this->entityQuery = $entity_query;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,7 +86,8 @@ class EntityComment extends EntityContentBase {
|
|||
$container->get('entity.manager')->getStorage($entity_type),
|
||||
array_keys($container->get('entity.manager')->getBundleInfo($entity_type)),
|
||||
$container->get('entity.manager'),
|
||||
$container->get('state')
|
||||
$container->get('state'),
|
||||
$container->get('entity.query')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -85,4 +105,37 @@ class EntityComment extends EntityContentBase {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processStubRow(Row $row) {
|
||||
parent::processStubRow($row);
|
||||
$stub_commented_entity_type = $row->getDestinationProperty('entity_type');
|
||||
|
||||
// While parent::getEntity() fills the bundle property for stub entities
|
||||
// if it's still empty, here we must also make sure entity_id/entity_type
|
||||
// are filled (so $comment->getCommentedEntity() always returns a value).
|
||||
if (empty($this->stubCommentedEntityIds[$stub_commented_entity_type])) {
|
||||
// Fill stub entity id. Any id will do, as long as it exists.
|
||||
$entity_type = $this->entityManager->getDefinition($stub_commented_entity_type);
|
||||
$id_key = $entity_type->getKey('id');
|
||||
$result = $this->entityQuery
|
||||
->get($stub_commented_entity_type)
|
||||
->range(0, 1)
|
||||
->execute();
|
||||
if ($result) {
|
||||
$this->stubCommentedEntityIds[$stub_commented_entity_type] = array_pop($result);
|
||||
$row->setSourceProperty($id_key, $this->stubCommentedEntityIds[$stub_commented_entity_type]);
|
||||
}
|
||||
else {
|
||||
throw new MigrateException(t('Could not find parent entity to use for comment %id', ['%id' => implode(':', $row->getSourceIdValues())]), MigrationInterface::MESSAGE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
$row->setDestinationProperty('entity_id', $this->stubCommentedEntityIds[$stub_commented_entity_type]);
|
||||
$row->setDestinationProperty('entity_type', $stub_commented_entity_type);
|
||||
$row->setDestinationProperty('created', REQUEST_TIME);
|
||||
$row->setDestinationProperty('changed', REQUEST_TIME);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,14 +41,21 @@ class CommentVariable extends DrupalSqlBase {
|
|||
protected function getCommentVariables() {
|
||||
$comment_prefixes = array_keys($this->commentPrefixes());
|
||||
$variables = array();
|
||||
$node_types = $this->getDatabase()->query('SELECT type FROM {node_type}')->fetchCol();
|
||||
$node_types = $this->select('node_type', 'nt')
|
||||
->fields('nt', ['type'])
|
||||
->execute()
|
||||
->fetchCol();
|
||||
foreach ($node_types as $node_type) {
|
||||
foreach ($comment_prefixes as $prefix) {
|
||||
$variables[] = $prefix . '_' . $node_type;
|
||||
}
|
||||
}
|
||||
$return = array();
|
||||
$values = $this->getDatabase()->query('SELECT name, value FROM {variable} WHERE name IN ( :name[] )', array(':name[]' => $variables))->fetchAllKeyed();
|
||||
$values = $this->select('variable', 'v')
|
||||
->fields('v', ['name', 'value'])
|
||||
->condition('name', $variables, 'IN')
|
||||
->execute()
|
||||
->fetchAllKeyed();
|
||||
foreach ($node_types as $node_type) {
|
||||
foreach ($comment_prefixes as $prefix) {
|
||||
$name = $prefix . '_' . $node_type;
|
||||
|
|
|
@ -33,6 +33,7 @@ class CommentType extends DrupalSqlBase {
|
|||
*/
|
||||
public function query() {
|
||||
return $this->select('field_config_instance', 'fci')
|
||||
->distinct()
|
||||
->fields('fci', array('bundle'))
|
||||
->condition('entity_type', 'comment');
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Drupal\comment\Plugin\views\argument;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -65,7 +64,7 @@ class UserUid extends ArgumentPluginBase {
|
|||
return $this->t('No user');
|
||||
}
|
||||
|
||||
return SafeMarkup::checkPlain($title);
|
||||
return $title;
|
||||
}
|
||||
|
||||
protected function defaultActions($which = NULL) {
|
||||
|
|
|
@ -15,6 +15,13 @@ use Drupal\user\RoleInterface;
|
|||
* @group comment
|
||||
*/
|
||||
class CommentAdminTest extends CommentTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comment approval functionality through admin/content/comment.
|
||||
*/
|
||||
|
|
|
@ -40,6 +40,32 @@ class CommentAnonymousTest extends CommentTestBase {
|
|||
$this->setCommentAnonymous(COMMENT_ANONYMOUS_MAYNOT_CONTACT);
|
||||
$this->drupalLogout();
|
||||
|
||||
// Preview comments (with `skip comment approval` permission).
|
||||
$edit = [];
|
||||
$title = 'comment title with skip comment approval';
|
||||
$body = 'comment body with skip comment approval';
|
||||
$edit['subject[0][value]'] = $title;
|
||||
$edit['comment_body[0][value]'] = $body;
|
||||
$this->drupalPostForm($this->node->urlInfo(), $edit, t('Preview'));
|
||||
// Cannot use assertRaw here since both title and body are in the form.
|
||||
$preview = (string) $this->cssSelect('.preview')[0]->asXML();
|
||||
$this->assertTrue(strpos($preview, $title) !== FALSE, 'Anonymous user can preview comment title.');
|
||||
$this->assertTrue(strpos($preview, $body) !== FALSE, 'Anonymous user can preview comment body.');
|
||||
|
||||
// Preview comments (without `skip comment approval` permission).
|
||||
user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']);
|
||||
$edit = [];
|
||||
$title = 'comment title without skip comment approval';
|
||||
$body = 'comment body without skip comment approval';
|
||||
$edit['subject[0][value]'] = $title;
|
||||
$edit['comment_body[0][value]'] = $body;
|
||||
$this->drupalPostForm($this->node->urlInfo(), $edit, t('Preview'));
|
||||
// Cannot use assertRaw here since both title and body are in the form.
|
||||
$preview = (string) $this->cssSelect('.preview')[0]->asXML();
|
||||
$this->assertTrue(strpos($preview, $title) !== FALSE, 'Anonymous user can preview comment title.');
|
||||
$this->assertTrue(strpos($preview, $body) !== FALSE, 'Anonymous user can preview comment body.');
|
||||
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']);
|
||||
|
||||
// Post anonymous comment without contact info.
|
||||
$anonymous_comment1 = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
|
||||
$this->assertTrue($this->commentExists($anonymous_comment1), 'Anonymous comment without contact info found.');
|
||||
|
@ -101,6 +127,7 @@ class CommentAnonymousTest extends CommentTestBase {
|
|||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('comment/' . $anonymous_comment3->id() . '/edit');
|
||||
$this->assertRaw($author_name, "The anonymous user's name is correct when editing the comment.");
|
||||
$this->assertFieldByName('uid', '', 'The author field is empty (i.e. anonymous) when editing the comment.');
|
||||
$this->assertRaw($author_mail, "The anonymous user's email address is correct when editing the comment.");
|
||||
|
||||
// Unpublish comment.
|
||||
|
@ -167,4 +194,5 @@ class CommentAnonymousTest extends CommentTestBase {
|
|||
$this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $anonymous_comment2->id());
|
||||
$this->assertResponse(403);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ use Drupal\Core\Cache\Cache;
|
|||
use Drupal\Core\Session\UserSession;
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\system\Tests\Entity\EntityUnitTestBase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
|
||||
/**
|
||||
* Tests the bubbling up of comment cache tags when using the Comment list
|
||||
|
@ -35,6 +38,16 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$session = new Session();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->setSession($session);
|
||||
|
||||
/** @var 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.
|
||||
|
@ -127,6 +140,24 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
|
|||
];
|
||||
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');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -213,17 +213,16 @@ class CommentFieldAccessTest extends EntityUnitTestBase {
|
|||
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, $set['user']->hasPermission('administer comments') || ($set['comment']->isPublished() && $set['user']->hasPermission('access comments')), SafeMarkup::format('User @user !state view field !field on comment @comment', [
|
||||
$this->assertTrue($may_view, SafeMarkup::format('User @user can view field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'!state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'!field' => $field,
|
||||
'@field' => $field,
|
||||
]));
|
||||
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments'), SafeMarkup::format('User @user !state update field !field on comment @comment', [
|
||||
$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',
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'!field' => $field,
|
||||
'@field' => $field,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
@ -231,9 +230,9 @@ class CommentFieldAccessTest extends EntityUnitTestBase {
|
|||
// 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', [
|
||||
$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',
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
]));
|
||||
}
|
||||
|
@ -244,18 +243,26 @@ class CommentFieldAccessTest extends EntityUnitTestBase {
|
|||
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, $field != 'hostname' && ($set['user']->hasPermission('administer comments') ||
|
||||
($set['comment']->isPublished() && $set['user']->hasPermission('access comments'))), SafeMarkup::format('User @user !state view field !field on comment @comment', [
|
||||
// Nobody has access to 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(),
|
||||
'!state' => $may_view ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'!field' => $field,
|
||||
'@field' => $field,
|
||||
'@state' => $state,
|
||||
]));
|
||||
$this->assertFalse($may_update, SafeMarkup::format('User @user !state update field !field on comment @comment', [
|
||||
$this->assertFalse($may_update, SafeMarkup::format('User @user @state update field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'!state' => $may_update ? 'can' : 'cannot',
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'!field' => $field,
|
||||
'@field' => $field,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
@ -266,18 +273,16 @@ class CommentFieldAccessTest extends EntityUnitTestBase {
|
|||
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, $field != 'hostname' && ($set['user']->hasPermission('administer comments') ||
|
||||
($set['comment']->isPublished() && $set['user']->hasPermission('access comments'))), SafeMarkup::format('User @user !state view field !field on comment @comment', [
|
||||
$this->assertEqual($may_view, TRUE, SafeMarkup::format('User @user can view field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'!state' => $may_view ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'!field' => $field,
|
||||
'@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', [
|
||||
$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',
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'!field' => $field,
|
||||
'@field' => $field,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
@ -295,11 +300,11 @@ class CommentFieldAccessTest extends EntityUnitTestBase {
|
|||
$set['comment']->isNew() &&
|
||||
$set['user']->hasPermission('post comments') &&
|
||||
$set['comment']->getFieldName() == 'comment_other'
|
||||
), SafeMarkup::format('User @user !state update field !field on comment @comment', [
|
||||
), SafeMarkup::format('User @user @state update field @field on comment @comment', [
|
||||
'@user' => $set['user']->getUsername(),
|
||||
'!state' => $may_update ? 'can' : 'cannot',
|
||||
'@state' => $may_update ? 'can' : 'cannot',
|
||||
'@comment' => $set['comment']->getSubject(),
|
||||
'!field' => $field,
|
||||
'@field' => $field,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ class CommentFieldsTest extends CommentTestBase {
|
|||
|
||||
// Test adding a field that defaults to CommentItemInterface::CLOSED.
|
||||
$this->addDefaultCommentField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies');
|
||||
$field = FieldConfig::load('node.test_node_type.who_likes_ponies');
|
||||
$this->assertEqual($field->default_value[0]['status'], CommentItemInterface::CLOSED);
|
||||
$field = FieldConfig::load('node.test_node_type.who_likes_ponies');;
|
||||
$this->assertEqual($field->getDefaultValueLiteral()[0]['status'], CommentItemInterface::CLOSED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,12 @@ class CommentInterfaceTest extends CommentTestBase {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// Make sure that comment field title is not displayed when there's no
|
||||
// comments posted.
|
||||
$this->drupalGet($this->node->urlInfo());
|
||||
$this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments title is not displayed.');
|
||||
|
||||
// Set comments to have subject and preview disabled.
|
||||
$this->setCommentPreview(DRUPAL_DISABLED);
|
||||
$this->setCommentForm(TRUE);
|
||||
$this->setCommentSubject(FALSE);
|
||||
|
@ -44,6 +50,10 @@ class CommentInterfaceTest extends CommentTestBase {
|
|||
$comment = $this->postComment($this->node, $comment_text);
|
||||
$this->assertTrue($this->commentExists($comment), 'Comment found.');
|
||||
|
||||
// Test the comment field title is displayed when there's comments.
|
||||
$this->drupalGet($this->node->urlInfo());
|
||||
$this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments title is displayed.');
|
||||
|
||||
// Set comments to have subject and preview to required.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
@ -83,7 +93,7 @@ class CommentInterfaceTest extends CommentTestBase {
|
|||
)));
|
||||
|
||||
// Test changing the comment author to "Anonymous".
|
||||
$comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), array('name' => ''));
|
||||
$comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), array('uid' => ''));
|
||||
$this->assertTrue($comment->getAuthorName() == t('Anonymous') && $comment->getOwnerId() == 0, 'Comment author successfully changed to anonymous.');
|
||||
|
||||
// Test changing the comment author to an unverified user.
|
||||
|
@ -95,7 +105,7 @@ class CommentInterfaceTest extends CommentTestBase {
|
|||
|
||||
// Test changing the comment author to a verified user.
|
||||
$this->drupalGet('comment/' . $comment->id() . '/edit');
|
||||
$comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), array('name' => $this->webUser->getUsername()));
|
||||
$comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), array('uid' => $this->webUser->getUsername() . ' (' . $this->webUser->id() . ')'));
|
||||
$this->assertTrue($comment->getAuthorName() == $this->webUser->getUsername() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.');
|
||||
|
||||
$this->drupalLogout();
|
||||
|
|
|
@ -60,6 +60,9 @@ class CommentItemTest extends FieldUnitTestBase {
|
|||
CommentItemInterface::CLOSED,
|
||||
CommentItemInterface::OPEN,
|
||||
]), 'Comment status value in defined range');
|
||||
|
||||
$mainProperty = $entity->comment[0]->mainPropertyName();
|
||||
$this->assertEqual('status', $mainProperty);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ class CommentNonNodeTest extends WebTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->drupalPlaceBlock('system_breadcrumb_block');
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
// Create a bundle for entity_test.
|
||||
entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test');
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\comment\Tests;
|
||||
|
||||
use Drupal\comment\CommentManagerInterface;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
|
||||
|
@ -39,17 +40,31 @@ class CommentPreviewTest extends CommentTestBase {
|
|||
$this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
|
||||
$this->drupalLogout();
|
||||
|
||||
// Login as web user and add a user picture.
|
||||
// Login as web user.
|
||||
$this->drupalLogin($this->webUser);
|
||||
$image = current($this->drupalGetTestFiles('image'));
|
||||
$edit['files[user_picture_0]'] = drupal_realpath($image->uri);
|
||||
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// As the web user, fill in the comment form and preview the comment.
|
||||
// Test escaping of the username on the preview form.
|
||||
\Drupal::service('module_installer')->install(['user_hooks_test']);
|
||||
\Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
|
||||
$edit = array();
|
||||
$edit['subject[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['comment_body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('node/' . $this->node->id(), $edit, t('Preview'));
|
||||
$this->assertEscaped('<em>' . $this->webUser->id() . '</em>');
|
||||
|
||||
\Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE);
|
||||
$this->drupalPostForm('node/' . $this->node->id(), $edit, t('Preview'));
|
||||
$this->assertTrue(SafeMarkup::isSafe($this->webUser->getDisplayName()), 'Username is marked safe');
|
||||
$this->assertNoEscaped('<em>' . $this->webUser->id() . '</em>');
|
||||
$this->assertRaw('<em>' . $this->webUser->id() . '</em>');
|
||||
|
||||
// Add a user picture.
|
||||
$image = current($this->drupalGetTestFiles('image'));
|
||||
$user_edit['files[user_picture_0]'] = drupal_realpath($image->uri);
|
||||
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $user_edit, t('Save'));
|
||||
|
||||
// As the web user, fill in the comment form and preview the comment.
|
||||
$this->drupalPostForm('node/' . $this->node->id(), $edit, t('Preview'));
|
||||
|
||||
// Check that the preview is displaying the title and body.
|
||||
$this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
|
||||
|
@ -125,7 +140,7 @@ class CommentPreviewTest extends CommentTestBase {
|
|||
$date = new DrupalDateTime('2008-03-02 17:23');
|
||||
$edit['subject[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['comment_body[0][value]'] = $this->randomMachineName(16);
|
||||
$edit['name'] = $web_user->getUsername();
|
||||
$edit['uid'] = $web_user->getUsername() . ' (' . $web_user->id() . ')';
|
||||
$edit['date[date]'] = $date->format('Y-m-d');
|
||||
$edit['date[time]'] = $date->format('H:i:s');
|
||||
$raw_date = $date->getTimestamp();
|
||||
|
@ -139,13 +154,13 @@ class CommentPreviewTest extends CommentTestBase {
|
|||
$this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
|
||||
$this->assertText($edit['subject[0][value]'], 'Subject displayed.');
|
||||
$this->assertText($edit['comment_body[0][value]'], 'Comment displayed.');
|
||||
$this->assertText($edit['name'], 'Author displayed.');
|
||||
$this->assertText($web_user->getUsername(), 'Author displayed.');
|
||||
$this->assertText($expected_text_date, 'Date displayed.');
|
||||
|
||||
// Check that the subject, comment, author and date fields are displayed with the correct values.
|
||||
$this->assertFieldByName('subject[0][value]', $edit['subject[0][value]'], 'Subject field displayed.');
|
||||
$this->assertFieldByName('comment_body[0][value]', $edit['comment_body[0][value]'], 'Comment field displayed.');
|
||||
$this->assertFieldByName('name', $edit['name'], 'Author field displayed.');
|
||||
$this->assertFieldByName('uid', $edit['uid'], 'Author field displayed.');
|
||||
$this->assertFieldByName('date[date]', $edit['date[date]'], 'Date field displayed.');
|
||||
$this->assertFieldByName('date[time]', $edit['date[time]'], 'Time field displayed.');
|
||||
|
||||
|
@ -157,7 +172,7 @@ class CommentPreviewTest extends CommentTestBase {
|
|||
$this->drupalGet('comment/' . $comment->id() . '/edit');
|
||||
$this->assertFieldByName('subject[0][value]', $edit['subject[0][value]'], 'Subject field displayed.');
|
||||
$this->assertFieldByName('comment_body[0][value]', $edit['comment_body[0][value]'], 'Comment field displayed.');
|
||||
$this->assertFieldByName('name', $edit['name'], 'Author field displayed.');
|
||||
$this->assertFieldByName('uid', $edit['uid'], 'Author field displayed.');
|
||||
$this->assertFieldByName('date[date]', $expected_form_date, 'Date field displayed.');
|
||||
$this->assertFieldByName('date[time]', $expected_form_time, 'Time field displayed.');
|
||||
|
||||
|
@ -165,7 +180,7 @@ class CommentPreviewTest extends CommentTestBase {
|
|||
$displayed = array();
|
||||
$displayed['subject[0][value]'] = (string) current($this->xpath("//input[@id='edit-subject-0-value']/@value"));
|
||||
$displayed['comment_body[0][value]'] = (string) current($this->xpath("//textarea[@id='edit-comment-body-0-value']"));
|
||||
$displayed['name'] = (string) current($this->xpath("//input[@id='edit-name']/@value"));
|
||||
$displayed['uid'] = (string) current($this->xpath("//input[@id='edit-uid']/@value"));
|
||||
$displayed['date[date]'] = (string) current($this->xpath("//input[@id='edit-date-date']/@value"));
|
||||
$displayed['date[time]'] = (string) current($this->xpath("//input[@id='edit-date-time']/@value"));
|
||||
$this->drupalPostForm('comment/' . $comment->id() . '/edit', $displayed, t('Save'));
|
||||
|
@ -173,10 +188,11 @@ class CommentPreviewTest extends CommentTestBase {
|
|||
// Check that the saved comment is still correct.
|
||||
$comment_storage = \Drupal::entityManager()->getStorage('comment');
|
||||
$comment_storage->resetCache(array($comment->id()));
|
||||
/** @var \Drupal\comment\CommentInterface $comment_loaded */
|
||||
$comment_loaded = Comment::load($comment->id());
|
||||
$this->assertEqual($comment_loaded->getSubject(), $edit['subject[0][value]'], 'Subject loaded.');
|
||||
$this->assertEqual($comment_loaded->comment_body->value, $edit['comment_body[0][value]'], 'Comment body loaded.');
|
||||
$this->assertEqual($comment_loaded->getAuthorName(), $edit['name'], 'Name loaded.');
|
||||
$this->assertEqual($comment_loaded->getOwner()->id(), $web_user->id(), 'Name loaded.');
|
||||
$this->assertEqual($comment_loaded->getCreatedTime(), $raw_date, 'Date loaded.');
|
||||
$this->drupalLogout();
|
||||
|
||||
|
@ -185,6 +201,8 @@ class CommentPreviewTest extends CommentTestBase {
|
|||
$user_edit = array();
|
||||
$expected_created_time = $comment_loaded->getCreatedTime();
|
||||
$this->drupalLogin($web_user);
|
||||
// Web user cannot change the comment author.
|
||||
unset($edit['uid']);
|
||||
$this->drupalPostForm('comment/' . $comment->id() . '/edit', $user_edit, t('Save'));
|
||||
$comment_storage->resetCache(array($comment->id()));
|
||||
$comment_loaded = Comment::load($comment->id());
|
||||
|
|
|
@ -70,6 +70,9 @@ abstract class CommentTestBase extends WebTestBase {
|
|||
'skip comment approval',
|
||||
'post comments',
|
||||
'access comments',
|
||||
// Usernames aren't shown in comment edit form autocomplete unless this
|
||||
// permission is granted.
|
||||
'access user profiles',
|
||||
'access content',
|
||||
));
|
||||
$this->webUser = $this->drupalCreateUser(array(
|
||||
|
@ -188,14 +191,22 @@ abstract class CommentTestBase extends WebTestBase {
|
|||
*/
|
||||
function commentExists(CommentInterface $comment = NULL, $reply = FALSE) {
|
||||
if ($comment) {
|
||||
$regex = '!' . ($reply ? '<div class="indented">(.*?)' : '');
|
||||
$regex .= '<a id="comment-' . $comment->id() . '"(.*?)';
|
||||
$regex .= $comment->getSubject() . '(.*?)';
|
||||
$regex .= $comment->comment_body->value . '(.*?)';
|
||||
$regex .= ($reply ? '</article>\s</div>(.*?)' : '');
|
||||
$regex .= '!s';
|
||||
$comment_element = $this->cssSelect('.comment-wrapper ' . ($reply ? '.indented ' : '') . '#comment-' . $comment->id() . ' ~ article');
|
||||
if (empty($comment_element)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (boolean) preg_match($regex, $this->getRawContent());
|
||||
$comment_title = $comment_element[0]->xpath('div/h3/a');
|
||||
if (empty($comment_title) || ((string)$comment_title[0]) !== $comment->getSubject()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$comment_body = $comment_element[0]->xpath('div/div/p');
|
||||
if (empty($comment_body) || ((string)$comment_body[0]) !== $comment->comment_body->value) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\comment\Tests;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
|
@ -32,13 +33,16 @@ class CommentTokenReplaceTest extends CommentTestBase {
|
|||
'language' => $language_interface,
|
||||
);
|
||||
|
||||
// Change the title of the admin user.
|
||||
$this->adminUser->name->value = 'This is a title with some special & > " stuff.';
|
||||
$this->adminUser->save();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Set comment variables.
|
||||
$this->setCommentSubject(TRUE);
|
||||
|
||||
// Create a node and a comment.
|
||||
$node = $this->drupalCreateNode(array('type' => 'article'));
|
||||
$node = $this->drupalCreateNode(['type' => 'article', 'title' => '<script>alert("123")</script>']);
|
||||
$parent_comment = $this->postComment($node, $this->randomMachineName(), $this->randomMachineName(), TRUE);
|
||||
|
||||
// Post a reply to the comment.
|
||||
|
@ -50,29 +54,29 @@ class CommentTokenReplaceTest extends CommentTestBase {
|
|||
// Add HTML to ensure that sanitation of some fields tested directly.
|
||||
$comment->setSubject('<blink>Blinking Comment</blink>');
|
||||
|
||||
// Generate and test sanitized tokens.
|
||||
// Generate and test tokens.
|
||||
$tests = array();
|
||||
$tests['[comment:cid]'] = $comment->id();
|
||||
$tests['[comment:hostname]'] = Html::escape($comment->getHostname());
|
||||
$tests['[comment:author]'] = Xss::filter($comment->getAuthorName());
|
||||
$tests['[comment:mail]'] = Html::escape($this->adminUser->getEmail());
|
||||
$tests['[comment:hostname]'] = $comment->getHostname();
|
||||
$tests['[comment:author]'] = Html::escape($comment->getAuthorName());
|
||||
$tests['[comment:mail]'] = $this->adminUser->getEmail();
|
||||
$tests['[comment:homepage]'] = UrlHelper::filterBadProtocol($comment->getHomepage());
|
||||
$tests['[comment:title]'] = Xss::filter($comment->getSubject());
|
||||
$tests['[comment:title]'] = Html::escape($comment->getSubject());
|
||||
$tests['[comment:body]'] = $comment->comment_body->processed;
|
||||
$tests['[comment:langcode]'] = Html::escape($comment->language()->getId());
|
||||
$tests['[comment:langcode]'] = $comment->language()->getId();
|
||||
$tests['[comment:url]'] = $comment->url('canonical', $url_options + array('fragment' => 'comment-' . $comment->id()));
|
||||
$tests['[comment:edit-url]'] = $comment->url('edit-form', $url_options);
|
||||
$tests['[comment:created]'] = \Drupal::service('date.formatter')->format($comment->getCreatedTime(), 'medium', array('langcode' => $language_interface->getId()));
|
||||
$tests['[comment:created:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($comment->getCreatedTime(), array('langcode' => $language_interface->getId()));
|
||||
$tests['[comment:changed:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($comment->getChangedTimeAcrossTranslations(), array('langcode' => $language_interface->getId()));
|
||||
$tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL;
|
||||
$tests['[comment:parent:title]'] = Html::escape($parent_comment->getSubject());
|
||||
$tests['[comment:parent:title]'] = $parent_comment->getSubject();
|
||||
$tests['[comment:entity]'] = Html::escape($node->getTitle());
|
||||
// Test node specific tokens.
|
||||
$tests['[comment:entity:nid]'] = $comment->getCommentedEntityId();
|
||||
$tests['[comment:entity:title]'] = Html::escape($node->getTitle());
|
||||
$tests['[comment:author:uid]'] = $comment->getOwnerId();
|
||||
$tests['[comment:author:name]'] = Html::escape($this->adminUser->getUsername());
|
||||
$tests['[comment:author:name]'] = Html::escape($this->adminUser->getDisplayName());
|
||||
|
||||
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($comment);
|
||||
$metadata_tests = [];
|
||||
|
@ -114,35 +118,16 @@ class CommentTokenReplaceTest extends CommentTestBase {
|
|||
foreach ($tests as $input => $expected) {
|
||||
$bubbleable_metadata = new BubbleableMetadata();
|
||||
$output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId()), $bubbleable_metadata);
|
||||
$this->assertEqual($output, $expected, format_string('Sanitized comment token %token replaced.', array('%token' => $input)));
|
||||
$this->assertEqual($output, $expected, new FormattableMarkup('Comment token %token replaced.', ['%token' => $input]));
|
||||
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
|
||||
}
|
||||
|
||||
// Generate and test unsanitized tokens.
|
||||
$tests['[comment:hostname]'] = $comment->getHostname();
|
||||
$tests['[comment:author]'] = $comment->getAuthorName();
|
||||
$tests['[comment:mail]'] = $this->adminUser->getEmail();
|
||||
$tests['[comment:homepage]'] = $comment->getHomepage();
|
||||
$tests['[comment:title]'] = $comment->getSubject();
|
||||
$tests['[comment:body]'] = $comment->comment_body->value;
|
||||
$tests['[comment:langcode]'] = $comment->language()->getId();
|
||||
$tests['[comment:parent:title]'] = $parent_comment->getSubject();
|
||||
$tests['[comment:entity]'] = $node->getTitle();
|
||||
$tests['[comment:author:name]'] = $this->adminUser->getUsername();
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
// Test anonymous comment author.
|
||||
$author_name = $this->randomString();
|
||||
$author_name = 'This is a random & " > string';
|
||||
$comment->setOwnerId(0)->setAuthorName($author_name);
|
||||
$input = '[comment:author]';
|
||||
$output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId()));
|
||||
$this->assertEqual($output, Xss::filter($author_name), format_string('Sanitized comment author token %token replaced.', array('%token' => $input)));
|
||||
$output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $author_name, format_string('Unsanitized comment author token %token replaced.', array('%token' => $input)));
|
||||
$this->assertEqual($output, Html::escape($author_name), format_string('Comment author token %token replaced.', array('%token' => $input)));
|
||||
|
||||
// Load node so comment_count gets computed.
|
||||
$node = Node::load($node->id());
|
||||
|
|
|
@ -37,11 +37,13 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
|
|||
*/
|
||||
protected $defaultCacheContexts = [
|
||||
'languages:language_interface',
|
||||
'session',
|
||||
'theme',
|
||||
'timezone',
|
||||
'url.query_args:_wrapper_format',
|
||||
'url.query_args.pagers:0',
|
||||
'user'
|
||||
'user.permissions',
|
||||
'user.roles',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -162,7 +164,7 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
|
|||
'created' => REQUEST_TIME - mt_rand(0, 1000),
|
||||
);
|
||||
$edit = array(
|
||||
'name' => $user->getUsername(),
|
||||
'uid' => $user->getUsername() . '(' . $user->id() . ')',
|
||||
'date[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'),
|
||||
'date[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'),
|
||||
);
|
||||
|
|
|
@ -43,6 +43,9 @@ class CommentTypeTest extends CommentTestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser($this->permissions);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,16 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
|
|||
|
||||
use CommentTestTrait;
|
||||
|
||||
static $modules = array('node', 'comment', 'text', 'filter');
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'comment',
|
||||
// Directly testing that a stub comment's entity_id is populated upon
|
||||
// importing is not straightforward, but RDF module serves as an implicit
|
||||
// test - its hook_comment_storage_load() references a stubbed comment.
|
||||
'rdf',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -30,35 +39,21 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
|
|||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installSchema('comment', ['comment_entity_statistics']);
|
||||
$this->installConfig(['node', 'comment']);
|
||||
$this->installSchema('system', ['router']);
|
||||
$this->installConfig(['comment']);
|
||||
|
||||
entity_create('node_type', array('type' => 'page'))->save();
|
||||
entity_create('node_type', array('type' => 'story'))->save();
|
||||
$this->addDefaultCommentField('node', 'story');
|
||||
$this->container->get('entity.manager')->getStorage('comment_type')->create(array(
|
||||
'id' => 'comment_no_subject',
|
||||
'label' => 'comment_no_subject',
|
||||
'target_entity_type_id' => 'node',
|
||||
))->save();
|
||||
\Drupal::service('comment.manager')->addBodyField('comment_no_subject');
|
||||
// The entity.node.canonical route must exist when the RDF hook is called.
|
||||
$this->container->get('router.builder')->rebuild();
|
||||
|
||||
$node = entity_create('node', array(
|
||||
'type' => 'story',
|
||||
'nid' => 1,
|
||||
'title' => $this->randomString(),
|
||||
));
|
||||
$node->enforceIsNew();
|
||||
$node->save();
|
||||
$id_mappings = array(
|
||||
'd6_filter_format' => array(array(array(1), array('filtered_html'))),
|
||||
'd6_node:*' => array(array(array(1), array(1))),
|
||||
'd6_user' => array(array(array(0), array(0))),
|
||||
'd6_comment_type' => array(array(array('comment'), array('comment_no_subject'))),
|
||||
'd6_comment_entity_display' => array(array(array('story'), array('node', 'story', 'default', 'comment'))),
|
||||
'd6_comment_entity_form_display' => array(array(array('story'), array('node', 'story', 'default', 'comment'))),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_comment');
|
||||
$this->migrateContent();
|
||||
$this->executeMigrations([
|
||||
'd6_comment_type',
|
||||
'd6_comment_field',
|
||||
'd6_comment_field_instance',
|
||||
'd6_comment_entity_display',
|
||||
'd6_comment_entity_form_display',
|
||||
'd6_comment',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,10 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
*/
|
||||
class MigrateCommentTypeTest extends MigrateDrupal6TestBase {
|
||||
|
||||
static $modules = array('node', 'comment', 'text', 'filter');
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['comment'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -15,57 +15,22 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
abstract class MigrateCommentVariableDisplayBase extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* The ID of migration to run.
|
||||
*
|
||||
* This constant needs to be set in the concrete class in order for the test
|
||||
* to work.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
const MIGRATION = '';
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $modules = array('comment', 'node');
|
||||
|
||||
/**
|
||||
* The node types being tested.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $types = array('page', 'story', 'article');
|
||||
public static $modules = ['comment'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
entity_create('field_storage_config', array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
'type' => 'comment',
|
||||
'translatable' => '0',
|
||||
))->save();
|
||||
foreach ($this->types as $type) {
|
||||
entity_create('node_type', array('type' => $type))->save();
|
||||
entity_create('field_config', array(
|
||||
'label' => 'Comments',
|
||||
'description' => '',
|
||||
'field_name' => 'comment',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type,
|
||||
'required' => 1,
|
||||
))->save();
|
||||
}
|
||||
$id_mappings = array(
|
||||
'd6_comment_field_instance' => array(
|
||||
array(array('page'), array('node', 'comment', 'page')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration(static::MIGRATION);
|
||||
|
||||
$this->installConfig(['comment']);
|
||||
$this->migrateContentTypes();
|
||||
$this->executeMigrations([
|
||||
'd6_comment_type',
|
||||
'd6_comment_field',
|
||||
'd6_comment_field_instance',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
|
||||
/**
|
||||
* Upgrade comment variables to entity.display.node.*.default.yml.
|
||||
*
|
||||
|
@ -15,21 +17,19 @@ namespace Drupal\comment\Tests\Migrate\d6;
|
|||
class MigrateCommentVariableEntityDisplayTest extends MigrateCommentVariableDisplayBase {
|
||||
|
||||
/**
|
||||
* The migration to run.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
const MIGRATION = 'd6_comment_entity_display';
|
||||
|
||||
/**
|
||||
* The node types being used.
|
||||
*/
|
||||
protected $types = array('page', 'story', 'article');
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d6_comment_entity_display');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests comment variables migrated into an entity display.
|
||||
*/
|
||||
public function testCommentEntityDisplay() {
|
||||
foreach ($this->types as $type) {
|
||||
$component = entity_get_display('node', $type, 'default')->getComponent('comment');
|
||||
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']);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
|
@ -17,43 +18,31 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
class MigrateCommentVariableEntityFormDisplaySubjectTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('comment', 'node');
|
||||
public static $modules = ['comment'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
foreach (['comment', 'comment_no_subject'] as $comment_type) {
|
||||
entity_create('comment_type', array(
|
||||
'id' => $comment_type,
|
||||
'target_entity_type_id' => 'node',
|
||||
))
|
||||
->save();
|
||||
}
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_comment_type' => array(
|
||||
array(array('comment'), array('comment_no_subject')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_comment_entity_form_display_subject');
|
||||
$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 = entity_get_form_display('comment', 'comment', 'default')
|
||||
$component = EntityFormDisplay::load('comment.comment.default')
|
||||
->getComponent('subject');
|
||||
$this->assertIdentical('string_textfield', $component['type']);
|
||||
$this->assertIdentical(10, $component['weight']);
|
||||
$component = entity_get_form_display('comment', 'comment_no_subject', 'default')
|
||||
$component = EntityFormDisplay::load('comment.comment_no_subject.default')
|
||||
->getComponent('subject');
|
||||
$this->assertNull($component);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
|
||||
/**
|
||||
* Upgrade comment variables to core.entity_form_display.node.*.default.yml.
|
||||
*
|
||||
|
@ -15,16 +17,20 @@ namespace Drupal\comment\Tests\Migrate\d6;
|
|||
class MigrateCommentVariableEntityFormDisplayTest extends MigrateCommentVariableDisplayBase {
|
||||
|
||||
/**
|
||||
* The migration to run.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
const MIGRATION = 'd6_comment_entity_form_display';
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d6_comment_entity_form_display');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests comment variables migrated into an entity display.
|
||||
*/
|
||||
public function testCommentEntityFormDisplay() {
|
||||
foreach ($this->types as $type) {
|
||||
$component = entity_get_form_display('node', $type, 'default')->getComponent('comment');
|
||||
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']);
|
||||
}
|
||||
|
|
|
@ -17,31 +17,19 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
*/
|
||||
class MigrateCommentVariableFieldTest extends MigrateDrupal6TestBase {
|
||||
|
||||
static $modules = array('comment', 'node');
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['comment'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
foreach (array('page', 'story', 'test') as $type) {
|
||||
entity_create('node_type', array('type' => $type))->save();
|
||||
}
|
||||
foreach (['comment', 'comment_no_subject'] as $comment_type) {
|
||||
entity_create('comment_type', array(
|
||||
'id' => $comment_type,
|
||||
'target_entity_type_id' => 'node',
|
||||
))
|
||||
->save();
|
||||
}
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_comment_type' => array(
|
||||
array(array('comment'), array('comment_no_subject')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_comment_field');
|
||||
$this->installConfig(['comment']);
|
||||
$this->migrateContentTypes();
|
||||
$this->executeMigrations(['d6_comment_type', 'd6_comment_field']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\comment\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
* Upgrade comment variables to field.instance.node.*.comment.yml.
|
||||
|
@ -16,47 +17,30 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
*/
|
||||
class MigrateCommentVariableInstanceTest extends MigrateDrupal6TestBase {
|
||||
|
||||
static $modules = array('comment', 'node');
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['comment'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_comment_field' => array(
|
||||
array(array('page'), array('node', 'page')),
|
||||
),
|
||||
'd6_node_type' => array(
|
||||
array(array('page'), array('page')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
foreach (array('page', 'story', 'article') as $type) {
|
||||
entity_create('node_type', array('type' => $type))->save();
|
||||
}
|
||||
entity_create('field_storage_config', array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
'type' => 'comment',
|
||||
'translatable' => '0',
|
||||
))->save();
|
||||
entity_create('field_storage_config', array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment_no_subject',
|
||||
'type' => 'comment',
|
||||
'translatable' => '0',
|
||||
))->save();
|
||||
$this->executeMigration('d6_comment_field_instance');
|
||||
$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 = entity_create('node', array('type' => 'page'));
|
||||
$node = Node::create(['type' => 'page']);
|
||||
$this->assertIdentical(0, $node->comment->status);
|
||||
$this->assertIdentical('comment', $node->comment->getFieldDefinition()->getName());
|
||||
$settings = $node->comment->getFieldDefinition()->getSettings();
|
||||
|
@ -66,7 +50,7 @@ class MigrateCommentVariableInstanceTest extends MigrateDrupal6TestBase {
|
|||
$this->assertIdentical(FALSE, $settings['form_location']);
|
||||
$this->assertIdentical(1, $settings['preview']);
|
||||
|
||||
$node = entity_create('node', array('type' => 'story'));
|
||||
$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();
|
||||
|
|
|
@ -25,11 +25,13 @@ class MigrateCommentEntityDisplayTest extends MigrateDrupal7TestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigration('d7_comment_field_instance');
|
||||
$this->executeMigration('d7_comment_entity_display');
|
||||
$this->executeMigrations([
|
||||
'd7_node_type',
|
||||
'd7_comment_type',
|
||||
'd7_comment_field',
|
||||
'd7_comment_field_instance',
|
||||
'd7_comment_entity_display',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,9 +25,11 @@ class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_entity_form_display_subject');
|
||||
$this->executeMigrations([
|
||||
'd7_node_type',
|
||||
'd7_comment_type',
|
||||
'd7_comment_entity_form_display_subject',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,11 +25,13 @@ class MigrateCommentEntityFormDisplayTest extends MigrateDrupal7TestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigration('d7_comment_field_instance');
|
||||
$this->executeMigration('d7_comment_entity_form_display');
|
||||
$this->executeMigrations([
|
||||
'd7_node_type',
|
||||
'd7_comment_type',
|
||||
'd7_comment_field',
|
||||
'd7_comment_field_instance',
|
||||
'd7_comment_entity_form_display',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,10 +28,12 @@ class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigration('d7_comment_field_instance');
|
||||
$this->executeMigrations([
|
||||
'd7_node_type',
|
||||
'd7_comment_type',
|
||||
'd7_comment_field',
|
||||
'd7_comment_field_instance',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,9 +27,11 @@ class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment_field');
|
||||
$this->executeMigrations([
|
||||
'd7_node_type',
|
||||
'd7_comment_type',
|
||||
'd7_comment_field',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,9 +32,11 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
|||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
|
||||
$this->executeMigration('d7_filter_format');
|
||||
$this->executeMigration('d7_user_role');
|
||||
$this->executeMigration('d7_user');
|
||||
$this->executeMigrations([
|
||||
'd7_filter_format',
|
||||
'd7_user_role',
|
||||
'd7_user',
|
||||
]);
|
||||
// The test database doesn't include uid 1, so we'll need to create it.
|
||||
User::create(array(
|
||||
'uid' => 1,
|
||||
|
@ -49,9 +51,11 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
|
|||
array(array(0), array(0)),
|
||||
),
|
||||
));
|
||||
$this->executeMigration('d7_node__test_content_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigration('d7_comment');
|
||||
$this->executeMigrations([
|
||||
'd7_node__test_content_type',
|
||||
'd7_comment_type',
|
||||
'd7_comment',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\comment\Tests\Migrate\d7;
|
|||
|
||||
use Drupal\comment\CommentTypeInterface;
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
|
@ -26,8 +27,10 @@ class MigrateCommentTypeTest extends MigrateDrupal7TestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_node_type');
|
||||
$this->executeMigration('d7_comment_type');
|
||||
$this->executeMigrations([
|
||||
'd7_node_type',
|
||||
'd7_comment_type',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,6 +59,11 @@ class MigrateCommentTypeTest extends MigrateDrupal7TestBase {
|
|||
$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');
|
||||
|
||||
// Validate that the source count and processed count match up.
|
||||
/** @var \Drupal\migrate\Entity\MigrationInterface $migration */
|
||||
$migration = Migration::load('d7_comment_type');
|
||||
$this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,6 +61,9 @@ class CommentFieldNameTest extends CommentTestBase {
|
|||
public function testCommentFieldName() {
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = \Drupal::service('renderer');
|
||||
// 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);
|
||||
|
||||
|
@ -79,14 +82,7 @@ class CommentFieldNameTest extends CommentTestBase {
|
|||
'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.
|
||||
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
|
||||
return $view->field['field_name']->advancedRender($view->result[0]);
|
||||
|
|
180
core/modules/comment/src/Tests/Views/CommentLinksTest.php
Normal file
180
core/modules/comment/src/Tests/Views/CommentLinksTest.php
Normal file
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Views\CommentLinksTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\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 CommentViewKernelTestBase {
|
||||
|
||||
/**
|
||||
* 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.");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Views\CommentViewKernelTestBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Views;
|
||||
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\views\Tests\ViewKernelTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
* Provides a common test base for comment views tests.
|
||||
*/
|
||||
abstract class CommentViewKernelTestBase extends ViewKernelTestBase {
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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: { }
|
|
@ -60,10 +60,10 @@ display:
|
|||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: '‹ previous'
|
||||
next: 'next ›'
|
||||
first: '« first'
|
||||
last: 'last »'
|
||||
previous: '‹ Previous'
|
||||
next: 'Next ›'
|
||||
first: '« First'
|
||||
last: 'Last »'
|
||||
quantity: 9
|
||||
style:
|
||||
type: default
|
||||
|
@ -200,4 +200,4 @@ display:
|
|||
contexts:
|
||||
- languages
|
||||
- user
|
||||
cacheable: false
|
||||
max-age: 0
|
||||
|
|
|
@ -65,10 +65,10 @@ display:
|
|||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: '‹ previous'
|
||||
next: 'next ›'
|
||||
first: '« first'
|
||||
last: 'last »'
|
||||
previous: '‹ Previous'
|
||||
next: 'Next ›'
|
||||
first: '« First'
|
||||
last: 'Last »'
|
||||
quantity: 9
|
||||
style:
|
||||
type: serializer
|
||||
|
|
|
@ -61,10 +61,10 @@ display:
|
|||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: '‹ previous'
|
||||
next: 'next ›'
|
||||
first: '« first'
|
||||
last: 'last »'
|
||||
previous: '‹ Previous'
|
||||
next: 'Next ›'
|
||||
first: '« First'
|
||||
last: 'Last »'
|
||||
quantity: 9
|
||||
style:
|
||||
type: default
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\comment\Unit\Migrate\d6\CommentVariablePerCommentTypeTest.
|
||||
*/
|
||||
|
||||
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_no_subject',
|
||||
),
|
||||
array(
|
||||
'comment_type' => 'comment',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\comment\Unit\Migrate\d6\CommentVariableTest.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue