Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -29,12 +29,12 @@ class CommentActionsTest extends CommentTestBase {
$comment = $this->postComment($this->node, $comment_text, $subject);
// Unpublish a comment.
$action = entity_load('action', 'comment_unpublish_action');
$action = Action::load('comment_unpublish_action');
$action->execute(array($comment));
$this->assertTrue($comment->isPublished() === FALSE, 'Comment was unpublished');
// Publish a comment.
$action = entity_load('action', 'comment_publish_action');
$action = Action::load('comment_publish_action');
$action->execute(array($comment));
$this->assertTrue($comment->isPublished() === TRUE, 'Comment was published');
}

View file

@ -5,6 +5,9 @@ namespace Drupal\comment\Tests;
use Drupal\comment\CommentManagerInterface;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Entity\Comment;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\user\RoleInterface;
use Drupal\filter\Entity\FilterFormat;
@ -292,4 +295,53 @@ class CommentInterfaceTest extends CommentTestBase {
$this->assertEqual('(No subject)', Comment::load(2)->getSubject());
}
/**
* Tests the comment formatter configured with a custom comment view mode.
*/
public function testViewMode() {
$this->drupalLogin($this->webUser);
$this->drupalGet($this->node->toUrl());
$comment_text = $this->randomMachineName();
// Post a comment.
$this->postComment($this->node, $comment_text);
// Comment displayed in 'default' display mode found and has body text.
$comment_element = $this->cssSelect('.comment-wrapper');
$this->assertTrue(!empty($comment_element));
$this->assertRaw('<p>' . $comment_text . '</p>');
// Create a new comment entity view mode.
$mode = Unicode::strtolower($this->randomMachineName());
EntityViewMode::create([
'targetEntityType' => 'comment',
'id' => "comment.$mode",
])->save();
// Create the corresponding entity view display for article node-type. Note
// that this new view display mode doesn't contain the comment body.
EntityViewDisplay::create([
'targetEntityType' => 'comment',
'bundle' => 'comment',
'mode' => $mode,
])->setStatus(TRUE)->save();
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $node_display */
$node_display = EntityViewDisplay::load('node.article.default');
$formatter = $node_display->getComponent('comment');
// Change the node comment field formatter to use $mode mode instead of
// 'default' mode.
$formatter['settings']['view_mode'] = $mode;
$node_display
->setComponent('comment', $formatter)
->save();
// Reloading the node page to show the same node with its same comment but
// with a different display mode.
$this->drupalGet($this->node->toUrl());
// The comment should exist but without the body text because we used $mode
// mode this time.
$comment_element = $this->cssSelect('.comment-wrapper');
$this->assertTrue(!empty($comment_element));
$this->assertNoRaw('<p>' . $comment_text . '</p>');
}
}

View file

@ -66,7 +66,7 @@ class CommentLinksTest extends CommentTestBase {
'subject' => $this->randomMachineName(),
'hostname' => '127.0.0.1',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'comment_body' => array(LanguageInterface::LANGCODE_NOT_SPECIFIED => array($this->randomMachineName())),
'comment_body' => array(array('value' => $this->randomMachineName())),
));
$comment->save();
$this->comment = $comment;
@ -101,6 +101,26 @@ class CommentLinksTest extends CommentTestBase {
$this->assertLink('Add new comment');
}
// Change weight to make links go before comment body.
entity_get_display('comment', 'comment', 'default')
->setComponent('links', array('weight' => -100))
->save();
$this->drupalGet($this->node->urlInfo());
$element = $this->cssSelect('article.js-comment > div');
// Get last child element.
$element = end($element[0]);
$this->assertIdentical($element[0]->getName(), 'div', 'Last element is comment body.');
// Change weight to make links go after comment body.
entity_get_display('comment', 'comment', 'default')
->setComponent('links', array('weight' => 100))
->save();
$this->drupalGet($this->node->urlInfo());
$element = $this->cssSelect('article.js-comment > div');
// Get last child element.
$element = end($element[0]);
$this->assertIdentical($element[0]->getName(), 'ul', 'Last element is comment links.');
// Make sure we can hide node links.
entity_get_display('node', $this->node->bundle(), 'default')
->removeComponent('links')

View file

@ -90,6 +90,38 @@ class CommentPagerTest extends CommentTestBase {
$this->drupalLogout();
}
/**
* Confirms comment paging works correctly with flat and threaded comments.
*/
function testCommentPermalink() {
$this->drupalLogin($this->adminUser);
// Set comment variables.
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentPreview(DRUPAL_DISABLED);
// Create a node and three comments.
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$comments = array();
$comments[] = $this->postComment($node, 'comment 1: ' . $this->randomMachineName(), $this->randomMachineName(), TRUE);
$comments[] = $this->postComment($node, 'comment 2: ' . $this->randomMachineName(), $this->randomMachineName(), TRUE);
$comments[] = $this->postComment($node, 'comment 3: ' . $this->randomMachineName(), $this->randomMachineName(), TRUE);
$this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT, 'Comment paging changed.');
// Set comments to one per page so that we are able to test paging without
// needing to insert large numbers of comments.
$this->setCommentsPerPage(1);
// Navigate to each comment permalink as anonymous and assert it appears on
// the page.
foreach ($comments as $index => $comment) {
$this->drupalGet($comment->toUrl());
$this->assertTrue($this->commentExists($comment), sprintf('Comment %d appears on page %d.', $index + 1, $index + 1));
}
}
/**
* Tests comment ordering and threading.
*/
@ -283,6 +315,7 @@ class CommentPagerTest extends CommentTestBase {
'weight' => 30,
'settings' => array(
'pager_id' => 1,
'view_mode' => 'default',
)
))
->save();

View file

@ -111,7 +111,7 @@ abstract class CommentTestBase extends WebTestBase {
$edit['comment_body[0][value]'] = $comment;
if ($entity !== NULL) {
$field = FieldConfig::loadByName('node', $entity->bundle(), $field_name);
$field = FieldConfig::loadByName($entity->getEntityTypeId(), $entity->bundle(), $field_name);
}
else {
$field = FieldConfig::loadByName('node', 'article', $field_name);
@ -120,7 +120,7 @@ abstract class CommentTestBase extends WebTestBase {
// Must get the page before we test for fields.
if ($entity !== NULL) {
$this->drupalGet('comment/reply/node/' . $entity->id() . '/' . $field_name);
$this->drupalGet('comment/reply/' . $entity->getEntityTypeId() . '/' . $entity->id() . '/' . $field_name);
}
// Determine the visibility of subject form field.

View file

@ -29,8 +29,11 @@ trait CommentTestTrait {
* CommentItemInterface::OPEN.
* @param string $comment_type_id
* (optional) ID of comment type to use. Defaults to 'comment'.
* @param string $comment_view_mode
* (optional) The comment view mode to be used in comment field formatter.
* Defaults to 'full'.
*/
public function addDefaultCommentField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment') {
public function addDefaultCommentField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment', $comment_view_mode = 'full') {
$entity_manager = \Drupal::entityManager();
// Create the comment type if needed.
$comment_type_storage = $entity_manager->getStorage('comment_type');
@ -106,6 +109,7 @@ trait CommentTestTrait {
'label' => 'above',
'type' => 'comment_default',
'weight' => 20,
'settings' => array('view_mode' => $comment_view_mode),
))
->save();
foreach ($entity_manager->getViewModes($entity_type) as $id => $view_mode) {

View file

@ -59,6 +59,12 @@ class CommentTitleTest extends CommentTestBase {
$this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.');
// Tests that markup is created for comment with heading.
$this->assertPattern('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|', 'Comment title is rendered in h3 when title populated.');
// Tests that the comment's title link is the permalink of the comment.
$comment_permalink = $this->cssSelect('.permalink');
$comment_permalink = (string) $comment_permalink[0]['href'];
// Tests that the comment's title link contains the url fragment.
$this->assertTrue(strpos($comment_permalink, '#comment-' . $comment1->id()), "The comment's title link contains the url fragment.");
$this->assertEqual($comment1->permalink()->toString(), $comment_permalink, "The comment's title has the correct link.");
}
}

View file

@ -2,12 +2,16 @@
namespace Drupal\comment\Tests;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\UrlHelper;
use Drupal\comment\Entity\Comment;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\user\Entity\User;
/**
* Generates text using placeholders for dummy content to check comment token
@ -16,6 +20,12 @@ use Drupal\node\Entity\Node;
* @group comment
*/
class CommentTokenReplaceTest extends CommentTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy'];
/**
* Creates a comment, then tests the tokens generated from it.
*/
@ -27,6 +37,12 @@ class CommentTokenReplaceTest extends CommentTestBase {
'language' => $language_interface,
);
// Setup vocabulary.
Vocabulary::create([
'vid' => 'tags',
'name' => 'Tags',
])->save();
// Change the title of the admin user.
$this->adminUser->name->value = 'This is a title with some special & > " stuff.';
$this->adminUser->save();
@ -122,18 +138,43 @@ class CommentTokenReplaceTest extends CommentTestBase {
$input = '[comment:author]';
$output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId()));
$this->assertEqual($output, Html::escape($author_name), format_string('Comment author token %token replaced.', array('%token' => $input)));
// Add comment field to user and term entities.
$this->addDefaultCommentField('user', 'user', 'comment', CommentItemInterface::OPEN, 'comment_user');
$this->addDefaultCommentField('taxonomy_term', 'tags', 'comment', CommentItemInterface::OPEN, 'comment_term');
// Load node so comment_count gets computed.
// Create a user and a comment.
$user = User::create(['name' => 'alice']);
$user->save();
$this->postComment($user, 'user body', 'user subject', TRUE);
// Create a term and a comment.
$term = Term::create([
'vid' => 'tags',
'name' => 'term',
]);
$term->save();
$this->postComment($term, 'term body', 'term subject', TRUE);
// Load node, user and term again so comment_count gets computed.
$node = Node::load($node->id());
$user = User::load($user->id());
$term = Term::load($term->id());
// Generate comment tokens for the node (it has 2 comments, both new).
// Generate comment tokens for node (it has 2 comments, both new),
// user and term.
$tests = array();
$tests['[entity:comment-count]'] = 2;
$tests['[entity:comment-count-new]'] = 2;
$tests['[node:comment-count]'] = 2;
$tests['[node:comment-count-new]'] = 2;
$tests['[user:comment-count]'] = 1;
$tests['[user:comment-count-new]'] = 1;
$tests['[term:comment-count]'] = 1;
$tests['[term:comment-count-new]'] = 1;
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('entity' => $node, 'node' => $node), array('langcode' => $language_interface->getId()));
$this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input)));
$output = $token_service->replace($input, ['entity' => $node, 'node' => $node, 'user' => $user, 'term' => $term], ['langcode' => $language_interface->getId()]);
$this->assertEqual($output, $expected, format_string('Comment token %token replaced.', ['%token' => $input]));
}
}

View file

@ -146,7 +146,10 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
* {@inheritdoc}
*/
protected function doTestAuthoringInfo() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
$values = array();
@ -166,7 +169,8 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
foreach ($this->langcodes as $langcode) {
$metadata = $this->manager->getTranslationMetadata($entity->getTranslation($langcode));
$this->assertEqual($metadata->getAuthor()->id(), $values[$langcode]['uid'], 'Translation author correctly stored.');
@ -195,7 +199,10 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {

View file

@ -0,0 +1,53 @@
<?php
namespace Drupal\comment\Tests\Update;
use Drupal\system\Tests\Update\UpdatePathTestBase;
/**
* Tests that comment settings are properly updated during database updates.
*
* @group comment
*/
class CommentUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.filled.standard.php.gz',
];
}
/**
* Tests comment_update_8200().
*
* @see comment_update_8200()
*/
public function testCommentUpdate8101() {
// Load the 'node.article.default' entity view display config, and check
// that component 'comment' does not contain the 'view_mode' setting.
$config = $this->config('core.entity_view_display.node.article.default');
$this->assertNull($config->get('content.comment.settings.view_mode'));
// Load the 'node.forum.default' entity view display config, and check that
// component 'comment_forum' does not contain the 'view_mode' setting.
$config = $this->config('core.entity_view_display.node.forum.default');
$this->assertNull($config->get('content.comment_forum.settings.view_mode'));
// Run updates.
$this->runUpdates();
// Check that 'node.article.default' entity view display setting 'view_mode'
// has the value 'default'.
$config = $this->config('core.entity_view_display.node.article.default');
$this->assertIdentical($config->get('content.comment.settings.view_mode'), 'default');
// Check that 'node.forum.default' entity view display setting 'view_mode'
// has the value 'default'.
$config = $this->config('core.entity_view_display.node.forum.default');
$this->assertIdentical($config->get('content.comment_forum.settings.view_mode'), 'default');
}
}