update drupal

This commit is contained in:
Tessier
2020-10-15 11:59:37 +02:00
parent ebb5db14b5
commit d8b9162932
558 changed files with 5954 additions and 4475 deletions
@@ -0,0 +1,8 @@
name: 'Comment base field test'
type: module
description: 'Test comment as a base field'
package: Testing
version: VERSION
dependencies:
- drupal:comment
- drupal:entity_test
@@ -0,0 +1,6 @@
langcode: en
status: true
id: test_comment_type
label: Test comment type
target_entity_type_id: comment_test_base_field
description: 'Test comment type.'
@@ -0,0 +1,39 @@
<?php
namespace Drupal\comment_base_field_test\Entity;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\entity_test\Entity\EntityTest;
/**
* Defines a test entity class for comment as a base field.
*
* @ContentEntityType(
* id = "comment_test_base_field",
* label = @Translation("Test comment - base field"),
* base_table = "comment_test_base_field",
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type"
* },
* )
*/
class CommentTestBaseField extends EntityTest {
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['test_comment'] = BaseFieldDefinition::create('comment')
->setLabel(t('A comment field'))
->setSetting('comment_type', 'test_comment_type')
->setDefaultValue([
'status' => CommentItemInterface::OPEN,
]);
return $fields;
}
}
@@ -0,0 +1,244 @@
langcode: en
status: true
dependencies:
module:
- node
- user
id: test_comment_count
label: 'test comment count'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: mini
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ‹‹
next: ››
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
fields:
title:
id: title
table: node_field_data
field: title
entity_type: node
entity_field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
settings:
link_to_entity: true
plugin_id: field
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
click_sort_column: value
type: string
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
comment_count:
id: comment_count
table: comment_entity_statistics
field: comment_count
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
set_precision: false
precision: 0
decimal: .
separator: ''
format_plural: false
format_plural_string: !!binary MQNAY291bnQ=
prefix: ''
suffix: ''
plugin_id: numeric
filters:
status:
value: '1'
table: node_field_data
field: status
plugin_id: boolean
entity_type: node
entity_field: status
id: status
expose:
operator: ''
operator_limit_selection: false
operator_list: { }
group: 1
sorts:
created:
id: created
table: node_field_data
field: created
order: DESC
entity_type: node
entity_field: created
plugin_id: date
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
granularity: second
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
- user.permissions
tags: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: test-comment-count
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
- user.permissions
tags: { }
@@ -188,7 +188,8 @@ class CommentAnonymousTest extends CommentTestBase {
'skip comment approval' => FALSE,
]);
$this->drupalGet('node/' . $this->node->id());
$this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments were displayed.');
// Verify that the comment field title is displayed.
$this->assertPattern('@<h2[^>]*>Comments</h2>@');
$this->assertSession()->linkExists('Log in', 1, 'Link to login was found.');
$this->assertSession()->linkExists('register', 1, 'Link to register was found.');
@@ -55,7 +55,7 @@ class CommentInterfaceTest extends CommentTestBase {
// Test the comment field title is displayed when there's comments.
$this->drupalGet($this->node->toUrl());
$this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments title is displayed.');
$this->assertPattern('@<h2[^>]*>Comments</h2>@');
// Set comments to have subject and preview to required.
$this->drupalLogout();
@@ -370,7 +370,8 @@ class CommentNonNodeTest extends BrowserTestBase {
'skip comment approval' => FALSE,
]);
$this->drupalGet('entity_test/' . $this->entity->id());
$this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments were displayed.');
// Verify that the comment field title is displayed.
$this->assertPattern('@<h2[^>]*>Comments</h2>@');
$this->assertSession()->linkExists('Log in', 0, 'Link to login was found.');
$this->assertSession()->linkExists('register', 0, 'Link to register was found.');
$this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
@@ -429,7 +429,6 @@ class CommentPagerTest extends CommentTestBase {
$urls = $this->xpath($xpath, $arguments);
if (isset($urls[$index])) {
$url_target = $this->getAbsoluteUrl($urls[$index]->getAttribute('href'));
$this->pass(new FormattableMarkup('Clicked link %label (@url_target) from @url_before', ['%label' => $xpath, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser');
return $this->drupalGet($url_target);
}
$this->fail(new FormattableMarkup('Link %label does not exist on @url_before', ['%label' => $xpath, '@url_before' => $url_before]), 'Browser');
@@ -45,7 +45,8 @@ class CommentTitleTest extends CommentTestBase {
$regex = '/<article(.*?)id="comment-' . $comment->id() . '"(.*?)';
$regex .= $comment->comment_body->value . '(.*?)';
$regex .= '/s';
$this->assertPattern($regex, 'Comment is created successfully');
// Verify that the comment is created successfully.
$this->assertPattern($regex);
// Tests that markup is not generated for the comment without header.
$this->assertSession()->responseNotMatches('|<h3[^>]*></h3>|', 'Comment title H3 element not found when title is an empty string.');
}
@@ -76,7 +77,7 @@ class CommentTitleTest extends CommentTestBase {
// Confirm that the comment was created.
$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.');
$this->assertPattern('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|');
// Tests that the comment's title link is the permalink of the comment.
$comment_permalink = $this->cssSelect('.permalink');
$comment_permalink = $comment_permalink[0]->getAttribute('href');
@@ -186,7 +186,7 @@ class CommentTypeTest extends CommentTestBase {
$this->fail('Exception not thrown.');
}
catch (\InvalidArgumentException $e) {
$this->pass('Exception thrown if attempting to re-use comment-type from another entity type.');
// Expected exception; just continue testing.
}
// Delete the comment type.
@@ -26,7 +26,7 @@ class NodeCommentsTest extends CommentTestBase {
*
* @var array
*/
public static $testViews = ['test_new_comments'];
public static $testViews = ['test_new_comments', 'test_comment_count'];
/**
* Test the new comments field plugin.
@@ -38,4 +38,30 @@ class NodeCommentsTest extends CommentTestBase {
$this->assertCount(1, $new_comments, 'Found the number of new comments for a certain node.');
}
/**
* Test the comment count field.
*/
public function testCommentCount() {
$this->drupalGet('test-comment-count');
$this->assertSession()->statusCodeEquals(200);
$this->assertCount(2, $this->cssSelect('.views-row'));
$comment_count_with_comment = $this->cssSelect(".views-field-comment-count span:contains('1')");
$this->assertCount(1, $comment_count_with_comment);
$comment_count_without_comment = $this->cssSelect(".views-field-comment-count span:contains('0')");
$this->assertCount(1, $comment_count_without_comment);
// Create a content type with no comment field, and add a node.
$this->drupalCreateContentType(['type' => 'no_comment', 'name' => t('No comment page')]);
$this->nodeUserPosted = $this->drupalCreateNode(['type' => 'no_comment']);
$this->drupalGet('test-comment-count');
// Test that the node with no comment field is also shown.
$this->assertSession()->statusCodeEquals(200);
$this->assertCount(3, $this->cssSelect('.views-row'));
$comment_count_with_comment = $this->cssSelect(".views-field-comment-count span:contains('1')");
$this->assertCount(1, $comment_count_with_comment);
$comment_count_without_comment = $this->cssSelect(".views-field-comment-count span:contains('0')");
$this->assertCount(2, $comment_count_without_comment);
}
}
@@ -0,0 +1,64 @@
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment_base_field_test\Entity\CommentTestBaseField;
use Drupal\Core\Language\LanguageInterface;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests that comment as a base field.
*
* @group comment
*/
class CommentBaseFieldTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'system',
'user',
'comment',
'comment_base_field_test',
];
protected function setUp() {
parent::setUp();
$this->installEntitySchema('comment_test_base_field');
$this->installEntitySchema('comment');
$this->installSchema('system', ['sequences']);
$this->installEntitySchema('user');
}
/**
* Tests comment as a base field.
*/
public function testCommentBaseField() {
// Verify entity creation.
$entity = CommentTestBaseField::create([
'name' => $this->randomMachineName(),
'test_comment' => CommentItemInterface::OPEN,
]);
$entity->save();
$comment = Comment::create([
'entity_id' => $entity->id(),
'entity_type' => 'comment_test_base_field',
'field_name' => 'test_comment',
'pid' => 0,
'uid' => 0,
'status' => CommentInterface::PUBLISHED,
'subject' => $this->randomMachineName(),
'hostname' => '127.0.0.1',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'comment_body' => [['value' => $this->randomMachineName()]],
]);
$comment->save();
$this->assertEquals('test_comment_type', $comment->bundle());
}
}
@@ -0,0 +1,134 @@
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\Tests\EntityViewTrait;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests loading and rendering orphan comments.
*
* @group comment
*/
class CommentOrphanTest extends EntityKernelTestBase {
use EntityViewTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('date_format');
$this->installEntitySchema('comment');
$this->installSchema('comment', ['comment_entity_statistics']);
}
/**
* Test loading/deleting/rendering orphaned comments.
*
* @dataProvider providerTestOrphan
*/
public function testOrphan($property) {
DateFormat::create([
'id' => 'fallback',
'label' => 'Fallback',
'pattern' => 'Y-m-d',
])->save();
$comment_storage = $this->entityTypeManager->getStorage('comment');
$node_storage = $this->entityTypeManager->getStorage('node');
// Create a page node type.
$this->entityTypeManager->getStorage('node_type')->create([
'type' => 'page',
'name' => 'page',
])->save();
$node = $node_storage->create([
'type' => 'page',
'title' => 'test',
]);
$node->save();
// Create comment field.
$this->entityTypeManager->getStorage('field_storage_config')->create([
'type' => 'text_long',
'entity_type' => 'node',
'field_name' => 'comment',
])->save();
// Add comment field to page content.
$this->entityTypeManager->getStorage('field_config')->create([
'field_storage' => FieldStorageConfig::loadByName('node', 'comment'),
'entity_type' => 'node',
'bundle' => 'page',
'label' => 'Comment',
])->save();
// Make two comments
$comment1 = $comment_storage->create([
'field_name' => 'comment',
'comment_body' => 'test',
'entity_id' => $node->id(),
'entity_type' => 'node',
'comment_type' => 'default',
])->save();
$comment_storage->create([
'field_name' => 'comment',
'comment_body' => 'test',
'entity_id' => $node->id(),
'entity_type' => 'node',
'comment_type' => 'default',
'pid' => $comment1,
])->save();
// Render the comments.
$renderer = \Drupal::service('renderer');
$comments = $comment_storage->loadMultiple();
foreach ($comments as $comment) {
$built = $this->buildEntityView($comment, 'full', NULL);
$renderer->renderPlain($built);
}
// Make comment 2 an orphan by setting the property to an invalid value.
\Drupal::database()->update('comment_field_data')
->fields([$property => 10])
->condition('cid', 2)
->execute();
$comment_storage->resetCache();
$node_storage->resetCache();
// Render the comments with an orphan comment.
$comments = $comment_storage->loadMultiple();
foreach ($comments as $comment) {
$built = $this->buildEntityView($comment, 'full', NULL);
$renderer->renderPlain($built);
}
$node = $node_storage->load($node->id());
$built = $this->buildEntityView($node, 'full', NULL);
$renderer->renderPlain($built);
}
/**
* Provides test data for testOrphan.
*/
public function providerTestOrphan() {
return [
['entity_id'],
['uid'],
['pid'],
];
}
}
@@ -40,28 +40,23 @@ class CommentStringIdEntitiesTest extends KernelTestBase {
* Tests that comment fields cannot be added entities with non-integer IDs.
*/
public function testCommentFieldNonStringId() {
try {
$bundle = CommentType::create([
'id' => 'foo',
'label' => 'foo',
'description' => '',
'target_entity_type_id' => 'entity_test_string_id',
]);
$bundle->save();
$field_storage = FieldStorageConfig::create([
'field_name' => 'foo',
'entity_type' => 'entity_test_string_id',
'settings' => [
'comment_type' => 'entity_test_string_id',
],
'type' => 'comment',
]);
$field_storage->save();
$this->fail('Did not throw an exception as expected.');
}
catch (\UnexpectedValueException $e) {
$this->pass('Exception thrown when trying to create comment field on Entity Type with string ID.');
}
$this->expectException(\UnexpectedValueException::class);
$bundle = CommentType::create([
'id' => 'foo',
'label' => 'foo',
'description' => '',
'target_entity_type_id' => 'entity_test_string_id',
]);
$bundle->save();
$field_storage = FieldStorageConfig::create([
'field_name' => 'foo',
'entity_type' => 'entity_test_string_id',
'settings' => [
'comment_type' => 'entity_test_string_id',
],
'type' => 'comment',
]);
$field_storage->save();
}
}
@@ -77,6 +77,7 @@ class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
$this->assertEntity('book', 'comment_node_book', 2, 1, 50, 0, TRUE, 1);
$this->assertEntity('forum', 'comment_forum', 2, 1, 50, 0, TRUE, 1);
$this->assertEntity('test_content_type', 'comment_node_test_content_type', 2, 1, 30, 0, TRUE, 1);
$this->assertEntity('et', 'comment_node_et', 2, 1, 50, 0, FALSE, 1);
}
}
@@ -51,6 +51,7 @@ class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
$this->assertEntity('comment_node_book');
$this->assertEntity('comment_forum');
$this->assertEntity('comment_node_test_content_type');
$this->assertEntity('comment_node_et');
}
}