Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
|
@ -86,11 +86,7 @@ class CommentCacheTagsTest extends EntityWithUriCacheTagsTestBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAdditionalCacheContextsForEntity(EntityInterface $entity) {
|
||||
return [
|
||||
// Field access for the user picture rendered as part of the node that
|
||||
// this comment is created on.
|
||||
'user.permissions',
|
||||
];
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\comment\Tests;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Session\UserSession;
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\system\Tests\Entity\EntityUnitTestBase;
|
||||
|
@ -69,7 +70,8 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
|
|||
->getViewBuilder('entity_test')
|
||||
->view($commented_entity);
|
||||
$renderer->renderRoot($build);
|
||||
$expected_cache_tags = array(
|
||||
$cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($build['#cache']['contexts'])->getCacheTags();
|
||||
$expected_cache_tags = Cache::mergeTags($cache_context_tags, [
|
||||
'entity_test_view',
|
||||
'entity_test:' . $commented_entity->id(),
|
||||
'comment_list',
|
||||
|
@ -78,9 +80,9 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
|
|||
'config:field.field.entity_test.entity_test.comment',
|
||||
'config:field.storage.comment.comment_body',
|
||||
'config:user.settings',
|
||||
);
|
||||
]);
|
||||
sort($expected_cache_tags);
|
||||
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags before it has comments.');
|
||||
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags);
|
||||
|
||||
// Create a comment on that entity. Comment loading requires that the uid
|
||||
// also exists in the {users} table.
|
||||
|
@ -111,7 +113,8 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
|
|||
->getViewBuilder('entity_test')
|
||||
->view($commented_entity);
|
||||
$renderer->renderRoot($build);
|
||||
$expected_cache_tags = array(
|
||||
$cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($build['#cache']['contexts'])->getCacheTags();
|
||||
$expected_cache_tags = Cache::mergeTags($cache_context_tags, [
|
||||
'entity_test_view',
|
||||
'entity_test:' . $commented_entity->id(),
|
||||
'comment_list',
|
||||
|
@ -125,9 +128,9 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
|
|||
'config:field.field.entity_test.entity_test.comment',
|
||||
'config:field.storage.comment.comment_body',
|
||||
'config:user.settings',
|
||||
);
|
||||
]);
|
||||
sort($expected_cache_tags);
|
||||
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags when it has comments.');
|
||||
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -165,12 +165,12 @@ class CommentFieldsTest extends CommentTestBase {
|
|||
// Install core content type module (book).
|
||||
$edit = array();
|
||||
$edit['modules[Core][book][enable]'] = 'book';
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Install'));
|
||||
|
||||
// Now install the comment module.
|
||||
$edit = array();
|
||||
$edit['modules[Core][comment][enable]'] = 'comment';
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Install'));
|
||||
$this->rebuildContainer();
|
||||
$this->assertTrue($this->container->get('module_handler')->moduleExists('comment'), 'Comment module enabled.');
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ class CommentNonNodeTest extends WebTestBase {
|
|||
* @param bool $reply
|
||||
* Boolean indicating whether the comment is a reply to another comment.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* Boolean indicating whether the comment was found.
|
||||
*/
|
||||
function commentExists(CommentInterface $comment = NULL, $reply = FALSE) {
|
||||
|
@ -201,7 +201,7 @@ class CommentNonNodeTest extends WebTestBase {
|
|||
/**
|
||||
* Checks whether the commenter's contact information is displayed.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* Contact info is available.
|
||||
*/
|
||||
function commentContactInfoAvailable() {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\comment\Tests;
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
|
@ -52,16 +53,23 @@ class CommentRssTest extends CommentTestBase {
|
|||
$this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
|
||||
$this->drupalGet('rss.xml');
|
||||
|
||||
$this->assertCacheTags([
|
||||
'config:views.view.frontpage', 'node:1', 'node_list', 'node_view', 'user:3',
|
||||
]);
|
||||
$this->assertCacheContexts([
|
||||
$cache_contexts = [
|
||||
'languages:language_interface',
|
||||
'theme',
|
||||
'url.site',
|
||||
'user.node_grants:view',
|
||||
'user.permissions',
|
||||
'timezone',
|
||||
]);
|
||||
];
|
||||
$this->assertCacheContexts($cache_contexts);
|
||||
|
||||
$cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)->getCacheTags();
|
||||
$this->assertCacheTags(Cache::mergeTags($cache_context_tags, [
|
||||
'config:views.view.frontpage',
|
||||
'node:1', 'node_list',
|
||||
'node_view',
|
||||
'user:3',
|
||||
]));
|
||||
|
||||
$raw = '<comments>' . $this->node->url('canonical', array('fragment' => 'comments', 'absolute' => TRUE)) . '</comments>';
|
||||
$this->assertRaw($raw, 'Comments as part of RSS feed.');
|
||||
|
|
|
@ -182,7 +182,7 @@ abstract class CommentTestBase extends WebTestBase {
|
|||
* @param bool $reply
|
||||
* Boolean indicating whether the comment is a reply to another comment.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* Boolean indicating whether the comment was found.
|
||||
*/
|
||||
function commentExists(CommentInterface $comment = NULL, $reply = FALSE) {
|
||||
|
@ -323,7 +323,7 @@ abstract class CommentTestBase extends WebTestBase {
|
|||
/**
|
||||
* Checks whether the commenter's contact information is displayed.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* Contact info is available.
|
||||
*/
|
||||
function commentContactInfoAvailable() {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Drupal\comment\Tests;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
|
||||
|
@ -42,10 +41,7 @@ trait CommentTestTrait {
|
|||
$comment_type_storage = $entity_manager->getStorage('comment_type');
|
||||
if ($comment_type = $comment_type_storage->load($comment_type_id)) {
|
||||
if ($comment_type->getTargetEntityTypeId() !== $entity_type) {
|
||||
throw new \InvalidArgumentException(SafeMarkup::format('The given comment type id %id can only be used with the %entity_type entity type', array(
|
||||
'%id' => $comment_type_id,
|
||||
'%entity_type' => $entity_type,
|
||||
)));
|
||||
throw new \InvalidArgumentException("The given comment type id $comment_type_id can only be used with the $entity_type entity type");
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Drupal\comment\Tests;
|
|||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
|
@ -60,6 +61,7 @@ class CommentTokenReplaceTest extends CommentTestBase {
|
|||
$tests['[comment:langcode]'] = SafeMarkup::checkPlain($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;
|
||||
|
@ -71,12 +73,48 @@ class CommentTokenReplaceTest extends CommentTestBase {
|
|||
$tests['[comment:author:uid]'] = $comment->getOwnerId();
|
||||
$tests['[comment:author:name]'] = SafeMarkup::checkPlain($this->adminUser->getUsername());
|
||||
|
||||
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($comment);
|
||||
$metadata_tests = [];
|
||||
$metadata_tests['[comment:cid]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:hostname]'] = $base_bubbleable_metadata;
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$bubbleable_metadata->addCacheableDependency($this->adminUser);
|
||||
$metadata_tests['[comment:author]'] = $bubbleable_metadata;
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$bubbleable_metadata->addCacheableDependency($this->adminUser);
|
||||
$metadata_tests['[comment:mail]'] = $bubbleable_metadata;
|
||||
$metadata_tests['[comment:homepage]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:title]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:body]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:langcode]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:url]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:edit-url]'] = $base_bubbleable_metadata;
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:created]'] = $bubbleable_metadata->addCacheTags(['rendered']);
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:created:since]'] = $bubbleable_metadata->setCacheMaxAge(0);
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:changed:since]'] = $bubbleable_metadata->setCacheMaxAge(0);
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:parent:cid]'] = $bubbleable_metadata->addCacheTags(['comment:1']);
|
||||
$metadata_tests['[comment:parent:title]'] = $bubbleable_metadata;
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:entity]'] = $bubbleable_metadata->addCacheTags(['node:2']);
|
||||
// Test node specific tokens.
|
||||
$metadata_tests['[comment:entity:nid]'] = $bubbleable_metadata;
|
||||
$metadata_tests['[comment:entity:title]'] = $bubbleable_metadata;
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$metadata_tests['[comment:author:uid]'] = $bubbleable_metadata->addCacheTags(['user:2']);
|
||||
$metadata_tests['[comment:author:name]'] = $bubbleable_metadata;
|
||||
|
||||
// Test to make sure that we generated something for each token.
|
||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId()));
|
||||
$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($bubbleable_metadata, $metadata_tests[$input]);
|
||||
}
|
||||
|
||||
// Generate and test unsanitized tokens.
|
||||
|
|
|
@ -32,6 +32,18 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
|
|||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {inheritdoc}
|
||||
*/
|
||||
protected $defaultCacheContexts = [
|
||||
'languages:language_interface',
|
||||
'theme',
|
||||
'user.permissions',
|
||||
'timezone',
|
||||
'url.query_args.pagers:0',
|
||||
'user.roles'
|
||||
];
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\comment\Tests\Views;
|
||||
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\Core\Render\RenderContext;
|
||||
use Drupal\Core\Session\AnonymousUserSession;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\views\Views;
|
||||
|
@ -58,6 +59,8 @@ class CommentFieldNameTest extends CommentTestBase {
|
|||
* Test comment field name.
|
||||
*/
|
||||
public function testCommentFieldName() {
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = \Drupal::service('renderer');
|
||||
$view = Views::getView('test_comment_field_name');
|
||||
$this->executeView($view);
|
||||
|
||||
|
@ -85,8 +88,14 @@ class CommentFieldNameTest extends CommentTestBase {
|
|||
$view = Views::getView('test_comment_field_name');
|
||||
$this->executeView($view);
|
||||
// Test that data rendered.
|
||||
$this->assertIdentical($this->comment->getFieldName(), $view->field['field_name']->advancedRender($view->result[0]));
|
||||
$this->assertIdentical($this->customComment->getFieldName(), $view->field['field_name']->advancedRender($view->result[1]));
|
||||
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
|
||||
return $view->field['field_name']->advancedRender($view->result[0]);
|
||||
});
|
||||
$this->assertIdentical($this->comment->getFieldName(), $output);
|
||||
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
|
||||
return $view->field['field_name']->advancedRender($view->result[1]);
|
||||
});
|
||||
$this->assertIdentical($this->customComment->getFieldName(), $output);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue