Commit f31fbaa2 authored by webchick's avatar webchick

Issue #2111163 by larowlan, geerlingguy: Fixed Can't Preview comments: Call to...

Issue #2111163 by larowlan, geerlingguy: Fixed Can't Preview comments: Call to a member function id() on a non-object in comment.module, line 1371.
parent 0f8b4e79
......@@ -1368,11 +1368,11 @@ function comment_preview(CommentInterface $comment) {
$account = $user;
}
if ($account->id()) {
if (!empty($account) && $account->isAuthenticated()) {
$comment->uid->target_id = $account->id();
$comment->name->value = check_plain($account->getUsername());
}
elseif (empty($comment->name->value)) {
else {
$comment->name->value = \Drupal::config('user.settings')->get('anonymous');
}
......
......@@ -52,7 +52,15 @@ function testCommentInterface() {
$comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
$this->assertTrue($this->commentExists($comment), 'Comment found.');
// Comment as anonymous with preview required.
$this->drupalLogout();
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments', 'post comments', 'skip comment approval'));
$anonymous_comment = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE);
$this->assertTrue($this->commentExists($anonymous_comment), 'Comment found.');
$anonymous_comment->delete();
// Check comment display.
$this->drupalLogin($this->web_user);
$this->drupalGet('node/' . $this->node->id());
$this->assertText($subject_text, 'Individual comment subject found.');
$this->assertText($comment_text, 'Individual comment body found.');
......
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