summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2015-04-19 18:41:59 (GMT)
committerxjm2015-04-19 18:41:59 (GMT)
commit0a1a3d8b98de0673062f0fcc461955dfda79833c (patch)
tree85f030266306a850dc45f3191411eac354896b06
parent310313ac38b8c3fd8ccde6d8bf27b72ea43db012 (diff)
Issue #2472043 by drumm, jcnventura: Canceling a user account, assigning content to Anonymous, should clear the comment name
-rw-r--r--core/modules/comment/comment.module1
-rw-r--r--core/modules/user/src/Tests/UserCancelTest.php24
2 files changed, 25 insertions, 0 deletions
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 035461f..debc2d3 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -499,6 +499,7 @@ function comment_user_cancel($edit, $account, $method) {
$comments = entity_load_multiple_by_properties('comment', array('uid' => $account->id()));
foreach ($comments as $comment) {
$comment->setOwnerId(0);
+ $comment->setAuthorName(\Drupal::config('user.settings')->get('anonymous'));
$comment->save();
}
break;
diff --git a/core/modules/user/src/Tests/UserCancelTest.php b/core/modules/user/src/Tests/UserCancelTest.php
index 1b92887..92e7ce0 100644
--- a/core/modules/user/src/Tests/UserCancelTest.php
+++ b/core/modules/user/src/Tests/UserCancelTest.php
@@ -11,6 +11,7 @@ use Drupal\comment\Tests\CommentTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
+use Drupal\user\Entity\User;
/**
* Ensure that account cancellation methods work as expected.
@@ -281,6 +282,8 @@ class UserCancelTest extends WebTestBase {
function testUserAnonymize() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
+ // Create comment field on page.
+ $this->addDefaultCommentField('node', 'page');
// Create a user.
$account = $this->drupalCreateUser(array('cancel account'));
@@ -291,6 +294,20 @@ class UserCancelTest extends WebTestBase {
// Create a simple node.
$node = $this->drupalCreateNode(array('uid' => $account->id()));
+ // Add a comment to the page.
+ $comment_subject = $this->randomMachineName(8);
+ $comment_body = $this->randomMachineName(8);
+ $comment = entity_create('comment', array(
+ 'subject' => $comment_subject,
+ 'comment_body' => $comment_body,
+ 'entity_id' => $node->id(),
+ 'entity_type' => 'node',
+ 'field_name' => 'comment',
+ 'status' => CommentInterface::PUBLISHED,
+ 'uid' => $account->id(),
+ ));
+ $comment->save();
+
// Create a node with two revisions, the initial one belonging to the
// cancelling user.
$revision_node = $this->drupalCreateNode(array('uid' => $account->id()));
@@ -316,6 +333,7 @@ class UserCancelTest extends WebTestBase {
$this->assertFalse(user_load($account->id(), TRUE), 'User is not found in the database.');
// Confirm that user's content has been attributed to anonymous user.
+ $anonymous_user = User::getAnonymousUser();
$node_storage->resetCache(array($node->id()));
$test_node = $node_storage->load($node->id());
$this->assertTrue(($test_node->getOwnerId() == 0 && $test_node->isPublished()), 'Node of the user has been attributed to anonymous user.');
@@ -325,6 +343,12 @@ class UserCancelTest extends WebTestBase {
$test_node = $node_storage->load($revision_node->id());
$this->assertTrue(($test_node->getOwnerId() != 0 && $test_node->isPublished()), "Current revision of the user's node was not attributed to anonymous user.");
+ $storage = \Drupal::entityManager()->getStorage('comment');
+ $storage->resetCache(array($comment->id()));
+ $test_comment = $storage->load($comment->id());
+ $this->assertTrue(($test_comment->getOwnerId() == 0 && $test_comment->isPublished()), 'Comment of the user has been attributed to anonymous user.');
+ $this->assertEqual($test_comment->getAuthorName(), $anonymous_user->getUsername(), 'Comment of the user has been attributed to anonymous user name.');
+
// Confirm that the confirmation message made it through to the end user.
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
}