diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index e35350123845555318be6f9484ffb4690c427e3d..d9d86d41553c547edb24f855261e02b2aa22da26 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1001,7 +1001,7 @@ function comment_user_cancel($edit, $account, $method) { case 'user_cancel_block_unpublish': $comments = entity_load_multiple_by_properties('comment', array('uid' => $account->id())); foreach ($comments as $comment) { - $comment->setPublished(COMMENT_NOT_PUBLISHED); + $comment->setPublished(CommentInterface::NOT_PUBLISHED); $comment->save(); } break; diff --git a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php index cc8f6525dba88afb15ff73c7db678b6fa257a42e..edd4ea1010523efbb4b4578c1b89a47104ceaf46 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php @@ -8,6 +8,7 @@ namespace Drupal\user\Tests; use Drupal\simpletest\WebTestBase; +use Drupal\comment\CommentInterface; /** * Test cancelling a user. @@ -19,7 +20,7 @@ class UserCancelTest extends WebTestBase { * * @var array */ - public static $modules = array('node'); + public static $modules = array('node', 'comment'); public static function getInfo() { return array( @@ -187,6 +188,8 @@ function testUserBlock() { */ function testUserBlockUnpublish() { \Drupal::config('user.settings')->set('cancel_method', 'user_cancel_block_unpublish')->save(); + // Create comment field on page. + \Drupal::service('comment.manager')->addDefaultField('node', 'page'); // Create a user. $account = $this->drupalCreateUser(array('cancel account')); @@ -200,6 +203,20 @@ function testUserBlockUnpublish() { $settings['revision'] = 1; $node = $this->drupalCreateNode($settings); + // Add a comment to the page. + $comment_subject = $this->randomName(8); + $comment_body = $this->randomName(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(); + // Attempt to cancel account. $this->drupalGet('user/' . $account->id() . '/edit'); $this->drupalPostForm(NULL, NULL, t('Cancel account')); @@ -222,6 +239,11 @@ function testUserBlockUnpublish() { $test_node = node_revision_load($node->getRevisionId()); $this->assertFalse($test_node->isPublished(), 'Node revision of the user has been unpublished.'); + $storage = \Drupal::entityManager()->getStorage('comment'); + $storage->resetCache(array($comment->id())); + $comment = $storage->load($comment->id()); + $this->assertFalse($comment->isPublished(), 'Comment of the user has been unpublished.'); + // Confirm that the confirmation message made it through to the end user. $this->assertRaw(t('%name has been disabled.', array('%name' => $account->getUsername())), "Confirmation message displayed to user."); }