Commit 669b898b authored by catch's avatar catch

Issue #2227465 by gremy, rbmboogie: comment_user_cancel() uses COMMENT_NOT_PUBLISHED.

parent 766586b8
......@@ -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;
......
......@@ -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.");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment